Gurobi Python API Callback
AnsweredGreetings,
I have been using the callback function in the python API for a MIP problem. For some reason running the code:
where == GRB.Callback.MIP
best_bnd = model.cbGet(GRB.Callback.MIP_OBJBND)
gives me the objective value rounded off to the closest integer value. The type is double according to the Gurobi documentation but for some reason the value in the output is an integer.
I have been using the "bm23" instance.
Is there a way to get the non-rounded value?
Hope I can find some help!
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?. -
The objective function of model \( \texttt{bm23} \) is integral. The objective bound reported by Gurobi through \( \texttt{GRB.Callback.MIP_OBJBND} \) exploits the integrality of the objective function by rounding up to the nearest integer. This results in a tighter (and completely valid) bound. Is there a reason you want to query the weaker objective bound?
0 -
Hello,
I am trying to query the objective function at the root node before cuts are applied. The value for instance "bm23" at the root node is 20.57092 but using the MIP callback function the value is rounded to 21. Is there a way to get the value without rounding?
Thank you
0 -
The Gurobi C API includes the constants necessary to query the "continuous" objective bound (ObjBoundC) in a callback. The continuous objective bound does not include the additional integrality strengthening. In \( \texttt{gurobi_c.h} \), we have:
#define GRB_CB_MIP_OBJBNDC 3007
#define GRB_CB_MIPSOL_OBJBNDC 4007
#define GRB_CB_MIPNODE_OBJBNDC 5008So, to query the continuous objective bound in a \( \texttt{MIP} \) callback through the Python API, pass in the integer code associated with the C API's \( \texttt{GRB_CB_MIP_OBJBNDC} \) constant to Model.cbGet():
MIP_OBJBNDC = 3007
def cb(model, where):
if where == GRB.Callback.MIP:
objbndc = model.cbGet(MIP_OBJBNDC)
print(objbndc)Note that these callback codes are intentionally undocumented, because (i) it's rare to want to query the continuous bound when a tighter bound is readily available, and (ii) the results may not be as expected on problems other than MILPs.
0 -
It worked!
Thank you!
0
Post is closed for comments.
Comments
5 comments