python-sat 1.9.dev23__tar.gz → 1.9.dev25__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.
- {python_sat-1.9.dev23/python_sat.egg-info → python_sat-1.9.dev25}/PKG-INFO +1 -1
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/seqcounter.hh +6 -6
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/bbscan.py +28 -28
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/hitman.py +3 -3
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/lbx.py +1 -1
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/models.py +13 -6
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/optux.py +10 -2
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/primer.py +3 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/rc2.py +51 -35
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/__init__.py +3 -2
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/card.py +22 -17
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/engines.py +49 -36
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/formula.py +150 -89
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/integer.py +13 -15
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/pb.py +1 -1
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/solvers.py +129 -424
- python_sat-1.9.dev25/pysat/vector.py +299 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25/python_sat.egg-info}/PKG-INFO +1 -1
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/python_sat.egg-info/SOURCES.txt +3 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/pysolvers.cc +347 -44
- python_sat-1.9.dev25/tests/test_projected_models.py +37 -0
- python_sat-1.9.dev25/tests/test_vector.py +278 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/LICENSE.txt +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/MANIFEST.in +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/README.rst +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/allies/__init__.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/allies/approxmc.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/allies/unigen.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/bitwise.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/card.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/clset.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/common.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/iseq.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/itot.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/ladder.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/mto.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/pairwise.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/ptypes.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/pycard.cc +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/sortcard.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/cardenc/utils.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/__init__.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/bica.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/fm.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/genhard.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/lsu.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/mcsls.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/musx.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/examples/usage.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_parse.cc +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_plus.cc +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_plus.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_py.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_scan.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_weight.cc +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pf_weight.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pyformula.cc +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/formula/pyformula.hh +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/_fileio.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/_utils.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/pysat/process.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/python_sat.egg-info/dependency_links.txt +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/python_sat.egg-info/requires.txt +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/python_sat.egg-info/top_level.txt +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/requirements.txt +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/setup.cfg +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/setup.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/cadical103.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/cadical153.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/cadical195.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/cadical300.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/ergo.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/glucose30.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/glucose41.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/glucose421.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/lingeling.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/maplechrono.zip +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/maplecm.zip +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/maplesat.zip +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/mergesat3.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/minicard.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/minisat22.tar.gz +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/minisatgh.zip +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/cadical103.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/cadical153.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/cadical195.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/cadical300.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/ergo.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/glucose30.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/glucose41.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/glucose421.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/gluecard30.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/gluecard41.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/kissat404.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/lingeling.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/maplechrono.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/maplecm.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/maplesat.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/mergesat3.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/minicard.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/minisat22.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/minisatep.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/patches/minisatgh.patch +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/solvers/prepare.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_accum_stats.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_activities.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_atmost.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_atmost1.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_atmostk.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_boolengine.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_clausification.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_cnf.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_empty_clause.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_empty_extclause.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_encode_pb_conditional.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_equals1.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_flip_bits.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_formula_parsing.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_formula_unique.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_hitman.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_idpool.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_integer.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_iseqcounter.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_lsu.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_oom.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_pb.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_process.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_proof.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_propagate.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_unique_model.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_unique_mus.py +0 -0
- {python_sat-1.9.dev23 → python_sat-1.9.dev25}/tests/test_warmstart.py +0 -0
|
@@ -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(
|
|
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 +
|
|
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 +
|
|
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
|
|
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
|
|
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=
|
|
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 =
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
429
|
-
model = [l for l in model if l
|
|
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
|
-
|
|
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 =
|
|
511
|
-
model = [l for l in model if l
|
|
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
|
|
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 =
|
|
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
|
|
540
|
+
return [self.idpool.id2obj[vid] for vid in self.hset]
|
|
541
541
|
|
|
542
542
|
def hit(self, to_hit, weights=None):
|
|
543
543
|
"""
|
|
@@ -66,7 +66,7 @@ import sys
|
|
|
66
66
|
|
|
67
67
|
#
|
|
68
68
|
#==============================================================================
|
|
69
|
-
def enumerate_models(formula, to_enum, solver, warm=False):
|
|
69
|
+
def enumerate_models(formula, to_enum, solver, warm=False, projection=[]):
|
|
70
70
|
"""
|
|
71
71
|
Enumeration procedure. It represents a loop iterating over satisfying
|
|
72
72
|
assignment for a given formula until either all or a given number of
|
|
@@ -76,11 +76,13 @@ def enumerate_models(formula, to_enum, solver, warm=False):
|
|
|
76
76
|
:param to_enum: number of models to compute
|
|
77
77
|
:param solver: name of SAT solver
|
|
78
78
|
:param warm: warm start flag
|
|
79
|
+
:param projection: optional variable IDs to enumerate
|
|
79
80
|
|
|
80
81
|
:type formula: :class:`.CNFPlus`
|
|
81
82
|
:type to_enum: int or 'all'
|
|
82
83
|
:type solver: str
|
|
83
84
|
:type warm: bool
|
|
85
|
+
:type projection: list(int)
|
|
84
86
|
"""
|
|
85
87
|
|
|
86
88
|
with Solver(name=solver, bootstrap_with=formula.clauses,
|
|
@@ -99,7 +101,7 @@ def enumerate_models(formula, to_enum, solver, warm=False):
|
|
|
99
101
|
|
|
100
102
|
# model enumeration and printing is done here
|
|
101
103
|
computed = 0
|
|
102
|
-
for i, model in enumerate(s.enum_models(), 1):
|
|
104
|
+
for i, model in enumerate(s.enum_models(projection=projection), 1):
|
|
103
105
|
print('v {0} 0'.format(' '.join(['{0}{1}'.format('+' if v > 0 else '', v) for v in model])))
|
|
104
106
|
|
|
105
107
|
computed = i
|
|
@@ -123,9 +125,10 @@ def parse_options():
|
|
|
123
125
|
|
|
124
126
|
try:
|
|
125
127
|
opts, args = getopt.getopt(sys.argv[1:],
|
|
126
|
-
'e:
|
|
128
|
+
'e:hp:s:w',
|
|
127
129
|
['enum=',
|
|
128
130
|
'help',
|
|
131
|
+
'project=',
|
|
129
132
|
'solver=',
|
|
130
133
|
'warm'])
|
|
131
134
|
except getopt.GetoptError as err:
|
|
@@ -136,6 +139,7 @@ def parse_options():
|
|
|
136
139
|
to_enum = 1
|
|
137
140
|
solver = 'g3'
|
|
138
141
|
warm = False
|
|
142
|
+
projection = []
|
|
139
143
|
|
|
140
144
|
for opt, arg in opts:
|
|
141
145
|
if opt in ('-e', '--enum'):
|
|
@@ -147,6 +151,8 @@ def parse_options():
|
|
|
147
151
|
elif opt in ('-h', '--help'):
|
|
148
152
|
usage()
|
|
149
153
|
sys.exit(0)
|
|
154
|
+
elif opt in ('-p', '--project'):
|
|
155
|
+
projection = [int(v) for v in arg.split(',')] if arg else []
|
|
150
156
|
elif opt in ('-s', '--solver'):
|
|
151
157
|
solver = str(arg)
|
|
152
158
|
elif opt in ('-w', '--warm'):
|
|
@@ -154,7 +160,7 @@ def parse_options():
|
|
|
154
160
|
else:
|
|
155
161
|
assert False, 'Unhandled option: {0} {1}'.format(opt, arg)
|
|
156
162
|
|
|
157
|
-
return to_enum, solver, warm, args
|
|
163
|
+
return to_enum, solver, warm, projection, args
|
|
158
164
|
|
|
159
165
|
|
|
160
166
|
#
|
|
@@ -169,6 +175,7 @@ def usage():
|
|
|
169
175
|
print(' -e, --enum=<int> Compute at most this number of models')
|
|
170
176
|
print(' Available values: [1 .. INT_MAX], all (default: 1)')
|
|
171
177
|
print(' -h, --help Show this message')
|
|
178
|
+
print(' -p, --project=<csv> Restrict models to these variables only (given as comma-separated integers)')
|
|
172
179
|
print(' -s, --solver=<string> SAT solver to use')
|
|
173
180
|
print(' Available values: cd, g3, g4, lgl, mcb, mcm, mpl, m22, mc, mgh (default = g3)')
|
|
174
181
|
print(' -w, --warm Use solver\'s warm start mode')
|
|
@@ -178,7 +185,7 @@ def usage():
|
|
|
178
185
|
#==============================================================================
|
|
179
186
|
if __name__ == '__main__':
|
|
180
187
|
# parsing command-line options
|
|
181
|
-
to_enum, solver, warm, files = parse_options()
|
|
188
|
+
to_enum, solver, warm, projection, files = parse_options()
|
|
182
189
|
|
|
183
190
|
# reading an input formula either from a file or from stdin
|
|
184
191
|
if files:
|
|
@@ -186,4 +193,4 @@ if __name__ == '__main__':
|
|
|
186
193
|
else:
|
|
187
194
|
formula = CNFPlus(from_fp=sys.stdin)
|
|
188
195
|
|
|
189
|
-
enumerate_models(formula, to_enum, solver, warm)
|
|
196
|
+
enumerate_models(formula, to_enum, solver, warm, projection)
|
|
@@ -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
|
|
|
@@ -134,7 +134,7 @@ from __future__ import print_function
|
|
|
134
134
|
import bisect
|
|
135
135
|
import collections
|
|
136
136
|
import getopt
|
|
137
|
-
|
|
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 =
|
|
577
|
-
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.
|
|
879
|
-
self.
|
|
880
|
-
self.
|
|
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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
1595
|
-
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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',
|
|
13
|
+
VERSION = (1, 9, 'dev', 25)
|
|
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']
|