def test_push_pop(self): self.assertTrue(solver.check()) solver.push() self.assertTrue(solver.check()) solver.add(z3False) self.assertFalse(solver.check()) solver.pop() self.assertTrue(solver.check())
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 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 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 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_context(self): with solver.context(): solver.add(z3False) self.assertFalse(solver.check()) self.assertTrue(solver.check())
def test_quick_check_pushes_and_pops(self): self.assertTrue(solver.check()) self.assertFalse(solver.quick_check(z3False)) self.assertTrue(solver.check())