Пример #1
0
    def print_espresso(self, bdd, restricted, name):
        global outF
        outF = open(name + ".pla", "w")

        str_head = ".ilb "
        self.espresso_head = []
        abvars = set(self.converter.var2atom.keys())
        atomList = []
        for idx in range(self.numvars):
            var = self.converter.idx2var[idx]
            atom = self.converter.var2atom[var]
            atomList.append(atom)
            if atom in restricted:
                self.espresso_head.append(atom)
                abvars.remove(var)

        for atom in self.espresso_head:
            str_head += pretty_serialize(atom).replace(" ", "") + " "
        fprint(".i %d" % len(self.espresso_head))
        fprint(".o 1")
        fprint(str_head)
        fprint(".ob out")
        fprint(".phase 0")
        abcube = self.converter.cube_from_var_list(list(abvars))
        #         bddnew = bdd
        bddnew = self.ddmanager.ExistAbstract(bdd, abcube)
        print("\t(printing pla)")
        for cube_tup in repycudd.ForeachCubeIterator(self.ddmanager, bddnew):
            str_cube = ""
            for idx, char in enumerate(cube_tup):
                if idx >= self.numvars:
                    break
                atom = atomList[idx]
                #                 var = self.converter.idx2var[idx]
                #                 atom = self.converter.var2atom[var]
                if atom in restricted:
                    if char == 2:
                        str_cube += '-'
                    else:
                        str_cube += str(char)
            str_cube += " 1"
            fprint(str_cube)
        fprint(".e")
        outF.close()
Пример #2
0
    def get_model(self):
        # TODO: We could provide a more sophisticated Model class,
        # that would contain the current Bdd and a copy of the
        # DdManager. This would make it possible to apply other
        # operations on the model (e.g., enumeration) in a simple way.
        if self.latest_model is None:
            _, current_state = self.assertions_stack[-1]
            assert current_state is not None, "solve() should be called before get_model()"
            # Build ddArray of variables
            var_array = self.converter.get_all_vars_array()
            minterm_set = self.ddmanager.PickOneMinterm(
                current_state, var_array, len(var_array))
            minterm = next(
                repycudd.ForeachCubeIterator(self.ddmanager, minterm_set))
            assignment = {}
            for i, node in enumerate(var_array):
                value = self.mgr.Bool(minterm[i] == 1)
                key = self.converter.idx2var[node.NodeReadIndex()]
                assignment[key] = value

            self.latest_model = EagerModel(assignment=assignment,
                                           environment=self.environment)
        return self.latest_model
Пример #3
0
 def extract_cubes(self, bdd, allowed):
     cubes = []
     for cube in repycudd.ForeachCubeIterator(self.ddmanager, bdd):
         atoms = []
         atomval = {}
         for i in range(self.numvars):
             lit = cube[i]
             if lit == 0 or lit == 1:
                 var = self.converter.idx2var[i]
                 if var in self.converter.var2atom:
                     atom = self.converter.var2atom[var]
                     #                     print("%d -> %s" % (i, atom))
                     if atom not in allowed:
                         continue
                     if lit == 0:
                         atomval[atom] = 0
                         atom = Not(atom)
                     else:
                         atomval[atom] = 1
                     atoms.append(atom)
         cubeNew = (And(atoms), atomval)
         cubes.append(cubeNew)
     return cubes
Пример #4
0
#rel = m.Or(rel, m.And(not_a, b))
#rel = m.Or(rel, m.And(a, not_b))

print("Going to iterate over the following function")
m.PrintMinterm(rel)

#
# The 3 iteration methods produce cubes, nodes and primes respectively
# Note that since the package uses complement edges, the nodes may not be what
# you expected!! Refer pyiter.i and ddnode.i for details on how this is done.
#
print("Testing iteration methods ...")
# Over cubes
print("Over cubes ...")
repycudd.set_iter_meth(0)
for cube in repycudd.ForeachCubeIterator(m, rel):
    print(repycudd.cube_tuple_to_str(cube))

# Over nodes
print("Over nodes ...")
repycudd.set_iter_meth(1)
for node in repycudd.ForeachNodeIterator(m, rel):
    print("***")
    m.PrintMinterm(node)

# Over primes
# print("Over primes ...")
# repycudd.set_iter_meth(2)
# for prime in repycudd.ForeachPrimeIterator(m, repycudd.NodePair(rel, rel)):
#     print(repycudd.cube_tuple_to_str(prime))