Usercut callback and lazycut callback via C
回答済みHello,
I am trying to understanding how I should inform Gurobi when it solves an MIP that there should be different functions called for usercuts and lazycuts. I have prior CPLEX experience and I am trying to see what is Gurobi's way of implementing things. In CPLEX, for e.g., one has to separately provide a function name to CPXsetusercutcallbackfunc() for user cuts and a different function name to CPXsetlazyconstraintcallbackfunc() for lazy cuts.
Looking at the C example provided at https://docs.gurobi.com/projects/examples/en/current/examples/callback.html
I notice that there is just a single callback function the user has to write:
int __stdcall mycallback(GRBmodel *model, void *cbdata, int where, void *usrdata) {
if(where == GRB_CB_MIP){//is this the user cut callback?
}
if(where == GRB_CB_MIPSOL){//is this the lazy cut callback?
}
}
and this callback is informed to Gurobi via just the same call:
GRBsetcallbackfunc(model, mycallback, (void *) &mydata);
Is this correct?
Thank you.
-
It is right, you need only one callback function. The "where" argument in the callback function indicates at which step of the algorithm the code is called, see Callback Codes.
The relevant function to add lazy constraints isGRBcblazy
. As the documentation says, it can only be called if the where is \(\texttt{GRB_CB_MIPSOL}\) or \(\texttt{GRB_CB_MIPNODE}\). So, you could add your lazy constraints whenever a new solution is found (\(\texttt{GRB_CB_MIPSOL}\)) as it is done in the example tsp_c.c or additionally in each MIP node (\(\texttt{GRB_CB_MIPNODE}\)).
The relevant function to add user cuts isGRBcbcut
which can only be called if the where is \(\texttt{GRB_CB_MIPNODE}\).1 -
Thank you Marika. I have two follow up questions
(1) Is there an example for adding usercuts via GRBcbcut as there is for lazycuts [tsp_c.c]? I did search on https://docs.gurobi.com/projects/examples/en/current/examples/callback.html but no cut seems to be added in that example -- only status display in the lazy cut section [where == GRB_CB_MIPSOL] and no cut was added in the user cut section [where == GRB_CB_MIPNODE]
(2) Is there a way to add user cuts locally, i.e., only valid within the subtree rooted at the current MIP node where the cut is found? In CPLEX, this is done via CPXcutcallbackaddlocal() as opposed to CPXcutcallbackadd() which adds the cuts globally. I'd presume that GRBcbcut is equivalent to the latter. Could you please confirm?
Thank you.
0 -
The documentation of
GRBcbcut
provides a small example. The usage is similar to adding lazy constraints. So, for the general guidelines, you can use the tsp example.It is not possible to add only locally valid user cuts,see Can I add locally valid constraints in Gurobi MIP?
1
サインインしてコメントを残してください。
コメント
3件のコメント