Skip to content

Commit

Permalink
Merge pull request #39 from JuliaOpt/ml/setparams
Browse files Browse the repository at this point in the history
implement MathProgBase.setparameters
  • Loading branch information
mlubin authored Mar 10, 2017
2 parents 42beef8 + 6a541fb commit ab5988f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/GLPKInterfaceMIP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,38 @@ function LinearQuadraticModel(s::GLPKSolverMIP)
return lpm
end

function setparameters!(s::GLPKSolverMIP; mpboptions...)
opts = collect(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 setparameters!(m::GLPKMathProgModelMIP; 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

setlazycallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.lazycb = f)
setcutcallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.cutcb = f)
setheuristiccallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.heuristiccb = f)
Expand Down
8 changes: 7 additions & 1 deletion test/mathprog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@

include(joinpath(mathprogbase_test,"conicinterface.jl"))
coniclineartest(GLPKSolverLP())
coniclineartest(GLPKSolverMIP())

solver = GLPKSolverMIP(msg_lev=GLPK.MSG_ALL)

# Silent should override GLPK.MSG_ALL
MathProgBase.setparameters!(solver, Silent=true, TimeLimit=100.0)
coniclineartest(solver)

end

0 comments on commit ab5988f

Please sign in to comment.