test_dimacs.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. """Various tests on satisfiability using dimacs cnf file syntax
  2. You can find lots of cnf files in
  3. ftp://dimacs.rutgers.edu/pub/challenge/satisfiability/benchmarks/cnf/
  4. """
  5. from sympy.logic.utilities.dimacs import load
  6. from sympy.logic.algorithms.dpll import dpll_satisfiable
  7. def test_f1():
  8. assert bool(dpll_satisfiable(load(f1)))
  9. def test_f2():
  10. assert bool(dpll_satisfiable(load(f2)))
  11. def test_f3():
  12. assert bool(dpll_satisfiable(load(f3)))
  13. def test_f4():
  14. assert not bool(dpll_satisfiable(load(f4)))
  15. def test_f5():
  16. assert bool(dpll_satisfiable(load(f5)))
  17. f1 = """c simple example
  18. c Resolution: SATISFIABLE
  19. c
  20. p cnf 3 2
  21. 1 -3 0
  22. 2 3 -1 0
  23. """
  24. f2 = """c an example from Quinn's text, 16 variables and 18 clauses.
  25. c Resolution: SATISFIABLE
  26. c
  27. p cnf 16 18
  28. 1 2 0
  29. -2 -4 0
  30. 3 4 0
  31. -4 -5 0
  32. 5 -6 0
  33. 6 -7 0
  34. 6 7 0
  35. 7 -16 0
  36. 8 -9 0
  37. -8 -14 0
  38. 9 10 0
  39. 9 -10 0
  40. -10 -11 0
  41. 10 12 0
  42. 11 12 0
  43. 13 14 0
  44. 14 -15 0
  45. 15 16 0
  46. """
  47. f3 = """c
  48. p cnf 6 9
  49. -1 0
  50. -3 0
  51. 2 -1 0
  52. 2 -4 0
  53. 5 -4 0
  54. -1 -3 0
  55. -4 -6 0
  56. 1 3 -2 0
  57. 4 6 -2 -5 0
  58. """
  59. f4 = """c
  60. c file: hole6.cnf [http://people.sc.fsu.edu/~jburkardt/data/cnf/hole6.cnf]
  61. c
  62. c SOURCE: John Hooker (jh38+@andrew.cmu.edu)
  63. c
  64. c DESCRIPTION: Pigeon hole problem of placing n (for file 'holen.cnf') pigeons
  65. c in n+1 holes without placing 2 pigeons in the same hole
  66. c
  67. c NOTE: Part of the collection at the Forschungsinstitut fuer
  68. c anwendungsorientierte Wissensverarbeitung in Ulm Germany.
  69. c
  70. c NOTE: Not satisfiable
  71. c
  72. p cnf 42 133
  73. -1 -7 0
  74. -1 -13 0
  75. -1 -19 0
  76. -1 -25 0
  77. -1 -31 0
  78. -1 -37 0
  79. -7 -13 0
  80. -7 -19 0
  81. -7 -25 0
  82. -7 -31 0
  83. -7 -37 0
  84. -13 -19 0
  85. -13 -25 0
  86. -13 -31 0
  87. -13 -37 0
  88. -19 -25 0
  89. -19 -31 0
  90. -19 -37 0
  91. -25 -31 0
  92. -25 -37 0
  93. -31 -37 0
  94. -2 -8 0
  95. -2 -14 0
  96. -2 -20 0
  97. -2 -26 0
  98. -2 -32 0
  99. -2 -38 0
  100. -8 -14 0
  101. -8 -20 0
  102. -8 -26 0
  103. -8 -32 0
  104. -8 -38 0
  105. -14 -20 0
  106. -14 -26 0
  107. -14 -32 0
  108. -14 -38 0
  109. -20 -26 0
  110. -20 -32 0
  111. -20 -38 0
  112. -26 -32 0
  113. -26 -38 0
  114. -32 -38 0
  115. -3 -9 0
  116. -3 -15 0
  117. -3 -21 0
  118. -3 -27 0
  119. -3 -33 0
  120. -3 -39 0
  121. -9 -15 0
  122. -9 -21 0
  123. -9 -27 0
  124. -9 -33 0
  125. -9 -39 0
  126. -15 -21 0
  127. -15 -27 0
  128. -15 -33 0
  129. -15 -39 0
  130. -21 -27 0
  131. -21 -33 0
  132. -21 -39 0
  133. -27 -33 0
  134. -27 -39 0
  135. -33 -39 0
  136. -4 -10 0
  137. -4 -16 0
  138. -4 -22 0
  139. -4 -28 0
  140. -4 -34 0
  141. -4 -40 0
  142. -10 -16 0
  143. -10 -22 0
  144. -10 -28 0
  145. -10 -34 0
  146. -10 -40 0
  147. -16 -22 0
  148. -16 -28 0
  149. -16 -34 0
  150. -16 -40 0
  151. -22 -28 0
  152. -22 -34 0
  153. -22 -40 0
  154. -28 -34 0
  155. -28 -40 0
  156. -34 -40 0
  157. -5 -11 0
  158. -5 -17 0
  159. -5 -23 0
  160. -5 -29 0
  161. -5 -35 0
  162. -5 -41 0
  163. -11 -17 0
  164. -11 -23 0
  165. -11 -29 0
  166. -11 -35 0
  167. -11 -41 0
  168. -17 -23 0
  169. -17 -29 0
  170. -17 -35 0
  171. -17 -41 0
  172. -23 -29 0
  173. -23 -35 0
  174. -23 -41 0
  175. -29 -35 0
  176. -29 -41 0
  177. -35 -41 0
  178. -6 -12 0
  179. -6 -18 0
  180. -6 -24 0
  181. -6 -30 0
  182. -6 -36 0
  183. -6 -42 0
  184. -12 -18 0
  185. -12 -24 0
  186. -12 -30 0
  187. -12 -36 0
  188. -12 -42 0
  189. -18 -24 0
  190. -18 -30 0
  191. -18 -36 0
  192. -18 -42 0
  193. -24 -30 0
  194. -24 -36 0
  195. -24 -42 0
  196. -30 -36 0
  197. -30 -42 0
  198. -36 -42 0
  199. 6 5 4 3 2 1 0
  200. 12 11 10 9 8 7 0
  201. 18 17 16 15 14 13 0
  202. 24 23 22 21 20 19 0
  203. 30 29 28 27 26 25 0
  204. 36 35 34 33 32 31 0
  205. 42 41 40 39 38 37 0
  206. """
  207. f5 = """c simple example requiring variable selection
  208. c
  209. c NOTE: Satisfiable
  210. c
  211. p cnf 5 5
  212. 1 2 3 0
  213. 1 -2 3 0
  214. 4 5 -3 0
  215. 1 -4 -3 0
  216. -1 -5 0
  217. """