From 79d3cb0ab7f4604c49e7e5e8fb0bdf1b27b11e86 Mon Sep 17 00:00:00 2001 From: Robert Schwarz Date: Sun, 24 Jun 2018 21:15:22 +0200 Subject: [PATCH 1/2] add MPB.setparameters! for GLPK{Solver,MathProgModel}LP --- src/GLPKInterfaceLP.jl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 From 554f78962fe8095968b5ebc7badbb51d049f2eeb Mon Sep 17 00:00:00 2001 From: Robert Schwarz Date: Sun, 24 Jun 2018 21:20:36 +0200 Subject: [PATCH 2/2] add more tests --- test/params.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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