Skip to content
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

Closed
wants to merge 27 commits into from

Conversation

a-matsuo
Copy link
Contributor

@a-matsuo a-matsuo commented May 31, 2021

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

  • to_docplex
  • from_docplex
  • converter
  • unittests
    • indicator to inequality converter
    • indicator constraint

@a-matsuo a-matsuo self-assigned this Jun 4, 2021
@a-matsuo a-matsuo added the Changelog: New feature Include in the Added section of the changelog label Jun 4, 2021
@a-matsuo a-matsuo marked this pull request as ready for review June 4, 2021 09:36
@a-matsuo a-matsuo changed the title [WIP]Added support for an indicator constraint to QuadraticProgram Added support for an indicator constraint to QuadraticProgram Jun 4, 2021
@a-matsuo
Copy link
Contributor Author

a-matsuo commented Jun 4, 2021

I think the PR is ready for review. Could you please review this?

@t-imamichi
Copy link
Collaborator

Thanks. Could you write a reno?

@a-matsuo
Copy link
Contributor Author

a-matsuo commented Jun 4, 2021

Sure (I had written reno but I had forgotten to add it).

@woodsp-ibm
Copy link
Member

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.

@a-matsuo
Copy link
Contributor Author

a-matsuo commented Jun 7, 2021

@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):
Copy link
Collaborator

@t-imamichi t-imamichi Jun 7, 2021

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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).

@t-imamichi t-imamichi added the on hold Can not fix yet label Jun 7, 2021
@t-imamichi
Copy link
Collaborator

The indicator constraints will be treated as part of a docplex translator #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New feature Include in the Added section of the changelog on hold Can not fix yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for docplex.mp.constr.IndicatorConstraint
5 participants