python-sat 1.9.dev24__tar.gz → 1.9.dev26__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. {python_sat-1.9.dev24/python_sat.egg-info → python_sat-1.9.dev26}/PKG-INFO +1 -1
  2. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/seqcounter.hh +6 -6
  3. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/bbscan.py +28 -28
  4. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/hitman.py +3 -3
  5. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/lbx.py +1 -1
  6. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/lsu.py +3 -3
  7. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/mcsls.py +4 -2
  8. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/optux.py +10 -2
  9. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/primer.py +3 -0
  10. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/rc2.py +51 -35
  11. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/__init__.py +3 -2
  12. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/card.py +22 -17
  13. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/engines.py +55 -36
  14. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/formula.py +166 -97
  15. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/integer.py +123 -37
  16. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/pb.py +1 -1
  17. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/solvers.py +60 -60
  18. python_sat-1.9.dev26/pysat/vector.py +299 -0
  19. {python_sat-1.9.dev24 → python_sat-1.9.dev26/python_sat.egg-info}/PKG-INFO +1 -1
  20. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/python_sat.egg-info/SOURCES.txt +10 -0
  21. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/pysolvers.cc +358 -45
  22. python_sat-1.9.dev26/tests/test_alien.py +42 -0
  23. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_boolengine.py +18 -0
  24. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_integer.py +115 -0
  25. python_sat-1.9.dev26/tests/test_itotalizer.py +126 -0
  26. python_sat-1.9.dev26/tests/test_lbx.py +247 -0
  27. python_sat-1.9.dev26/tests/test_lsu.py +93 -0
  28. python_sat-1.9.dev26/tests/test_mcsls.py +277 -0
  29. python_sat-1.9.dev26/tests/test_musx.py +94 -0
  30. python_sat-1.9.dev26/tests/test_negate.py +57 -0
  31. python_sat-1.9.dev26/tests/test_primer.py +90 -0
  32. python_sat-1.9.dev26/tests/test_rc2.py +185 -0
  33. python_sat-1.9.dev26/tests/test_vector.py +278 -0
  34. python_sat-1.9.dev24/tests/test_lsu.py +0 -15
  35. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/LICENSE.txt +0 -0
  36. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/MANIFEST.in +0 -0
  37. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/README.rst +0 -0
  38. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/allies/__init__.py +0 -0
  39. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/allies/approxmc.py +0 -0
  40. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/allies/unigen.py +0 -0
  41. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/bitwise.hh +0 -0
  42. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/card.hh +0 -0
  43. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/clset.hh +0 -0
  44. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/common.hh +0 -0
  45. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/iseq.hh +0 -0
  46. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/itot.hh +0 -0
  47. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/ladder.hh +0 -0
  48. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/mto.hh +0 -0
  49. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/pairwise.hh +0 -0
  50. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/ptypes.hh +0 -0
  51. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/pycard.cc +0 -0
  52. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/sortcard.hh +0 -0
  53. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/cardenc/utils.hh +0 -0
  54. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/__init__.py +0 -0
  55. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/bica.py +0 -0
  56. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/fm.py +0 -0
  57. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/genhard.py +0 -0
  58. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/models.py +0 -0
  59. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/musx.py +0 -0
  60. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/examples/usage.py +0 -0
  61. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_parse.cc +0 -0
  62. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_plus.cc +0 -0
  63. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_plus.hh +0 -0
  64. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_py.hh +0 -0
  65. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_scan.hh +0 -0
  66. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_weight.cc +0 -0
  67. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pf_weight.hh +0 -0
  68. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pyformula.cc +0 -0
  69. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/formula/pyformula.hh +0 -0
  70. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/_fileio.py +0 -0
  71. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/_utils.py +0 -0
  72. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/pysat/process.py +0 -0
  73. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/python_sat.egg-info/dependency_links.txt +0 -0
  74. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/python_sat.egg-info/requires.txt +0 -0
  75. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/python_sat.egg-info/top_level.txt +0 -0
  76. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/requirements.txt +0 -0
  77. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/setup.cfg +0 -0
  78. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/setup.py +0 -0
  79. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/cadical103.tar.gz +0 -0
  80. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/cadical153.tar.gz +0 -0
  81. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/cadical195.tar.gz +0 -0
  82. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/cadical300.tar.gz +0 -0
  83. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/ergo.tar.gz +0 -0
  84. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/glucose30.tar.gz +0 -0
  85. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/glucose41.tar.gz +0 -0
  86. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/glucose421.tar.gz +0 -0
  87. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/lingeling.tar.gz +0 -0
  88. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/maplechrono.zip +0 -0
  89. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/maplecm.zip +0 -0
  90. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/maplesat.zip +0 -0
  91. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/mergesat3.tar.gz +0 -0
  92. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/minicard.tar.gz +0 -0
  93. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/minisat22.tar.gz +0 -0
  94. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/minisatgh.zip +0 -0
  95. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/cadical103.patch +0 -0
  96. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/cadical153.patch +0 -0
  97. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/cadical195.patch +0 -0
  98. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/cadical300.patch +0 -0
  99. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/ergo.patch +0 -0
  100. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/glucose30.patch +0 -0
  101. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/glucose41.patch +0 -0
  102. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/glucose421.patch +0 -0
  103. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/gluecard30.patch +0 -0
  104. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/gluecard41.patch +0 -0
  105. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/kissat404.patch +0 -0
  106. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/lingeling.patch +0 -0
  107. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/maplechrono.patch +0 -0
  108. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/maplecm.patch +0 -0
  109. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/maplesat.patch +0 -0
  110. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/mergesat3.patch +0 -0
  111. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/minicard.patch +0 -0
  112. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/minisat22.patch +0 -0
  113. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/minisatep.patch +0 -0
  114. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/patches/minisatgh.patch +0 -0
  115. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/solvers/prepare.py +0 -0
  116. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_accum_stats.py +0 -0
  117. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_activities.py +0 -0
  118. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_atmost.py +0 -0
  119. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_atmost1.py +0 -0
  120. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_atmostk.py +0 -0
  121. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_clausification.py +0 -0
  122. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_cnf.py +0 -0
  123. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_empty_clause.py +0 -0
  124. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_empty_extclause.py +0 -0
  125. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_encode_pb_conditional.py +0 -0
  126. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_equals1.py +0 -0
  127. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_flip_bits.py +0 -0
  128. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_formula_parsing.py +0 -0
  129. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_formula_unique.py +0 -0
  130. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_hitman.py +0 -0
  131. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_idpool.py +0 -0
  132. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_iseqcounter.py +0 -0
  133. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_oom.py +0 -0
  134. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_pb.py +0 -0
  135. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_process.py +0 -0
  136. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_projected_models.py +0 -0
  137. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_proof.py +0 -0
  138. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_propagate.py +0 -0
  139. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_unique_model.py +0 -0
  140. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_unique_mus.py +0 -0
  141. {python_sat-1.9.dev24 → python_sat-1.9.dev26}/tests/test_warmstart.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-sat
3
- Version: 1.9.dev24
3
+ Version: 1.9.dev26
4
4
  Summary: A Python library for prototyping with SAT oracles
5
5
  Home-page: https://github.com/pysathq/pysat
6
6
  Author: Alexey Ignatiev, Joao Marques-Silva, Antonio Morgado
@@ -102,27 +102,27 @@ void seqcounter_encode_atmostN(
102
102
  /* variant of the encoding, as suggested by Alex Healy */
103
103
  for (size_t j = 0; j < vars.size() - tval; ++j) {
104
104
  // k = 0, eq 19:
105
- int s0j = mk_yvar(top_id, p2i_map, make_pair(0, j));
105
+ int s0j = mk_yvar(top_id, p2i_map, make_pair(1, j + 1));
106
106
  clset.create_binary_clause(-vars[j], s0j);
107
107
 
108
108
  // main part, i.e. when 0 <= k < tval - 1:
109
109
  for (int k = 0; k < tval - 1; ++k) {
110
110
  // eq 18:
111
- int skj = mk_yvar(top_id, p2i_map, make_pair(k, j));
111
+ int skj = mk_yvar(top_id, p2i_map, make_pair(k + 1, j + 1));
112
112
  if (j < vars.size() - tval - 1) {
113
- int skj1 = mk_yvar(top_id, p2i_map, make_pair(k, j + 1));
113
+ int skj1 = mk_yvar(top_id, p2i_map, make_pair(k + 1, j + 2));
114
114
  clset.create_binary_clause(-skj, skj1);
115
115
  }
116
116
 
117
117
  // eq 19:
118
- int sk1j = mk_yvar(top_id, p2i_map, make_pair(k + 1, j));
118
+ int sk1j = mk_yvar(top_id, p2i_map, make_pair(k + 2, j + 1));
119
119
  clset.create_ternary_clause(-vars[j + k + 1], -skj, sk1j);
120
120
  }
121
121
 
122
122
  // k = tval - 1, eq 18:
123
- int stj = mk_yvar(top_id, p2i_map, make_pair(tval - 1, j));
123
+ int stj = mk_yvar(top_id, p2i_map, make_pair(tval, j + 1));
124
124
  if (j < vars.size() - tval - 1) {
125
- int stj1 = mk_yvar(top_id, p2i_map, make_pair(tval - 1, j + 1));
125
+ int stj1 = mk_yvar(top_id, p2i_map, make_pair(tval, j + 2));
126
126
  clset.create_binary_clause(-stj, stj1);
127
127
  }
128
128
 
@@ -253,7 +253,7 @@ class BBScan:
253
253
 
254
254
  if isinstance(chunk_size, float):
255
255
  assert 0 < chunk_size <= 1, f'Wrong chunk proportion {chunk_size}'
256
- chunk_size = int(min(self.formula.nv, len(self.model)) * chunk_size)
256
+ chunk_size = max(1, int(min(self.formula.nv, len(self.model)) * chunk_size))
257
257
 
258
258
  if algorithm == 'enum':
259
259
  result = self._compute_enum()
@@ -270,33 +270,28 @@ class BBScan:
270
270
  else:
271
271
  assert 0, f'Unknown algorithm: {algorithm}'
272
272
 
273
- return sorted(trivial + result, key=lambda l: abs(l))
273
+ return sorted(trivial + result, key=abs)
274
274
 
275
275
  def _filter_rotatable(self, model):
276
276
  """
277
277
  Filter out rotatable literals.
278
278
  """
279
279
 
280
- def get_unit(cl):
281
- # this is supposed to be a faster alternative to the
282
- # complete clause traversal with a conditional inside
283
- unit = None
284
- for l in cl:
285
- if l in model:
286
- if unit:
287
- return
288
- else:
289
- unit = l
290
- return unit
291
-
292
280
  # result of this procedure
293
- units = set([])
281
+ units, clauses = set(), self.formula.clauses
294
282
 
295
- # determining unit literals
283
+ # determining unit literals, i.e. the only literals of the model
284
+ # satisfying a clause; traversal stops at a second such literal
296
285
  for i in self.focuscl:
297
- unit = get_unit(self.formula.clauses[i])
298
- if unit:
299
- units.add(unit)
286
+ unit = None
287
+ for l in clauses[i]:
288
+ if l in model:
289
+ if unit:
290
+ break
291
+ unit = l
292
+ else:
293
+ if unit:
294
+ units.add(unit)
300
295
 
301
296
  self.filtered += len(model) - len(units)
302
297
  return units
@@ -320,8 +315,10 @@ class BBScan:
320
315
  if not self.oracle.solve():
321
316
  break
322
317
 
323
- # updating backbone estimate - intersection
324
- bbone &= set(self.oracle.get_model())
318
+ # updating backbone estimate - intersection; checking the
319
+ # estimate's literals only, rather than the entire model
320
+ m = self.oracle.get_model()
321
+ bbone = {l for l in bbone if m[abs(l) - 1] == l}
325
322
 
326
323
  if self.rotate:
327
324
  bbone = self._filter_rotatable(bbone)
@@ -356,7 +353,8 @@ class BBScan:
356
353
  else:
357
354
  # it isn't and we've got a counterexample
358
355
  # => using it to filter out more literals
359
- model &= set(self.oracle.get_model())
356
+ m = self.oracle.get_model()
357
+ model = {l for l in model if m[abs(l) - 1] == l}
360
358
 
361
359
  if self.rotate:
362
360
  model = self._filter_rotatable(model)
@@ -385,7 +383,8 @@ class BBScan:
385
383
  if self.oracle.solve() == False:
386
384
  break
387
385
  else:
388
- bbone &= set(self.oracle.get_model())
386
+ m = self.oracle.get_model()
387
+ bbone = {l for l in bbone if m[abs(l) - 1] == l}
389
388
 
390
389
  if self.rotate:
391
390
  bbone = self._filter_rotatable(bbone)
@@ -425,8 +424,8 @@ class BBScan:
425
424
  bbone.append(lit)
426
425
  self.oracle.add_clause([lit])
427
426
  else:
428
- coex = set(self.oracle.get_model())
429
- model = [l for l in model if l in coex]
427
+ coex = self.oracle.get_model()
428
+ model = [l for l in model if coex[abs(l) - 1] == l]
430
429
 
431
430
  if self.rotate:
432
431
  model = list(self._filter_rotatable(set(model)))
@@ -455,7 +454,8 @@ class BBScan:
455
454
  self.calls += 1
456
455
 
457
456
  if self.oracle.solve(assumptions=assumps):
458
- model &= set(self.oracle.get_model())
457
+ m = self.oracle.get_model()
458
+ model = {l for l in model if m[abs(l) - 1] == l}
459
459
 
460
460
  if self.rotate:
461
461
  model = self._filter_rotatable(model)
@@ -507,8 +507,8 @@ class BBScan:
507
507
  self.calls += 1
508
508
 
509
509
  if self.oracle.solve(assumptions=assumps):
510
- coex = set(self.oracle.get_model())
511
- model = [l for l in model if l in coex]
510
+ coex = self.oracle.get_model()
511
+ model = [l for l in model if coex[abs(l) - 1] == l]
512
512
 
513
513
  if self.rotate:
514
514
  model = list(self._filter_rotatable(set(model)))
@@ -531,13 +531,13 @@ class Hitman(object):
531
531
 
532
532
  if model is not None:
533
533
  if self.htype in ('rc2', 'sat'):
534
- # extracting a hitting set; the use of map may look
534
+ # extracting a hitting set; the use of abs may look
535
535
  # silly but this is to support negative phases too
536
- self.hset = map(lambda v: abs(v), filter(lambda v: v * self.phase > 0, model))
536
+ self.hset = [abs(v) for v in model if v * self.phase > 0]
537
537
  else:
538
538
  self.hset = model
539
539
 
540
- return list(map(lambda vid: self.idpool.id2obj[vid], self.hset))
540
+ return [self.idpool.id2obj[vid] for vid in self.hset]
541
541
 
542
542
  def hit(self, to_hit, weights=None):
543
543
  """
@@ -409,7 +409,7 @@ class LBX(object):
409
409
  self.satc[i] = True
410
410
  self.ss_assumps.append(self.sels[i])
411
411
  else:
412
- setd = setd.union(set(cl))
412
+ setd.update(cl)
413
413
 
414
414
  if update_setd:
415
415
  self.setd = sorted(setd)
@@ -164,8 +164,8 @@ class LSU:
164
164
  # (ITotalizer must be extended to support PB constraints first)
165
165
  self.topv += 1
166
166
  selv = self.topv
167
- cl.append(self.topv)
168
- self.oracle.add_clause(cl)
167
+ # the selector is added to a copy: the input formula must stay intact
168
+ self.oracle.add_clause(cl + [self.topv])
169
169
  self.sels.append(selv)
170
170
 
171
171
  if self.verbose > 1:
@@ -285,7 +285,7 @@ class LSU:
285
285
  cost = 0
286
286
 
287
287
  for i, cl in enumerate(formula.soft):
288
- cost += formula.wght[i] if all(l not in model_set for l in filter(lambda l: abs(l) <= self.formula.nv, cl)) else 0
288
+ cost += formula.wght[i] if all(l not in model_set for l in cl) else 0
289
289
 
290
290
  return cost
291
291
 
@@ -175,7 +175,9 @@ class MCSls(object):
175
175
 
176
176
  for cl in formula.soft:
177
177
  new_cl = cl[:]
178
- if len(cl) > 1 or cl[0] < 0:
178
+ # a unit soft clause can serve as its own selector unless an
179
+ # identical one has already taken it (selectors must be unique)
180
+ if len(cl) > 1 or cl[0] < 0 or cl[0] in self.smap:
179
181
  self.topv += 1
180
182
  sel = self.topv
181
183
 
@@ -277,7 +279,7 @@ class MCSls(object):
277
279
  else:
278
280
  # soft clauses should be augmented with a selector
279
281
  sel = cl[0]
280
- if len(cl) > 1 or cl[0] < 0:
282
+ if len(cl) > 1 or cl[0] < 0 or cl[0] in self.smap:
281
283
  self.topv += 1
282
284
  sel = self.topv
283
285
 
@@ -244,6 +244,9 @@ class OptUx(object):
244
244
  Constructor.
245
245
  """
246
246
 
247
+ # the oracles
248
+ self.hitman, self.oracle = None, None
249
+
247
250
  assert not puresat or unsorted, '\'unsorted\' needs to be True for pure SAT mode'
248
251
 
249
252
  # verbosity level
@@ -479,6 +482,10 @@ class OptUx(object):
479
482
  # extracting the MCS corresponding to the model
480
483
  falsified = [l for l in self.sels if model[abs(l) - 1] == -l]
481
484
 
485
+ if not falsified:
486
+ # all soft clauses are satisfiable => no more MCSes
487
+ break
488
+
482
489
  # unit size or not?
483
490
  if len(falsified) > 1:
484
491
  to_hit.append(falsified)
@@ -516,13 +523,14 @@ class OptUx(object):
516
523
  while True:
517
524
  # computing a new optimal hitting set
518
525
  hs = self.hitman.get()
519
- if self.verbose > 3:
520
- self.cost = sum(map(lambda l: self.weights[l], hs)) + units_cost
521
526
 
522
527
  if hs is None:
523
528
  # no more hitting sets exist
524
529
  break
525
530
 
531
+ if self.verbose > 3:
532
+ self.cost = sum(map(lambda l: self.weights[l], hs)) + units_cost
533
+
526
534
  # setting all the selector polarities to true
527
535
  self.oracle.set_phases(self.sels)
528
536
 
@@ -228,6 +228,9 @@ class Primer:
228
228
  # number of SAT oracle calls
229
229
  self.calls = 0
230
230
 
231
+ # the oracles
232
+ self.hitman, self.checker, self.reducer = None, None, None
233
+
231
234
  # creating hitman
232
235
  if not unsorted:
233
236
  # MaxSAT-based hitting set enumerator
@@ -134,7 +134,7 @@ from __future__ import print_function
134
134
  import bisect
135
135
  import collections
136
136
  import getopt
137
- from math import copysign
137
+ import heapq
138
138
  import os
139
139
  from pysat.formula import CNFPlus, WCNFPlus, IDPool
140
140
  from pysat.card import ITotalizer
@@ -573,9 +573,8 @@ class RC2(object):
573
573
  if self.processor:
574
574
  self.model = self.processor.restore(self.model)
575
575
 
576
- self.model = filter(lambda l: abs(l) in self.vmap.i2e, self.model)
577
- self.model = map(lambda l: int(copysign(self.vmap.i2e[abs(l)], l)), self.model)
578
- self.model = sorted(self.model, key=lambda l: abs(l))
576
+ self.model = [self.vmap.i2e[l] if l > 0 else -self.vmap.i2e[-l] for l in self.model if abs(l) in self.vmap.i2e]
577
+ self.model.sort(key=abs)
579
578
 
580
579
  return self.model
581
580
 
@@ -873,11 +872,11 @@ class RC2(object):
873
872
  del neigh[j:]
874
873
 
875
874
  if confl:
876
- # processing unit size cores
875
+ # processing unit size cores; each is immediately hardened
877
876
  for l in confl:
878
- self.core, self.minw = [l], self.wght[l]
879
- self.core_sels, self.core_sums = [l], []
880
- self.process_core()
877
+ self.cost += self.wght[l]
878
+ self.oracle.add_clause([-l])
879
+ self.garbage.add(l)
881
880
 
882
881
  if self.verbose > 1:
883
882
  print('c unit cores found: {0}; cost: {1}'.format(len(confl),
@@ -902,8 +901,17 @@ class RC2(object):
902
901
  nof_am1 = 0
903
902
  len_am1 = []
904
903
 
904
+ # literals ordered by their current degree; an entry is outdated
905
+ # (and skipped) if its literal is gone or its degree has changed
906
+ heap = [(degree[l], l) for l in lits]
907
+ heapq.heapify(heap)
908
+
905
909
  while lits:
906
- am1 = [min(lits, key=lambda l: degree[l])]
910
+ d, l = heapq.heappop(heap)
911
+ if l not in lits or d != degree[l]:
912
+ continue
913
+
914
+ am1 = [l]
907
915
 
908
916
  for l in sorted(conns[am1[0]], key=lambda l: degree.get(l, 0)):
909
917
  if l in lits:
@@ -924,6 +932,7 @@ class RC2(object):
924
932
  for l2 in conns.get(l, []):
925
933
  if l2 in lits:
926
934
  degree[l2] -= 1
935
+ heapq.heappush(heap, (degree[l2], l2))
927
936
 
928
937
  if len(am1) > 1:
929
938
  # treat the new atmost1 relation
@@ -931,6 +940,9 @@ class RC2(object):
931
940
  nof_am1 += 1
932
941
  len_am1.append(len(am1))
933
942
 
943
+ # removing unnecessary assumptions (once for all the AM1s)
944
+ self.filter_assumps()
945
+
934
946
  # updating the set of selectors
935
947
  self.sels_set = set(self.sels)
936
948
 
@@ -990,9 +1002,6 @@ class RC2(object):
990
1002
  self.wght[selv] = self.minw
991
1003
  self.smap[selv] = len(self.wght) - 1
992
1004
 
993
- # removing unnecessary assumptions
994
- self.filter_assumps()
995
-
996
1005
  def trim_core(self):
997
1006
  """
998
1007
  This method trims a previously extracted unsatisfiable
@@ -1316,6 +1325,9 @@ class RC2(object):
1316
1325
  :func:`process_sels`, and :func:`process_sums`.
1317
1326
  """
1318
1327
 
1328
+ if not self.garbage:
1329
+ return
1330
+
1319
1331
  # updating the list of selectors and sums
1320
1332
  self.sels = [l for l in self.sels if l not in self.garbage]
1321
1333
  self.sums = [l for l in self.sums if l not in self.garbage]
@@ -1363,14 +1375,14 @@ class RC2(object):
1363
1375
  v = abs(l)
1364
1376
 
1365
1377
  if v in self.vmap.e2i:
1366
- return int(copysign(self.vmap.e2i[v], l))
1378
+ return self.vmap.e2i[v] if l > 0 else -self.vmap.e2i[v]
1367
1379
  else:
1368
1380
  i = self.pool.id()
1369
1381
 
1370
1382
  self.vmap.e2i[v] = i
1371
1383
  self.vmap.i2e[i] = v
1372
1384
 
1373
- return int(copysign(i, l))
1385
+ return i if l > 0 else -i
1374
1386
 
1375
1387
  def interrupt(self):
1376
1388
  """
@@ -1591,9 +1603,8 @@ class RC2Stratified(RC2, object):
1591
1603
  if self.processor:
1592
1604
  self.model = self.processor.restore(self.model)
1593
1605
 
1594
- self.model = filter(lambda l: abs(l) in self.vmap.i2e, self.model)
1595
- self.model = map(lambda l: int(copysign(self.vmap.i2e[abs(l)], l)), self.model)
1596
- self.model = sorted(self.model, key=lambda l: abs(l))
1606
+ self.model = [self.vmap.i2e[l] if l > 0 else -self.vmap.i2e[-l] for l in self.model if abs(l) in self.vmap.i2e]
1607
+ self.model.sort(key=abs)
1597
1608
 
1598
1609
  return self.model
1599
1610
 
@@ -1621,16 +1632,20 @@ class RC2Stratified(RC2, object):
1621
1632
  # cluster of weights to build (if needed)
1622
1633
  cluster = [self.levl]
1623
1634
 
1635
+ # number of selectors with weight less than current weight
1636
+ numr = sum([len(self.wstr[w]) for w in self.blop[(self.levl + 1):]])
1637
+
1638
+ # sum of their weights
1639
+ sumr = sum([w * len(self.wstr[w]) for w in self.blop[(self.levl + 1):]])
1640
+
1641
+ # number of selectors in the cluster and the sum of their weights
1642
+ numc = len(self.wstr[self.blop[self.levl]])
1643
+ sumc = self.blop[self.levl] * numc
1644
+
1624
1645
  while self.levl < len(self.blop) - 1:
1625
1646
  # current weight
1626
1647
  wght = self.blop[self.levl]
1627
1648
 
1628
- # number of selectors with weight less than current weight
1629
- numr = sum([len(self.wstr[w]) for w in self.blop[(self.levl + 1):]])
1630
-
1631
- # sum of their weights
1632
- sumr = sum([w * len(self.wstr[w]) for w in self.blop[(self.levl + 1):]])
1633
-
1634
1649
  # partial BLO
1635
1650
  if wght > sumr and sumr != 0:
1636
1651
  break
@@ -1640,13 +1655,11 @@ class RC2Stratified(RC2, object):
1640
1655
  break
1641
1656
 
1642
1657
  # last resort = cluster-based stratification
1658
+ # note that the starting level is added to the cluster twice
1643
1659
  if clu_str:
1644
1660
  # is the distance from current weight to the cluster
1645
1661
  # being built larger than the distance to the mean of
1646
1662
  # smaller weights?
1647
- numc = sum([len(self.wstr[self.blop[l]]) for l in cluster])
1648
- sumc = sum([self.blop[l] * len(self.wstr[self.blop[l]]) for l in cluster])
1649
-
1650
1663
  if abs(wght - sumc / numc) > abs(wght - sumr / numr):
1651
1664
  # remaining weights are too far from the cluster; stop
1652
1665
  # here and report the splitting to be last-added weight
@@ -1654,9 +1667,15 @@ class RC2Stratified(RC2, object):
1654
1667
  break
1655
1668
 
1656
1669
  cluster.append(self.levl)
1670
+ numc += len(self.wstr[wght])
1671
+ sumc += wght * len(self.wstr[wght])
1657
1672
 
1658
1673
  self.levl += 1
1659
1674
 
1675
+ # the new level's selectors are no longer among the smaller ones
1676
+ numr -= len(self.wstr[self.blop[self.levl]])
1677
+ sumr -= self.blop[self.levl] * len(self.wstr[self.blop[self.levl]])
1678
+
1660
1679
  def activate_clauses(self, beg):
1661
1680
  """
1662
1681
  This method is used for activating the clauses that belong
@@ -1726,9 +1745,6 @@ class RC2Stratified(RC2, object):
1726
1745
  this.
1727
1746
  """
1728
1747
 
1729
- # assumptions to remove
1730
- self.garbage = set()
1731
-
1732
1748
  # clauses to deactivate
1733
1749
  to_deactivate = set([])
1734
1750
 
@@ -1773,10 +1789,8 @@ class RC2Stratified(RC2, object):
1773
1789
  to_deactivate.add(l)
1774
1790
 
1775
1791
  # deactivating unnecessary selectors
1776
- self.sels = [l for l in self.sels if l not in to_deactivate]
1777
-
1778
- # removing unnecessary assumptions
1779
- self.filter_assumps()
1792
+ if to_deactivate:
1793
+ self.sels = [l for l in self.sels if l not in to_deactivate]
1780
1794
 
1781
1795
  def process_sels(self):
1782
1796
  """
@@ -1813,7 +1827,8 @@ class RC2Stratified(RC2, object):
1813
1827
  self.rels.append(-l)
1814
1828
 
1815
1829
  # deactivating unnecessary selectors
1816
- self.sels = [l for l in self.sels if l not in to_deactivate]
1830
+ if to_deactivate:
1831
+ self.sels = [l for l in self.sels if l not in to_deactivate]
1817
1832
 
1818
1833
  def process_sums(self):
1819
1834
  """
@@ -1856,7 +1871,8 @@ class RC2Stratified(RC2, object):
1856
1871
  self.rels.append(-l)
1857
1872
 
1858
1873
  # deactivating unnecessary sums
1859
- self.sums = [l for l in self.sums if l not in to_deactivate]
1874
+ if to_deactivate:
1875
+ self.sums = [l for l in self.sums if l not in to_deactivate]
1860
1876
 
1861
1877
 
1862
1878
  #
@@ -10,7 +10,7 @@
10
10
 
11
11
  # current version
12
12
  #==============================================================================
13
- VERSION = (1, 9, 'dev', 24)
13
+ VERSION = (1, 9, 'dev', 26)
14
14
 
15
15
 
16
16
  # PEP440 Format
@@ -21,4 +21,5 @@ __version__ = '%d.%d.%s%d' % VERSION if len(VERSION) == 4 else \
21
21
 
22
22
  # all submodules
23
23
  #==============================================================================
24
- __all__ = ['card', 'engines', 'formula', 'integer', 'pb', 'process', 'solvers']
24
+ __all__ = ['card', 'engines', 'formula', 'integer', 'pb', 'process', 'solvers',
25
+ 'vector']
@@ -95,7 +95,6 @@
95
95
 
96
96
  #
97
97
  #==============================================================================
98
- import math
99
98
  from pysat.formula import CNF, CNFPlus, IDPool
100
99
  from pysat._utils import MainThread
101
100
  import pycard
@@ -226,13 +225,16 @@ class CardEnc(object):
226
225
  vpool.top = max(vpool.top, cnf.nv)
227
226
  return
228
227
 
229
- # mapping each auxiliary variable to a free id,
230
- # taking into account variables marked as "occupied"
231
- vmap = {var: vpool._next() for var in range(top + 1, cnf.nv + 1)}
228
+ # mapping each auxiliary variable to a free id, taking into
229
+ # account variables marked as "occupied"; both signs are mapped
230
+ vmap = {}
231
+ for var in range(top + 1, cnf.nv + 1):
232
+ vmap[var] = vpool._next()
233
+ vmap[-var] = -vmap[var]
232
234
 
233
235
  # updating the clauses
234
236
  for cl in cnf.clauses:
235
- cl[:] = map(lambda l: int(math.copysign(vmap[abs(l)], l)) if abs(l) in vmap else l, cl)
237
+ cl[:] = [vmap.get(l, l) for l in cl]
236
238
 
237
239
  # updating the number of variables
238
240
  cnf.nv = vpool.top
@@ -250,6 +252,9 @@ class CardEnc(object):
250
252
  if encoding < 0 or encoding > 9:
251
253
  raise(NoSuchEncodingError(encoding))
252
254
 
255
+ # making sure we are dealing with a list of literals
256
+ lits = list(lits)
257
+
253
258
  # checking if the bound is meaningless for any encoding
254
259
  if bound < 0:
255
260
  raise ValueError('Wrong bound: {0}'.format(bound))
@@ -271,11 +276,8 @@ class CardEnc(object):
271
276
  if vpool:
272
277
  top_id = vpool.top
273
278
 
274
- # making sure we are dealing with a list of literals
275
- lits = list(lits)
276
-
277
279
  # choosing the maximum id among the current top and the list of literals
278
- top_id = max(map(lambda x: abs(x), lits + [top_id if top_id != None else 0]))
280
+ top_id = max(map(abs, lits + [top_id if top_id != None else 0]))
279
281
 
280
282
  # MiniCard's native representation is handled separately
281
283
  if encoding == 9:
@@ -346,6 +348,9 @@ class CardEnc(object):
346
348
  if encoding < 0 or encoding > 9:
347
349
  raise(NoSuchEncodingError(encoding))
348
350
 
351
+ # making sure we are dealing with a list of literals
352
+ lits = list(lits)
353
+
349
354
  # checking if the bound is meaningless for any encoding
350
355
  if bound > len(lits):
351
356
  raise ValueError('Wrong bound: {0}'.format(bound))
@@ -367,11 +372,8 @@ class CardEnc(object):
367
372
  if vpool:
368
373
  top_id = vpool.top
369
374
 
370
- # making sure we are dealing with a list of literals
371
- lits = list(lits)
372
-
373
375
  # choosing the maximum id among the current top and the list of literals
374
- top_id = max(map(lambda x: abs(x), lits + [top_id if top_id != None else 0]))
376
+ top_id = max(map(abs, lits + [top_id if top_id != None else 0]))
375
377
 
376
378
  # Minicard's native representation is handled separately
377
379
  if encoding == 9:
@@ -401,6 +403,9 @@ class CardEnc(object):
401
403
  with method :meth:`CardEnc.atleast`. Please, see it for details.
402
404
  """
403
405
 
406
+ # making sure we are dealing with a list of literals
407
+ lits = list(lits)
408
+
404
409
  if vpool:
405
410
  res1 = cls.atleast(lits, bound=bound, vpool=vpool, encoding=encoding)
406
411
  res2 = cls.atmost(lits, bound=bound, vpool=vpool, encoding=encoding)
@@ -510,7 +515,7 @@ class ITotalizer(object):
510
515
 
511
516
  self.lits = list(lits)
512
517
  self.ubound = ubound
513
- self.top_id = max(map(lambda x: abs(x), self.lits + [top_id if top_id != None else 0]))
518
+ self.top_id = max(map(abs, self.lits + [top_id if top_id != None else 0]))
514
519
 
515
520
  # creating the object
516
521
  self.tobj, clauses, self.rhs, self.top_id = pycard.itot_new(self.lits,
@@ -682,7 +687,7 @@ class ITotalizer(object):
682
687
  """
683
688
 
684
689
  # preparing a new list of distinct input literals
685
- lits = sorted(set(lits).difference(set(self.lits)))
690
+ lits = sorted(set(lits).difference(self.lits))
686
691
 
687
692
  if not lits:
688
693
  # nothing to merge with -> just increase the bound
@@ -691,7 +696,7 @@ class ITotalizer(object):
691
696
 
692
697
  return
693
698
 
694
- self.top_id = max(map(lambda x: abs(x), self.lits + [self.top_id, top_id if top_id != None else 0]))
699
+ self.top_id = max(map(abs, lits + [self.top_id, top_id if top_id != None else 0]))
695
700
  self.ubound = max(self.ubound, ubound if ubound != None else 0)
696
701
 
697
702
  # updating the object and adding more variables and clauses
@@ -869,7 +874,7 @@ class ISeqCounter(object):
869
874
  """
870
875
 
871
876
  self.lits = list(lits)
872
- self.top_id = max(map(lambda x: abs(x), self.lits + [top_id if top_id != None else 0]))
877
+ self.top_id = max(map(abs, self.lits + [top_id if top_id != None else 0]))
873
878
 
874
879
  # Fail if the bound is negative. ITotalizer does not do this, but I am
875
880
  # not sure how or if it is handling it lower down the chain, so I will