Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

Monitoring Progress - Logging and Callbacks#

voidGRBmsg(GRBenv*env,constchar*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 theOutputFlag parameter is set. In addition, it is ignoredfrom within aMESSAGE callback (seeWHERE values)and logging callback. The console logging can becontroled withLogToConsole.

Example:
error=GRBmsg(env,"Add this message to the log");
intGRBsetcallbackfunc(GRBmodel*model,int(*cb)(GRBmodel*model,void*cbdata,intwhere,void*usrdata),void*usrdata)#

Set up a user callback function which will be invoked for all possiblewhereflags. Note that a model can only have a single callback method, so anexisting callback will be replaced. To disable a previously setcallback, use this function with acb argument ofNULL.

When solving a model using multiple threads, the user callback is onlyever called from a single thread, so you don’t need to worry about thethread-safety of your callback.

A few parameters arecallback settable. These parameters can be modified from withina callback call usingGRBcbsetdblparam,GRBcbsetintparam,GRBcbsetstrparam, orGRBcbsetparam depending on the parameter type.

Return value:

A non-zero return value indicates that a problem occurred while setting the user callback.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model in which the callback should be installed.

  • cb – A function pointer to the user callback function. The callbackwill be called regularly from the Gurobi Optimizer. Thewhereargument to the callback function will indicate where in theoptimization process the callback was invoked. Possible values aredescribed in theCallback Codes section. Theuser callback can then call a number of routines to retrieve additionaldetails 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 ifno error was encountered, or it can return one of the GurobiError Codes if the user callback would like theoptimization to stop and return an error result.

  • usrdata – An optional pointer to user data that will be passed backto the user callback function each time it is invoked (in theusrdata argument).

Example:
intmycallback(GRBmodel*model,void*cbdata,intwhere,void*usrdata);error=GRBsetcallbackfunc(model,mycallback,NULL);
intGRBsetcallbackfuncadv(GRBmodel*model,int(*cb)(GRBmodel*model,void*cbdata,intwhere,void*usrdata),void*usrdata,unsignedintwheres)#

Set up a user callback function and allows for specifying for whichwhere flags the callback should be invoked. Note that a model canonly have a single callback method, so this call will replace anexisting callback. To disable a previously set callback, call thisfunction with acb argument ofNULL.

When solving a model using multiple threads, the user callback is onlyever called from a single thread, so you don’t need to worry about thethread-safety of your callback.

A few parameters arecallback settable. These parameters can be modified from withina callback call usingGRBcbsetdblparam,GRBcbsetintparam,GRBcbsetstrparam, orGRBcbsetparam depending on the parameter type.

Return value:

A non-zero return value indicates that a problem occurred while setting the user callback.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model in which the callback should be installed.

  • cb – A function pointer to the user callback function. The callbackwill be called regularly from the Gurobi Optimizer. Thewhereargument to the callback function will indicate from where in theoptimization process the callback is invoked. Possible values aredescribed in theCallback Codes section. Theuser callback can then call a number of routines to retrieve additionaldetails 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 ifno error was encountered, or it can return one of the GurobiError Codes if you would like theoptimization to stop and return an error result.

  • usrdata – An optional pointer to user data that will be passed backto the user callback function each time it is invoked (in theusrdata argument).

  • wheres – A bit vector defining for whichwhere flags thecallback should be invoked. It should contain value 1 in the n-thposition if you want the callback to be invoked for thewhere flagof value n. See the possible values atCallback Codes, andthe example below.

Note

Even if thePOLLING bit is not setin thewheres bit vector, the callback may still be invoked withwhere set to that value.

Example:
intmycallback(GRBmodel*model,void*cbdata,intwhere,void*usrdata);error=GRBsetcallbackfuncadv(model,mycallback,NULL,(1<<GRB_CB_POLLING)|(1<<GRB_CB_MESSAGE));
intGRBgetcallbackfunc(GRBmodel*model,int(**cb)(GRBmodel*model,void*cbdata,intwhere,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 theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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,intwhere,void*usrdata);error=GRBgetcallbackfunc(model,&mycallback);
intGRBcbget(void*cbdata,intwhere,intwhat,void*resultP)#

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

Return value:

A non-zero return value indicates that a problem occurred while retrieving the requested data.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • cbdata – Thecbdata argument that was passed into the usercallback by the Gurobi Optimizer. This argument must be passedunmodified from the user callback toGRBcbget().

  • where – Thewhere argument that was passed into the user callbackby the Gurobi Optimizer. This argument must be passed unmodified fromthe user callback toGRBcbget().

  • what – The data requested by the user callback. Valid values aredescribed in theCallback Codes section.

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

Example:
if(where==GRB_CB_MIP){doublenodecount;error=GRBcbget(cbdata,where,GRB_CB_MIP_NODECNT,(void*)&nodecount);if(error)return0;printf("MIP node count is %d\n",nodecount);}
voidGRBversion(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 beplaced. May beNULL.

  • minorP – The location in which the minor version number should beplaced. May beNULL.

  • technicalP – The location in which the technical version numbershould be placed. May beNULL.

Example:
intmajor,minor,technical;GRBversion(&major,&minor,&technical);printf("Gurobi library version %d.%d.%d\n",major,minor,technical);
intGRBsetlogcallbackfunc(GRBmodel*model,int(*cb)(char*msg,void*logdata),void*logdata)#

Sets a logging callback function to query all output posted by the model. Amodel can only have a single log callback, so this call will replace anexisting log callback. To disable a previously set log callback, call thisfunction with acb argument ofNULL.

Return value:

A non-zero return value indicates that a problem occurred while setting the log callback.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model in which the log callback should be installed.

  • cb – A function pointer to the log callback function. The callback willbe called whenever the model produces a log line, with the log linecontents passed as a character string.

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

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

Sets a logging callback function to query all output posted by theenvironment. An environment can only have a single log callback, so thiscall will replace an existing log callback. To disable a previously setlog callback, call this function with acb argument ofNULL.

Return value:

A non-zero return value indicates that a problem occurred while setting the log callback.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • env – The environment in which the log callback should be installed.

  • cb – A function pointer to the log callback function. The callback willbe called whenever the environment produces a log line, with the log linecontents passed as a character string.

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

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp