From fe0a352bc8f1ecd3c335aa6fa1c5d017bb89d9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 23 Oct 2020 12:14:35 +0200 Subject: [PATCH] Drop MPB wrapper --- Project.toml | 7 +-- src/CSDP.jl | 1 - src/MPB_wrapper.jl | 147 -------------------------------------------- test/MPB_wrapper.jl | 34 ---------- test/runtests.jl | 3 - 5 files changed, 1 insertion(+), 191 deletions(-) delete mode 100644 src/MPB_wrapper.jl delete mode 100644 test/MPB_wrapper.jl diff --git a/Project.toml b/Project.toml index e516236..4baa1e3 100644 --- a/Project.toml +++ b/Project.toml @@ -10,8 +10,6 @@ Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" -MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73" -SemidefiniteModels = "169818f4-1a3d-53bf-95b3-11177825b1e3" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] @@ -19,13 +17,10 @@ BinaryProvider = "0.5.9" CSDP_jll = "=6.2.0" Glob = "1.2" MathOptInterface = "0.9.14" -MathProgBase = "0.7" -SemidefiniteModels = "~0.1.1" julia = "1" [extras] -Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Compat", "Test"] +test = ["Test"] diff --git a/src/CSDP.jl b/src/CSDP.jl index 05f0fe5..f57aa29 100644 --- a/src/CSDP.jl +++ b/src/CSDP.jl @@ -27,6 +27,5 @@ include("declarations.jl") include("debug-mat.jl") include("options.jl") include("MOI_wrapper.jl") -include("MPB_wrapper.jl") end # module diff --git a/src/MPB_wrapper.jl b/src/MPB_wrapper.jl deleted file mode 100644 index a8cfca3..0000000 --- a/src/MPB_wrapper.jl +++ /dev/null @@ -1,147 +0,0 @@ -import MathProgBase -const MPB = MathProgBase.SolverInterface -import SemidefiniteModels -const SDM = SemidefiniteModels - -export CSDPMathProgModel, CSDPSolver - -function checkoptions(d::Dict{Symbol, Any}) - for key in keys(d) - if !(key in ALLOWED_OPTIONS) - error("Option $key is not not a valid CSDP option. The valid options are $ALLOWED_OPTIONS.") - end - end - return d -end - -struct CSDPSolver <: MPB.AbstractMathProgSolver - options::Dict{Symbol,Any} -end -CSDPSolver(; kwargs...) = CSDPSolver(checkoptions(Dict{Symbol,Any}(kwargs))) - -mutable struct CSDPMathProgModel <: SDM.AbstractSDModel - blockdims::Vector{CSDP_INT} - b::Vector{Cdouble} - entries::Vector{Tuple{CSDP_INT,CSDP_INT,CSDP_INT,CSDP_INT,Cdouble}} - C::blockmatrix - problem::Union{Nothing, LoadingProblem} - X::blockmatrix - y::Union{Nothing, Vector{Cdouble}} - Z::blockmatrix - status::CSDP_INT - pobj::Cdouble - dobj::Cdouble - options::Dict{Symbol,Any} - function CSDPMathProgModel(; kwargs...) - new(CSDP_INT[], Cdouble[], Tuple{CSDP_INT,CSDP_INT,CSDP_INT,CSDP_INT,Cdouble}[], - blockmatrix(), nothing, blockmatrix(), nothing, blockmatrix(), - -1, 0.0, 0.0, checkoptions(Dict{Symbol, Any}(kwargs))) - end -end -SDM.SDModel(s::CSDPSolver) = CSDPMathProgModel(; s.options...) -MPB.ConicModel(s::CSDPSolver) = SDM.SDtoConicBridge(SDM.SDModel(s)) -MPB.LinearQuadraticModel(s::CSDPSolver) = MPB.ConicToLPQPBridge(MPB.ConicModel(s)) - -MPB.supportedcones(s::CSDPSolver) = [:Free,:Zero,:NonNeg,:NonPos,:SOC,:RSOC,:SDP] -function MPB.setvartype!(m::CSDPMathProgModel, vtype, blk, i, j) - if vtype != :Cont - error("Unsupported variable type $vtype by CSDP") - end -end - -function MPB.loadproblem!(m::CSDPMathProgModel, filename::AbstractString) - if m.problem !== nothing - if m.y !== nothing - free_loaded_prob(m.problem, m.X, m.y, m.Z) - end - free_loading_prob(m.problem) - end - m.problem = nothing - m.y = nothing - if endswith(filename,".dat-s") - m.problem = load_prob_from_file(filename, Ref(m.C)) - else - error("unrecognized input format extension in $filename") - end -end -#writeproblem(m, filename::String) -function MPB.loadproblem!(m::CSDPMathProgModel, blkdims::Vector{Int}, constr::Int) - if m.problem !== nothing - if m.y !== nothing - free_loaded_prob(m.problem, m.X, m.y, m.Z) - end - free_loading_prob(m.problem) - end - m.problem = nothing - m.y = nothing - m.blockdims = blkdims - m.b = zeros(Cdouble, constr) - empty!(m.entries) -end - -function SDM.setconstrB!(m::CSDPMathProgModel, val, constr::Integer) - m.b[constr] = val -end -function SDM.setconstrentry!(m::CSDPMathProgModel, coef, constr::Integer, blk::Integer, i::Integer, j::Integer) - push!(m.entries, (constr, blk, i, j, coef)) -end -function SDM.setobjentry!(m::CSDPMathProgModel, coef, blk::Integer, i::Integer, j::Integer) - push!(m.entries, (0, blk, i, j, coef)) -end - -function MPB.optimize!(m::CSDPMathProgModel) - if m.problem === nothing - # `m.problem` is not `nothing` if it was loaded from a file. - m.C.nblocks = length(m.blockdims) - num_entries = zeros(CSDP_INT, length(m.b), length(m.blockdims)) - for entry in m.entries - if entry[1] > 0 - num_entries[entry[1], entry[2]] += 1 - end - end - m.problem = allocate_loading_prob(Ref(m.C), m.blockdims, length(m.b), num_entries, 3) - for (i, x) in enumerate(m.b) - setconstant(m.problem, i, x) - end - for entry in m.entries - duplicate = addentry(m.problem, entry..., true) - @assert !duplicate - end - end - m.y = loaded_initsoln(m.problem, length(m.b), Ref(m.X), Ref(m.Z)) - m.status, m.pobj, m.dobj = loaded_sdp(m.problem, Ref(m.X), m.y, Ref(m.Z), m.options) -end - -function MPB.status(m::CSDPMathProgModel) - status = m.status - if status == 0 - return :Optimal - elseif status == 1 - return :Infeasible - elseif status == 2 - return :Unbounded - elseif status == 3 - return :Suboptimal - elseif status == 4 - return :UserLimit - elseif 5 <= status <= 9 - return :Error - elseif status == -1 - return :Uninitialized - else - error("Internal library error: status=$status") - end -end - -function MPB.getobjval(m::CSDPMathProgModel) - m.pobj -end -function MPB.getsolution(m::CSDPMathProgModel) - m.X -end -function MPB.getdual(m::CSDPMathProgModel) - m.y -end -function MPB.getvardual(m::CSDPMathProgModel) - m.Z -end diff --git a/test/MPB_wrapper.jl b/test/MPB_wrapper.jl deleted file mode 100644 index 4948c8a..0000000 --- a/test/MPB_wrapper.jl +++ /dev/null @@ -1,34 +0,0 @@ -const solver = CSDP.CSDPSolver(printlevel=0) - -import MathProgBase -const MPB_test_path = joinpath(dirname(pathof(MathProgBase)), "..", "test") - -@testset "Linear tests" begin - include(joinpath(MPB_test_path, "linproginterface.jl")) - linprogsolvertest(solver, 1e-6) -end - -@testset "Conic tests" begin - include(joinpath(MPB_test_path, "conicinterface.jl")) - # FIXME fails on Windows 32 bits... Maybe I should put linear vars/cons - # in a diagonal matrix in SemidefiniteModels.jl instead of many 1x1 blocks - @static if !Sys.iswindows() || Sys.WORD_SIZE != 32 - @testset "Conic linear tests" begin - coniclineartest(solver, duals=true, tol=1e-6) - end - -# :Error for SOC1 on Mac OS: https://travis-ci.org/JuliaOpt/CSDP.jl/jobs/601461403#L389-L391 -#@testset "Conic SOC tests" begin -# conicSOCtest(CSDP.CSDPSolver(printlevel=0, write_prob="soc.prob"), duals=true, tol=1e-6) -#end - -# CSDP returns :Suboptimal for SOCRotated1 -# @testset "Conic SOC rotated tests" begin -# conicSOCRotatedtest(solver, duals=true, tol=1e-6) -# end - end - - @testset "Conic SDP tests" begin - conicSDPtest(solver, duals=false, tol=1e-6) - end -end diff --git a/test/runtests.jl b/test/runtests.jl index f14d9b6..a91bd60 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -65,6 +65,3 @@ end @testset "MathOptInterface" begin include("MOI_wrapper.jl") end -@testset "MathProgBase" begin - include("MPB_wrapper.jl") -end