python-sat 1.9.dev24__cp313-cp313-win_amd64.whl → 1.9.dev26__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 +55 -36
- pysat/examples/bbscan.py +28 -28
- pysat/examples/hitman.py +3 -3
- pysat/examples/lbx.py +1 -1
- pysat/examples/lsu.py +3 -3
- pysat/examples/mcsls.py +4 -2
- pysat/examples/optux.py +10 -2
- pysat/examples/primer.py +3 -0
- pysat/examples/rc2.py +51 -35
- pysat/formula.py +166 -97
- pysat/integer.py +123 -37
- pysat/pb.py +1 -1
- pysat/solvers.py +60 -60
- pysat/vector.py +299 -0
- pysolvers.cp313-win_amd64.pyd +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/bbscan.py +28 -28
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/lbx.py +1 -1
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/lsu.py +3 -3
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/mcsls.py +4 -2
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/optux.py +10 -2
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/primer.py +3 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/rc2.py +51 -35
- python_sat-1.9.dev26.dist-info/DELVEWHEEL +2 -0
- {python_sat-1.9.dev24.dist-info → python_sat-1.9.dev26.dist-info}/METADATA +1 -1
- python_sat-1.9.dev26.dist-info/RECORD +53 -0
- python_sat-1.9.dev24.dist-info/DELVEWHEEL +0 -2
- python_sat-1.9.dev24.dist-info/RECORD +0 -52
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/platlib/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/approxmc.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/bica.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/fm.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/genhard.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/models.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/musx.py +0 -0
- {python_sat-1.9.dev24.data → python_sat-1.9.dev26.data}/scripts/unigen.py +0 -0
- {python_sat-1.9.dev24.dist-info → python_sat-1.9.dev26.dist-info}/WHEEL +0 -0
- {python_sat-1.9.dev24.dist-info → python_sat-1.9.dev26.dist-info}/licenses/LICENSE.txt +0 -0
- {python_sat-1.9.dev24.dist-info → python_sat-1.9.dev26.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', 26)
|
|
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
|
|
|
@@ -174,7 +173,13 @@ class LinearConstraint:
|
|
|
174
173
|
|
|
175
174
|
if min(self.wght.values()) == max(self.wght.values()):
|
|
176
175
|
if self.wght[self.lits[0]] != 1:
|
|
176
|
+
unsat = self.rbnd < 0
|
|
177
177
|
self.rbnd //= self.wght[self.lits[0]]
|
|
178
|
+
|
|
179
|
+
# Decimal's // rounds towards zero, so a negative
|
|
180
|
+
# bound, i.e. an unsatisfiable constraint, may become 0
|
|
181
|
+
if unsat and self.rbnd >= 0:
|
|
182
|
+
self.rbnd = -1
|
|
178
183
|
self.wght = {l: 1 for l in lits}
|
|
179
184
|
|
|
180
185
|
# unweighted / cardinality propagation
|
|
@@ -189,6 +194,9 @@ class LinearConstraint:
|
|
|
189
194
|
# weighted / pseudo-Boolean propagation
|
|
190
195
|
self.propagate = self.propagate_weighted
|
|
191
196
|
|
|
197
|
+
# the largest weight, to quickly check if anything can propagate
|
|
198
|
+
self.wmax = max(self.wght.values())
|
|
199
|
+
|
|
192
200
|
# constraint may propagate different literals
|
|
193
201
|
# at different points in time, reasons may differ
|
|
194
202
|
self.expl = defaultdict(lambda: [])
|
|
@@ -229,9 +237,8 @@ class LinearConstraint:
|
|
|
229
237
|
self.vcnt += self.wght[lit]
|
|
230
238
|
|
|
231
239
|
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)
|
|
240
|
+
self.expl = [-l for l in self.lits if self.lval[abs(l)] == l]
|
|
241
|
+
to_entail = [-l for l in self.lits if self.lval[abs(l)] is None]
|
|
235
242
|
|
|
236
243
|
return to_entail
|
|
237
244
|
|
|
@@ -262,16 +269,21 @@ class LinearConstraint:
|
|
|
262
269
|
right-hand side of the constraint.
|
|
263
270
|
"""
|
|
264
271
|
|
|
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])
|
|
272
|
+
self.vcnt += self.wght[lit]
|
|
271
273
|
|
|
272
|
-
|
|
273
|
-
#
|
|
274
|
-
|
|
274
|
+
if not self.done and self.vcnt + self.wmax > self.rbnd:
|
|
275
|
+
# collecting the reason, the literals to propagate, and the number
|
|
276
|
+
# of unassigned literals, the latter is to check whether there is
|
|
277
|
+
# something left to do in the future
|
|
278
|
+
expl, to_entail, nunknown = [], [], 0
|
|
279
|
+
for l in self.lits:
|
|
280
|
+
val = self.lval[abs(l)]
|
|
281
|
+
if val == l:
|
|
282
|
+
expl.append(-l)
|
|
283
|
+
elif val is None:
|
|
284
|
+
nunknown += 1
|
|
285
|
+
if self.vcnt + self.wght[l] > self.rbnd and not self.expl[-l]:
|
|
286
|
+
to_entail.append(-l)
|
|
275
287
|
|
|
276
288
|
# are we done with constraint for now?
|
|
277
289
|
if len(to_entail) == nunknown:
|
|
@@ -317,10 +329,10 @@ class LinearConstraint:
|
|
|
317
329
|
Check if the constraint is violated by a given assignment. Upon
|
|
318
330
|
receiving such an input assignment, the method counts the sum of
|
|
319
331
|
the weights of all satisfied literals and checks if it exceeds the
|
|
320
|
-
right-hand side.
|
|
332
|
+
right-hand side. The assignment is expected as a set of literals.
|
|
321
333
|
"""
|
|
322
334
|
|
|
323
|
-
value =
|
|
335
|
+
value = sum([self.wght[l] for l in self.lits if l in model])
|
|
324
336
|
|
|
325
337
|
if value > self.rbnd:
|
|
326
338
|
self.fmod = model
|
|
@@ -334,7 +346,8 @@ class LinearConstraint:
|
|
|
334
346
|
the constraint. This will clause will be added to the solver.
|
|
335
347
|
"""
|
|
336
348
|
|
|
337
|
-
|
|
349
|
+
# literals are ordered by variable, as in the model
|
|
350
|
+
return sorted([-l for l in self.lits if l in self.fmod], key=abs)
|
|
338
351
|
|
|
339
352
|
|
|
340
353
|
#
|
|
@@ -510,10 +523,11 @@ class ParityConstraint:
|
|
|
510
523
|
"""
|
|
511
524
|
Check if the constraint is violated by a given assignment, which
|
|
512
525
|
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.
|
|
526
|
+
a model) and comparing with the right-hand side value. The
|
|
527
|
+
assignment is expected as a set of literals.
|
|
514
528
|
"""
|
|
515
529
|
|
|
516
|
-
value =
|
|
530
|
+
value = sum([1 for l in self.lits if l in model]) % 2
|
|
517
531
|
|
|
518
532
|
if value != self.rval:
|
|
519
533
|
self.fmod = model
|
|
@@ -527,7 +541,7 @@ class ParityConstraint:
|
|
|
527
541
|
the constraint. This will clause will be added to the solver.
|
|
528
542
|
"""
|
|
529
543
|
|
|
530
|
-
return [-l
|
|
544
|
+
return [-l if l in self.fmod else l for l in self.lits]
|
|
531
545
|
|
|
532
546
|
|
|
533
547
|
#
|
|
@@ -1094,14 +1108,16 @@ class BooleanEngine(Propagator):
|
|
|
1094
1108
|
Update the propagator's state given a new assignment.
|
|
1095
1109
|
"""
|
|
1096
1110
|
|
|
1111
|
+
var = abs(lit)
|
|
1112
|
+
|
|
1097
1113
|
if fixed:
|
|
1098
|
-
self.fixed[
|
|
1114
|
+
self.fixed[var] = True
|
|
1099
1115
|
|
|
1100
1116
|
# the solver may notify us again when an assigned literal gets fixed
|
|
1101
|
-
if self.level[
|
|
1117
|
+
if self.level[var] is not None:
|
|
1102
1118
|
return
|
|
1103
1119
|
|
|
1104
|
-
self.level[
|
|
1120
|
+
self.level[var] = self.decision_level
|
|
1105
1121
|
|
|
1106
1122
|
if self.qhead is None:
|
|
1107
1123
|
# this is the first assignment we get after backtracking
|
|
@@ -1124,29 +1140,29 @@ class BooleanEngine(Propagator):
|
|
|
1124
1140
|
"""
|
|
1125
1141
|
|
|
1126
1142
|
cursor = self.qhead
|
|
1143
|
+
trail, trlim, value, origin = self.trail, self.trlim, self.value, self.origin
|
|
1127
1144
|
|
|
1128
1145
|
# undoing the assignments
|
|
1129
|
-
while len(
|
|
1130
|
-
while len(
|
|
1131
|
-
lit =
|
|
1146
|
+
while len(trlim) > to:
|
|
1147
|
+
while len(trail) > trlim[-1]:
|
|
1148
|
+
lit = trail.pop()
|
|
1132
1149
|
var = abs(lit)
|
|
1133
1150
|
|
|
1134
|
-
if
|
|
1151
|
+
if value[var] is not None and not self.fixed[var]:
|
|
1135
1152
|
# informing all the constraints
|
|
1136
1153
|
for cs in self.wlst[lit]:
|
|
1137
1154
|
cs.unassign(lit)
|
|
1138
1155
|
|
|
1139
|
-
|
|
1156
|
+
value[var] = None
|
|
1140
1157
|
|
|
1141
1158
|
self.level[var] = None
|
|
1142
1159
|
|
|
1143
1160
|
# cleaning all the consequences
|
|
1144
|
-
for l in self.props[
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
self.props[lit] = []
|
|
1161
|
+
for l in self.props.pop(lit, []):
|
|
1162
|
+
origin[l].abandon(l)
|
|
1163
|
+
origin[l] = None
|
|
1148
1164
|
|
|
1149
|
-
|
|
1165
|
+
trlim.pop()
|
|
1150
1166
|
|
|
1151
1167
|
# updating decision level
|
|
1152
1168
|
self.decision_level = to
|
|
@@ -1161,6 +1177,9 @@ class BooleanEngine(Propagator):
|
|
|
1161
1177
|
|
|
1162
1178
|
st = True # no falsified constraints by default
|
|
1163
1179
|
|
|
1180
|
+
# constraints check literals for membership in the model
|
|
1181
|
+
model = set(model)
|
|
1182
|
+
|
|
1164
1183
|
# checking all constraints one by one
|
|
1165
1184
|
for cs in self.cons:
|
|
1166
1185
|
if cs.falsified_by(model):
|
|
@@ -1220,8 +1239,8 @@ class BooleanEngine(Propagator):
|
|
|
1220
1239
|
|
|
1221
1240
|
self.value[abs(lit)] = lit # actually setting the value
|
|
1222
1241
|
|
|
1223
|
-
watched_holes = []
|
|
1224
|
-
for csid, cs in enumerate(
|
|
1242
|
+
watched, watched_holes = self.wlst[lit], []
|
|
1243
|
+
for csid, cs in enumerate(watched):
|
|
1225
1244
|
# checking the constraint
|
|
1226
1245
|
propagated = cs.propagate(lit)
|
|
1227
1246
|
|
|
@@ -1238,10 +1257,10 @@ class BooleanEngine(Propagator):
|
|
|
1238
1257
|
self.props[lit].append(l)
|
|
1239
1258
|
|
|
1240
1259
|
# checking whether or not this cs is still watched
|
|
1241
|
-
if
|
|
1260
|
+
if watched[csid] is None or type(watched[csid]) == int:
|
|
1242
1261
|
# instead of cs, we have None or an integer, i.e. we
|
|
1243
1262
|
# removed cs from the watched list for this literal
|
|
1244
|
-
watched_holes.append((csid,
|
|
1263
|
+
watched_holes.append((csid, watched[csid]))
|
|
1245
1264
|
|
|
1246
1265
|
# cleaning up watches, should be more-or-less cheap,
|
|
1247
1266
|
# 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/lsu.py
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
pysat/examples/mcsls.py
CHANGED
|
@@ -175,7 +175,9 @@ class MCSls(object):
|
|
|
175
175
|
|
|
176
176
|
for cl in formula.soft:
|
|
177
177
|
new_cl = cl[:]
|
|
178
|
-
|
|
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
|
|
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