Skip to content

Define dimension for AbstractScalarSet, add some tests. #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2018
Merged
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
29 changes: 23 additions & 6 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,43 @@ Abstract supertype for set objects used to encode constraints.
"""
abstract type AbstractSet end

"""
dimension(s::AbstractSet)

Return the output dimension that an [`AbstractFunction`](@ref) should have to be used with the set `s`.

### Examples

```julia-repl
julia> dimension(Reals(4))
4

julia> dimension(LessThan(3.0))
1

julia> dimension(PositiveSemidefiniteConeTriangle(2))
3
```

"""
function dimension end

"""
AbstractScalarSet

Abstract supertype for subsets of ``\\mathbb{R}``.
"""
abstract type AbstractScalarSet <: AbstractSet end

dimension(s::AbstractScalarSet) = 1

"""
AbstractVectorSet

Abstract supertype for subsets of ``\\mathbb{R}^n`` for some ``n``.
"""
abstract type AbstractVectorSet <: AbstractSet end

"""
dimension(s::AbstractVectorSet)

Return the underlying dimension (number of vector components) in the set `s`, i.e.,
``n`` if the set is a subset of ``\\mathbb{R}^n``.
"""
dimension(s::AbstractVectorSet) = s.dimension # .dimension field is conventional, overwrite this method if not applicable

"""
Expand Down
13 changes: 13 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
@test MOIU.getconstant(MOI.GreaterThan(6)) == 6
@test MOIU.getconstant(MOI.LessThan(2)) == 2
end

@testset "Set dimension" begin
@test MOI.dimension(MOI.EqualTo(3.0)) === 1
@test MOI.dimension(MOI.Reals(8)) === 8
@test MOI.dimension(MOI.DualExponentialCone()) === 3
@test MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(4)) === 10
@test MOI.dimension(MOI.PositiveSemidefiniteConeSquare(5)) === 25
@test MOI.dimension(MOI.RootDetConeTriangle(6)) === 22
@test MOI.dimension(MOI.LogDetConeTriangle(6)) === 22
@test MOI.dimension(MOI.RootDetConeSquare(4)) === 17
@test MOI.dimension(MOI.LogDetConeSquare(4)) === 17
@test MOI.dimension(MOI.SOS2(collect(1 : 6))) === 6
end