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])
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))
def check_sat(self): # returns a boolean 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) return solver.check()
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()
def test_validity_of_name_implies_name(self): v = datatypes.new_variable() s1 = "Same Name" s2 = "Same Name" pred1 = atomic_predicate.Named(v, s1) pred2 = atomic_predicate.Named(v, s2) with solver.context(): solver.add(pred1._assert(self.submodel, self.interpretation)) self.assertTrue(solver.check()) status = solver.quick_check_implied( pred2._assert(self.submodel, self.interpretation)) self.assertTrue(status)
def test_add(self): with solver.context(): self.assertTrue(solver.check()) solver.add(z3True) self.assertTrue(solver.check()) x = z3.Const('x', z3.IntSort()) solver.add(x == 2) self.assertTrue(solver.check()) solver.add(x == 3) self.assertFalse(solver.check()) solver.add(z3False) self.assertFalse(solver.check())
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()
def test_equal_transitive(self): v1 = datatypes.new_variable() v2 = datatypes.new_variable() v3 = datatypes.new_variable() pred1 = atomic_predicate.Equal(v1, v2) pred2 = atomic_predicate.Equal(v2, v3) pred3 = atomic_predicate.Equal(v1, v3) with solver.context(): solver.add(pred1._assert(self.submodel, self.interpretation)) solver.add(pred2._assert(self.submodel, self.interpretation)) sat = solver.check() self.assertTrue(sat) solver.add( z3.Not(pred3._assert(self.submodel, self.interpretation))) unsat = solver.check() self.assertFalse(unsat)
def test_quick_check_implied_t_f(self): with solver.context(): solver.add(z3True) self.assertFalse(solver.quick_check_implied(z3False))
def test_context(self): with solver.context(): solver.add(z3False) self.assertFalse(solver.check()) self.assertTrue(solver.check())