Skip to content

Commit 2963677

Browse files
committed
double check shape when making aux vars
1 parent 816abba commit 2963677

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

cpmpy/expressions/globalconstraints.py

+6
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ def decompose(self):
868868
"""
869869
X, Y = cpm_array(self.args)
870870

871+
if len(X) == 0 == len(Y):
872+
return [cp.BoolVal(False)], [] # based on the decomp, it's false...
873+
871874
bvar = boolvar(shape=(len(X) + 1))
872875

873876
# Constraint ensuring that each element in X is less than or equal to the corresponding element in Y,
@@ -914,6 +917,9 @@ def decompose(self):
914917
"""
915918
X, Y = cpm_array(self.args)
916919

920+
if len(X) == 0 == len(Y):
921+
return [cp.BoolVal(False)], [] # based on the decomp, it's false...
922+
917923
bvar = boolvar(shape=(len(X) + 1))
918924
defining = [bvar == ((X <= Y) & ((X < Y) | bvar[1:]))]
919925
defining.append(bvar[-1] == (X[-1] <= Y[-1]))

cpmpy/expressions/globalfunctions.py

+1-1
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,))
399399

400400
args = cpm_array(self.args)
401401
# bvar is true if the value is taken by any variable

0 commit comments

Comments
 (0)