Resetting TimeLimit of Gurobi Optimizer

I am currently using JuMP with the Gurobi Solver to optimise a tournament schedule. I use a local search heuristic to try and solve each round in a given time limit after having found a first feasible solution. The problem I now face is, that it takes quite a while to find a first initial solution. Therefore my time limit is quite high. I would like to lower it before reoptimizing each round, but I could not find any examples on how to modify this parameter from the Gurobi Solver in Julia. (E.g in Java I could do the following: m.set(“TimeLimit”, “100.0”); )

Below is a very simple example, where I would like to change the time limit before the second call to optimize!().

using JuMP
using Gurobi

m = Model(with_optimizer(Gurobi.Optimizer, TimeLimit=720))
@variable(m, x[1:2] >= 0, Int)

@constraint(m, 4*x[1] <= 400)
@constraint(m, x[2] <= 120)
@constraint(m, 8*x[1] + 4*x[2] <= 1000)

@objective(m, Max, sum(24*x[1] + 20*x[2]))
optimize!(m)

@constraint(m, x[2] <= 100)
@objective(m, Max, sum(24*x[1] + 20*x[2]))
#set new TimeLimit?
optimize!(m)

It should be

MOI.set(m, MOI.RawParameter("TimeLimit"), 100.0);

but for this to work at the moment, you should checkout https://github.com/JuliaOpt/JuMP.jl/pull/2003, MOI master and https://github.com/JuliaOpt/Gurobi.jl/pull/216/. It should work with JuMP v0.20.

In JuMP v0.19, you can hack your way around with

Gurobi.setparam!(backend(m).optimizer.model.inner, "TimeLimit", 100.0)
1 Like

@blegat I happened to see your answer. I think you are an expert in this field. How do you add the solution time limit to the gurobi / CPLEX solver in jump, so as to finish earlier and get the value of the solution.

I tried to add this line of code to the bileveljump package, but I got an error

Gurobi.setparam!(backend(model).optimizer.model.inner, "TimeLimit", 100.0)
ERROR: LoadError: MethodError: no method matching backend(::BilevelModel)
Closest candidates are:

Stacktrace:
 [1] top-level scope at E:\Julia程序\加整数0-1测试.jl:6
in expression starting at E:\Julia程序\加整数0-1测试.jl:6

As you have a BilevelModel instead of a JuMP.Model, you should replace backend(m) by m.solver.
Note that the post above is outdated and you can now do MOI.set(m, MOI.TimeLimitSec(), 100.0) (you should probably replace m by m.solver if it is a BilevelModel)

yes,you are right!
thank you so much!