-
Notifications
You must be signed in to change notification settings - Fork 270
BUG: _VarArray
can't handle MatrixVar
#1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
885865a
9451cc6
7ee3a6f
2cde7a6
50bb995
d72f951
110679f
f181cf4
0346c52
68f2e44
5580e12
8fc900c
d52eb54
8424c6d
710a836
3b64e79
2be1117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,40 @@ def test_cons_indicator(): | |
assert m.isEQ(m.getVal(x), 1) | ||
assert c1.getConshdlrName() == "indicator" | ||
|
||
def test_cons_indicator_with_matrix_binvar(): | ||
# test matrix variable binvar #1043 | ||
m = Model() | ||
|
||
with pytest.raises(TypeError): | ||
m.addConsIndicator(m.addVar(vtype="B") <= 1, 1) | ||
|
||
# test binvar with (1, 1, 1) shape of matrix variable | ||
x = m.addVar(vtype="B") | ||
binvar1 = m.addMatrixVar(((1, 1, 1)), vtype="B") | ||
m.addConsIndicator(x >= 1, binvar1, activeone=True) | ||
m.addConsIndicator(x <= 0, binvar1, activeone=False) | ||
|
||
# test binvar with (2, 3) shape of matrix variable | ||
y = m.addVar(vtype="B") | ||
binvar2 = m.addMatrixVar(((2, 3)), vtype="B") | ||
m.addConsIndicator(y >= 1, binvar2, activeone=True) | ||
m.addConsIndicator(y <= 0, binvar2, activeone=False) | ||
|
||
# test binvar with (2, 1) shape of list of lists | ||
z = m.addVar(vtype="B") | ||
binvar3 = [[m.addVar(vtype="B")], [m.addVar(vtype="B")]] | ||
m.addConsIndicator(z >= 1, binvar3, activeone=True) | ||
m.addConsIndicator(z <= 0, binvar3, activeone=False) | ||
Comment on lines
+190
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there somewhere documented when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused. We add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't directly access There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if any other methods would use all the results of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constraint addition methods, which get a list of variables like you mentioned in #1044 (comment), but for these I doubt that the ravelling is expected. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Joao-Dionisio what do you think about this. In my opinion, matrix is also a list. But _VarArray can’t handle matrix, so it’s a bug for _VarArray. This pr is done for that. So for addConsIndicator binvar type problem should be done in another pr not this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
m.setObjective( | ||
binvar1.sum() + binvar2.sum() + binvar3[0][0] + binvar3[1][0], "maximize" | ||
) | ||
m.optimize() | ||
|
||
assert m.getVal(x) == 1 | ||
assert m.getVal(y) == 1 | ||
assert m.getVal(z) == 1 | ||
|
||
@pytest.mark.xfail( | ||
reason="addConsIndicator doesn't behave as expected when binary variable is False. See Issue #717." | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, indicator constraints do not support matrix variables yet, which would require some documentation of this addition function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many methods like
addConsSOS1
,addConsSOS2
,addConsAnd
, and more that use_VarArray
This pr doesn't work for
addConsIndicator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, can we then add a passing test and mention in the changelog what works now?