Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Monitoring Progress - Logging and Callbacks

void GRBmsg(GRBenv *env, const char *message)

  Write a message to the console and the log file.

  Arguments:

    - env – The environment whose log file should receive the message.

    - message – The message to be written.

  Note

  This call has no effect unless the OutputFlag parameter is set. In addition, it is ignored from within a `MESSAGE` callback (see WHERE values) and logging callback. The console logging can be controled with LogToConsole.

  Example:

        error = GRBmsg(env, "Add this message to the log");

int GRBsetcallbackfunc(GRBmodel *model, int (*cb)(GRBmodel *model, void *cbdata, int where, void *usrdata), void *usrdata)

  Set up a user callback function which will be invoked for all possible `where` flags. Note that a model can only have a single callback method, so an existing callback will be replaced. To disable a previously set callback, use this function with a `cb` argument of `NULL`.

  When solving a model using multiple threads, 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.

  A few parameters are callback settable. These parameters can be modified from within a callback call using `GRBcbsetdblparam`, `GRBcbsetintparam`, `GRBcbsetstrparam`, or `GRBcbsetparam` depending on the parameter type.

  Return value:

    A non-zero return value indicates that a problem occurred while setting the user callback. Refer to the Error Codes 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:

        int mycallback(GRBmodel *model, void *cbdata, int where, void *usrdata);
        error = GRBsetcallbackfunc(model, mycallback, NULL);

int GRBsetcallbackfuncadv(GRBmodel *model, int (*cb)(GRBmodel *model, void *cbdata, int where, void *usrdata), void *usrdata, unsigned int wheres)

  Set up a user callback function and allows for specifying for which `where` flags the callback should be invoked. 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, 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.

  A few parameters are callback settable. These parameters can be modified from within a callback call using `GRBcbsetdblparam`, `GRBcbsetintparam`, `GRBcbsetstrparam`, or `GRBcbsetparam` depending on the parameter type.

  Return value:

    A non-zero return value indicates that a problem occurred while setting the user callback. Refer to the Error Codes 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 from where in the optimization process the callback is 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 you 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).

    - wheres – A bit vector defining for which `where` flags the callback should be invoked. It should contain value 1 in the n-th position if you want the callback to be invoked for the `where` flag of value n. See the possible values at Callback Codes, and the example below.

  Note

  Even if the `POLLING` bit is not set in the wheres bit vector, the callback may still be invoked with `where` set to that value.

  Example:

        int mycallback(GRBmodel *model, void *cbdata, int where, void *usrdata);
        error = GRBsetcallbackfuncadv(model, mycallback, NULL,
                                      (1<<GRB_CB_POLLING)|(1<<GRB_CB_MESSAGE));

int GRBgetcallbackfunc(GRBmodel *model, int (**cb)(GRBmodel *model, void *cbdata, int where, void *usrdata))

  Retrieve the current user callback function.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the user callback. Refer to the Error Codes 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.

  Example:

        int (*mycallback)(GRBmodel *model, void *cbdata, int where, void *usrdata);
        error = GRBgetcallbackfunc(model, &mycallback);

int GRBcbget(void *cbdata, int where, int what, void *resultP)

  Retrieve additional information about the progress of the optimization. Note that this routine can only be called from within a user callback function.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the requested data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - cbdata – The `cbdata` argument that was passed into the user callback by the Gurobi Optimizer. This argument must be passed unmodified from the user callback to `GRBcbget()`.

    - where – The `where` argument that was passed into the user callback by the Gurobi Optimizer. This argument must be passed unmodified from the user callback to `GRBcbget()`.

    - what – The data requested by the user callback. Valid values are described in the Callback Codes section.

    - resultP – The location in which the requested data should be placed.

  Example:

        if (where == GRB_CB_MIP) {
          double nodecount;
          error = GRBcbget(cbdata, where, GRB_CB_MIP_NODECNT, (void *) &nodecount);
          if (error) return 0;
          printf("MIP node count is %d\n", nodecount);
        }

void GRBversion(int *majorP, int *minorP, int *technicalP)

  Return the Gurobi library version number (major, minor, and technical).

  Arguments:

    - majorP – The location in which the major version number should be placed. May be `NULL`.

    - minorP – The location in which the minor version number should be placed. May be `NULL`.

    - technicalP – The location in which the technical version number should be placed. May be `NULL`.

  Example:

        int major, minor, technical;
        GRBversion(&major, &minor, &technical);
        printf("Gurobi library version %d.%d.%d\n", major, minor, technical);

int GRBsetlogcallbackfunc(GRBmodel *model, int (*cb)(char *msg, void *logdata), void *logdata)

  Sets a logging callback function to query all output posted by the model. A model can only have a single log callback, so this call will replace an existing log callback. To disable a previously set log callback, call this function with a `cb` argument of `NULL`.

  Return value:

    A non-zero return value indicates that a problem occurred while setting the log callback. Refer to the Error Codes 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 log callback should be installed.

    - cb – A function pointer to the log callback function. The callback will be called whenever the model produces a log line, with the log line contents passed as a character string.

    - logdata – An optional pointer to user data that will be passed back to the log callback function each time it is invoked (in the `logdata` argument).

int GRBsetlogcallbackfuncenv(GRBenv *env, int (*cb)(char *msg, void *logdata), void *logdata)

  Sets a logging callback function to query all output posted by the environment. An environment can only have a single log callback, so this call will replace an existing log callback. To disable a previously set log callback, call this function with a `cb` argument of `NULL`.

  Return value:

    A non-zero return value indicates that a problem occurred while setting the log callback. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - env – The environment in which the log callback should be installed.

    - cb – A function pointer to the log callback function. The callback will be called whenever the environment produces a log line, with the log line contents passed as a character string.

    - logdata – An optional pointer to user data that will be passed back to the log callback function each time it is invoked (in the `logdata` argument).

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support