From 84a1329f5d46f7369c2fa664cc4316bdd6165a85 Mon Sep 17 00:00:00 2001 From: Miles Lubin Date: Thu, 26 Nov 2015 08:26:43 -0500 Subject: [PATCH 1/2] updates for MPB 0.4; drop Julia 0.3 --- .travis.yml | 1 - REQUIRE | 5 ++--- src/GLPKInterfaceBase.jl | 4 +--- src/GLPKInterfaceLP.jl | 7 ++----- src/GLPKInterfaceMIP.jl | 17 +++++++---------- src/GLPKMathProgInterface.jl | 5 +++++ test/runtests.jl | 4 ++-- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 53c5292..e156bf2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - linux - osx julia: - - 0.3 - 0.4 - nightly env: diff --git a/REQUIRE b/REQUIRE index 6c8f9d1..9339230 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,3 @@ -julia 0.3 +julia 0.4 GLPK 0.2.8 -MathProgBase 0.3.0 0.4.0- -Compat 0.7.1 +MathProgBase 0.4.0 0.5.0- diff --git a/src/GLPKInterfaceBase.jl b/src/GLPKInterfaceBase.jl index 67197e7..674145c 100644 --- a/src/GLPKInterfaceBase.jl +++ b/src/GLPKInterfaceBase.jl @@ -1,7 +1,5 @@ module GLPKInterfaceBase -using Compat - import GLPK importall MathProgBase.SolverInterface @@ -31,7 +29,7 @@ export getrawsolver -abstract GLPKMathProgModel <: AbstractMathProgModel +abstract GLPKMathProgModel <: AbstractLinearQuadraticModel function loadproblem!(lpm::GLPKMathProgModel, filename::AbstractString) if endswith(filename, ".mps") || endswith(filename, ".mps.gz") diff --git a/src/GLPKInterfaceLP.jl b/src/GLPKInterfaceLP.jl index a3f4ff0..b299ed6 100644 --- a/src/GLPKInterfaceLP.jl +++ b/src/GLPKInterfaceLP.jl @@ -1,14 +1,11 @@ module GLPKInterfaceLP -using Compat - import GLPK importall MathProgBase.SolverInterface importall ..GLPKInterfaceBase export GLPKSolverLP, - model, optimize!, loadproblem!, writeproblem, @@ -39,7 +36,7 @@ export getinfeasibilityray, getunboundedray -@compat type GLPKMathProgModelLP <: GLPKMathProgModel +type GLPKMathProgModelLP <: GLPKMathProgModel inner::GLPK.Prob method::Symbol param::Union{GLPK.SimplexParam, GLPK.InteriorParam} @@ -61,7 +58,7 @@ type GLPKSolverLP <: AbstractMathProgSolver end end -function model(s::GLPKSolverLP) +function LinearQuadraticModel(s::GLPKSolverLP) if s.method == :Simplex || s.method == :Exact param = GLPK.SimplexParam() if s.presolve diff --git a/src/GLPKInterfaceMIP.jl b/src/GLPKInterfaceMIP.jl index 623307a..cec1ace 100644 --- a/src/GLPKInterfaceMIP.jl +++ b/src/GLPKInterfaceMIP.jl @@ -4,12 +4,9 @@ import GLPK importall MathProgBase.SolverInterface importall ..GLPKInterfaceBase -using Compat - export GLPKSolverMIP, GLPKCallbackData, - model, optimize!, loadproblem!, writeproblem, @@ -51,7 +48,7 @@ export cbaddcut!, cbaddsolution -@compat type GLPKMathProgModelMIP <: GLPKMathProgModel +type GLPKMathProgModelMIP <: GLPKMathProgModel inner::GLPK.Prob param::GLPK.IntoptParam smplxparam::GLPK.SimplexParam @@ -168,7 +165,7 @@ function _internal_callback(tree::Ptr{Void}, info::Ptr{Void}) return end -function model(s::GLPKSolverMIP) +function LinearQuadraticModel(s::GLPKSolverMIP) lpm = GLPKMathProgModelMIP() lpm.param.msg_lev = GLPK.MSG_ERR lpm.smplxparam.msg_lev = GLPK.MSG_ERR @@ -203,10 +200,10 @@ function model(s::GLPKSolverMIP) return lpm end -@compat setlazycallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.lazycb = f) -@compat setcutcallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.cutcb = f) -@compat setheuristiccallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.heuristiccb = f) -@compat setinfocallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.infocb = f) +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) +setinfocallback!(m::GLPKMathProgModel, f::Union{Function,Void}) = (m.infocb = f) _check_tree(d::GLPKCallbackData, funcname::AbstractString) = (d.tree != C_NULL && d.reason != -1) || error("$funcname can only be called from within a callback") @@ -396,7 +393,7 @@ function setvartype!(lpm::GLPKMathProgModelMIP, vartype::Vector{Symbol}) end end -@compat const vartype_map = Dict( +const vartype_map = Dict( GLPK.CV => :Cont, GLPK.IV => :Int, GLPK.BV => :Bin diff --git a/src/GLPKMathProgInterface.jl b/src/GLPKMathProgInterface.jl index 5ce6501..da54d94 100644 --- a/src/GLPKMathProgInterface.jl +++ b/src/GLPKMathProgInterface.jl @@ -13,4 +13,9 @@ include("GLPKInterfaceMIP.jl") const GLPKSolverLP = GLPKInterfaceLP.GLPKSolverLP const GLPKSolverMIP = GLPKInterfaceMIP.GLPKSolverMIP +# Enables GLPK to act as a conic solver +import MathProgBase +MathProgBase.ConicModel(s::Union{GLPKSolverLP,GLPKSolverMIP}) = MathProgBase.LPQPtoConicBridge(MathProgBase.LinearQuadraticModel(s)) +MathProgBase.supportedcones(::Union{GLPKSolverLP,GLPKSolverMIP}) = [:Free,:Zero,:NonNeg,:NonPos] + end diff --git a/test/runtests.jl b/test/runtests.jl index 9da3f74..1337554 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,9 +11,9 @@ linprogsolvertest(GLPKSolverLP()) include(joinpath(mathprogbase_test, "mixintprog.jl")) mixintprogtest(GLPKSolverMIP()) -lpm = GLPKInterfaceLP.model(GLPKSolverLP(it_lim=9513, tol_bnd=4.149)) +lpm = GLPKInterfaceLP.LinearQuadraticModel(GLPKSolverLP(it_lim=9513, tol_bnd=4.149)) @test lpm.param.it_lim == 9513 @test lpm.param.tol_bnd == 4.149 -mipm = GLPKInterfaceMIP.model(GLPKSolverMIP(it_lim=5910, tol_obj=1.52e-3)) +mipm = GLPKInterfaceMIP.LinearQuadraticModel(GLPKSolverMIP(it_lim=5910, tol_obj=1.52e-3)) @test mipm.smplxparam.it_lim == 5910 @test mipm.param.tol_obj == 1.52e-3 From f60c69c8103d7b3677321a2898a44d9d989a960b Mon Sep 17 00:00:00 2001 From: Miles Lubin Date: Mon, 30 Nov 2015 15:39:17 -0500 Subject: [PATCH 2/2] test GLPK as a conic solver --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 1337554..3d8db88 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,10 @@ linprogsolvertest(GLPKSolverLP()) include(joinpath(mathprogbase_test, "mixintprog.jl")) mixintprogtest(GLPKSolverMIP()) +include(joinpath(mathprogbase_test,"conicinterface.jl")) +coniclineartest(GLPKSolverLP()) +coniclineartest(GLPKSolverMIP()) + lpm = GLPKInterfaceLP.LinearQuadraticModel(GLPKSolverLP(it_lim=9513, tol_bnd=4.149)) @test lpm.param.it_lim == 9513 @test lpm.param.tol_bnd == 4.149