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
Added support for an indicator constraint to QuadraticProgram #151
Conversation
I think the PR is ready for review. Could you please review this? |
Thanks. Could you write a reno? |
Sure (I had written reno but I had forgotten to add it). |
Should we be adding a new tutorial, or updating an existing one, to show this new capability. For significant new features I think it would be good, since we have the tutorials now in this same repo, that they are updated/improved at the same time if the new/updated feature warrants it. |
…tion into indicator_const
…tion into indicator_const
@woodsp-ibm Thank you for your helpful comments. I fixed the code. I haven't fixed all the f string and typehints, but I fixed them at least in this code. |
from ..problems.variable import Variable | ||
|
||
|
||
class IndicatorToInequality(QuadraticProgramConverter): |
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.
I suggest IndicatorToLinear
because this converts not only inequality constraints but also equality constraints. Another reason is that there is another way to convert indicator constraints into quadratic constraints.
new_name = indicator_const.name + self._delimiter + "indicator" | ||
if sense == Constraint.Sense.LE: | ||
_, lhs_ub = self._calc_linear_bounds(problem, new_linear) | ||
big_m = lhs_ub - new_rhs |
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.
make sure that big_m is a positive value.
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.
I think it does work even when big_m is a negative value in this case. When it's inactive, it becomes lhs <= the upperbounds of lhs. (When rhs is larger than the upper bound of lhs, the constraint doesn't make sense though).
The indicator constraints will be treated as part of a docplex translator #122 |
Summary
resolve #13
The PR adds support for an indicator constraint to
QuadraticProgram
.Details and comments
An indicator constraint control the satisfaction of a linear constraint by the value of a binary variable. If the binary variable equals the active value, then the constraint must be satisfied, but otherwise the constraint might or might not be satisfied.
e.g.
x = 1 -> y + z = 1