There’s an optimization-type contest, I’m participating using MathOptInterface.jl and Gurobi.jl. Seeing as I don’t feel I’ll be able to improve the program formulation any more, I think the only way to further improve my score is to give Gurobi as much solving time as possible. Thus my current strategy is to set a timeout for the solver using MOI.TimeLimitSec so that the solve would time out a few hours before the deadline, producing the best possible solution given the limited time.
A potential problem with this strategy, though, is that if the laptop the solver is running on suffers some kind of fault, all the work done by Gurobi would be lost. I wonder if there’s some way to interrupt the solving process, querying the current best value of the solution, and then allow the solver to resume where it left off? This would allow me to continuously (e.g., every hour) interrupt the solver for reports.
Is something like this possible using MOI and Gurobi.jl?
But you could write a callback that saves the primal feasible points that are encountered:
I didn’t test locally, but something like this?
using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
function my_callback_function(cb_data, cb_where::Cint)
if cb_where == GRB_CB_MIPSOL
Gurobi.load_callback_variable_primal(cb_data, cb_where)
open("solution.txt", "a") do io
println(io, callback_value.(cb_data, all_variables.(model)))
end
end
return
end
set_attriute(model, Gurobi.CallbackFunction(), my_callback_function)
optimize!(model)
You should take a careful look at the log though. Is the primal solution improving even after hours? Or is Gurobi trying to close the dual bound to prove optimality?
i believe that simply calling optimize!(model) again will continue the optimization for the same duration as spécificités by TimeLimitSec. Would that address your issue?