Hi!
I am solving a large instance MILP using Gurobi, and I am trying to set the WorkLimit
parameter (see: https://www.gurobi.com/documentation/current/refman/worklimit.html) 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)
or
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));
optimize!(model)
println("Optimal value: ", objective_value(model))