Skip to content

Commit 43d54a8

Browse files
committed
Add tests for MatrixConsIndicator input types
Expanded test_matrix_cons_indicator to check TypeError for invalid input types and added tests for MatrixExprCons and ExprCons cases. Also updated objective and assertions to include new binary variable.
1 parent 1a0347d commit 43d54a8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/test_matrix_variable.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ def test_matrix_cons_indicator():
375375
with pytest.raises(Exception):
376376
m.addMatrixConsIndicator(x >= y, is_equal)
377377

378+
# require MatrixExprCons or ExprCons
379+
with pytest.raises(TypeError):
380+
m.addMatrixConsIndicator(x)
381+
382+
# test MatrixExprCons
378383
for i in range(2):
379384
m.addMatrixConsIndicator(x[i] >= y[i], is_equal[0, i])
380385
m.addMatrixConsIndicator(x[i] <= y[i], is_equal[0, i])
@@ -386,9 +391,16 @@ def test_matrix_cons_indicator():
386391
m.addMatrixConsIndicator(x[:, i] >= y[:, i], is_equal[0])
387392
m.addMatrixConsIndicator(x[:, i] <= y[:, i], is_equal[0])
388393

389-
m.setObjective(is_equal.sum(), "maximize")
394+
# test ExprCons
395+
z = m.addVar(vtype="B")
396+
binvar = m.addVar(vtype="B")
397+
m.addMatrixConsIndicator(z >= 1, binvar, activeone=True)
398+
m.addMatrixConsIndicator(z <= 0, binvar, activeone=False)
399+
400+
m.setObjective(is_equal.sum() + binvar, "maximize")
390401
m.optimize()
391402

392403
assert m.getVal(is_equal).sum() == 2
393404
assert (m.getVal(x) == m.getVal(y)).all().all()
394405
assert (m.getVal(x) == np.array([[5, 5, 5], [5, 5, 5]])).all().all()
406+
assert m.getVal(z) == 1

0 commit comments

Comments
 (0)