-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_DPLL_PySAT.py
More file actions
63 lines (55 loc) · 2.64 KB
/
test_DPLL_PySAT.py
File metadata and controls
63 lines (55 loc) · 2.64 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
from pysat.solvers import Solver, Minisat22
class tests_DPLL_Gordon(unittest.TestCase):
def test_satisfiable1(self):
# (a OR b) AND (~a OR b) AND (a OR ~b)
with Minisat22(bootstrap_with=[[1, 2], [-1, 2], [1, -2]]) as m:
sat = m.solve()
self.assertEqual(sat, True)
# result = m.get_model()
def test_unsatisfiable1(self):
# (a OR b) AND (~a OR b) AND (a OR ~b) AND (~a OR ~b)
with Minisat22(bootstrap_with=[[1, 2], [-1, 2], [1, -2], [-1, -2]]) as m:
sat = m.solve()
self.assertEqual(sat, False)
# result = m.get_model()
def test_satisfiable2(self):
# (a OR b) AND (~a OR c) AND (b OR ~c)
with Minisat22(bootstrap_with=[[1, 2], [-1, 3], [2, -3]]) as m:
sat = m.solve()
self.assertEqual(sat, True)
# result = m.get_model()
def test_unsatisfiable_long(self):
# (a OR b OR c OR d OR e OR f OR g OR h) AND
# (i OR j OR k OR l OR m OR n OR o OR p) AND
# (~a OR ~i) AND (~b OR ~j) AND (~c OR ~k) AND
# (~d OR ~l) AND (~e OR ~m) AND (~f OR ~n) AND
# (~g OR ~o) AND (~h OR ~p) AND
# (a OR i) AND (~a OR i) AND (a OR ~i)
with Minisat22(bootstrap_with=[[1, 2, 3, 4, 5, 6, 7, 8],
[9, 10, 11, 12, 13, 14, 15, 16],
[-1, -9], [-2, -10], [-3, -11],
[-4, -12], [-5, -13], [-6, -14],
[-7, -15], [-8, -16], [1, 9],
[-1, 9], [1, -9]]) as m:
sat = m.solve()
self.assertEqual(sat, False)
# result = m.get_model()
def test_satisfiable_long(self):
# (a OR b OR c OR d OR e OR f OR g OR h) AND
# (i OR j OR k OR l OR m OR n OR o OR p) AND
# (~a OR ~i) AND (~b OR ~j) AND (~c OR ~k) AND
# (~d OR ~l) AND (~e OR ~m) AND (~f OR ~n) AND
# (~g OR ~o) AND (~h OR ~p) AND
# (a OR i) AND (~a OR i)
with Minisat22(bootstrap_with=[[1, 2, 3, 4, 5, 6, 7, 8],
[9, 10, 11, 12, 13, 14, 15, 16],
[-1, -9], [-2, -10], [-3, -11],
[-4, -12], [-5, -13], [-6, -14],
[-7, -15], [-8, -16], [1, 9],
[-1, 9]]) as m:
sat = m.solve()
self.assertEqual(sat, True)
# result = m.get_model()
if __name__ == '__main__':
unittest.main()