@@ -48,7 +48,7 @@ def musx(soft_constraints, hard_constraints=[], verbose=False):
48
48
for con in soft_constraints :
49
49
# see if solver supports reification of 'con'
50
50
try :
51
- m = Model (BoolVar ().implies (con ))
51
+ m = Model ([ BoolVar ().implies (con )] )
52
52
CPMpyORTools (m ).solve ()
53
53
# it did
54
54
soft_assum .append (con )
@@ -89,21 +89,28 @@ def musx_pure(soft_constraints, hard_constraints=[], verbose=False):
89
89
hard = flatten_constraint (hard_constraints ) # batch flatten
90
90
soft = [flatten_constraint (c ) for c in soft_constraints ]
91
91
92
+ if Model (hard + soft ).solve ():
93
+ if verbose :
94
+ print ("Unexpectedly, the model is SAT" )
95
+ return []
96
+
92
97
mus_idx = [] # index into 'soft_constraints' that belong to the MUS
93
98
94
99
# init solver with hard constraints
95
- s_base = CPMpyORTools (Model (hard ))
100
+ #s_base = CPMpyORTools(Model(hard))
101
+ m_base = Model (hard )
96
102
for i in range (len (soft_constraints )):
97
- s_without_i = copy .deepcopy (s_base ) # deep copy solver state
103
+ # s_without_i = copy.deepcopy(s_base) # deep copy solver state
98
104
# add all other remaining (flattened) constraints
105
+ s_without_i = CPMpyORTools (m_base )
99
106
s_without_i += soft [i + 1 :]
100
107
101
108
if s_without_i .solve ():
102
109
# with all but 'i' it is SAT, so 'i' belongs to the MUS
103
110
if verbose :
104
111
print ("\t SAT so in MUS:" , soft_constraints [i ])
105
112
mus_idx .append (i )
106
- s_base += [soft [i ]]
113
+ m_base += [soft [i ]]
107
114
else :
108
115
# still UNSAT, 'i' does not belong to the MUS
109
116
if verbose :
@@ -149,6 +156,8 @@ def musx_assum(soft_constraints, hard_constraints=[], verbose=False):
149
156
else :
150
157
# unsat core is an unsatisfiable subset
151
158
mus_vars = assum_solver .get_core ()
159
+ if verbose :
160
+ assert (not assum_solver .solve (assumptions = mus_vars )), "core is SAT!?"
152
161
153
162
# now we shrink the unsatisfiable subset further
154
163
i = 0 # we wil dynamically shrink mus_vars
0 commit comments