def test_disj(self): disj = self.bare_disj() assert (disj.clauses() == 7) cnf = pbool.CNFFormula(disj) assert (len(cnf.conjuncts()) == 1) s = pilp.Solver(cnf) assert (len(list(s.solutions())) == 15)
def Ntest_basic_ilp(self): base = self.basic() cnf = pbool.CNFFormula(base) s = pilp.Solver(cnf) for soln in s.solutions(): print "SOL: " + str(soln)
def NNNtest_big_ilp(self): fg = pbool.FormulaGenerator(100, 8) fst = fg.formula(8) cnf = pbool.CNFFormula(fst) s = pilp.Solver(cnf) for soln in s.solutions(): print "SOL: " + str(soln)
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)
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 ])
def test_prob(self): fg = pbool.FormulaGenerator(20, 8) fst = fg.formula(4) cnf = pbool.CNFFormula(fst) i = pilp.Solver(cnf) p = pilp.ProbSolver(cnf, {}) isols = list(i.solutions()) psols = list(p.solutions()) print("SOL1 " + str(isols)) print("SOL2 " + str(psols)) assert (isols == psols) p2 = pilp.ProbSolver(cnf, { "I2": 0.0001, "I9": 0.000001, "I4": 0.000000000001 }) p2sols = list(p2.solutions()) print("SOL3 " + str(p2sols))