def __init__(self, environment, logic=None): QuantifierEliminator.__init__(self) self.environment = environment self.logic = logic self.ddmanager = repycudd.DdManager() self.converter = BddConverter(environment=environment, ddmanager=self.ddmanager)
def __init__(self, environment, logic, user_options): Solver.__init__(self, environment=environment, logic=logic, user_options=user_options) self.mgr = environment.formula_manager self.ddmanager = repycudd.DdManager() self.converter = BddConverter(environment=self.environment, ddmanager=self.ddmanager) # Impose initial ordering if self.options.static_ordering is not None: for var in self.options.static_ordering: if not var.is_symbol(types.BOOL): raise ValueError("The BDD static ordering must be a " \ "list of Boolean variables") self.declare_variable(var) if self.options.dynamic_reordering: self.ddmanager.AutodynEnable(self.options.reordering_algorithm) else: self.ddmanager.AutodynDisable() # This stack keeps a pair (Expr, Bdd), with the semantics that # the bdd at the i-th element of the list contains the bdd of # the conjunction of all previous expressions. # The construction of the Bdd is done during solve() self.assertions_stack = None self.reset_assertions() # Initialize the stack self.backtrack = [] self.latest_model = None
def __init__(self, environment, logic, **options): Solver.__init__(self, environment=environment, logic=logic, **options) self.mgr = environment.formula_manager self.ddmanager = repycudd.DdManager() self.converter = BddConverter(environment=self.environment, ddmanager=self.ddmanager) self.options(self) # This stack keeps a pair (Expr, Bdd), with the semantics that # the bdd at the i-th element of the list contains the bdd of # the conjunction of all previous expressions. # The construction of the Bdd is done during solve() self.assertions_stack = None self.reset_assertions() # Initialize the stack self.backtrack = [] self.latest_model = None
#!/usr/bin/python -i # This example shows the 3 different ways to iterate over a DdNode # Import the module, create the manager import repycudd m = repycudd.DdManager() # # Create a random function as an example # Note that you don't need to create the variable individually to use them -- # you can directly use IthVar() to provide the variable # a = m.IthVar(0) b = m.IthVar(1) c = m.IthVar(2) # (~a & ~b & ((~c & ~m.IthVar(3)) | # (c & m.IthVar(3)))) | # (a & b & ((~c & m.IthVar(3)) | (c & ~m.IthVar(3)))) not_a = m.Not(a) not_b = m.Not(b) not_c = m.Not(c) rel_a = m.And(m.And(not_a, not_b), m.Or(m.And(not_c, m.Not(m.IthVar(3))), m.And(c, m.IthVar(3)))) rel_b = m.And(m.And(a, b), m.Or(m.And(not_c, m.IthVar(3)), m.And(c, m.Not(m.IthVar(3))))) rel = m.Or(rel_a, rel_b) #rel = m.Or(rel, m.And(not_a, b)) #rel = m.Or(rel, m.And(a, not_b))
def __init__(self, environment, logic=None): self.environment = environment self.logic = logic self.ddmanager = repycudd.DdManager() self.converter = BddConverter(environment=environment, ddmanager=self.ddmanager)
def execute(self): """Forward Reachability using BDDs.""" prop = prop_formula(self) print("\nChecking property %s...\n" % prop) self.ddmanager = repycudd.DdManager() self.converter = BddConverter(environment=get_env(), ddmanager=self.ddmanager) # self.ddmanager.AutodynDisable() for k, v in self.system._enumsorts.items(): if str(k).startswith("epoch"): self.converter.zero = v[0] break self.initialize_atoms() eprint(time_str(), "(building bdds)") bddI = self.formula2bdd(init_formula(self)) # pathCount = bddI.CountPathsToNonZero() # print("Found %d paths in init" % pathCount) # self.dump_dot(bddI) # assert(0) self.build_actions() self.build_axioms() # bddT = self.formula2bdd(trel_formula(self)) # eprint(time_str(), "(building bdd for T done)") # # self.dump_dot(bddT) # # assert(0) # # if axiom_formula(self) != TRUE(): # bddA = self.formula2bdd(axiom_formula(self)) # # self.dump_dot(bddA) # # assert(0) # bddT = self.ddmanager.And(bddT, bddA) # # pathCount = bddT.CountPathsToNonZero() # # print("Found %d paths in trel /\ axioms" % pathCount) # # self.print_pla(bddI, bddT) # assert(0) # bddP = self.formula2bdd(prop_formula(self)) # pathCount = bddP.CountPathsToNonZero() # print("Found %d paths in prop" % pathCount) # self.extract_pcubes(bddI, "Init") # self.extract_pcubes(bddT, "Trel") # self.extract_pcubes(bddA, "Axiom") # self.extract_pcubes(bddP, "Property") # self.set_atoms() # self.set_bddvars() # self.set_p2nVars() self.bddP = self.formula2bdd(prop_formula(self)) self.bddnotP = self.ddmanager.Not(self.bddP) # self.dump_dot(self.bddP) # self.execute_espresso(self.bddP, self.patoms, True) # assert(0) self.set_abstract() sources = list() initSrc = self.ddmanager.AndAbstract(bddI, self.axiom, self.projPre) totalR = initSrc sources.append((initSrc, "init")) iteration = 0 eprint("\t(running forward reachability)") while (len(sources) != 0): # print("#sources = %d" % len(sources)) src, comment = sources.pop() iteration += 1 if src == self.ddmanager.ReadLogicZero(): print("#%d Found no new states" % iteration) continue else: print("#%d Found #%d new states: %s" % (iteration, len(sources) + 1, comment)) self.check_safe(src) # src = self.ddmanager.And(src, self.axiom) notTotalR = self.ddmanager.Not(totalR) destinations = [] for action, actionBdds in self.actions.items(): nex = self.ddmanager.Zero() done = False for actionBdd in actionBdds: image = self.ddmanager.AndAbstract(src, actionBdd, self.projNex) if image == self.ddmanager.ReadLogicZero(): continue image = self.ddmanager.SwapVariables( image, self.preV, self.nexV, self.N) image = self.ddmanager.AndAbstract(image, self.axiom, self.projPre) if image == self.ddmanager.ReadLogicZero(): continue image = self.ddmanager.And(image, notTotalR) if image == self.ddmanager.ReadLogicZero(): continue nex = self.ddmanager.Or(nex, image) done = True # print("found a state in %s" % action) # break if done: destinations.append((nex, action)) for dest, comment in destinations: sources.append((dest, comment)) totalR = self.ddmanager.Or(totalR, dest) # eprint("\t(found total #%d paths)" % totalPathCount) # print("\t(found total #%d paths)" % totalPathCount) # print("Reachable states:") # self.ddmanager.PrintMinterm(totalR) totalR = self.ddmanager.ExistAbstract(totalR, self.projPre) if self.converter.zero != None: proj_vars = set(self.converter.var2node.keys()) proj_vars = proj_vars.difference(self.pvars) for atom in self.gatoms.keys(): enumc = atom.get_enum_constants() if self.converter.zero in enumc: var = self.converter.atom2var[atom] proj_vars.add(var) self.patoms.pop(atom) projCustom = self.converter.cube_from_var_list(proj_vars) totalR = self.ddmanager.ExistAbstract(totalR, projCustom) self.dump_dot(totalR) # self.experiment(totalR) # assert(0) eprint("\t(forward reachability done)") print("\t(forward reachability done)") self.check_safe(totalR) notCubes_fast = self.execute_espresso(totalR, self.patoms, "fast") notCubes = notCubes_fast # notCubes_primes = self.execute_espresso(totalR, self.patoms, "primes") # notCubes = notCubes_primes # notCubes_exact = self.execute_espresso(totalR, self.patoms, "exact") # notCubes = notCubes_exact symCubes = set() eprint("\t(invoking symmetry on #%d)" % len(notCubes)) print("\t(invoking symmetry on #%d)" % len(notCubes)) for cube, cubeMap, l in notCubes: print("%s i.e. " % l, end='') pretty_print(cube) cubesOut = symmetry_cube(self, cube, 0, False) assert (len(cubesOut) == 1) for cubeSym, _ in cubesOut: symCubes.add(cubeSym) print("\t", end="") pretty_print(Not(cubeSym)) # print("Symmetric notR: #%d" % len(symCubes)) for idx, cubeSym in enumerate(symCubes): label = "frpo%d" % str(len(self.inferences) + 1) clause = Not(cubeSym) self.inferences.append((label, clause)) pretty_print_inv(self.inferences, "Forward inferences") return self.inferences