Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement setparameters! for LP model/solver #48

Merged
merged 2 commits into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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