メインコンテンツへスキップ

Concurrent Optimizer and callbacks

回答済み

コメント

7件のコメント

  • David Torres Sanchez
    • Gurobi Staff Gurobi Staff

    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, 
    David

    0
  • Thomas Leveringhaus
    • Gurobi-versary
    • Collaborator
    • Investigator

    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
  • Thomas Leveringhaus
    • Gurobi-versary
    • Collaborator
    • Investigator

    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
  • David Torres Sanchez
    • Gurobi Staff Gurobi Staff

    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,
    David

    0
  • Thomas Leveringhaus
    • Gurobi-versary
    • Collaborator
    • Investigator

    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
  • David Torres Sanchez
    • Gurobi Staff Gurobi Staff

    Hi Thomas,

    I think it is not yet implemented.
    I will relay this feature request to the developers.

    Cheers, 
    David

    0
  • Thomas Leveringhaus
    • Gurobi-versary
    • Collaborator
    • Investigator

    Thank you David!

    0

サインインしてコメントを残してください。