Skip to content

Commit

Permalink
Merge pull request #48 from leethargo/rs/setparamLP
Browse files Browse the repository at this point in the history
Implement setparameters! for LP model/solver
  • Loading branch information
mlubin authored Jun 24, 2018
2 parents 1491068 + 554f789 commit 242ef3a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/GLPKInterfaceLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/params.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 242ef3a

Please sign in to comment.