示例#1
0
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)
示例#2
0
文件: runMe.py 项目: KingsleyZ/PyBool
#!  /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")
示例#3
0
#!  /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")
示例#4
0
import PyBool_public_interface as pb

ERR_str = ""
STAT_str = ""

def exit_err():
    f = open("python/programoutput/error" + uniqid + ".txt", "w")
    f.write(ERR_str)
    f.close()
    exit(0)
    

if __name__ == "__main__":
   
    try:
        bdd = BDD.bdd_init("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"]) > 14:
        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.reorder_ite_build(bdd)
示例#5
0
文件: runMe.py 项目: KingsleyZ/PyBool
#Tyler Sorensen
#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")
示例#6
0
文件: RunMe.py 项目: ganeshutah/Jove
#!/usr/bin/python2.7

#Tyler Sorensen
#Sept 18, 2011

#This example shows how BDD's can be used to show how many
#4 colorings of a given map are available.

#The relationships are that:
#Navada   <-> Utah
#Navada   <-> Arizona
#Utah     <-> Arizona
#Colorado <-> Arizona
#Colorado <-> Utah

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("constraints.txt")

    BDD.build(x)
    print "There are " + str(BDD.sat_count(x)) + " four colorings of the map"
示例#7
0
文件: runMe.py 项目: KingsleyZ/PyBool
# 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!"
示例#8
0
文件: runMe.py 项目: ganeshutah/Jove
#Tyler Sorensen
#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")
示例#9
0
文件: runMe.py 项目: KingsleyZ/PyBool
#Tyler Sorensen
#Sept 18, 2011

#This example shows how BDD's can be used to test
#the equivalence of formulas.

import sys
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("xor.txt")

    #building the tree
    BDD.ite_build(x)

    print "Are the formulas the same?"
    if BDD.sat_count(x) == 32:
        print "yes"
    else:
        print "No, Here is a counter example:"
        print ""
        print BDD.any_sat(x)

    #BDD.dot_bdd(x, "myDot.dot")
示例#10
0
#Tyler Sorensen
#Sept 18, 2011

#Simple example first example. Shows off public for the BDD.

import sys
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 ""
示例#11
0
文件: runMe.py 项目: KingsleyZ/PyBool
#Tyler Sorensen
#Sept 18, 2011

#Simple example first example. Shows off public for the BDD.

import sys
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 ""
示例#12
0
文件: runMe.py 项目: ganeshutah/Jove
#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!"
示例#13
0
ERR_str = ""
STAT_str = ""


def exit_err():
    f = open("python/programoutput/error" + uniqid + ".txt", "w")
    f.write(ERR_str)
    f.close()
    exit(0)


if __name__ == "__main__":

    try:
        bdd = BDD.bdd_init("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.reorder_ite_build(bdd)
示例#14
0
文件: runMe.py 项目: KingsleyZ/PyBool
#Tyler Sorensen
#Sept 18, 2011

#This example shows a simple bit-blasting decision procedure.
#See formula.txt for more info

import sys
sys.path.append("../../include/")
sys.path.append("../../../../PyBool/include/")
import BDD
import pdb

if __name__ == "__main__":
    
    #creating and initializing the BDD
    bdd = BDD.bdd_init("formaula2.txt")


    #building the tree
    BDD.ite_build(x)
    BDD.dot_bdd(x,"dotfile4.dot")

    #find and display all sat assignments
    print("All Sat assignments: ")
    print("----------------------------")#

    b = BDD.all_sat(x)

    for q in b:
        print(q)
示例#15
0
文件: RunMe.py 项目: KingsleyZ/PyBool
#!/usr/bin/python2.7

#Tyler Sorensen
#Sept 18, 2011

#This example shows how BDD's can be used to show how many
#4 colorings of a given map are available.

#The relationships are that:
#Navada   <-> Utah
#Navada   <-> Arizona
#Utah     <-> Arizona
#Colorado <-> Arizona
#Colorado <-> Utah

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("constraints.txt")
    
    BDD.build(x)
    print "There are " + str(BDD.sat_count(x)) + " four colorings of the map"
示例#16
0
#Tyler Sorensen
#Sept 18, 2011

#This example shows how BDD's can be used to test
#the equivalence of formulas.

import sys
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("xor.txt")

    #building the tree
    BDD.ite_build(x)

    print "Are the formulas the same?"
    if BDD.sat_count(x) == 32:
        print "yes"
    else:
        print "No, Here is a counter example:"
        print ""
        print BDD.any_sat(x)

    #BDD.dot_bdd(x, "myDot.dot")
示例#17
0
#Tyler Sorensen
#Sept 18, 2011

#This example shows a simple bit-blasting decision procedure.
#See formula.txt for more info

import sys
sys.path.append("../../include/")
sys.path.append("../../../../PyBool/include/")
import BDD
import pdb

if __name__ == "__main__":

    #creating and initializing the BDD
    bdd = BDD.bdd_init("formaula2.txt")

    #building the tree
    BDD.ite_build(x)
    BDD.dot_bdd(x, "dotfile4.dot")

    #find and display all sat assignments
    print("All Sat assignments: ")
    print("----------------------------")  #

    b = BDD.all_sat(x)

    for q in b:
        print(q)

    print "There are: " + str(BDD.sat_count(x)) + " satisfying assignments"