Can we add user cuts on root node only?
AnsweredHi,
I believe this is an easy question but I couldn't find any related post. In my branch-and-cut, below is how I code the user cut callback
if where == GRB.Callback.MIPNODE:
status = MyModel.cbGet(GRB.Callback.MIPNODE_STATUS)
if status == GRB.OPTIMAL:
My understanding is that Gurobi execute this user cut callback in every node. What if I just want my user cut to be added at root node only (as many as possible) to strengthen the LP relaxation bound and then start the regular branch-and-cut process (with GRB cuts only) without user cut callback on all the leaf nodes? Also, how to set a specific condition to force Gurobi to branch after adding user cut on root node only? For example, say if the violation is less than a threshold, then I want Gurobi to stop adding user cuts on root node and start branching.
Could you please let me know what parameter I should change? Thank you.
-
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?. -
Hi,
It is possible to add cuts at root node only. The value \(\texttt{MIPNODE_NODCNT}\) provides you the current number of B&B nodes inside a callback. If this number equals \(0\), then you are at the root node. You can add an \(\texttt{if}\)-clause checking for the \(\texttt{MIPNODE_NODCNT}\) inside your callback.
Also, how to set a specific condition to force Gurobi to branch after adding user cut on root node only?
You can define a private model variable, e.g.,
model._terminate_callback = False
and use and set it inside your callback, e.g.,
if where == GRB.Callback.MIPNODE:
if model._terminate_callback:
return
if some_condition == True:
model._terminate_callback = TrueBest regards,
Jaromił0 -
Hi Jaromił,
Thank you so much and save my life!!!
0
Post is closed for comments.
Comments
3 comments