# Time limit with GLPK

**URL:** <https://discourse.julialang.org/t/time-limit-with-glpk/6263>\
**Category:** Optimization (Mathematical)\
**Created:** [October 5, 2017, 1:48pm UTC](https://discourse.julialang.org/t/time-limit-with-glpk/6263 "2017-10-05T13:48:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![XavierG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavierg/32/1768_2.png) [@XavierG](https://discourse.julialang.org/u/XavierG)\
**Post date:** [October 5, 2017, 1:48pm UTC](https://discourse.julialang.org/t/time-limit-with-glpk/6263/1 "2017-10-05T13:48:35Z")

</div>

Hi all,

GLPK proposes an option to stop the (MIP) solver after an elapsed time: TmLim (TmLim=value). Probably I am invoking the option in a wrong manner because it is not recognized (WARNING: Ignored option: TmLim). Somebody has a suggestion to this (or know an alternative to stop the solver)?

Here my Julia code, and the output. Thanks, Xavier

* * *

using JuMP, GLPKMathProgInterface

function set01UKP(solverSelected, p, w, c)  
n = size(p,1)  
m = Model(solver=solverSelected)  
@variable(m, x[1:n], Bin)  
@objective(m, Max, dot(p, x))  
@constraint(m, dot(w, x) \<= c)  
return m, x  
end

profit = rand(1:100,100)  
weight = rand(1:100,100)  
capacity = convert(Int64,ceil(sum(weight)\*0.5))

solverSelected = GLPKSolverMIP(msg\_lev=GLPK.MSG\_ON, TmLim=1)  
ip, ip\_x = set01UKP(solverSelected, profit, weight, capacity)  
solve(ip)

* * *

julia\> solverSelected = GLPKSolverMIP(msg\_lev=GLPK.MSG\_ON, TmLim=1)  
GLPKMathProgInterface.GLPKInterfaceMIP.GLPKSolverMIP(false, Any[(:msg\_lev, 2), (:TmLim, 1)])

julia\> ip, ip\_x = set01UKP(solverSelected, profit, weight, capacity)  
(Maximization problem with:

- 1 linear constraint
- 100 variables: 100 binary  
Solver is GLPKInterfaceMIP, x[i] ∈ {0,1} ∀ i ∈ {1,2,…,99,100})

julia\> solve(ip)  
WARNING: Ignored option: TmLim

- 

```
0: obj = -0,000000000e+00 inf = 0,000e+00 (100)

```

- 73: obj = 3,979188889e+03 inf = 0,000e+00 (0)

- 73: mip = not found yet \<= +inf (1; 0)  
Solution found by heuristic: 3951  
Solution found by heuristic: 3974
- 81: mip = 3,974000000e+03 \<= tree is empty 0.0% (0; 9)  
:Optimal

julia\>

---

<div class="post-metadata">

**Author:** ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Post date:** [October 13, 2017, 8:08pm UTC](https://discourse.julialang.org/t/time-limit-with-glpk/6263/2 "2017-10-13T20:08:14Z")

</div>

Hi Xavier,

you can use an info callback function checking the time or a gap or whatever you want and then use:

`throw(CallbackAbort())`

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 13, 2017, 8:27pm UTC](https://discourse.julialang.org/t/time-limit-with-glpk/6263/3 "2017-10-13T20:27:56Z")

</div>

I think the option might be spelled `tm_lim` not `TmLim`. See page 53 of [http://kam.mff.cuni.cz/~elias/glpk](http://kam.mff.cuni.cz/~elias/glpk)

---

<div class="post-metadata">

**Author:** ![XavierG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavierg/32/1768_2.png) [@XavierG](https://discourse.julialang.org/u/XavierG)\
**Post date:** [October 17, 2017, 1:04pm UTC](https://discourse.julialang.org/t/time-limit-with-glpk/6263/4 "2017-10-17T13:04:06Z")

</div>

Thanks a lot for your suggestions.

GLPKSolverMIP( tm\_lim=1 )

is perfect!
