Skip to content

Commit 313a9ba

Browse files
committed
update musx to beta
1 parent e4913e1 commit 313a9ba

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/advanced/musx.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
import sys
1010
import copy
1111
from cpmpy import *
12-
from cpmpy.solver_interfaces.ortools import CPMpyORTools
13-
from cpmpy.model_tools.get_variables import vars_expr
14-
from cpmpy.model_tools.flatten_model import flatten_constraint
12+
from cpmpy.solvers.ortools import CPM_ortools
13+
from cpmpy.transformations.get_variables import get_variables
14+
from cpmpy.transformations.flatten_model import flatten_constraint
1515

1616
def main():
17-
x, y = IntVar(-9,9, shape=2)
18-
m = Model([
17+
x, y = intvar(-9,9, shape=2)
18+
m = Model(
1919
x < 0,
2020
x < 1,
2121
x > 2,
2222
(x + y > 0) | (y < 0),
2323
(y >= 0) | (x >= 0),
2424
(y < 0) | (x < 0),
2525
(y > 0) | (x < 0),
26-
alldifferent([x,y]) # invalid for musx_assum
27-
])
26+
AllDifferent(x,y) # invalid for musx_assum
27+
)
2828
assert (m.solve() is False)
2929

3030
mus = musx(m.constraints, [], verbose=True)
@@ -49,7 +49,7 @@ def musx(soft_constraints, hard_constraints=[], verbose=False):
4949
# see if solver supports reification of 'con'
5050
try:
5151
m = Model([BoolVar().implies(con)])
52-
CPMpyORTools(m).solve()
52+
CPM_ortools(m).solve()
5353
# it did
5454
soft_assum.append(con)
5555
except:
@@ -82,7 +82,7 @@ def musx_pure(soft_constraints, hard_constraints=[], verbose=False):
8282
# this will favor MUS with few variables per constraint,
8383
# and will remove large constraints earlier which may speed it up
8484
# TODO: count nr of subexpressions? (generalisation of nr of vars)
85-
soft_constraints = sorted(soft_constraints, key=lambda c: -len(vars_expr(c)))
85+
soft_constraints = sorted(soft_constraints, key=lambda c: -len(get_variables(c)))
8686

8787
# small optimisation: pre-flatten all constraints once
8888
# so it needs not be done over-and-over in solving
@@ -97,12 +97,12 @@ def musx_pure(soft_constraints, hard_constraints=[], verbose=False):
9797
mus_idx = [] # index into 'soft_constraints' that belong to the MUS
9898

9999
# init solver with hard constraints
100-
#s_base = CPMpyORTools(Model(hard))
100+
#s_base = CPM_ortools(Model(hard))
101101
m_base = Model(hard)
102102
for i in range(len(soft_constraints)):
103103
#s_without_i = copy.deepcopy(s_base) # deep copy solver state
104104
# add all other remaining (flattened) constraints
105-
s_without_i = CPMpyORTools(m_base)
105+
s_without_i = CPM_ortools(m_base)
106106
s_without_i += soft[i+1:]
107107

108108
if s_without_i.solve():
@@ -148,7 +148,7 @@ def musx_assum(soft_constraints, hard_constraints=[], verbose=False):
148148
indmap = dict((v,i) for (i,v) in enumerate(ind))
149149

150150
# make solver once, check that it is unsat and start from core
151-
assum_solver = CPMpyORTools(assum_model)
151+
assum_solver = CPM_ortools(assum_model)
152152
if assum_solver.solve(assumptions=ind):
153153
if verbose:
154154
print("Unexpectedly, the model is SAT")

0 commit comments

Comments
 (0)