Try our new documentation site (beta).
GRBsetcallbackfunc
int | GRBsetcallbackfunc ( | GRBmodel | *model, |
int | (*cb)(GRBmodel *model, void *cbdata, int where, void *usrdata), | ||
void | *usrdata ) |
Set up a user callback function. Note that a model can only have a single callback function, so this call will replace an existing callback.
Note that a model can only have a single callback method, so this call
will replace an existing callback. To disable a previously set
callback, call this function with a cb
argument
of NULL
.
When solving a model using multiple threads, note that the user callback is only ever called from a single thread, so you don't need to worry about the thread-safety of your callback.
Return value:
A non-zero return value indicates that a problem occurred while setting the user callback. Refer to the Error Code table for a list of possible return values. Details on the error can be obtained by calling GRBgeterrormsg.
Arguments:
model: The model in which the callback should be installed.
cb: A function pointer to the user callback function. The callback will be called regularly from the Gurobi optimizer. The where argument to the callback function will indicate where in the optimization process the callback was invoked. Possible values are described in the Callback Codes section. The user callback can then call a number of routines to retrieve additional details about the state of the optimization (e.g., GRBcbget), or to inject new information (e.g., GRBcbcut, GRBcbsolution). The user callback function should return 0 if no error was encountered, or it can return one of the Gurobi Error Codes if the user callback would like the optimization to stop and return an error result.
usrdata: An optional pointer to user data that will be passed back to the user callback function each time it is invoked (in the usrdata argument).
Example usage:
int mycallback(GRBmodel *model, void *cbdata, int where, void *usrdata); error = GRBsetcallbackfunc(model, mycallback, NULL);