def test_normalize_name(self):
        normalized = SatSolverFactory.normalize_name("minisat")
        self.assertEquals(normalized, "MiniSat")

        normalized = SatSolverFactory.normalize_name("MINISAT")
        self.assertEquals(normalized, "MiniSat")

        normalized = SatSolverFactory.normalize_name("mInIsAt")
        self.assertEquals(normalized, "MiniSat")

        normalized = SatSolverFactory.normalize_name("MiniSat")
        self.assertEquals(normalized, "MiniSat")

        normalized = SatSolverFactory.normalize_name("zchaff")
        self.assertEquals(normalized, "ZChaff")

        normalized = SatSolverFactory.normalize_name("ZCHAFF")
        self.assertEquals(normalized, "ZChaff")

        normalized = SatSolverFactory.normalize_name("ZcHaFf")
        self.assertEquals(normalized, "ZChaff")

        normalized = SatSolverFactory.normalize_name("ZChaff")
        self.assertEquals(normalized, "ZChaff")

        with self.assertRaises(ValueError):
            SatSolverFactory.normalize_name("bonjour")
    def test_generate_sat_problem(self):
        theta = Node.from_ptr(parse_simple_expression("TRUE"))
        theta = bmcutils.make_nnf_boolean_wff(theta)

        sigma_12 = Node.from_ptr(parse_ltl_spec("TRUE"))
        sigma_12 = bmcutils.make_nnf_boolean_wff(sigma_12).to_node()

        observable = diagnosability.mk_observable_vars(["mouse"])
        f1 = Node.from_ptr(parse_simple_expression("status = active"))
        f2 = Node.from_ptr(parse_simple_expression("status = inactive"))

        for i in range(5):
            problem = diagnosability.generate_sat_problem(
                observable, (f1, f2), i, theta, sigma_12, sigma_12)
            solver = SatSolverFactory.create()
            cnf = problem.to_cnf()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())

        f1 = Node.from_ptr(parse_simple_expression("status = active"))
        f2 = Node.from_ptr(parse_simple_expression("status = highlight"))

        for i in range(1, 4):
            # length zero has no input => only an initial state and the
            # diagnosability condition is not checked
            problem = diagnosability.generate_sat_problem(
                observable, (f1, f2), i, theta, sigma_12, sigma_12)
            solver = SatSolverFactory.create()
            cnf = problem.to_cnf()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())
Beispiel #3
0
    def test_normalize_name(self):
        normalized = SatSolverFactory.normalize_name("minisat")
        self.assertEquals(normalized, 'MiniSat')

        normalized = SatSolverFactory.normalize_name("MINISAT")
        self.assertEquals(normalized, 'MiniSat')

        normalized = SatSolverFactory.normalize_name("mInIsAt")
        self.assertEquals(normalized, 'MiniSat')

        normalized = SatSolverFactory.normalize_name("MiniSat")
        self.assertEquals(normalized, 'MiniSat')

        if self.zchaff:
            normalized = SatSolverFactory.normalize_name("zchaff")
            self.assertEquals(normalized, 'ZChaff')

            normalized = SatSolverFactory.normalize_name("ZCHAFF")
            self.assertEquals(normalized, 'ZChaff')

            normalized = SatSolverFactory.normalize_name("ZcHaFf")
            self.assertEquals(normalized, 'ZChaff')

            normalized = SatSolverFactory.normalize_name("ZChaff")
            self.assertEquals(normalized, 'ZChaff')

        with self.assertRaises(ValueError):
            SatSolverFactory.normalize_name("bonjour")
Beispiel #4
0
 def test_generate_sat_problem(self):
     theta = Node.from_ptr(parse_simple_expression("TRUE"))
     theta = bmcutils.make_nnf_boolean_wff(theta)
     
     sigma_12= Node.from_ptr(parse_ltl_spec("TRUE"))
     sigma_12= bmcutils.make_nnf_boolean_wff(sigma_12).to_node()
     
     observable = diagnosability.mk_observable_vars(["mouse"])
     f1 = Node.from_ptr(parse_simple_expression("status = active"))
     f2 = Node.from_ptr(parse_simple_expression("status = inactive"))
      
     for i in range(5):
         problem = diagnosability.generate_sat_problem(observable, (f1, f2), i, theta, sigma_12, sigma_12)
         solver  = SatSolverFactory.create()
         cnf     = problem.to_cnf()
         solver += cnf
         solver.polarity(cnf, Polarity.POSITIVE)
         self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())
          
     f1 = Node.from_ptr(parse_simple_expression("status = active"))
     f2 = Node.from_ptr(parse_simple_expression("status = highlight"))
      
     for i in range(1, 4): 
         # length zero has no input => only an initial state and the 
         # diagnosability condition is not checked
         problem = diagnosability.generate_sat_problem(observable, (f1, f2), i, theta, sigma_12, sigma_12)
         solver  = SatSolverFactory.create()
         cnf     = problem.to_cnf()
         solver += cnf
         solver.polarity(cnf, Polarity.POSITIVE)
         self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())
Beispiel #5
0
    def test_concat(self):
        with BmcSupport():
            sexp_fsm = master_bool_sexp_fsm()
            be_fsm = master_be_fsm()

            trace = Trace.create("Dummy example",
                                 TraceType.COUNTER_EXAMPLE,
                                 sexp_fsm.symbol_table,
                                 sexp_fsm.symbols_list,
                                 is_volatile=True)

            spec = Node.from_ptr(parse_ltl_spec("F (w <-> v)"))
            bound = 2
            problem = generate_ltl_problem(be_fsm, spec,
                                           bound=bound)  #.inline(True)
            cnf = problem.to_cnf()
            solver = SatSolverFactory.create()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            solver.solve()

            other = generate_counter_example(be_fsm, problem, solver, bound)

            trace.concat(other)

            self.assertEquals(-1, trace.id)
            self.assertFalse(trace.is_registered)
            self.assertEquals("Dummy example", trace.description)
            self.assertEquals(TraceType.COUNTER_EXAMPLE, trace.type)
            self.assertTrue(trace.is_volatile)
            self.assertEquals(2, trace.length)
            self.assertEquals(2, len(trace))
            self.assertFalse(trace.is_empty)
            self.assertFalse(trace.is_frozen)
            self.assertTrue(trace.is_thawed)
    def test_decode_sat_model(self):
        """
        Tests the behavior of BeEnc.decode_sat_model which may be used to build
        counter examples for complex logics
        """
        with Configure(self, __file__, "/models/multibit.smv"):
            b0 = self.enc.by_name["two_bits.0"]
            b1 = self.enc.by_name["two_bits.1"]

            # Dummy expression satisfied iff Ko at time 0 and Ok at time 1
            expr= b0.at_time[0].boolean_expression  &\
                  b1.at_time[0].boolean_expression  &\
                  -b0.at_time[1].boolean_expression &\
                  -b1.at_time[1].boolean_expression

            cnf = expr.to_cnf()
            solver = SatSolverFactory.create()
            solver += cnf
            # this is not required though
            solver.polarity(cnf, polarity=Polarity.POSITIVE)
            solver.solve()

            decoded = self.enc.decode_sat_model(solver.model)
            # it's true iff all bits are on, that is to day Ko at both times
            expect = "{0: {'two_bits': Ko}, 1: {'two_bits': Ok}}"

            self.assertEqual("{'two_bits': Ko}", str(decoded[0]))
            self.assertEqual("{'two_bits': Ok}", str(decoded[1]))
def verify_for_size_exactly_k(observable_names, observable_vars, formula_nodes, k, theta, sigma1, sigma2):
    """
    Performs the verification of the diagnosability problem for `formula_node`
    when a maximum of `k` execution steps are allowed.

    :param observable_vars: the list of the boolean variables that are considered
        visible in the scope of this diagnosability test
    :param formula: the node (NuSMV ast representation) representing the formula
        whose diagnosability is under verification
    :param k: the maximum length of the generated traces.
    :param theta: the initial condition placed on the initial belief state
        (in the form of a :see:`pynusmv.node.Node`)
    :param sigma1: the shape of the traces considered relevant for the first
        member of the critical pair in the ongoing diagnosability test
        (in the form of a :see:`pynusmv.node.Node`)
    :param sigma2: the shape of the traces considered relevant for the second
        member of the critical pair in the ongoing diagnosability test
        (in the form of a :see:`pynusmv.node.Node`)
    :return: the text 'No Violation' if no counter example could be found,
        and a counter example when one could be identified.
    """
    problem = generate_sat_problem(observable_vars, formula_nodes, k, theta, sigma1, sigma2)
    problem_= problem.inline(True)  # remove potentially redundant information
    cnf     = problem_.to_cnf()

    solver  = SatSolverFactory.create()
    solver += cnf
    solver.polarity(cnf, Polarity.POSITIVE)

    if solver.solve() == SatSolverResult.SATISFIABLE:
        return diagnosability_violation(observable_names, solver, k)
    else:
        return "No Violation"
Beispiel #8
0
    def test_create_minisat(self):
        solver = SatSolverFactory.create('minisat', True, True)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatIncProofSolver)

        solver = SatSolverFactory.create('minisat', True, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatIncSolver)

        solver = SatSolverFactory.create('minisat', False, True)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatProofSolver)

        solver = SatSolverFactory.create('minisat', False, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatSolver)
Beispiel #9
0
    def test_group_features(self):
        solver = SatSolverFactory.create("MiniSat", incremental=True)
        var = self.fsm.encoding.by_name["v"].boolean_expression
        clause = var.to_cnf()
        nclause = (-var).to_cnf()

        # TEST create group
        group = solver.create_group()

        # TEST add to group
        solver.add_to_group(clause, group)
        solver.polarity(clause, Polarity.POSITIVE, group)
        solver.add_to_group(nclause, group)
        solver.polarity(nclause, group)

        # solve all groups
        solution = solver.solve_all_groups()
        self.assertEqual(SatSolverResult.UNSATISFIABLE, solution)

        # solve all but group
        solution = solver.solve_without_groups([group])
        self.assertEqual(SatSolverResult.SATISFIABLE, solution)

        # solve all but group cannot exclude permanent
        with self.assertRaises(ValueError):
            solver.solve_without_groups([group, solver.permanent_group])

        # move to perm
        solver.move_to_permanent(group)
        solution = solver.solve()
        self.assertEqual(SatSolverResult.UNSATISFIABLE, solution)
Beispiel #10
0
    def test_destroy_group(self):
        solver = SatSolverFactory.create("MiniSat", incremental=True)
        gp = solver.create_group()
        solver.destroy_group(gp)

        with self.assertRaises(Exception):
            solver.destroy_group(solver.permanent_group)
Beispiel #11
0
    def test_fill_counter_example(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
                    init(w) := FALSE;
                    next(w) := !w;
            """)
        with BmcSupport():
            bound = 2
            fsm = master_be_fsm()
            sexpfsm = master_bool_sexp_fsm()
            expr = Node.from_ptr(parse_ltl_spec("F ( w <-> v )"))

            pb = generate_ltl_problem(fsm, expr, bound=bound)
            cnf = pb.inline(True).to_cnf()

            solver = SatSolverFactory.create()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())

            trace = Trace.create("FILLED", TraceType.COUNTER_EXAMPLE,
                                 sexpfsm.symbol_table, sexpfsm.symbols_list,
                                 True)

            bmcutils.fill_counter_example(fsm, solver, bound, trace)
            self.assertIsNotNone(trace)
            self.assertEqual(2, len(trace))
            print(trace)
Beispiel #12
0
 def test_group_features(self):
     solver = SatSolverFactory.create("MiniSat", incremental=True)
     var    = self.fsm.encoding.by_name["v"].boolean_expression
     clause = var.to_cnf()
     nclause= (-var).to_cnf()
     
     # TEST create group
     group  = solver.create_group()
     
     # TEST add to group
     solver.add_to_group(clause, group)
     solver.polarity(clause, Polarity.POSITIVE, group)
     solver.add_to_group(nclause, group)
     solver.polarity(nclause, group)
     
     # solve all groups
     solution = solver.solve_all_groups()
     self.assertEqual(SatSolverResult.UNSATISFIABLE, solution)
     
     # solve all but group
     solution = solver.solve_without_groups([group])
     self.assertEqual(SatSolverResult.SATISFIABLE, solution)
     
     # solve all but group cannot exclude permanent
     with self.assertRaises(ValueError):
         solver.solve_without_groups([group, solver.permanent_group])
     
     # move to perm
     solver.move_to_permanent(group)
     solution = solver.solve()
     self.assertEqual(SatSolverResult.UNSATISFIABLE, solution)
Beispiel #13
0
def verify_for_size_exactly_k(observable_names, observable_vars, formula_nodes, k, theta, sigma1, sigma2):
    """
    Performs the verification of the diagnosability problem for `formula_node`
    when a maximum of `k` execution steps are allowed.
    
    :param observable_vars: the list of the boolean variables that are considered
        visible in the scope of this diagnosability test
    :param formula: the node (NuSMV ast representation) representing the formula
        whose diagnosability is under verification
    :param k: the maximum length of the generated traces.
    :param theta: the initial condition placed on the initial belief state 
        (in the form of a :see:`pynusmv.node.Node`)
    :param sigma1: the shape of the traces considered relevant for the first
        member of the critical pair in the ongoing diagnosability test 
        (in the form of a :see:`pynusmv.node.Node`)
    :param sigma2: the shape of the traces considered relevant for the second
        member of the critical pair in the ongoing diagnosability test 
        (in the form of a :see:`pynusmv.node.Node`) 
    :return: the text 'No Violation' if no counter example could be found, 
        and a counter example when one could be identified.
    """
    problem = generate_sat_problem(observable_vars, formula_nodes, k, theta, sigma1, sigma2)
    problem_ = problem.inline(True)  # remove potentially redundant information
    cnf = problem_.to_cnf()

    solver = SatSolverFactory.create()
    solver += cnf
    solver.polarity(cnf, Polarity.POSITIVE)

    if solver.solve() == SatSolverResult.SATISFIABLE:
        return diagnosability_violation(observable_names, solver, k)
    else:
        return "No Violation"
Beispiel #14
0
 def test_destroy_group(self):
     solver = SatSolverFactory.create("MiniSat", incremental=True)
     gp     = solver.create_group()
     solver.destroy_group(gp)
     
     with self.assertRaises(Exception):
         solver.destroy_group(solver.permanent_group)
    def test_create_minisat(self):
        solver = SatSolverFactory.create("minisat", True, True)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatIncProofSolver)

        solver = SatSolverFactory.create("minisat", True, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatIncSolver)

        solver = SatSolverFactory.create("minisat", False, True)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatProofSolver)

        solver = SatSolverFactory.create("minisat", False, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatSolver)
 def test_decode_sat_model(self):
     """
     Tests the behavior of BeEnc.decode_sat_model which may be used to build
     counter examples for complex logics
     """
     with Configure(self, __file__, "/models/multibit.smv"):
         b0 = self.enc.by_name["two_bits.0"]
         b1 = self.enc.by_name["two_bits.1"]
         
         # Dummy expression satisfied iff Ko at time 0 and Ok at time 1
         expr= b0.at_time[0].boolean_expression  &\
               b1.at_time[0].boolean_expression  &\
               -b0.at_time[1].boolean_expression &\
               -b1.at_time[1].boolean_expression
         
         cnf    = expr.to_cnf()      
         solver = SatSolverFactory.create()
         solver+= cnf
         # this is not required though
         solver.polarity(cnf, polarity=Polarity.POSITIVE)
         solver.solve()
         
         decoded= self.enc.decode_sat_model(solver.model)
         # it's true iff all bits are on, that is to day Ko at both times
         expect = "{0: {'two_bits': Ko}, 1: {'two_bits': Ok}}"
         
         self.assertEqual(expect, str(decoded))
Beispiel #17
0
    def do_verify(self, problem):
        cnf = problem.to_cnf()
        solver = SatSolverFactory.create()
        solver += cnf
        solver.polarity(cnf, Polarity.POSITIVE)

        if solver.solve() == SatSolverResult.UNSATISFIABLE:
            return "No counter example"
        else:
            return "Violation found"
Beispiel #18
0
 def do_verify(self, problem):
     cnf    = problem.to_cnf()
     solver = SatSolverFactory.create()
     solver+= cnf
     solver.polarity(cnf, Polarity.POSITIVE)
     
     if solver.solve() == SatSolverResult.UNSATISFIABLE:
         return "No counter example"
     else:
         return "Violation found"
Beispiel #19
0
    def test_solve(self):
        """
        This function tests the following functionalities::
         
        - add (and __iadd__)
        - solve
        - polarity
         
        """
        v = self.fsm.encoding.by_name['v'].boolean_expression
        ########################################################################
        # THIS IS THE INCREMENTAL WAY OF DOING IT
        ########################################################################
        # solver.add_to_group(unsat, solver.permanent_group)
        # solver.group_polarity(unsat, Polarity.POSITIVE, solver.permanent_group)
        # solution = solver.solve_all_groups()
        ########################################################################
        # Tests with a satisfiable problem
        solver = SatSolverFactory.create('MiniSat')
        sat = (v + -v).to_cnf()
        solver.add(sat)
        solver.polarity(sat, Polarity.POSITIVE)
        self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())

        # test with a simple unsat problem
        solver = SatSolverFactory.create('MiniSat')
        unsat = (v * -v).to_cnf()
        solver.add(unsat)
        solver.polarity(unsat, Polarity.POSITIVE)
        self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())

        # another way to represent that same unsat problem
        solver = SatSolverFactory.create('MiniSat')
        sat = (v).to_cnf()
        # add the clause V
        solver += sat
        solver.polarity(sat, Polarity.POSITIVE)
        # and its negation (the add it actually not necessary but clearer)
        solver += sat
        solver.polarity(sat, Polarity.NEGATIVE)
        self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())
Beispiel #20
0
 def test_solve(self):
     """
     This function tests the following functionalities::
      
     - add (and __iadd__)
     - solve
     - polarity
      
     """
     v   = self.fsm.encoding.by_name['v'].boolean_expression
     ########################################################################
     # THIS IS THE INCREMENTAL WAY OF DOING IT
     ########################################################################
     # solver.add_to_group(unsat, solver.permanent_group)
     # solver.group_polarity(unsat, Polarity.POSITIVE, solver.permanent_group)
     # solution = solver.solve_all_groups()
     ########################################################################
     # Tests with a satisfiable problem
     solver= SatSolverFactory.create('MiniSat')
     sat   = (v + -v).to_cnf()
     solver.add(sat)
     solver.polarity(sat, Polarity.POSITIVE)
     self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())
      
     # test with a simple unsat problem
     solver= SatSolverFactory.create('MiniSat')
     unsat = (v * -v).to_cnf()
     solver.add(unsat)
     solver.polarity(unsat, Polarity.POSITIVE)
     self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())
      
     # another way to represent that same unsat problem
     solver= SatSolverFactory.create('MiniSat')
     sat   = (v).to_cnf()
     # add the clause V
     solver += sat
     solver.polarity(sat, Polarity.POSITIVE)
     # and its negation (the add it actually not necessary but clearer) 
     solver += sat
     solver.polarity(sat, Polarity.NEGATIVE)
     self.assertEqual(SatSolverResult.UNSATISFIABLE, solver.solve())
Beispiel #21
0
 def test_cnf_to_be_model(self):
     solver= SatSolverFactory.create('MiniSat')
     a     = self.enc.by_name['a'].boolean_expression
     b     = self.enc.by_name['b'].boolean_expression
     sat   = (a and -b).to_cnf()
       
     solver.add(sat)
     solver.polarity(sat, Polarity.POSITIVE)
     solver.solve()
     cnf_model = solver.model
     be_model  = self.mgr.cnf_to_be_model(cnf_model)
     self.assertEqual("Slist[-4]", str(be_model))
Beispiel #22
0
    def test_cnf_to_be_model(self):
        solver = SatSolverFactory.create('MiniSat')
        a = self.enc.by_name['a'].boolean_expression
        b = self.enc.by_name['b'].boolean_expression
        sat = (a and -b).to_cnf()

        solver.add(sat)
        solver.polarity(sat, Polarity.POSITIVE)
        solver.solve()
        cnf_model = solver.model
        be_model = self.mgr.cnf_to_be_model(cnf_model)
        self.assertEqual("Slist[-4]", str(be_model))
Beispiel #23
0
def check_problem(pb, length):
    fsm    = master_be_fsm()
    cnf    = pb.to_cnf(Polarity.POSITIVE)

    solver = SatSolverFactory.create()
    solver+= cnf
    solver.polarity(cnf, Polarity.POSITIVE)

    if solver.solve() == SatSolverResult.SATISFIABLE:
        cnt_ex = bmcutils.generate_counter_example(fsm, pb, solver, length, "Violation")
        return ("Violation", cnt_ex)
    else:
        return ("Ok", None)
    def test_eventually_critical_pair(self):
        enc = master_be_fsm().encoding
        f1 = Node.from_ptr(parse_simple_expression("status = active"))
        f2 = Node.from_ptr(parse_simple_expression("status = highlight"))

        constraint = diagnosability.constraint_eventually_critical_pair(
            (f1, f2), 0, 5, 5)

        nnf1 = bmcutils.make_nnf_boolean_wff(f1).to_be(enc)
        nnf2 = bmcutils.make_nnf_boolean_wff(f2).to_be(enc)
        manual = Be.false(enc.manager)

        for i in range(6):  # again, from 0 to 5
            manual |= (enc.shift_to_time(nnf1, i)
                       & enc.shift_to_time(nnf2, 5 + i))

        # observing the clauses generated in both cases, one observes that
        # the generated clauses are the same except that the number of the cnf
        # literals do not match, example:
        #                        [-59, -24, 58]
        #                        [-65, -24, 64]
        # This is due to the fact that some 'fresh' cnf literals are used in the
        # generation of the epxression. Therefore, a comparison (even on the
        # canonical form of the CNF) is not feasible.
        #
        # Satisfiability is just an indication but at least that is .. something
        solver_c = SatSolverFactory.create()
        cnf = constraint.to_cnf()
        solver_c += cnf
        solver_c.polarity(cnf, Polarity.POSITIVE)
        result_c = solver_c.solve()

        solver_m = SatSolverFactory.create()
        cnf = manual.to_cnf()
        solver_m += cnf
        solver_m.polarity(cnf, Polarity.POSITIVE)
        result_m = solver_m.solve()

        self.assertEqual(result_c, result_m)
Beispiel #25
0
def check_problem(pb, length):
    fsm    = master_be_fsm()
    cnf    = pb.to_cnf(Polarity.POSITIVE)

    solver = SatSolverFactory.create()
    solver+= cnf
    solver.polarity(cnf, Polarity.POSITIVE)

    if solver.solve() == SatSolverResult.SATISFIABLE:
        cnt_ex = bmcutils.generate_counter_example(fsm, pb, solver, length, "Violation")
        return ("Violation", cnt_ex)
    else:
        return ("Ok", None)
Beispiel #26
0
 def test_eventually_critical_pair(self):
     enc= master_be_fsm().encoding
     f1 = Node.from_ptr(parse_simple_expression("status = active"))
     f2 = Node.from_ptr(parse_simple_expression("status = highlight"))
     
     constraint = diagnosability.constraint_eventually_critical_pair((f1, f2), 0, 5, 5)
     
     nnf1   = bmcutils.make_nnf_boolean_wff(f1).to_be(enc)
     nnf2   = bmcutils.make_nnf_boolean_wff(f2).to_be(enc)
     manual = Be.false(enc.manager)
     
     for i in range(6): # again, from 0 to 5
         manual |= ( enc.shift_to_time(nnf1 , i)
                   & enc.shift_to_time(nnf2 , 5+i))
     
     # observing the clauses generated in both cases, one observes that 
     # the generated clauses are the same except that the number of the cnf
     # literals do not match, example:
     #                        [-59, -24, 58]
     #                        [-65, -24, 64]
     # This is due to the fact that some 'fresh' cnf literals are used in the
     # generation of the epxression. Therefore, a comparison (even on the 
     # canonical form of the CNF) is not feasible.
     #
     # Satisfiability is just an indication but at least that is .. something
     solver_c = SatSolverFactory.create()
     cnf      = constraint.to_cnf()
     solver_c+= cnf
     solver_c.polarity(cnf, Polarity.POSITIVE)
     result_c = solver_c.solve()
     
     solver_m = SatSolverFactory.create()
     cnf      = manual.to_cnf()
     solver_m+= cnf
     solver_m.polarity(cnf, Polarity.POSITIVE)
     result_m = solver_m.solve()
     
     self.assertEqual(result_c, result_m)
Beispiel #27
0
 def test_model(self):    
     beenc = self.fsm.encoding
     solver= SatSolverFactory.create('MiniSat')
     v     = beenc.by_name['v']
     w     = beenc.by_name['w']
     vexp  = v.boolean_expression
     wexp  = w.boolean_expression
     
     sat   = (vexp * -wexp).to_cnf()
      
     solver.add(sat)
     solver.polarity(sat, Polarity.POSITIVE)
     solver.solve()
     cnf_model = solver.model
      
     self.assertTrue( v.index in set(cnf_model), 'v must be true')        
     self.assertTrue(-w.index in set(cnf_model), 'w must be false')
Beispiel #28
0
    def test_model(self):
        beenc = self.fsm.encoding
        solver = SatSolverFactory.create('MiniSat')
        v = beenc.by_name['v']
        w = beenc.by_name['w']
        vexp = v.boolean_expression
        wexp = w.boolean_expression

        sat = (vexp * -wexp).to_cnf()

        solver.add(sat)
        solver.polarity(sat, Polarity.POSITIVE)
        solver.solve()
        cnf_model = solver.model

        self.assertTrue(v.index in set(cnf_model), 'v must be true')
        self.assertTrue(-w.index in set(cnf_model), 'w must be false')
    def test_create_zchaff(self):
        with self.assertRaises(ValueError):
            SatSolverFactory.create("zchaff", True, True)

        with self.assertRaises(ValueError):
            SatSolverFactory.create("zchaff", False, True)

        solver = SatSolverFactory.create("zchaff", True, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatIncSolver)

        solver = SatSolverFactory.create("zchaff", False, False)
        self.assertIsNotNone(solver)
        self.assertEquals(type(solver), SatSolver)
def check_ltl_onepb(fml,
                    length,
                    no_fairness=False,
                    no_invar=False,
                    dry_run=False):
    """
    This function verifies that the given FSM satisfies the given property
    for paths with an exact length of `length`.
    
    :param fml: an LTL formula parsed with `pynusmv_tools.bmcLTL.parsing` (hence the 
        abstract syntax tree of that formula). Note, this is *NOT* the NuSMV
        format (Node).
    :param length: the exact length of the considered paths
    :param no_fairness: a flag telling whether or not the generated problem should
        focus on fair executions only (the considered fairness constraints must
        be declared in the SMV model).
    :param no_invar: a flag telling whether or not the generated problem 
        should enforce the declared invariants (these must be declared in the
        SMV text).
    :return: a tuple ('OK', None) if the property is satisfied on all paths of 
        length `length`
    :return: a tuple ('Violation', counter_example) if the property is violated. 
        The counter_example passed along is a trace leading to a violation of
        the property
    """
    fsm = master_be_fsm()
    pb = generate_problem(fml, fsm, length, no_fairness, no_invar)

    if not dry_run:
        cnf = pb.to_cnf(Polarity.POSITIVE)

        solver = SatSolverFactory.create()
        solver += cnf
        solver.polarity(cnf, Polarity.POSITIVE)

        if solver.solve() == SatSolverResult.SATISFIABLE:
            cnt_ex = generate_counter_example(fsm, pb, solver, length,
                                              str(fml))
            return ("Violation", cnt_ex)
        else:
            return ("Ok", None)
    return ("Ok", None)
Beispiel #31
0
    def test_create_zchaff(self):
        if self.zchaff:
            with self.assertRaises(ValueError):
                SatSolverFactory.create('zchaff', True, True)

            with self.assertRaises(ValueError):
                SatSolverFactory.create('zchaff', False, True)

            solver = SatSolverFactory.create('zchaff', True, False)
            self.assertIsNotNone(solver)
            self.assertEquals(type(solver), SatIncSolver)

            solver = SatSolverFactory.create('zchaff', False, False)
            self.assertIsNotNone(solver)
            self.assertEquals(type(solver), SatSolver)
        else:
            pass
Beispiel #32
0
def check_ltl_onepb(fml, length, no_fairness=False, no_invar=False, dry_run=False):
    """
    This function verifies that the given FSM satisfies the given property
    for paths with an exact length of `length`.
    
    :param fml: an LTL formula parsed with `tools.bmcLTL.parsing` (hence the 
        abstract syntax tree of that formula). Note, this is *NOT* the NuSMV
        format (Node).
    :param length: the exact length of the considered paths
    :param no_fairness: a flag telling whether or not the generated problem should
        focus on fair executions only (the considered fairness constraints must
        be declared in the SMV model).
    :param no_invar: a flag telling whether or not the generated problem 
        should enforce the declared invariants (these must be declared in the
        SMV text).
    :return: a tuple ('OK', None) if the property is satisfied on all paths of 
        length `length`
    :return: a tuple ('Violation', counter_example) if the property is violated. 
        The counter_example passed along is a trace leading to a violation of
        the property
    """
    fsm    = master_be_fsm()
    pb     = generate_problem(fml, fsm, length, no_fairness, no_invar)
    
    if not dry_run:
        cnf    = pb.to_cnf(Polarity.POSITIVE)
        
        solver = SatSolverFactory.create()
        solver+= cnf
        solver.polarity(cnf, Polarity.POSITIVE)
        
        if solver.solve() == SatSolverResult.SATISFIABLE:
            cnt_ex = generate_counter_example(fsm, pb, solver, length, str(fml))
            return ("Violation", cnt_ex)
        else:
            return ("Ok", None)
    return ("Ok", None)
Beispiel #33
0
    def test_concat(self):
        with BmcSupport():
            sexp_fsm = master_bool_sexp_fsm()
            be_fsm = master_be_fsm()

            trace = Trace.create(
                "Dummy example",
                TraceType.COUNTER_EXAMPLE,
                sexp_fsm.symbol_table,
                sexp_fsm.symbols_list,
                is_volatile=True,
            )

            spec = Node.from_ptr(parse_ltl_spec("F (w <-> v)"))
            bound = 2
            problem = generate_ltl_problem(be_fsm, spec, bound=bound)  # .inline(True)
            cnf = problem.to_cnf()
            solver = SatSolverFactory.create()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            solver.solve()

            other = generate_counter_example(be_fsm, problem, solver, bound)

            trace.concat(other)

            self.assertEquals(-1, trace.id)
            self.assertFalse(trace.is_registered)
            self.assertEquals("Dummy example", trace.description)
            self.assertEquals(TraceType.COUNTER_EXAMPLE, trace.type)
            self.assertTrue(trace.is_volatile)
            self.assertEquals(2, trace.length)
            self.assertEquals(2, len(trace))
            self.assertFalse(trace.is_empty)
            self.assertFalse(trace.is_frozen)
            self.assertTrue(trace.is_thawed)
Beispiel #34
0
 def test_printAvailableSolvers(self):
     SatSolverFactory.print_available_solvers()
Beispiel #35
0
 def test_create_group(self):
     solver = SatSolverFactory.create("MiniSat", incremental=True)
     gp = solver.create_group()
     self.assertEqual(gp, 1)
     self.assertNotEqual(gp, solver.permanent_group)
 def test_printAvailableSolvers(self):
     SatSolverFactory.print_available_solvers()
Beispiel #37
0
 def test_name(self):
     solver = SatSolverFactory.create('MiniSat')
     self.assertEqual('MiniSat', solver.name)
Beispiel #38
0
 def satisfiability(self, problem):
     solver = SatSolverFactory.create()
     solver+= problem.to_cnf()
     solver.polarity(problem.to_cnf(), Polarity.POSITIVE)
     return solver.solve()
Beispiel #39
0
 def test_permanent_group(self):
     solver = SatSolverFactory.create('MiniSat')
     # note: Zchaff returns 0 for its perm. group id
     self.assertEqual(-1, solver.permanent_group)
Beispiel #40
0
 def test_random_mode(self):
     solver = SatSolverFactory.create('MiniSat')
     solver.random_mode = 0.1
Beispiel #41
0
 def test_name(self):
     solver = SatSolverFactory.create('MiniSat')
     self.assertEqual('MiniSat', solver.name)
Beispiel #42
0
 def test_last_solving_time(self):
     solver = SatSolverFactory.create('MiniSat')
     # didn't solve anything yet
     self.assertEqual(0, solver.last_solving_time)
 def test_getAvailableSolvers(self):
     self.assertEqual({"ZChaff", "MiniSat"}, SatSolverFactory.available_solvers())
Beispiel #44
0
 def test_last_solving_time(self):
     solver = SatSolverFactory.create('MiniSat')
     # didn't solve anything yet
     self.assertEqual(0, solver.last_solving_time)
Beispiel #45
0
 def test_permanent_group(self):
     solver = SatSolverFactory.create('MiniSat')
     # note: Zchaff returns 0 for its perm. group id
     self.assertEqual(-1, solver.permanent_group)
Beispiel #46
0
 def test_random_mode(self):
     solver= SatSolverFactory.create('MiniSat')
     solver.random_mode = 0.1
Beispiel #47
0
 def test_getAvailableSolvers(self):
     if self.zchaff:
         self.assertEqual({'ZChaff', 'MiniSat'},
                          SatSolverFactory.available_solvers())
     else:
         self.assertEqual({'MiniSat'}, SatSolverFactory.available_solvers())
Beispiel #48
0
 def satisfiability(self, problem):
     solver = SatSolverFactory.create()
     solver += problem.to_cnf()
     solver.polarity(problem.to_cnf(), Polarity.POSITIVE)
     return solver.solve()
Beispiel #49
0
 def test_create_group(self):
     solver = SatSolverFactory.create("MiniSat", incremental=True)
     gp     = solver.create_group()
     self.assertEqual(gp, 1)
     self.assertNotEqual(gp, solver.permanent_group)