Concurrent Optimizer and callbacks
AnsweredDear Gurobi-Team,
I am using Concurrent Optimizer and callbacks and it seems to me, that callbacks are not called, although they should (or shouldn't?).
In the reference manual (https://www.gurobi.com/documentation/current/refman/concurrent_optimizer.html#sec:ConcurrentCallbacks) it says:
"Information retrieved by your callback (solutions, objective bounds, etc.) will come from a single model."
In the following post it was said that new incumbents are interexchanged between different threads:
https://support.gurobi.com/hc/en-us/community/posts/360058506892-Is-Parallel-exploration-of-tree-for-MIP-concurrent-with-callback-execution-?input_string=Concurrent%20Optimizer%20and%20callbacks
In my callback I am using
if where == GRB.Callback.MIPSOL:
to write a solution to file when a new solution is found. I can't investigate it in the last details but it seems to me, that this only happens if a new solution was found in Instance 0. When the log says "Instance 1 was solved" the new solution is not written to file.
Is that the wanted behaviour?
-
Hi Thomas,
I am not sure what you mean here. Could you provide your code example?
Also, you may want to have a look the callback.py example and the callback codes page.Cheers,
David0 -
Hi David,
I have a callback-function like this (in python):
def writesolution_callback(model, where):
if where == GRB.Callback.MIPSOL:
[...] # processing of the solution and creation of the dictionary named dictionary
with open("solution.json", "w") as outfile:
json.dump(dictionary, outfile)This callback-function is called by gurobi:
model._vars = model.getVars()
model.optimize(writesolution_callback)With model.setParam(GRB.Param.ConcurrentMIP, 2) I observed that the solution is only written to file (as wanted with the callback) if a new solution was found in Instance 0 of ConcurrentMIP. When the log says "Instance 1 was solved" the new solution is not written to file. It seems to me that callbacks are only called from Instance 0 - is that the wanted behaviour of Gurobi?
Best regards
Thomas
0 -
Or maybe Callbacks are called from alle ConcurrentMIP-Instances but maybe identifying "if where == GRB.Callback.MIPSOL" doesn't work properly in different instances?
0 -
Hi Thomas,
Sorry for the delay.
Thanks for the extra info. Indeed as you mention in the first message callbacks are only registered for a single solve or instance (this solve uses multiple threads).
If you want to explore an alternative maybe the Pool related parameters might be helpful: Finding Multiple Solutions.
Cheers,
David0 -
Hi David,
thank you for your answer: Then it is a feature not a bug ;-)
But that is a pity for me, because I can't save the new found solution to file during optimization.
Is there a special reason why callbacks are only used in one instance? Do you fear race conditions or something like that? I would be interested in a scientific reason. Or is it just not yet implemented? Are there plans to enable callbacks (or at least some types of them) for all instances in ConcurrentMIP?
Best regards
Thomas
0 -
Hi Thomas,
I think it is not yet implemented.
I will relay this feature request to the developers.Cheers,
David0 -
Thank you David!
0
Please sign in to leave a comment.
Comments
7 comments