Skip to main content

Saving solutions as soon as they are found

Answered

Comments

9 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Sonja Mars
    • Gurobi Staff

    Hi,

    For getting any objective values and/or solution vectors during an optimization, you can use a MIPSOL Callback. Within this you can query MIPSOL_SOL and write it down to a file.

    Best regards,

      Sonja

    0
  • Gehan Abouelseoud
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you for your reply.

    According to the manual MIPSOL_SOL is available only for C interface. I am using python and it would not be practical for me to transfer my work to C. Currently, I am using some trial and error to guess a suitable time limit that would be sufficient for Gurobi to find some updated solution. I save the solution after the run ends and re-run with the saved solution as initial guess. It does not work always (for some problems no solution is available till hours) but it is better than nothing.

    0
  • Sonja Mars
    • Gurobi Staff

    I am sorry, these where general guidelines as I did not know the language you are using. For Python you can use the Model.cbGetSolution() method to retrieve the solution values.

     

    0
  • Gehan Abouelseoud
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you very much. This helps a lot. I really appreciate your support.

    0
  • Eli Towle
    • Gurobi Staff

    Hi Gehan,

    With the release of Gurobi 9.0, you can also use the SolFiles parameter to automatically write solution files for newly found incumbent solutions.

    Thanks!

    Eli

    1
  • Gehan Abouelseoud
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you for this special much needed feature

    I really appreciate your support

    0
  • Robert Hildebrand
    • Gurobi-versary
    • Conversationalist
    • First Question

    Is there a simple way to load the solution file as an initial starting solution for resolving the MIP later?

    For instance, if on one run I solve and store the solution

    model.write('model.sol')

    can I later, recreate the model, and then run something like

    model.start('model.sol')?

    0
  • Tobias Achterberg
    • Gurobi Staff

    You just read in the *.sol file: model.read('model.sol')

    1

Post is closed for comments.