Skip to content

Commit ab5988f

Browse files
authored
Merge pull request #39 from JuliaOpt/ml/setparams
implement MathProgBase.setparameters
2 parents 42beef8 + 6a541fb commit ab5988f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/GLPKInterfaceMIP.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,38 @@ function LinearQuadraticModel(s::GLPKSolverMIP)
224224
return lpm
225225
end
226226

227+
function setparameters!(s::GLPKSolverMIP; mpboptions...)
228+
opts = collect(s.opts)
229+
for (optname, optval) in mpboptions
230+
if optname == :TimeLimit
231+
push!(opts, (:tm_lim,round(Int,1000*optval))) # milliseconds
232+
elseif optname == :Silent
233+
if optval == true
234+
push!(opts, (:msg_lev,GLPK.MSG_OFF))
235+
end
236+
else
237+
error("Unrecognized parameter $optname")
238+
end
239+
end
240+
s.opts = opts
241+
nothing
242+
end
243+
244+
function setparameters!(m::GLPKMathProgModelMIP; mpboptions...)
245+
for (optname, optval) in mpboptions
246+
if optname == :TimeLimit
247+
m.param.tm_lim = round(Int,1000*optval)
248+
elseif optname == :Silent
249+
if optval == true
250+
m.param.msg_lev = GLPK.MSG_OFF
251+
m.smplxparam.msg_lev = GLPK.MSG_OFF
252+
end
253+
else
254+
error("Unrecognized parameter $optname")
255+
end
256+
end
257+
end
258+
227259
setlazycallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.lazycb = f)
228260
setcutcallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.cutcb = f)
229261
setheuristiccallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.heuristiccb = f)

test/mathprog.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@
1212

1313
include(joinpath(mathprogbase_test,"conicinterface.jl"))
1414
coniclineartest(GLPKSolverLP())
15-
coniclineartest(GLPKSolverMIP())
15+
16+
solver = GLPKSolverMIP(msg_lev=GLPK.MSG_ALL)
17+
18+
# Silent should override GLPK.MSG_ALL
19+
MathProgBase.setparameters!(solver, Silent=true, TimeLimit=100.0)
20+
coniclineartest(solver)
21+
1622
end

0 commit comments

Comments
 (0)