-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
40 lines (26 loc) · 979 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""A module for solving SATISFIABILITY problems.
The algorithms used are based on the lecture "Formal Methods of Computer Science" at Vienna University of Technology.
"""
from .parsing import DimacsParser
from .solvers import SimpleSatSolver
from collections import defaultdict
test_instance_string = "1 2 0 -1 -2 0 3 4 0 -2 4 2 0 -3 -4 0"
def parse_dimacs(text):
return DimacsParser().parse(text)
def get_default_solver(*args, **kwargs):
return SimpleSatSolver(*args, **kwargs)
def test():
clauses = parse_dimacs(test_instance_string)
solver = get_default_solver()
solver.solve(clauses)
return solver.get_assignment()
if __name__ == "__main__":
parser = DimacsParser()
clauses = parser.parse(test_instance_string)
print(" ^ ".join((repr(c) for c in clauses)))
solver = SimpleSatSolver()
sat = solver.solve(clauses)
print("SAT:", bool(sat))
if sat:
print("witnessing assignment:")
print("\t", sat)