Skip to content

Commit a827d26

Browse files
committed
Merge branch 'master' into indomain-second-arg
2 parents cb0ad18 + f501f15 commit a827d26

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cpmpy/expressions/globalconstraints.py

+6
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,9 @@ def decompose(self):
890890
"""
891891
X, Y = cpm_array(self.args)
892892

893+
if len(X) == 0 == len(Y):
894+
return [cp.BoolVal(False)], [] # based on the decomp, it's false...
895+
893896
bvar = boolvar(shape=(len(X) + 1))
894897

895898
# Constraint ensuring that each element in X is less than or equal to the corresponding element in Y,
@@ -936,6 +939,9 @@ def decompose(self):
936939
"""
937940
X, Y = cpm_array(self.args)
938941

942+
if len(X) == 0 == len(Y):
943+
return [cp.BoolVal(False)], [] # based on the decomp, it's false...
944+
939945
bvar = boolvar(shape=(len(X) + 1))
940946
defining = [bvar == ((X <= Y) & ((X < Y) | bvar[1:]))]
941947
defining.append(bvar[-1] == (X[-1] <= Y[-1]))

cpmpy/expressions/globalfunctions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def decompose_comparison(self, cmp_op, cpm_rhs):
395395
constraints = []
396396

397397
# introduce boolvar for each possible value
398-
bvars = boolvar(shape=(ub+1-lb))
398+
bvars = boolvar(shape=(ub+1-lb,)) # shape is tuple to ensure it is a 1D array
399399

400400
args = cpm_array(self.args)
401401
# bvar is true if the value is taken by any variable
@@ -447,7 +447,7 @@ def decompose_comparison(self, cmp_op, cpm_rhs):
447447
constraints = []
448448

449449
# introduce boolvar for each possible value
450-
bvars = boolvar(shape=(ub + 1 - lb))
450+
bvars = boolvar(shape=(ub+1-lb,)) # shape is tuple to ensure it is a 1D array
451451
idx_of_n = n - lb
452452
if 0 <= idx_of_n < len(bvars):
453453
count_of_vals = cp.sum(bvars[:idx_of_n]) + cp.sum(bvars[idx_of_n+1:])

cpmpy/solvers/choco.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def _get_constraint(self, cpm_expr):
592592
return self.chc_model.int_value_precede_chain(self._to_vars(cpm_expr.args[0]), cpm_expr.args[1])
593593
elif cpm_expr.name == "gcc":
594594
vars, vals, occ = cpm_expr.args
595-
return self.chc_model.global_cardinality(*self.solver_vars([vars, vals]), self._to_vars(occ), cpm_expr.closed)
595+
return self.chc_model.global_cardinality(self._to_vars(vars), self.solver_vars(vals), self._to_vars(occ), cpm_expr.closed)
596596
else:
597597
raise NotImplementedError(f"Unknown global constraint {cpm_expr}, should be decomposed! If you reach this, please report on github.")
598598

0 commit comments

Comments
 (0)