Skip to content

Commit 242ef3a

Browse files
authored
Merge pull request #48 from leethargo/rs/setparamLP
Implement setparameters! for LP model/solver
2 parents 1491068 + 554f789 commit 242ef3a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/GLPKInterfaceLP.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ function MPB.LinearQuadraticModel(s::GLPKSolverLP)
7171
return lpm
7272
end
7373

74+
function MPB.setparameters!(s::GLPKSolverLP; mpboptions...)
75+
opts = collect(Any, s.opts)
76+
for (optname, optval) in mpboptions
77+
if optname == :TimeLimit
78+
push!(opts, (:tm_lim,round(Int,1000*optval))) # milliseconds
79+
elseif optname == :Silent
80+
if optval == true
81+
push!(opts, (:msg_lev,GLPK.MSG_OFF))
82+
end
83+
else
84+
error("Unrecognized parameter $optname")
85+
end
86+
end
87+
s.opts = opts
88+
nothing
89+
end
90+
91+
function MPB.setparameters!(m::GLPKMathProgModelLP; mpboptions...)
92+
for (optname, optval) in mpboptions
93+
if optname == :TimeLimit
94+
m.param.tm_lim = round(Int,1000*optval)
95+
elseif optname == :Silent
96+
if optval == true
97+
m.param.msg_lev = GLPK.MSG_OFF
98+
m.smplxparam.msg_lev = GLPK.MSG_OFF
99+
end
100+
else
101+
error("Unrecognized parameter $optname")
102+
end
103+
end
104+
end
105+
74106
function MPB.optimize!(lpm::GLPKMathProgModelLP)
75107
lpm.infeasible_bounds = false
76108
lp = lpm.inner

test/params.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@
66
@test mipm.smplxparam.it_lim == 5910
77
@test mipm.param.tol_obj == 1.52e-3
88
end
9+
10+
@testset "Set MPB parameters" begin
11+
# setparameters! on model
12+
lpm = MathProgBase.LinearQuadraticModel(GLPKSolverLP())
13+
MathProgBase.setparameters!(lpm, TimeLimit=23.0)
14+
@test lpm.param.tm_lim == 23000.0
15+
16+
# setparameters! on solver
17+
lps = GLPKSolverLP()
18+
MathProgBase.setparameters!(lps, TimeLimit=23.0)
19+
lpm2 = MathProgBase.LinearQuadraticModel(lps)
20+
@test lpm2.param.tm_lim == 23000.0
21+
end

0 commit comments

Comments
 (0)