class TestCNFParser(object): SAT = """ c This is a comment of the example file. p cnf 3 3 1 2 -3 0 -1 2 0 -2 0 """ SAT2 = """c A sample .cnf file. p cnf 3 2 1 -3 0 2 3 -1 0""" def setup_method(self, mthd): self.parser = CNFParser() self.parser.prepared = True def test_parse(self): f = self.parser.parse_string(self.SAT) assert isinstance(f, Formula) assert len(f.variables) == 3 assert len(f.clauses) == 3 assert f.clauses[1].literals[1] == f.clauses[2].literals[0].var def test_parse2(self): f = self.parser.parse_string(self.SAT2) assert isinstance(f, Formula) assert len(f.variables) == 3 assert len(f.clauses) == 2
def main(argv): """Main entry point of the stand-alone executable: takes a file and invokes the solver on it """ if len(argv) < 2: print "Usage: %s filename" % (argv[0],) return 2 f = argv[1] assert os.path.isfile(f) parse_start = time() formula = CNFParser().parse_file(f) parse_end = time() solve_start = time() assignment = formula.dpll() solve_end = time() print '------------------------------------------------------------' print 'Runtime %d ms' % int((solve_end - parse_start) * 1000) print 'Parser %d ms' % int((parse_end - parse_start) * 1000) print 'DPLL %d ms' % int((solve_end - solve_start) * 1000) print 'Conflicts %d' % formula.conflicts print '------------------------------------------------------------' if assignment: print 'SATISFIABLE' else: print 'NOT SATISFIABLE' return 0
def setup_method(self, mthd): self.parser = CNFParser() self.parser.prepared = True