how to use the C api "GRBsetlogcallbackfuncenv" correctly
回答済みI try to use the api like:

I expect that “Hello World” and other solving process messages are sent to “callback”, but actually, the callback isn't called at all. Nothing is shown in the console. Did I misunderstand how this api works?
What I exactly want to do is redirect the Gurobi logging to another stream.
Gurobi version: 11.0.0
system: win11
complier: msvc
-
Hi Qi,
When I compile and run the following code (with v11 Gurobi):
#include "gurobi_c.h" int callback(char *msg, void *logdata) { fprintf(stderr, "Callback: %s\n", msg); fflush(stderr); return 0; } int main() { int error = 0; GRBenv *env = NULL; GRBmodel *model = NULL; error = GRBemptyenv(&env); if (error) goto QUIT; error = GRBsetstrparam(env, "LogFile", "mip1.log"); if (error) goto QUIT; error = GRBstartenv(env); if (error) goto QUIT; error = GRBsetlogcallbackfuncenv(env, callback, NULL); if (error) goto QUIT; GRBmsg(env, "---------------- Hello World ---------------- \n"); error = GRBsetlogcallbackfuncenv(env, NULL, NULL); if (error) goto QUIT; QUIT: if (error) { printf( "ERROR: %s\n", GRBgeterrormsg(env)); return 1; } GRBfreeenv(env); return 0; }I get the following output to console:
Set parameter LicenseID to value xxxxxx Set parameter LogFile to value "mip1.log" ---------------- Hello World ---------------- Callback: ---------------- Hello World ----------------You don't see similar output?
- Riley
0 -
Thanks!
Only when I add a ‘\n’ at the end of the string passed to GRBmsg, I can see the same output.0 -
Ok, is your problem now solved then? Or is there still an issue?
Don't forget you will also need to use
GRBsetlogcallbackfuncin a similar way so you can redirect output from the model.0 -
yes, after i add a ‘\n’, no problem anymore. Thanks again!
0
サインインしてコメントを残してください。
コメント
4件のコメント