def buildBDDmain(example): try: bdd = BDD.bdd_init( example) # "python/programoutput/" + uniqid + ".txt" except pb.Parse_Error as e: ERR_str = "There was an error parsing your file, please check your syntax\n" \ + e.value + "\n" exit_err() if len(bdd["var_order"]) > BDD_VAR_LENGTH: ERR_str = "Your formula contains too many variables for the web interface. Please try again with less than 14 variables or download the BDD package and run it on your own machine." exit_err() if len(pb.print_expr(bdd["expr"])) > 500: ERR_str = "Your formula is too long for the web interface. Please try again with a smaller formula or download the BDD package and run it on your own machine." exit_err() BDD.ite_build(bdd) stats = BDD.stat_string(bdd) sat_count = BDD.sat_count(bdd) variable_order = bdd["var_order"] sat_assigns = BDD.all_sat(bdd) sat_assigns_string = "" for x in sat_assigns: sat_assigns_string += str(list(map(lambda y: 0 if '~' in y else 1, x))) + '\n' dot_file = uniqid + ".dot" # print("dot_file = ", dot_file) # print("BDD = ", bdd) BDD.dot_bdd(bdd, dot_file) #print reduce(lambda x, y : x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT]) #err = os.system(reduce(lambda x, y : x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT])) #print( rm + " " + dot_file ) # print("Dot file left behind as", dot_file) #os.system(rm + " " + dot_file) # if err != 0: # ERR_str = "There was an error running dot on the server" # exit_err() STAT_str = "Number of satisfying assignments: " + str(sat_count) + "\n"\ + stats + "\n\nAll satisfying assignments:\n" + "------------------------------\n"\ + sat_assigns_string print("Satisfying string is", STAT_str)
#! /usr/bin/env python2.7 #Tyler Sorensen #Oct 10, 2011 #Simple BDD script to prove that Babies cannot manage crocodiles #See Solution.txt for a complete walkthrough. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("BabiesAndCrocs.txt") #building the tree BDD.ite_build(x) #Can babies manage crocs? If they can't then we should have #No satisfying assignments BDD.dot_bdd(x,"dotfile.dot") print("Can Babies Manage Crocs?") if BDD.sat_count(x) == 0: print("No") else: print("Yes")
if len(pb.print_expr(bdd["expr"])) > 500: ERR_str = "Your formula is too long for the web interface. Please try again with a smaller formula or download the BDD package and run it on your own machine." exit_err() BDD.reorder_ite_build(bdd) stats = BDD.stat_string(bdd) sat_count = BDD.sat_count(bdd) variable_order = bdd["var_order"] sat_assigns = BDD.all_sat(bdd) sat_assigns_string = "" for x in sat_assigns: sat_assigns_string += str(map(lambda y : 0 if '~' in y else 1, x)) + '\n' dot_file = "python/programoutput/" + uniqid + ".dot" BDD.dot_bdd(bdd, dot_file) #print reduce(lambda x, y : x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT]) err = os.system(reduce(lambda x, y : x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT])) #print rm + " " + dot_file os.system(rm + " " + dot_file) if err != 0: ERR_str = "There was an error running dot on the server" exit_err() STAT_str = "Number of satisfying assignments: " + str(sat_count) + "\n"\ + stats + "\n\nAll satisfying assignts:\n" + "------------------------------\n"\ + sat_assigns_string f = open("python/programoutput/programoutput" + uniqid + ".txt", "w") f.write(STAT_str)
#! /usr/bin/env python2.7 #Tyler Sorensen #Oct 10, 2011 #Simple BDD script to prove that Babies cannot manage crocodiles #See Solution.txt for a complete walkthrough. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("BabiesAndCrocs.txt") #building the tree BDD.ite_build(x) #Can babies manage crocs? If they can't then we should have #No satisfying assignments BDD.dot_bdd(x, "dotfile.dot") print("Can Babies Manage Crocs?") if BDD.sat_count(x) == 0: print("No") else: print("Yes")
# Oct 10, 2011 # Simple BDD script to prove that Babies cannot manage crocodiles # See Solution.txt for a complete walkthrough. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD import os if __name__ == "__main__": # creating and initializing the BDD x = BDD.bdd_init("build8.txt") y = BDD.bdd_init("build8.txt") # building the tree BDD.build(x) BDD.ite_build(y) BDD.dot_bdd(x, "dotfile1.dot") BDD.dot_bdd(y, "dotfile2.dot") if BDD.sat_count(x) != BDD.sat_count(y): print "error!" if BDD.all_sat(x) != BDD.all_sat(y): print "error!"
#This example shows the second more complicated Lewis Carroll puzzle. #See wiseYoungPigs.txt for the formula. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("wiseYoungPigs.txt") #building the tree BDD.ite_build(x) print "Can wise young pigs go up in balloons?" if BDD.sat_count(x) == 0: print "No" else: print "Yes, and here's how:" print "" print BDD.any_sat(x) BDD.dot_bdd(x,"my_dot.dot") #BDD.dot_bdd(x, "myDot.dot")
sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD import pdb if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("formula.txt") #building the tree BDD.ite_build(x) #find and display all sat assignments print("All Sat assignments: ") print("----------------------------") b = BDD.all_sat(x) for q in b: print(q) print "" print BDD.stat_string(x) print "" print "One satisfying assignment is: " print BDD.any_sat(x) BDD.dot_bdd(x, "myDot.dot")
sys.path.append("../../../../PyBool/include/") import BDD import pdb if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("formula.txt") #building the tree BDD.ite_build(x) #find and display all sat assignments print("All Sat assignments: ") print("----------------------------") b = BDD.all_sat(x) for q in b: print(q) print "" print BDD.stat_string(x) print "" print "One satisfying assignment is: " print BDD.any_sat(x) BDD.dot_bdd(x, "myDot.dot")
#Tyler Sorensen #Oct 10, 2011 #Simple BDD script to prove that Babies cannot manage crocodiles #See Solution.txt for a complete walkthrough. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD import os if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("build8.txt") y = BDD.bdd_init("build8.txt") #building the tree BDD.build(x) BDD.ite_build(y) BDD.dot_bdd(x, "dotfile1.dot") BDD.dot_bdd(y, "dotfile2.dot") if BDD.sat_count(x) != BDD.sat_count(y): print "error!" if BDD.all_sat(x) != BDD.all_sat(y): print "error!"
ERR_str = "Your formula is too long for the web interface. Please try again with a smaller formula or download the BDD package and run it on your own machine." exit_err() BDD.reorder_ite_build(bdd) stats = BDD.stat_string(bdd) sat_count = BDD.sat_count(bdd) variable_order = bdd["var_order"] sat_assigns = BDD.all_sat(bdd) sat_assigns_string = "" for x in sat_assigns: sat_assigns_string += str(map(lambda y: 0 if '~' in y else 1, x)) + '\n' dot_file = "python/programoutput/" + uniqid + ".dot" BDD.dot_bdd(bdd, dot_file) #print reduce(lambda x, y : x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT]) err = os.system( reduce(lambda x, y: x + " " + y, [dot_PATH, dot_ARGS, dot_file, dot_OUT])) #print rm + " " + dot_file os.system(rm + " " + dot_file) if err != 0: ERR_str = "There was an error running dot on the server" exit_err() STAT_str = "Number of satisfying assignments: " + str(sat_count) + "\n"\ + stats + "\n\nAll satisfying assignts:\n" + "------------------------------\n"\ + sat_assigns_string
#Sept 18, 2011 #This example shows the second more complicated Lewis Carroll puzzle. #See wiseYoungPigs.txt for the formula. import sys sys.path.append("../../include/") sys.path.append("../../../../PyBool/include/") import BDD if __name__ == "__main__": #creating and initializing the BDD x = BDD.bdd_init("wiseYoungPigs.txt") #building the tree BDD.ite_build(x) print "Can wise young pigs go up in balloons?" if BDD.sat_count(x) == 0: print "No" else: print "Yes, and here's how:" print "" print BDD.any_sat(x) BDD.dot_bdd(x, "my_dot.dot") #BDD.dot_bdd(x, "myDot.dot")