# Resetting TimeLimit of Gurobi Optimizer

**URL:** https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [July 22, 2019, 12:30pm UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627 "2019-07-22T12:30:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![TheLoooser](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@TheLoooser](https://discourse.julialang.org/u/TheLoooser)
#### Post date: [July 22, 2019, 12:30pm UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627/1 "2019-07-22T12:30:37Z")

</div>

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!().

```julia
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)

```

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [July 22, 2019, 1:05pm UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627/2 "2019-07-22T13:05:54Z")

</div>

It should be

```julia
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](https://github.com/JuliaOpt/JuMP.jl/pull/2003), [MOI](https://github.com/JuliaOpt/MathOptInterface.jl) master and [https://github.com/JuliaOpt/Gurobi.jl/pull/216/](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

```julia
Gurobi.setparam!(backend(m).optimizer.model.inner, "TimeLimit", 100.0)

```

---

<div class="post-metadata">

### Author: ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)
#### Post date: [August 11, 2020, 8:21am UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627/3 "2020-08-11T08:21:05Z")

</div>

@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

```julia
Gurobi.setparam!(backend(model).optimizer.model.inner, "TimeLimit", 100.0)

```

```julia
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

```

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [August 12, 2020, 10:52am UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627/4 "2020-08-12T10:52:06Z")

</div>

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`)

---

<div class="post-metadata">

### Author: ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)
#### Post date: [August 12, 2020, 11:23am UTC](https://discourse.julialang.org/t/resetting-timelimit-of-gurobi-optimizer/26627/5 "2020-08-12T11:23:06Z")

</div>

yes,you are right!  
thank you so much!
