Skip to content

Commit 134f99f

Browse files
committed
test list of lists
1 parent 5580e12 commit 134f99f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tests/test_cons.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,27 @@ def test_cons_indicator():
180180
assert c1.getConshdlrName() == "indicator"
181181

182182
def test_cons_indicator_with_matrix_binvar():
183+
# to fix #1043
183184
m = Model()
184185

185186
x = m.addVar(vtype="B")
186-
binvar = m.addMatrixVar(1, vtype="B")
187-
# binvar is a matrix variable to fix #1043
188-
m.addConsIndicator(x >= 1, binvar, activeone=True)
189-
m.addConsIndicator(x <= 0, binvar, activeone=False)
190-
191-
m.setObjective(binvar.sum(), "maximize")
187+
# binvar is a matrix variable
188+
binvar1 = m.addMatrixVar(1, vtype="B")
189+
m.addConsIndicator(x >= 1, binvar1, activeone=True)
190+
m.addConsIndicator(x <= 0, binvar1, activeone=False)
191+
192+
y = m.addMatrixVar(2, vtype="B")
193+
# binvar2 is a list of lists
194+
binvar2 = [[m.addVar(vtype="B")], [m.addVar(vtype="B")]]
195+
m.addConsIndicator(y >= 1, binvar2, activeone=True)
196+
m.addConsIndicator(y <= 0, binvar2, activeone=False)
197+
198+
m.setObjective(binvar1[0] + binvar2[0][0] + binvar2[0][1], "maximize")
192199
m.optimize()
193200

194201
assert m.getVal(x) == 1
202+
assert m.getVal(y[0]) == 1
203+
assert m.getVal(y[1]) == 1
195204

196205
@pytest.mark.xfail(
197206
reason="addConsIndicator doesn't behave as expected when binary variable is False. See Issue #717."

0 commit comments

Comments
 (0)