Time limit with GLPK


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

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)

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)



Hi Xavier,

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



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


Thanks a lot for your suggestions.

GLPKSolverMIP( tm_lim=1 )

is perfect!