diff --git a/src/GLPKInterfaceLP.jl b/src/GLPKInterfaceLP.jl index 73930ba..85146f0 100644 --- a/src/GLPKInterfaceLP.jl +++ b/src/GLPKInterfaceLP.jl @@ -71,6 +71,38 @@ function MPB.LinearQuadraticModel(s::GLPKSolverLP) return lpm end +function MPB.setparameters!(s::GLPKSolverLP; mpboptions...) + opts = collect(Any, s.opts) + for (optname, optval) in mpboptions + if optname == :TimeLimit + push!(opts, (:tm_lim,round(Int,1000*optval))) # milliseconds + elseif optname == :Silent + if optval == true + push!(opts, (:msg_lev,GLPK.MSG_OFF)) + end + else + error("Unrecognized parameter $optname") + end + end + s.opts = opts + nothing +end + +function MPB.setparameters!(m::GLPKMathProgModelLP; mpboptions...) + for (optname, optval) in mpboptions + if optname == :TimeLimit + m.param.tm_lim = round(Int,1000*optval) + elseif optname == :Silent + if optval == true + m.param.msg_lev = GLPK.MSG_OFF + m.smplxparam.msg_lev = GLPK.MSG_OFF + end + else + error("Unrecognized parameter $optname") + end + end +end + function MPB.optimize!(lpm::GLPKMathProgModelLP) lpm.infeasible_bounds = false lp = lpm.inner diff --git a/test/params.jl b/test/params.jl index 00fd09b..d548620 100644 --- a/test/params.jl +++ b/test/params.jl @@ -6,3 +6,16 @@ @test mipm.smplxparam.it_lim == 5910 @test mipm.param.tol_obj == 1.52e-3 end + +@testset "Set MPB parameters" begin + # setparameters! on model + lpm = MathProgBase.LinearQuadraticModel(GLPKSolverLP()) + MathProgBase.setparameters!(lpm, TimeLimit=23.0) + @test lpm.param.tm_lim == 23000.0 + + # setparameters! on solver + lps = GLPKSolverLP() + MathProgBase.setparameters!(lps, TimeLimit=23.0) + lpm2 = MathProgBase.LinearQuadraticModel(lps) + @test lpm2.param.tm_lim == 23000.0 +end