def ite_build(bdd): """ Implementation of the efficient 'ite' method of building a BDD discussed in Bryan et al's paper "Efficient Implementation of a BDD Package" """ ite.ite_build(bdd)
def _walk_variable_up(num_nodes, current_position, bdd, out, verbose): best_order = bdd["var_order"] #walk var to top while(current_position > 0): _reset_bdd(bdd) tmp = bdd["var_order"][current_position-1] bdd["var_order"][current_position-1] = bdd["var_order"][current_position] bdd["var_order"][current_position] = tmp current_position -= 1 ite.ite_build(bdd) if num_nodes > bdd["u"]+1: num_nodes = bdd["u"]+1 best_order = list(bdd["var_order"]) if verbose: print "Walk Up New Number of Nodes: %d" % num_nodes print "Walk Up New Var Order: %s" % str(bdd["var_order"]) out["num_nodes"] = num_nodes out["best_order"] = best_order
def _walk_variable_up(num_nodes, current_position, bdd, out, verbose): best_order = bdd["var_order"] #walk var to top while (current_position > 0): _reset_bdd(bdd) tmp = bdd["var_order"][current_position - 1] bdd["var_order"][current_position - 1] = bdd["var_order"][current_position] bdd["var_order"][current_position] = tmp current_position -= 1 ite.ite_build(bdd) if num_nodes > bdd["u"] + 1: num_nodes = bdd["u"] + 1 best_order = list(bdd["var_order"]) if verbose: print("Walk Up New Number of Nodes: %d" % num_nodes) print("Walk Up New Var Order: %s" % str(bdd["var_order"])) out["num_nodes"] = num_nodes out["best_order"] = best_order
def reorder_ite_build(bdd, vars_to_consider=[], verbose=False): """ Parameters: bdd - the bdd to build and minimize vars_to_consider - the list of varibles to reorder verbose - whether info should be printed during build time """ ite.ite_build(bdd) num_nodes = bdd["u"]+1 num_vars = len(bdd["var_order"]) if verbose: print "Original Number of Nodes: %d" % num_nodes print "Number of Variables: %d" % num_vars checked_vars = {} if not vars_to_consider: vars_to_consider = bdd["var_order"] for v in vars_to_consider: checked_vars[v] = False while False in checked_vars.values(): var_to_be_checked = None for key in checked_vars: if not checked_vars[key]: var_to_be_checked = key break best_order = list(bdd["var_order"]) original_order = best_order current_position = bdd["var_order"].index(var_to_be_checked) if verbose: print "Current Variable: %s" % var_to_be_checked original_position = current_position #start thread to walk to top walk_up_bdd = copy.deepcopy(bdd) walk_up_out = {"num_nodes":None, "best_order":None} walk_up_thread = threading.Thread( target=_walk_variable_up, args=(copy.copy(num_nodes), copy.copy(current_position), walk_up_bdd, walk_up_out, verbose) ) walk_up_thread.start() #walk var to bottom for j in range(original_position,num_vars): _reset_bdd(bdd) #reset our bdd to try again tmp = bdd["var_order"][j] bdd["var_order"][j] = bdd["var_order"][current_position] bdd["var_order"][current_position] = tmp current_position = j ite.ite_build(bdd) if num_nodes > bdd["u"]+1: num_nodes = bdd["u"]+1 best_order = list(bdd["var_order"]) if verbose: print "Walk Down New Number of Nodes: %d" % num_nodes print "Walk Down New Var Order: %s" % str(bdd["var_order"]) walk_up_thread.join() if num_nodes > walk_up_out["num_nodes"]: num_nodes = walk_up_out["num_nodes"] best_order = walk_up_out["best_order"] #mark var as checked checked_vars[var_to_be_checked] = True bdd["var_order"] = best_order _reset_bdd(bdd) bdd["var_order"] = best_order ite.ite_build(bdd) if verbose: print "Final Number of Nodes: %d" % num_nodes print "Final Var Order %s" % str(bdd["var_order"])
def ite_build(bdd): ite.ite_build(bdd)
def reorder_ite_build(bdd, vars_to_consider=[], verbose=False): """ Parameters: bdd - the bdd to build and minimize vars_to_consider - the list of varibles to reorder verbose - whether info should be printed during build time """ ite.ite_build(bdd) num_nodes = bdd["u"] + 1 num_vars = len(bdd["var_order"]) if verbose: print("Original Number of Nodes: %d" % num_nodes) print("Number of Variables: %d" % num_vars) checked_vars = {} if not vars_to_consider: vars_to_consider = bdd["var_order"] for v in vars_to_consider: checked_vars[v] = False while False in checked_vars.values(): var_to_be_checked = None for key in checked_vars: if not checked_vars[key]: var_to_be_checked = key break best_order = list(bdd["var_order"]) original_order = best_order current_position = bdd["var_order"].index(var_to_be_checked) if verbose: print("Current Variable: %s" % var_to_be_checked) original_position = current_position #start thread to walk to top walk_up_bdd = copy.deepcopy(bdd) walk_up_out = {"num_nodes": None, "best_order": None} walk_up_thread = threading.Thread(target=_walk_variable_up, args=(copy.copy(num_nodes), copy.copy(current_position), walk_up_bdd, walk_up_out, verbose)) walk_up_thread.start() #walk var to bottom for j in range(original_position, num_vars): _reset_bdd(bdd) #reset our bdd to try again tmp = bdd["var_order"][j] bdd["var_order"][j] = bdd["var_order"][current_position] bdd["var_order"][current_position] = tmp current_position = j ite.ite_build(bdd) if num_nodes > bdd["u"] + 1: num_nodes = bdd["u"] + 1 best_order = list(bdd["var_order"]) if verbose: print("Walk Down New Number of Nodes: %d" % num_nodes) print("Walk Down New Var Order: %s" % str(bdd["var_order"])) walk_up_thread.join() if num_nodes > walk_up_out["num_nodes"]: num_nodes = walk_up_out["num_nodes"] best_order = walk_up_out["best_order"] #mark var as checked checked_vars[var_to_be_checked] = True bdd["var_order"] = best_order _reset_bdd(bdd) bdd["var_order"] = best_order ite.ite_build(bdd) if verbose: print("Final Number of Nodes: %d" % num_nodes) print("Final Var Order %s" % str(bdd["var_order"]))