Lazy constraints as general constraints?
AnsweredSorry if I repeat any previous related post, but I could not find any.
In the documentation for Model.cbLazy it says: "Your callback should be prepared to cut off solutions that violate any of your lazy constraints, including those that have already been added. Node solutions will usually respect previously added lazy constraints, but not always."
Is there any way to ensure that the lazy constraints added are always considered for the rest of the branch and cut ramification process? In other words, can I add the lazy constraint identified during the branch and cut process as a general constraint without rebooting the ramification process?
As a consequence, same lazy constraints are added several times during the process. Is it possible to avoid this?
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Lazy constraints are stored in a cut pool as described by Eli in a similar post. This means that a lazy constraint is not guaranteed to be used throughout the B&B process.
In other words, can I add the lazy constraint identified during the branch and cut process as a general constraint without rebooting the ramification process?
By general constraint, do you mean a constraint in the original model or the general constraint type? I assume you mean a constraint in the original model. Then, it is only possible by terminating the optimization, adding the constraint and continuing the optimization.
Is the number of possible lazy constraint in your case very large? Or is it moderate enough such that you can just add all lazy constraint to your model.
As a consequence, same lazy constraints are added several times during the process. Is it possible to avoid this?
This is not a problem, because Gurobi will filter duplicates. This filtering is usually very cheap and negligible.
Best regards,
Jaromił0 -
Hi Jaromił,
I stumbled upon this post while searching for general constraints.
In my case I actually try to do the latter of the options you gave: I have a general constraint (indicator constraint) that I'd like to add lazily in during callbacks.
The constraint could be modelled "manually/linearly" with big-M constraints. However that seems difficult to do within a callback because I would need to introduce a new variable as an indicator variable.
Specifically, the indicator constraint would be:
IF (x1+x2+x3 >= c) THEN (x4+x5+x6 = 0)
Where x are binary GRBVar and c is a constant.
There are an exponential of these, they're "just cuts" as opposed to lazy constraints if I understand the terminology correctly, in the sense that the model would be valid without them, too.What would be the best way to add this type of logical implication to the model?
Best regards,
Taihao0 -
Hi Taihao,
In my case I actually try to do the latter of the options you gave: I have a general constraint (indicator constraint) that I'd like to add lazily in during callbacks.
It is currently not possible to add an indicator constraint as a user cut or lazy constraint.
One way to achieve your goal would be to start your optimization without these indicator constraints and write a callback which would collect different missing indicator constraints but not add them yet. After some time you would then terminate the optimization process from within the callback (or in any other way) and then add the collected indicator constraints to your model together with possibly additional variables and auxiliary constraints. You would then have to start the optimization process again.
An alternative would be to add all of the indicator constraints to the model to begin with. However, if the number is too large (as you said it is exponential), then this might have a negative effect on the overall performance of the solver.
You could also try adding only a subset of these indicator constraints to begin with and then apply the first idea.
Best regards,
Jaromił0 -
Hi Jaromił,
thank you for your explanation. I tried adding all indicator variables in the beginning, which however messed up my initial heuristic for MIPStart, and as you said, them being exponential in number doesn't really make this approach sustainable.
I may have found a way to implement the logical constraints (or at least a weaker variant of them) without auxiliary constraints/variables, which can run within a callback. For now, I'll experiment with that.
Thanks again!
Best regards,
Taihao
0
Post is closed for comments.
Comments
5 comments