python-sat 1.9.dev23__cp313-cp313-win_amd64.whl → 1.9.dev25__cp313-cp313-win_amd64.whl
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.
- pycard.cp313-win_amd64.pyd +0 -0
- pyformula.cp313-win_amd64.pyd +0 -0
- pysat/__init__.py +3 -2
- pysat/card.py +22 -17
- pysat/engines.py +49 -36
- pysat/examples/bbscan.py +28 -28
- pysat/examples/hitman.py +3 -3
- pysat/examples/lbx.py +1 -1
- pysat/examples/models.py +13 -6
- pysat/examples/optux.py +10 -2
- pysat/examples/primer.py +3 -0
- pysat/examples/rc2.py +51 -35
- pysat/formula.py +150 -89
- pysat/integer.py +13 -15
- pysat/pb.py +1 -1
- pysat/solvers.py +129 -424
- pysat/vector.py +299 -0
- pysolvers.cp313-win_amd64.pyd +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/bbscan.py +28 -28
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/lbx.py +1 -1
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/models.py +13 -6
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/optux.py +10 -2
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/primer.py +3 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/rc2.py +51 -35
- python_sat-1.9.dev25.dist-info/DELVEWHEEL +2 -0
- {python_sat-1.9.dev23.dist-info → python_sat-1.9.dev25.dist-info}/METADATA +1 -1
- python_sat-1.9.dev25.dist-info/RECORD +53 -0
- python_sat-1.9.dev23.dist-info/DELVEWHEEL +0 -2
- python_sat-1.9.dev23.dist-info/RECORD +0 -52
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/platlib/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/approxmc.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/bica.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/fm.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/genhard.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/lsu.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/mcsls.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/musx.py +0 -0
- {python_sat-1.9.dev23.data → python_sat-1.9.dev25.data}/scripts/unigen.py +0 -0
- {python_sat-1.9.dev23.dist-info → python_sat-1.9.dev25.dist-info}/WHEEL +0 -0
- {python_sat-1.9.dev23.dist-info → python_sat-1.9.dev25.dist-info}/licenses/LICENSE.txt +0 -0
- {python_sat-1.9.dev23.dist-info → python_sat-1.9.dev25.dist-info}/top_level.txt +0 -0
pycard.cp313-win_amd64.pyd
CHANGED
|
Binary file
|
pyformula.cp313-win_amd64.pyd
CHANGED
|
Binary file
|
pysat/__init__.py
CHANGED
|
@@ -22,7 +22,7 @@ del _delvewheel_patch_1_13_2
|
|
|
22
22
|
|
|
23
23
|
# current version
|
|
24
24
|
#==============================================================================
|
|
25
|
-
VERSION = (1, 9, 'dev',
|
|
25
|
+
VERSION = (1, 9, 'dev', 25)
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# PEP440 Format
|
|
@@ -33,4 +33,5 @@ __version__ = '%d.%d.%s%d' % VERSION if len(VERSION) == 4 else \
|
|
|
33
33
|
|
|
34
34
|
# all submodules
|
|
35
35
|
#==============================================================================
|
|
36
|
-
__all__ = ['card', 'engines', 'formula', 'integer', 'pb', 'process', 'solvers'
|
|
36
|
+
__all__ = ['card', 'engines', 'formula', 'integer', 'pb', 'process', 'solvers',
|
|
37
|
+
'vector']
|
pysat/card.py
CHANGED
|
@@ -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
|
-
#
|
|
231
|
-
vmap = {
|
|
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[:] =
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
pysat/engines.py
CHANGED
|
@@ -90,7 +90,6 @@
|
|
|
90
90
|
#
|
|
91
91
|
#==============================================================================
|
|
92
92
|
from collections import Counter, defaultdict
|
|
93
|
-
import functools
|
|
94
93
|
import itertools
|
|
95
94
|
from typing import List
|
|
96
95
|
|
|
@@ -189,6 +188,9 @@ class LinearConstraint:
|
|
|
189
188
|
# weighted / pseudo-Boolean propagation
|
|
190
189
|
self.propagate = self.propagate_weighted
|
|
191
190
|
|
|
191
|
+
# the largest weight, to quickly check if anything can propagate
|
|
192
|
+
self.wmax = max(self.wght.values())
|
|
193
|
+
|
|
192
194
|
# constraint may propagate different literals
|
|
193
195
|
# at different points in time, reasons may differ
|
|
194
196
|
self.expl = defaultdict(lambda: [])
|
|
@@ -229,9 +231,8 @@ class LinearConstraint:
|
|
|
229
231
|
self.vcnt += self.wght[lit]
|
|
230
232
|
|
|
231
233
|
if self.vcnt == self.rbnd: # this is when we should propagate
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
to_entail = list(-l for l in iter2 if self.lval[abs(l)] is None)
|
|
234
|
+
self.expl = [-l for l in self.lits if self.lval[abs(l)] == l]
|
|
235
|
+
to_entail = [-l for l in self.lits if self.lval[abs(l)] is None]
|
|
235
236
|
|
|
236
237
|
return to_entail
|
|
237
238
|
|
|
@@ -262,16 +263,21 @@ class LinearConstraint:
|
|
|
262
263
|
right-hand side of the constraint.
|
|
263
264
|
"""
|
|
264
265
|
|
|
265
|
-
|
|
266
|
-
self.vcnt += self.wght[lit]
|
|
267
|
-
|
|
268
|
-
iter1, iter2, iter3 = itertools.tee(self.lits, 3)
|
|
269
|
-
expl = list(-l for l in iter1 if self.lval[abs(l)] == l)
|
|
270
|
-
to_entail = list(-l for l in iter2 if self.lval[abs(l)] is None and self.vcnt + self.wght[l] > self.rbnd and not self.expl[-l])
|
|
266
|
+
self.vcnt += self.wght[lit]
|
|
271
267
|
|
|
272
|
-
|
|
273
|
-
#
|
|
274
|
-
|
|
268
|
+
if not self.done and self.vcnt + self.wmax > self.rbnd:
|
|
269
|
+
# collecting the reason, the literals to propagate, and the number
|
|
270
|
+
# of unassigned literals, the latter is to check whether there is
|
|
271
|
+
# something left to do in the future
|
|
272
|
+
expl, to_entail, nunknown = [], [], 0
|
|
273
|
+
for l in self.lits:
|
|
274
|
+
val = self.lval[abs(l)]
|
|
275
|
+
if val == l:
|
|
276
|
+
expl.append(-l)
|
|
277
|
+
elif val is None:
|
|
278
|
+
nunknown += 1
|
|
279
|
+
if self.vcnt + self.wght[l] > self.rbnd and not self.expl[-l]:
|
|
280
|
+
to_entail.append(-l)
|
|
275
281
|
|
|
276
282
|
# are we done with constraint for now?
|
|
277
283
|
if len(to_entail) == nunknown:
|
|
@@ -317,10 +323,10 @@ class LinearConstraint:
|
|
|
317
323
|
Check if the constraint is violated by a given assignment. Upon
|
|
318
324
|
receiving such an input assignment, the method counts the sum of
|
|
319
325
|
the weights of all satisfied literals and checks if it exceeds the
|
|
320
|
-
right-hand side.
|
|
326
|
+
right-hand side. The assignment is expected as a set of literals.
|
|
321
327
|
"""
|
|
322
328
|
|
|
323
|
-
value =
|
|
329
|
+
value = sum([self.wght[l] for l in self.lits if l in model])
|
|
324
330
|
|
|
325
331
|
if value > self.rbnd:
|
|
326
332
|
self.fmod = model
|
|
@@ -334,7 +340,8 @@ class LinearConstraint:
|
|
|
334
340
|
the constraint. This will clause will be added to the solver.
|
|
335
341
|
"""
|
|
336
342
|
|
|
337
|
-
|
|
343
|
+
# literals are ordered by variable, as in the model
|
|
344
|
+
return sorted([-l for l in self.lits if l in self.fmod], key=abs)
|
|
338
345
|
|
|
339
346
|
|
|
340
347
|
#
|
|
@@ -510,10 +517,11 @@ class ParityConstraint:
|
|
|
510
517
|
"""
|
|
511
518
|
Check if the constraint is violated by a given assignment, which
|
|
512
519
|
is done by xor'ing up all the values on the left-hand side (given
|
|
513
|
-
a model) and comparing with the right-hand side value.
|
|
520
|
+
a model) and comparing with the right-hand side value. The
|
|
521
|
+
assignment is expected as a set of literals.
|
|
514
522
|
"""
|
|
515
523
|
|
|
516
|
-
value =
|
|
524
|
+
value = sum([1 for l in self.lits if l in model]) % 2
|
|
517
525
|
|
|
518
526
|
if value != self.rval:
|
|
519
527
|
self.fmod = model
|
|
@@ -527,7 +535,7 @@ class ParityConstraint:
|
|
|
527
535
|
the constraint. This will clause will be added to the solver.
|
|
528
536
|
"""
|
|
529
537
|
|
|
530
|
-
return [-l
|
|
538
|
+
return [-l if l in self.fmod else l for l in self.lits]
|
|
531
539
|
|
|
532
540
|
|
|
533
541
|
#
|
|
@@ -1094,14 +1102,16 @@ class BooleanEngine(Propagator):
|
|
|
1094
1102
|
Update the propagator's state given a new assignment.
|
|
1095
1103
|
"""
|
|
1096
1104
|
|
|
1105
|
+
var = abs(lit)
|
|
1106
|
+
|
|
1097
1107
|
if fixed:
|
|
1098
|
-
self.fixed[
|
|
1108
|
+
self.fixed[var] = True
|
|
1099
1109
|
|
|
1100
1110
|
# the solver may notify us again when an assigned literal gets fixed
|
|
1101
|
-
if self.level[
|
|
1111
|
+
if self.level[var] is not None:
|
|
1102
1112
|
return
|
|
1103
1113
|
|
|
1104
|
-
self.level[
|
|
1114
|
+
self.level[var] = self.decision_level
|
|
1105
1115
|
|
|
1106
1116
|
if self.qhead is None:
|
|
1107
1117
|
# this is the first assignment we get after backtracking
|
|
@@ -1124,29 +1134,29 @@ class BooleanEngine(Propagator):
|
|
|
1124
1134
|
"""
|
|
1125
1135
|
|
|
1126
1136
|
cursor = self.qhead
|
|
1137
|
+
trail, trlim, value, origin = self.trail, self.trlim, self.value, self.origin
|
|
1127
1138
|
|
|
1128
1139
|
# undoing the assignments
|
|
1129
|
-
while len(
|
|
1130
|
-
while len(
|
|
1131
|
-
lit =
|
|
1140
|
+
while len(trlim) > to:
|
|
1141
|
+
while len(trail) > trlim[-1]:
|
|
1142
|
+
lit = trail.pop()
|
|
1132
1143
|
var = abs(lit)
|
|
1133
1144
|
|
|
1134
|
-
if
|
|
1145
|
+
if value[var] is not None and not self.fixed[var]:
|
|
1135
1146
|
# informing all the constraints
|
|
1136
1147
|
for cs in self.wlst[lit]:
|
|
1137
1148
|
cs.unassign(lit)
|
|
1138
1149
|
|
|
1139
|
-
|
|
1150
|
+
value[var] = None
|
|
1140
1151
|
|
|
1141
1152
|
self.level[var] = None
|
|
1142
1153
|
|
|
1143
1154
|
# cleaning all the consequences
|
|
1144
|
-
for l in self.props[
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
self.props[lit] = []
|
|
1155
|
+
for l in self.props.pop(lit, []):
|
|
1156
|
+
origin[l].abandon(l)
|
|
1157
|
+
origin[l] = None
|
|
1148
1158
|
|
|
1149
|
-
|
|
1159
|
+
trlim.pop()
|
|
1150
1160
|
|
|
1151
1161
|
# updating decision level
|
|
1152
1162
|
self.decision_level = to
|
|
@@ -1161,6 +1171,9 @@ class BooleanEngine(Propagator):
|
|
|
1161
1171
|
|
|
1162
1172
|
st = True # no falsified constraints by default
|
|
1163
1173
|
|
|
1174
|
+
# constraints check literals for membership in the model
|
|
1175
|
+
model = set(model)
|
|
1176
|
+
|
|
1164
1177
|
# checking all constraints one by one
|
|
1165
1178
|
for cs in self.cons:
|
|
1166
1179
|
if cs.falsified_by(model):
|
|
@@ -1220,8 +1233,8 @@ class BooleanEngine(Propagator):
|
|
|
1220
1233
|
|
|
1221
1234
|
self.value[abs(lit)] = lit # actually setting the value
|
|
1222
1235
|
|
|
1223
|
-
watched_holes = []
|
|
1224
|
-
for csid, cs in enumerate(
|
|
1236
|
+
watched, watched_holes = self.wlst[lit], []
|
|
1237
|
+
for csid, cs in enumerate(watched):
|
|
1225
1238
|
# checking the constraint
|
|
1226
1239
|
propagated = cs.propagate(lit)
|
|
1227
1240
|
|
|
@@ -1238,10 +1251,10 @@ class BooleanEngine(Propagator):
|
|
|
1238
1251
|
self.props[lit].append(l)
|
|
1239
1252
|
|
|
1240
1253
|
# checking whether or not this cs is still watched
|
|
1241
|
-
if
|
|
1254
|
+
if watched[csid] is None or type(watched[csid]) == int:
|
|
1242
1255
|
# instead of cs, we have None or an integer, i.e. we
|
|
1243
1256
|
# removed cs from the watched list for this literal
|
|
1244
|
-
watched_holes.append((csid,
|
|
1257
|
+
watched_holes.append((csid, watched[csid]))
|
|
1245
1258
|
|
|
1246
1259
|
# cleaning up watches, should be more-or-less cheap,
|
|
1247
1260
|
# doing so for +lit but also for -lit if it is affected
|
pysat/examples/bbscan.py
CHANGED
|
@@ -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)))
|
pysat/examples/hitman.py
CHANGED
|
@@ -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
|
"""
|
pysat/examples/lbx.py
CHANGED
pysat/examples/models.py
CHANGED
|
@@ -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)
|
pysat/examples/optux.py
CHANGED
|
@@ -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
|
|
pysat/examples/primer.py
CHANGED