Skip to content

Commit 23d4344

Browse files
committed
Add test for knapsack constraint with matrix variables
1 parent 36e9066 commit 23d4344

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/test_cons.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ def test_cons_indicator_with_matrix_binvar():
210210

211211
assert m.isEQ(m.getVal(x), 1)
212212

213+
def test_cons_knapsack_with_matrix_vars():
214+
# test matrix variable vars #1043
215+
m = Model()
216+
vars = m.addMatrixVar(3, vtype="B")
217+
m.addConsKnapsack(vars, [1, 2, 3], 5)
218+
219+
m.setObjective(vars.sum(), "maximize")
220+
m.optimize()
221+
222+
assert (m.getVal(vars) == [0, 1, 1]).all()
223+
213224
@pytest.mark.xfail(
214225
reason="addConsIndicator doesn't behave as expected when binary variable is False. See Issue #717."
215226
)

0 commit comments

Comments
 (0)