Пример #1
0
 def Ntest_solve(self):
     fg = pbool.FormulaGenerator(50, 8)
     fst = fg.formula(4)
     cnf = pbool.CNFFormula(fst)
     s = psat.Solver(cnf)
     for soln in s.minimal_solutions():
         print "SOLN1 " + str(soln)
Пример #2
0
    def test_ilp_sat_equivalence(self):
        fg = pbool.FormulaGenerator(20, 8)
        fst = fg.formula(4)

        cnf = pbool.CNFFormula(fst)

        s = psat.Solver(cnf)
        i = pilp.Solver(cnf)

        ssols = sorted(list(s.solutions()))
        isols = sorted(list(i.solutions()))

        print "LENs " + str(len(ssols)) + " vs " + str(len(isols))
        print "SOLs " + str(ssols) + " vs " + str(isols)
Пример #3
0
def do_experiment(fg, i, j):
    formula = fg.formula(i)
    ctm = timeout_timeit(lambda: pbool.CNFFormula(formula), number=1, timeo=15)

    if ctm == -1:
        return
    cnf = pbool.CNFFormula(formula)

    ssolv = psat.Solver(cnf)
    isolv = pilp.Solver(cnf)

    ssolv2 = psat.Solver(cnf)
    isolv2 = pilp.Solver(cnf)

    ssolv3 = psat.Solver(cnf)
    isolv3 = pilp.Solver(cnf)

    imtm = timeout_timeit(lambda: next(isolv.solutions()), number=1)
    smtm = timeout_timeit(lambda: next(ssolv.minimal_solutions()), number=1)
    sftm = timeout_timeit(lambda: next(ssolv2.solutions()), number=1)
    #iftm = timeout_timeit(lambda: next(isolv2.solutions()), number=1)

    ssiz = len(next(ssolv3.solutions()))
    isiz = len(next(isolv3.solutions()))

    if smtm == -1:
        solns = -1
    else:
        solns = len(list(ssolv2.solutions()))

    return map(str, [
        i, j,
        formula.clauses(),
        cnf.formula.clauses(),
        len(formula.variables()), solns, ssiz, isiz, ctm, sftm, smtm, imtm
    ])
Пример #4
0
 def Ntest_basic_solve(self):
     base = self.basic()
     cnf = pbool.CNFFormula(base)
     s = psat.Solver(cnf)
     for soln in s.minimal_solutions():
         print "SOLN " + str(soln)