예제 #1
0
 def get_all_vars_array(self):
     # NOTE: This way of building the var_array does not look
     #       robust.  There might be an issue if variables are
     #       added and the order of enumeration of the dictionary
     #       changes and we rely on this order outside of this class.
     var_array = repycudd.DdArray(self.ddmanager, len(self.idx2var))
     for i, node_idx in enumerate(self.idx2var):
         var_array[i] = self.ddmanager[node_idx]
     return var_array
예제 #2
0
    def set_abstract(self):
        all_vars = set(self.converter.var2node.keys())
        pabstract = all_vars.difference(self.pvars)
        nabstract = all_vars.difference(self.nvars)
        self.projPre = self.converter.cube_from_var_list(pabstract)
        self.projNex = self.converter.cube_from_var_list(nabstract)

        pnabstract = all_vars.difference(self.pvars)
        pnabstract = pnabstract.difference(self.nvars)
        self.projAll = self.converter.cube_from_var_list(pnabstract)

        self.N = len(self.p2nvars)
        self.preV = repycudd.DdArray(self.ddmanager, self.N)
        self.nexV = repycudd.DdArray(self.ddmanager, self.N)
        count = 0
        for pv, nv in self.p2nvars.items():
            self.preV[count] = self.converter.var2node[pv]
            self.nexV[count] = self.converter.var2node[nv]
            assert (self.preV[count] != self.nexV[count])
            count += 1
예제 #3
0
#!/usr/bin/python -i
# This example shows how to use the BREL interface
#

######################################
###
### NOTE: THIS IS STILL IN BETA
###
######################################

import repycudd
m = repycudd.DdManager()

# Note how the DdArrays are created and initialised
ips = repycudd.DdArray(m, 2)
ops = repycudd.DdArray(m, 2)
a = m.IthVar(0)
not_a = m.Not(a)
b = m.IthVar(1)
not_b = m.Not(b)
c = m.IthVar(2)
not_c = m.Not(c)
d = m.IthVar(3)
not_d = m.Not(d)
ips.Push(a)
ips.Push(b)
ops.Push(c)
ops.Push(d)

#
# Create a relation -- this maps 00 -> 00, 11; 11 -> 01, 10; 01 -> --; 10 -> --
예제 #4
0
3. Put these functions in a function array to enable the construction of a multi-rooted BDD
4. Dump the function array into a .dot file which can be visualized with the unix dot command
"""

# Create variables
# Variable names can be arbitrary strings that start with a letter.
a = mgr.IthVar(0)
b = mgr.IthVar(1)
c = mgr.IthVar(2)

# Create functions.
# The sample functions here are f = (a | (~b & c)) and g = (b xor c) & a
# For complex expressions, it is better to build the functions incrementally for better readability
# This is uncessary for these sample functions, but is presented here (for function g) for illustration purposes
f = mgr.Or(a, mgr.And(mgr.Not(b), c))
g = mgr.Xor(b, c)
g = mgr.And(g, a)

# Create function array for printing to a .dot file
# You need to specify the size of the array (2 in this case), and push the functions into the array
# CUDD labels the resulting BDD with variable numbers instead of names.
# It also labels the functions F0, F1, etc. based on the order in which they were pushed into the function array.
farray = repycudd.DdArray(mgr, 2)
farray.Push(mgr.BddToAdd(f))
farray.Push(mgr.BddToAdd(g))

# Generate BDD
# If you want to generate a BDD using your variable and function names, simply open the .dot file with a text editor
# and use find/replace to map back variable and function numbers to their names.
mgr.DumpDotArray(farray, "repycudd_template.dot")
예제 #5
0
x4 = mgr.IthVar(4)
x5 = mgr.IthVar(5)
x6 = mgr.IthVar(6)
x7 = mgr.IthVar(7)
x8 = mgr.IthVar(8)
x9 = mgr.IthVar(9)
x10 = mgr.IthVar(10)
x11 = mgr.IthVar(11)

t1 = mgr.And(mgr.And(x0, x1), mgr.And(x2, x3))
t2 = mgr.And(mgr.And(x4, x5), mgr.And(x6, x7))
t3 = mgr.And(mgr.And(x8, x9), mgr.And(x10, x11))

f = mgr.And(mgr.And(t1, t2), t3)

output = repycudd.DdArray(mgr, 1)
output.Push(mgr.BddToAdd(
    f))  # only g is printed, reverse order of the push calls to print only f

mgr.DumpDotArray(output, 'testfile.dot')

var_dict = bidict(
    {
        "x0": "0",
        "x1": "1",
        "x2": "2",
        "x3": "3",
        "x4": "4",
        "x5": "5",
        "x6": "6",
        "x7": "7",