Saving solutions as soon as they are found
AnsweredI am solving a large MIP problem. It typically takes no less than six hours to find a MIP solution with an objective better than initial guess. Sometimes the computer hangs or power blackouts occur before the end of the run. Is it possible to save an MIP solution with an updated objective function value to a file as soon as it is found?This will help me use it as a starting point if any problem occurs instead of having to re-start from scratch.
-
Official comment
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?. -
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 -
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 -
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 -
Thank you very much. This helps a lot. I really appreciate your support.
0 -
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 -
Thank you for this special much needed feature
I really appreciate your support
0 -
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 -
You just read in the *.sol file: model.read('model.sol')
1
Post is closed for comments.
Comments
9 comments