Setting WorkLimit for Gurobi.jl and JuMP

I am solving a large instance MILP using Gurobi, and I am trying to set the WorkLimit parameter (see: instead of setting a TimeLimit, but I am struggling to do so…

For setting a TimeLimit, things like

model = Model(Gurobi.Optimizer)
set_attribute(model, "TimeLimit", 100)


model = Model(optimizer_with_attributes(Gurobi.Optimizer, "TimeLimit" => 100))

works fine, but for WorkLimit, I get an error saying

ERROR: LoadError: MathOptInterface.UnsupportedAttribute{MathOptInterface.RawOptimizerAttribute}: Attribute MathOptInterface.RawOptimizerAttribute("WorkLimit") is not supported by the model.

I figured that WorkLimit is Gurobi specific, so I tried things like

MOI.set(backend(model), Gurobi.ModelAttribute("WorkLimit"), 100)

which does not complain immediately, but when I then call optimize!(model), I get the error

ERROR: LoadError: Gurobi Error 10004: Unknown attribute 'WorkLimit'

I would appreciate any help or suggestions, thank you!

Minimum (not) working example:

using JuMP, Gurobi

# test data for sample problem
m = 30
n = 30
x_c, y_c = rand(m), rand(m)
x_f, y_f = rand(n), rand(n)
f = ones(n);
c = rand(m, n)

# create model and set TimeLimit --- works
#model = Model(Gurobi.Optimizer)
#set_attribute(model, "WorkLimit", 100)
# ... or 
#model = Model(optimizer_with_attributes(Gurobi.Optimizer, "TimeLimit" => 100))

# create model and set WorkLimit --- does NOT work
model = Model(Gurobi.Optimizer)
#set_attribute(model, "WorkLimit", 100)                             # does NOT work
#set_optimizer_attribute(model, "WorkLimit", 100)                   # does NOT work
MOI.set(backend(model), Gurobi.ModelAttribute("WorkLimit"), 100)    # does NOT work

@variable(model, y[1:n], Bin);
@variable(model, x[1:m, 1:n], Bin);
# Each client is served exactly once
@constraint(model, client_service[i in 1:m], sum(x[i, j] for j in 1:n) == 1);
# A facility must be open to serve a client
@constraint(model, open_facility[i in 1:m, j in 1:n], x[i, j] <= y[j]);
@objective(model, Min, f' * y + sum(c .* x));

println("Optimal value: ", objective_value(model))


set_attribute(model, "WorkLimit", 100) 
set_optimizer_attribute(model, "WorkLimit", 100)

work for me. Can you share more details of your setup: what version of Gurobi.jl, Julia, and Gurobi?

1 Like

I’m on Julia v"1.8.5", with JuMP at v1.14.1, Gurobi.jl at v1.0.3, and Gurobi is 9.1.1.
Out of curiosity, could you please let me know the versions that worked for you?

I think WorkLimit was added to Gurobi 9.5.

You can see the parameters available for Gurobi 9.1 here: Parameters - Gurobi Optimization

1 Like

I see - I will update Gurobi and see if it works, thank you!

1 Like

I’ve now upgraded to Gurobi 9.5 and it works!
For future reference - I had to pkg> remove Gurobi then pkg> add Gurobi to reflect the Gurobi version update.

1 Like