Skip to content

Commit

Permalink
#58 - modified AbstractSingleton types
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 19, 2017
1 parent f6113d7 commit a28e804
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 69 deletions.
78 changes: 14 additions & 64 deletions src/Singleton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,103 +3,53 @@ import Base: ∈, ⊆
export Singleton

"""
Singleton{N<:Real} <: LazySet
Singleton{N<:Real} <: AbstractSingleton{N}
Type that represents a singleton, that is, a set with a unique element.
### Fields
- `element` -- the only element of the set
"""
struct Singleton{N<:Real} <: LazySet
struct Singleton{N<:Real} <: AbstractSingleton{N}
element::Vector{N}
end

"""
dim(S::Singleton)::Int
Return the dimension of a singleton.

### Input
# --- AbstractSingleton interface functions ---

- `S` -- singleton

### Output
The ambient dimension of the singleton.
"""
function dim(S::Singleton)::Int
return length(S.element)
end
element(S::Singleton{N})::Vector{N} where {N<:Real}
"""
σ(d::AbstractVector{<:Real}, S::LazySets.Singleton{N})::Vector{N} where {N<:Real}
Return the support vector of a singleton.
Return the element of a singleton.
### Input
- `d` -- direction
- `B` -- singleton
- `S` -- singleton
### Output
The support vector, which is the singleton's vector itself, irrespective of the
given direction.
The element of the singleton.
"""
function σ(d::AbstractVector{<:Real},
S::LazySets.Singleton{N})::Vector{N} where {N<:Real}
function element(S::Singleton{N})::Vector{N} where {N<:Real}
return S.element
end

"""
∈(x::AbstractVector{N}, S::Singleton{N})::Bool where {N<:Real}
element(S::Singleton{N}, i::Int)::N where {N<:Real}
Check whether a given point is contained in a singleton.
Return the i-th entry of the element of a singleton.
### Input
- `x` -- point/vector
- `S` -- singleton
- `i` -- dimension
### Output
`true` iff ``x ∈ S``.
### Notes
This implementation performs an exact comparison, which may be insufficient with
floating point computations.
### Examples
```jldoctest
julia> S = Singleton([1., 1.]);
julia> ∈([0.9, 1.1], S)
false
julia> ∈([1.0, 1.0], S)
true
```
"""
function (x::AbstractVector{N}, S::Singleton{N})::Bool where {N<:Real}
return x == S.element
end

"""
⊆(S::Singleton, set::LazySet)::Bool
Check whether a given singleton is contained in a convex set.
### Input
- `S` -- singleton
- `set` -- convex set
### Output
`true` iff ``S ⊆ \\text{set}``.
The i-th entry of the element of the singleton.
"""
function (S::Singleton, set::LazySet)::Bool
return (S.element, set)
function element(S::Singleton{N}, i::Int)::N where {N<:Real}
return S.element[i]
end
55 changes: 50 additions & 5 deletions src/ZeroSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,62 @@ import Base.∈
export ZeroSet

"""
ZeroSet <: LazySet
ZeroSet{N<:Real} <: AbstractSingleton{N}
Type that represents the zero set, i.e., the set that only contains the origin.
### Fields
- `dim` -- the ambient dimension of this zero set
"""
struct ZeroSet <: LazySet
struct ZeroSet{N<:Real} <: AbstractSingleton{N}
dim::Int
end
# type-less convenience constructor
ZeroSet(dim::Int) = ZeroSet{Float64}(dim)


# --- AbstractSingleton interface functions ---


"""
element(S::ZeroSet{N})::Vector{N} where {N<:Real}
Return the element of a zero set.
### Input
- `S` -- zero set
### Output
The element of the zero set, i.e., a zero vector.
"""
function element(S::ZeroSet{N})::Vector{N} where {N<:Real}
return zeros(N, S.dim)
end

"""
element(S::ZeroSet{N}, ::Int)::N where {N<:Real}
Return the i-th entry of the element of a zero set.
### Input
- `S` -- zero set
- `i` -- dimension
### Output
The i-th entry of the element of the zero set, i.e., 0.
"""
function element(S::ZeroSet{N}, ::Int)::N where {N<:Real}
return zero(N)
end


# --- LazySet interface functions ---


"""
dim(Z::ZeroSet)::Int
Expand All @@ -33,7 +78,7 @@ function dim(Z::ZeroSet)::Int
end

"""
σ(d, Z)
σ(d::AbstractVector{N}, Z::ZeroSet)::Vector{N} where {N<:Real}
Return the support vector of a zero set.
Expand All @@ -51,7 +96,7 @@ function σ(d::AbstractVector{N}, Z::ZeroSet)::Vector{N} where {N<:Real}
end

"""
∈(x::AbstractVector, Z::ZeroSet)::Bool
∈(x::AbstractVector{N}, Z::ZeroSet{N})::Bool where {N<:Real}
Check whether a given point is contained in a zero set.
Expand All @@ -75,7 +120,7 @@ julia> ∈([0.0, 0.0], Z)
true
```
"""
function (x::AbstractVector{N}, Z::ZeroSet)::Bool where {N<:Real}
function (x::AbstractVector{N}, Z::ZeroSet{N})::Bool where {N<:Real}
@assert length(x) == dim(Z)

zero_N = zero(N)
Expand Down

0 comments on commit a28e804

Please sign in to comment.