Efficiently Retrieving Variable Values after Gurobi optimization with JuMP

Mathis_3
Mon, 17 Mar 2025 10:51:06 +0000
Optimization (Mathematical)

Hello,

I’m solving a large number of LPs using Gurobi with JuMP, and I noticed that most of the computation time is spent retrieving variable values rather than optimizing the model. Is there a more efficient way to extract variable values after optimization?

Here’s a small example:

using JuMP
using Gurobi

function test(N)
    model = Model(Gurobi.Optimizer)
    set_silent(model)

    @variable(model, x[20:200]>=0);

    @objective(model, Min, sum(x))

    opt_time=0
    time_value=0
    for i in 1:N
        start=time()
        optimize!(model)
        opt_time+=time()-start
        start_value=time()
        a=value.(x)
        time_value+=time()-start_value
    end
    println("optimization time: ", opt_time)
    println("get solution time: ", time_value)
end

test(5000) gives the following output:
optimization time: 0.2440018653869629
get solution time: 1.5249981880187988

Is there a way to speed up the retrieval process?

30 posts - 4 participants