Skip to content

Commit

Permalink
Add support for VectorOfVariables constraints and add qcp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 30, 2019
1 parent 32b7b5e commit 38cc791
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ const VI = MOI.VariableIndex

const MOIU = MOI.Utilities

const SF = Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{Float64}}
const SS = Union{MOI.Zeros, MOI.Nonnegatives, MOI.SecondOrderCone,
MOI.ExponentialCone}

struct Solution
ret_val::Int
primal::Vector{Float64}
Expand Down Expand Up @@ -89,7 +85,13 @@ function MOI.supports(::Optimizer,
return true
end

MOI.supports_constraint(::Optimizer, ::Type{<:SF}, ::Type{<:SS}) = true
function MOI.supports_constraint(::Optimizer,
::Type{MOI.VectorAffineFunction{Float64}},
::Type{<:Union{MOI.Zeros, MOI.Nonnegatives,
MOI.SecondOrderCone,
MOI.ExponentialCone}})
return true
end

function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kws...)
return MOIU.automatic_copy_to(dest, src; kws...)
Expand Down Expand Up @@ -140,7 +142,6 @@ constrrows(instance::Optimizer, ci::CI{<:MOI.AbstractVectorFunction, <:MOI.Abstr
matrix(data::ModelData, s::MOI.Zeros) = data.b, data.IA, data.JA, data.VA
matrix(data::ModelData, s::Union{MOI.Nonnegatives, MOI.SecondOrderCone, MOI.ExponentialCone}) = data.h, data.IG, data.JG, data.VG
matrix(instance::Optimizer, s) = matrix(instance.data, s)
MOIU.load_constraint(instance::Optimizer, ci, f::MOI.VectorOfVariables, s) = MOIU.load_constraint(instance, ci, MOI.VectorAffineFunction{Float64}(f), s)
# ECOS orders differently than MOI the second and third dimension of the exponential cone
orderval(val, s) = val
function orderval(val, s::Union{MOI.ExponentialCone, Type{MOI.ExponentialCone}})
Expand Down
21 changes: 11 additions & 10 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@ MOIU.@model(ECOSModelData,
MOI.ExponentialCone),
(),
(), (), # No scalar sets
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction,))
(), (MOI.VectorAffineFunction,))
# UniversalFallback is needed for starting values, even if they are ignored by ECOS
const cache = MOIU.UniversalFallback(ECOSModelData{Float64}())
const cached = MOIU.CachingOptimizer(cache, optimizer)

# Essential bridges that are needed for all tests
const bridged = MOIB.Vectorize{Float64}(MOIB.NonposToNonneg{Float64}(cached))
const bridged = MOIB.full_bridge_optimizer(cached, Float64)

# SOC2 requires 1e-4
const config = MOIT.TestConfig(atol=1e-4, rtol=1e-4)

@testset "Unit" begin
MOIT.unittest(MOIB.SplitInterval{Float64}(bridged),
MOIT.unittest(bridged,
config,
[# Quadratic functions are not supported
"solve_qcp_edge_cases", "solve_qp_edge_cases",
[# Need https://github.com/JuliaOpt/MathOptInterface.jl/issues/529
"solve_qp_edge_cases",
# Integer and ZeroOne sets are not supported
"solve_integer_edge_cases", "solve_objbound_edge_cases"])
end

@testset "Continuous linear problems" begin
MOIT.contlineartest(MOIB.SplitInterval{Float64}(bridged),
config)
MOIT.contlineartest(bridged, config)
end

@testset "Continuous quadratic problems" begin
MOIT.qcptest(bridged, config)
end

@testset "Continuous conic problems" begin
exclude = ["sdp", "rootdet", "logdet"]
MOIT.contconictest(MOIB.GeoMean{Float64}(MOIB.RSOC{Float64}(bridged)),
config, exclude)
MOIT.contconictest(bridged, config, exclude)
end

0 comments on commit 38cc791

Please sign in to comment.