-
Notifications
You must be signed in to change notification settings - Fork 38
added addindconstr! interface for indicator constraints #155
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
Conversation
Could you add corresponding documentation at |
In both Gurobi and CPLEX MathProgInterfaces a constraint is defined by
I also think it would be simpler to pass |
replacing ``ind`` by ``binvar``, and ``comp`` to ``binval``, where ``binval`` is the actual value of the indicator variable. Simpler to understand and aligned with the definition of indicator constraints in Gurobi
The convention in MathProgBase is to preferably have exactly one way to accomplish a task. Given that some solvers like Clp naturally take two-sided constraints in |
Your call... If we go with
I was trying to take advantage of the LinearContraint object. I think I was able to figure out everything but how to construct the @indicatorconstraint macro... so, stick to regards Braulio |
JuMP doesn't have trouble putting constraints into |
doc/lpqcqp.rst
Outdated
|
||
Adds a new indicator constraint to the model, of the form | ||
.. math:: | ||
y = 1 \Rightarrow ax \leq b | ||
|
||
``binvar`` is the indicator variable (binary), and ``binval`` is the value of the binary variable. | ||
The rest of the arguments are the same as addconstr! | ||
``binvar`` is the indicator variable (binary), and ``binval`` is the value of the binary variable. Coefficients for the linear constraint are specified in a sparse format: the ``coef`` vector contains the nonzero coefficients, and the ``varidx`` vector contains the indices of the corresponding variables. ``sense`` is the sense of the linear constraint ``('<','=','>')``, and ``rhs`` is the right hand side. |
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.
binvar
is the indicator variable (binary)
Is the index of the indicator variable. Is it assumed to be marked binary already?
binval
is the value of the binary variable
I don't know what this means.
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 played a little bit with CPLEX to get your answers
- binvar must be the index of the variable
- CPLEX will not complain if the variable is not marked as binary beforehand or will it mark it if declared if used in an indicator constraint. However, using the variable as indicator will make it behave as binary, even if not marked. See the examples below
- an indicator constraint has the form
binvar = binval => linearconstraint
wherebinval
is in {0,1}.
Let me know how do we proceed from here.
A few examples for 2, all of them constructed using JuMP and CPLEX:
Maximize
obj: 0 x1 + x2
Subject To
c1: x2 <= 10
i1: x1 = 1 -> x2 <= 5
Bounds
x1 = 1
Binaries
x1
End
works, obj= 5
Maximize
obj: 0 x1 + x2
Subject To
c1: x2 <= 10
i1: x1 = 1 -> x2 <= 5
Bounds
x1 = 1
End
CPLEX Error 1017: Not available for mixed-integer problems. Probably caused because an LP cannot have indicators.
Maximize
obj: 0 x1 + x2 + 0 x3
Subject To
c1: x2 <= 10
i1: x1 = 1 -> x2 <= 5
Bounds
x1 = 1
0 <= x3 <= 1
Binaries
x3
End
works, obj=5. Column types [:Cont, :Cont, :Bin]
Maximize
obj: 0 x1 + x2 + 0 x3
Subject To
c1: x2 <= 10
i1: x1 = 1 -> x2 <= 5
Bounds
x1 = 0.5
0 <= x3 <= 1
Binaries
x3
End
Infeasible. Even though x1 is not marked as binary it cannot take a value different than {0,1}
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.
Could you clarify these points in the documentation?
|
||
``binvar`` is the index of the indicator variable (binary), and ``binval`` is the value of the binary variable, either ``0`` or ``1``. Coefficients for the linear constraint are specified in a sparse format: the ``coef`` vector contains the nonzero coefficients, and the ``varidx`` vector contains the indices of the corresponding variables. ``sense`` is the sense of the linear constraint ``('<','=','>')``, and ``rhs`` is the right hand side. | ||
|
||
This builds the constraint ``binvar = binval => ax <= b``, where ``ax <= b`` is specified with ``(varidx,coef,sense,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.
backtick quotes are not matching here
.. math:: | ||
y = 1 \Rightarrow ax \leq b | ||
|
||
``binvar`` is the index of the indicator variable (binary), and ``binval`` is the value of the binary variable, either ``0`` or ``1``. Coefficients for the linear constraint are specified in a sparse format: the ``coef`` vector contains the nonzero coefficients, and the ``varidx`` vector contains the indices of the corresponding variables. ``sense`` is the sense of the linear constraint ``('<','=','>')``, and ``rhs`` is the right hand side. |
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.
Could you add a mention of what the solver should do if binvar isn't already marked as a binary variable? E.g., the indicator constraint also enforces that binvar
is binary.
@bbrunaud, there are just a couple more comments to address here. Do you plan on completing this PR and the corresponding implementation in JuMP and solver interfaces? |
Hi Miles I have almost everything working on my local forks. I'm just missing the JuMP macro. However, based on the amount of work that it's taking to insert 1 line of code into MathProgBase, I'm not sure I have the time to commit to take care of every little detail. Is there a more efficient way to collaborate with the project?. Please, shoot me an email to brunaud at cmu.edu so we can discuss further. BTW, congrats on your defense Braulio |
This will be made much simpler following #173. It's still a work in progress, but your comments are welcome there. We will also need help updating the solver interfaces for the new API.
Thanks! |
Gurobi (since version 7), CPLEX and SCIP support indicator constraints. Which are something like
added addindconstr! interface to allow the implementation by CPLEX.jl, Gurobi.jl, SCIP.jl and also the implementation in JuMP. An example of usage with CPLEX would be
Ref.
http://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.1/ilog.odms.cplex.help/refcallablelibrary/html/functions/CPXaddindconstr.html