Ejemplo n.º 1
0
    def test_model_is_refreshed(self):
        """
        After a push and a pop, the model should be updated.
        After adding a new assertion, the model should be updated.
        """
        TestVariable = z3.Datatype('TestVariable')
        TestVariable.declare('test_variable',
            ('number', z3.IntSort()))
        TestVariable = TestVariable.create()

        v1 = z3.Const('v1', TestVariable)
        v2 = z3.Const('v2', TestVariable)

        with solver.context():
            solver.add(TestVariable.number(v1) == 42)
            m1 = solver.model()
            self.assertIsNotNone(m1[v1])
            self.assertIsNone(m1[v2])

            solver.add(TestVariable.number(v2) == 3)
            m2 = solver.model()
            self.assertIsNotNone(m2[v1])
            self.assertIsNotNone(m2[v2])

        m3 = solver.model()
        self.assertIsNone(m3[v1])
        self.assertIsNone(m3[v2])
Ejemplo n.º 2
0
    def test_model_is_refreshed(self):
        """
        After a push and a pop, the model should be updated.
        After adding a new assertion, the model should be updated.
        """
        TestVariable = z3.Datatype('TestVariable')
        TestVariable.declare('test_variable', ('number', z3.IntSort()))
        TestVariable = TestVariable.create()

        v1 = z3.Const('v1', TestVariable)
        v2 = z3.Const('v2', TestVariable)

        with solver.context():
            solver.add(TestVariable.number(v1) == 42)
            m1 = solver.model()
            self.assertIsNotNone(m1[v1])
            self.assertIsNone(m1[v2])

            solver.add(TestVariable.number(v2) == 3)
            m2 = solver.model()
            self.assertIsNotNone(m2[v1])
            self.assertIsNotNone(m2[v2])

        m3 = solver.model()
        self.assertIsNone(m3[v1])
        self.assertIsNone(m3[v2])
Ejemplo n.º 3
0
 def test_named_get_model(self):
     v = datatypes.new_variable()
     s = "Name"
     pred = atomic_predicate.Named(v, s)
     z3pred = pred._assert(self.submodel, self.interpretation)
     with solver.context():
         solver.add(z3pred)
         model = solver.model()
         self.assertIsNotNone(model[v])
         self.assertEquals(model[v], datatypes.Variable.variable(1))
Ejemplo n.º 4
0
 def get_model(self):
     # returns a set of sets of <graph, action> pairs, or at the very least
     # something that behaves on the surface as such. It might not
     # necessarily be a complete set. Actions should also behave as sets
     # (sets of atomic actions).
     with solver.context():
         predicate = self.get_predicate()
         solver.add(predicate)
         if not solver.check():
             raise ValueError("Tried to get model of unsat predicate")
         return solver.model()
Ejemplo n.º 5
0
 def get_model(self):
     # returns a set of sets of <graph, action> pairs, or at the very least
     # something that behaves on the surface as such. It might not
     # necessarily be a complete set. Actions should also behave as sets
     # (sets of atomic actions).
     with solver.context():
         predicate = self.get_predicate()
         solver.add(predicate)
         if not solver.check():
             raise ValueError("Tried to get model of unsat predicate")
         return solver.model()
Ejemplo n.º 6
0
 def get_model(self):
     # returns a set of sets of <graph, action> pairs, or at the very least
     # something that behaves on the surface as such. It might not
     # necessarily be a complete set. Actions should also behave as sets
     # (sets of atomic actions).
     with solver.context():
         modelset = new_modelset()
         interpretation = z3.Function('interpretation', Variable, Node)
         predicate = self._assert(modelset, interpretation)
         #if DEBUG:
         #    import pdb; pdb.set_trace()
         solver.add(predicate)
         if not solver.check():
             raise ValueError("Tried to get model of unsat predicate")
         return solver.model()