3

In Julia JuMP, I am wondering whether it is possible to access an array, or similar, of the GAP history, the GAP improvements.

I know that at the end of the optimization, I can access the final gap with relative_gap(m) with m of type Model and I want the history of improvements over the solving process.

It could be for instance a vector of Float64 in percent: gaps=[20.2, 16.7, 13.8, 5.1, 0]. In such case my problem is solved to optimality as the final gap is 0.

At the end, I would like to plot the gap improvement in function of time of solving. So maybe all values of gaps could be a couple of two elements, the gap and the solving time until this new gap improvement?

Maybe this is not possible in JuMP so you could answer for Gurobi ?

Thanks!

JKHA
  • 1,800
  • 11
  • 28

2 Answers2

1

It's not possible using JuMP in general.

You could do this in Gurobi using a solver-specific callback: https://github.com/jump-dev/Gurobi.jl#callbacks

Or you could just parse the Gurobi log file that gets printed.

In general though, this information isn't all that useful as it can be quite noisy. Why do you want it?

Oscar Dowson
  • 2,395
  • 1
  • 5
  • 13
  • Regarding application I will share my experience. In big models I am always asking myself - does it make sense to give Gurobi another 4 hours or accept solution as it is. Looking at the gap history (whether it is staled or gradually decreasing) really might help to decide. – Przemyslaw Szufel Mar 02 '22 at 00:34
1

The Gurobi callback solution has been answered by Oscar at another post - see Julia JUMP Gurobi MIP - query and store best objective and bound at runtime.

However, since Gurobi is very serious about its TimeLimit and has low times to continue computations there is also a simpler approach (this code assumes mo is your JuMP Gurobi model):

set_optimizer_attribute(mo, "TimeLimit", 2.0)
gap_history = Float64[]
max_steps = 1800
for t in 1:max_steps
    optimize!(mo)
    gap = MOI.get(mo, MOI.RelativeGap())
    status=termination_status(mo)
    push!(gap_history, gap)
    gap > 0.01 || status == MOI.TIME_LIMIT || break  
end
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62