Skip to content

Commit

Permalink
Merge pull request #8 from blegat/moit
Browse files Browse the repository at this point in the history
Transition to MOIT and remove solver
  • Loading branch information
joehuchette authored Dec 29, 2017
2 parents 22e6bfd + e1031fe commit b509d50
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ notifications:
before_script:
- julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterface.jl.git")'
- julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterfaceUtilities.jl.git")'
- julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterfaceTests.jl.git")'
- julia -e 'Pkg.clone("https://github.com/JuliaOpt/SemidefiniteOptInterface.jl.git")'
# uncomment the following lines to override the default test script
#script:
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.6
BinDeps
MathOptInterface
MathOptInterfaceTests
SemidefiniteOptInterface
41 changes: 17 additions & 24 deletions src/DSDPSolverInterface.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using SemidefiniteOptInterface
SOI = SemidefiniteOptInterface
SDOI = SemidefiniteOptInterface

using MathOptInterface
MOI = MathOptInterface

export DSDPSolver
export DSDPInstance

struct DSDPSolver <: SOI.AbstractSDSolver
options::Dict{Symbol,Any}
end
DSDPSolver(;kwargs...) = DSDPSolver(Dict{Symbol,Any}(kwargs))

mutable struct DSDPSolverInstance <: SOI.AbstractSDSolverInstance
mutable struct DSDPSolverInstance <: SDOI.AbstractSDSolverInstance
dsdp::DSDPT
lpcone::LPCone.LPConeT
nconstrs::Int
Expand All @@ -36,7 +31,7 @@ mutable struct DSDPSolverInstance <: SOI.AbstractSDSolverInstance
m
end
end
SOI.SDSolverInstance(s::DSDPSolver) = DSDPSolverInstance(; s.options...)
DSDPInstance(; kws...) = SDOI.SDOIInstance(DSDPSolverInstance(; kws...))

function _free(m::DSDPSolverInstance)
if m.dsdp != C_NULL
Expand Down Expand Up @@ -78,12 +73,10 @@ const options = Dict(

const options_setters = Dict{Symbol, Function}()

abstract type Option <: MOI.AbstractSolverAttribute end
abstract type Option <: MOI.AbstractInstanceAttribute end
abstract type GettableOption <: Option end

MOI.canget(solver::Union{DSDPSolver, DSDPSolverInstance}, ::Option) = true
MOI.set!(solver::DSDPSolver, o::Option, val) = _dict_set!(solver.options, o, val)
MOI.get(solver::DSDPSolver, o::Option) = _dict_get(solver.options, o)
MOI.canget(solver::DSDPSolverInstance, ::Option) = true
function MOI.set!(m::DSDPSolverInstance, o::Option, val)
# Need to set it in the dictionary so that it is also used when initinstance! is called again
_dict_set!(m.options, o, val)
Expand Down Expand Up @@ -135,7 +128,7 @@ for (param, default) in Iterators.flatten((options, gettable_options))
end
end

function SOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs::Int)
function SDOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs::Int)
_free(m)
@assert nconstrs >= 0
m.nconstrs = nconstrs
Expand Down Expand Up @@ -176,7 +169,7 @@ function SOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs
m.z_computed = false
end

function SOI.setconstraintconstant!(m::DSDPSolverInstance, val, constr::Integer)
function SDOI.setconstraintconstant!(m::DSDPSolverInstance, val, constr::Integer)
SetDualObjective(m.dsdp, constr, val)
end
function _setcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer)
Expand All @@ -189,11 +182,11 @@ function _setcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Int
error("TODO")
end
end
function SOI.setconstraintcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer)
function SDOI.setconstraintcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer)
_setcoefficient!(m, coef, constr, blk, i, j)
end
function SOI.setobjectivecoefficient!(m::DSDPSolverInstance, coef, blk::Integer, i::Integer, j::Integer)
# in SOI, convention is MAX but in DSDP, convention is MIN so we reverse the sign of coef
function SDOI.setobjectivecoefficient!(m::DSDPSolverInstance, coef, blk::Integer, i::Integer, j::Integer)
# in SDOI, convention is MAX but in DSDP, convention is MIN so we reverse the sign of coef
_setcoefficient!(m, -coef, 0, blk, i, j)
end

Expand Down Expand Up @@ -271,10 +264,10 @@ function MOI.get(m::DSDPSolverInstance, ::MOI.DualStatus)
end
end

function SOI.getprimalobjectivevalue(m::DSDPSolverInstance)
function SDOI.getprimalobjectivevalue(m::DSDPSolverInstance)
-GetPPObjective(m.dsdp)
end
function SOI.getdualobjectivevalue(m::DSDPSolverInstance)
function SDOI.getdualobjectivevalue(m::DSDPSolverInstance)
-GetDDObjective(m.dsdp)
end

Expand Down Expand Up @@ -304,15 +297,15 @@ function Base.getindex(x::XBlockMat, i)
@assert x.instance.blkdims[i] < 0
LPXBlock(x.instance.lpcone, x.instance.blk[i])
end
function SOI.getX(m::DSDPSolverInstance)
function SDOI.getX(m::DSDPSolverInstance)
XBlockMat(m)
end

function SOI.gety(m::DSDPSolverInstance)
function SDOI.gety(m::DSDPSolverInstance)
if !m.y_valid
m.y = Vector{Cdouble}(m.nconstrs)
GetY(m.dsdp, m.y)
map!(-, m.y, m.y) # The primal objective is Max in SOI but Min in DSDP
map!(-, m.y, m.y) # The primal objective is Max in SDOI but Min in DSDP
end
m.y
end
Expand Down Expand Up @@ -342,6 +335,6 @@ function Base.getindex(z::ZBlockMat, i)
@assert z.instance.blkdims[i] < 0
LPZBlock(z.instance.lpcone, z.instance.blk[i])
end
function SOI.getZ(m::DSDPSolverInstance)
function SDOI.getZ(m::DSDPSolverInstance)
ZBlockMat(m)
end
2 changes: 1 addition & 1 deletion test/maxcut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function maxcut(nnodes, edges)
DSDP.SetPNormTolerance(dsdp, 1.0)
#info = TCheckArgs(dsdp,argc,argv)

DSDP.SetStandardMonitor(dsdp,1)
DSDP.SetStandardMonitor(dsdp,0)

DSDP.Setup(dsdp)

Expand Down
17 changes: 7 additions & 10 deletions test/moi.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using MathOptInterfaceTests
const MOIT = MathOptInterfaceTests

const solver = () -> DSDP.DSDPInstance()
const config = MOIT.TestConfig(1e-6, 1e-6, true, true, true, true)

@testset "Linear tests" begin
include(joinpath(Pkg.dir("MathOptInterface"), "test", "contlinear.jl"))
linear2test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear3test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear4test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear5test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear6test(DSDP.DSDPSolver(), atol=1e-6, rtol=1e-6)
linear7test(DSDP.DSDPSolver(), atol=1e-6, rtol=1e-6)
linear8test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear9test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
linear10test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7)
MOIT.contlineartest(solver, config, ["linear1", "linear11", "linear12"])
end
#@testset "Conic tests" begin
# include(joinpath(Pkg.dir("MathOptInterface"), "test", "contconic.jl"))
Expand Down
5 changes: 2 additions & 3 deletions test/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ using SemidefiniteOptInterface
const SOI = SemidefiniteOptInterface

@testset "Options" begin
solver = DSDPSolver()
instance = SOI.SDSolverInstance(solver)
instance = DSDP.DSDPSolverInstance()
SOI.initinstance!(instance, [1], 42)
for (option, default) in Iterators.flatten((DSDP.options, DSDP.gettable_options))
@eval begin
@test MOI.get($solver, DSDP.$option()) == MOI.get($instance, DSDP.$option()) == $default
@test MOI.get($instance, DSDP.$option()) == $default
end
end
end

0 comments on commit b509d50

Please sign in to comment.