Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,19 @@ MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables, MathOptInte
"""
struct SOS1{T<:Real} <: AbstractVectorSet
weights::Vector{T}

function SOS1{T}(weights::Vector{T}) where {T<:Real}
if isempty(weights)
throw(DimensionMismatch("Dimension of SOS1 must be > 0."))
end
return new{T}(weights)
end
end

SOS1(w::AbstractVector{T}) where {T<:Real} = SOS1{T}(w)

SOS1{T}(w::AbstractVector) where {T<:Real} = SOS1{T}(convert(Vector{T}, w))

dimension(set::SOS1) = length(set.weights)

Base.copy(set::SOS1{T}) where {T} = SOS1{T}(copy(set.weights))
Expand Down Expand Up @@ -1889,8 +1900,19 @@ MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables, MathOptInte
"""
struct SOS2{T<:Real} <: AbstractVectorSet
weights::Vector{T}

function SOS2{T}(weights::Vector{T}) where {T<:Real}
if isempty(weights)
throw(DimensionMismatch("Dimension of SOS2 must be > 0."))
end
return new{T}(weights)
end
end

SOS2(w::AbstractVector{T}) where {T<:Real} = SOS2{T}(w)

SOS2{T}(w::AbstractVector) where {T<:Real} = SOS2{T}(convert(Vector{T}, w))

dimension(set::SOS2) = length(set.weights)

Base.copy(set::SOS2{T}) where {T} = SOS2{T}(copy(set.weights))
Expand Down
18 changes: 18 additions & 0 deletions test/General/test_sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,24 @@ function test_VectorNonlinearOracle()
return
end

function test_SOS1_constructor()
@test_throws DimensionMismatch MOI.SOS1{Float64}(Float64[])
@test_throws DimensionMismatch MOI.SOS1(Float64[])
@test_throws DimensionMismatch MOI.SOS1(1:0)
@test MOI.SOS1(1:3) == MOI.SOS1{Int}(Int[1, 2, 3])
@test MOI.SOS1{Float64}(1:3) == MOI.SOS1{Float64}([1.0, 2.0, 3.0])
return
end

function test_SOS2_constructor()
@test_throws DimensionMismatch MOI.SOS2{Float64}(Float64[])
@test_throws DimensionMismatch MOI.SOS2(Float64[])
@test_throws DimensionMismatch MOI.SOS2(1:0)
@test MOI.SOS2(1:3) == MOI.SOS2{Int}(Int[1, 2, 3])
@test MOI.SOS2{Float64}(1:3) == MOI.SOS2{Float64}([1.0, 2.0, 3.0])
return
end

end # module

TestSets.runtests()
Loading