Skip to content

Commit

Permalink
#58 - added abstract type hierarchy skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 13, 2017
1 parent 1195cc7 commit 62b01bb
Show file tree
Hide file tree
Showing 20 changed files with 231 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Ball1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base.∈
export Ball1

"""
Ball1 <: LazySet
Ball1{N<:Real} <: PointSymmetric_Polytopic{N}
Type that represents a ball in the 1-norm, also known as Manhattan or Taxicab
norm.
Expand Down Expand Up @@ -40,7 +40,7 @@ julia> σ([0.,1], B)
1.0
```
"""
struct Ball1{N<:Real} <: LazySet
struct Ball1{N<:Real} <: PointSymmetric_Polytopic{N}
center::Vector{N}
radius::N

Expand Down
4 changes: 2 additions & 2 deletions src/Ball2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base.∈
export Ball2

"""
Ball2{N<:Real} <: LazySet
Ball2{N<:Real} <: PointSymmetric{N}
Type that represents a ball in the 2-norm.
Expand Down Expand Up @@ -48,7 +48,7 @@ julia> σ([1.,2.,3.,4.,5.], B)
0.3371
```
"""
struct Ball2{N<:Real} <: LazySet
struct Ball2{N<:Real} <: PointSymmetric{N}
center::Vector{N}
radius::N

Expand Down
4 changes: 2 additions & 2 deletions src/BallInf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export BallInf,

"""
BallInf{N<:Real} <: LazySet
BallInf{N<:Real} <: Box{N}
Type that represents a ball in the infinity norm.
Expand Down Expand Up @@ -44,7 +44,7 @@ julia> ρ([1., 1.], B)
2.0
```
"""
struct BallInf{N<:Real} <: LazySet
struct BallInf{N<:Real} <: Box{N}
center::Vector{N}
radius::N

Expand Down
4 changes: 2 additions & 2 deletions src/Ballp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base.∈
export Ballp

"""
Ballp <: LazySet
Ballp{N<:Real} <: PointSymmetric{N}
Type that represents a ball in the p-norm, for ``1 ≤ p ≤ ∞``.
Expand Down Expand Up @@ -52,7 +52,7 @@ julia> σ(1.:5, B)
0.3379
```
"""
struct Ballp{N<:Real} <: LazySet
struct Ballp{N<:Real} <: PointSymmetric{N}
p::Real
center::Vector{N}
radius::N
Expand Down
23 changes: 23 additions & 0 deletions src/Box.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export Box

"""
Box{N<:Real} <: PointSymmetric_Polytopic{N}
Abstract type for box-shaped sets.
### Notes
Every concrete `Box` must define the following functions:
- `radius(::Box{N})::Vector{N}` -- return the full-dimensional radius
- `radius(::Box{N}, i::Int)::N` -- return the radius entry in the `i`-th
dimension
```jldoctest
subtypes(Box)
3-element Array{Union{DataType, UnionAll},1}:
LazySets.BallInf
LazySets.Hyperrectangle
LazySets.SingleSet
```
"""
abstract type Box{N<:Real} <: PointSymmetric_Polytopic{N} end
4 changes: 2 additions & 2 deletions src/HPolygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export HPolygon,
vertices_list

"""
HPolygon{N<:Real} <: LazySet
HPolygon{N<:Real} <: HPolygonal{N}
Type that represents a convex polygon in constraint representation whose edges
are sorted in counter-clockwise fashion with respect to their normal directions.
Expand All @@ -27,7 +27,7 @@ Use `addconstraint!` to iteratively add the edges in a sorted way.
- `HPolygon()`
-- constructor with no constraints
"""
struct HPolygon{N<:Real} <: LazySet
struct HPolygon{N<:Real} <: HPolygonal{N}
constraints_list::Vector{LinearConstraint{N}}
end
# constructor for an HPolygon with no constraints
Expand Down
4 changes: 2 additions & 2 deletions src/HPolygonOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export HPolygonOpt,
vertices_list

"""
HPolygonOpt{N<:Real} <: LazySet
HPolygonOpt{N<:Real} <: HPolygonal{N}
Type that represents a convex polygon in constraint representation whose edges
are sorted in counter-clockwise fashion with respect to their normal directions.
Expand Down Expand Up @@ -37,7 +37,7 @@ Use `addconstraint!` to iteratively add the edges in a sorted way.
- `HPolygonOpt(H::HPolygon{<:Real})`
-- constructor from an HPolygon
"""
mutable struct HPolygonOpt{N<:Real} <: LazySet
mutable struct HPolygonOpt{N<:Real} <: HPolygonal{N}
constraints_list::Vector{LinearConstraint{N}}
ind::Int

Expand Down
20 changes: 20 additions & 0 deletions src/HPolygonal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export HPolygonal

"""
HPolygonal{N<:Real} <: Polygonal{N}
Abstract type for polygons in H-representation (i.e., constraints).
### Notes
Every concrete `HPolygonal` must define the following functions:
- `TODO()`
```jldoctest
subtypes(HPolygonal)
2-element Array{Union{DataType, UnionAll},1}:
LazySets.HPolygon
LazySets.HPolygonOpt
```
"""
abstract type HPolygonal{N<:Real} <: Polygonal{N} end
4 changes: 2 additions & 2 deletions src/Hyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export Hyperrectangle,

"""
Hyperrectangle{N<:Real} <: LazySet
Hyperrectangle{N<:Real} <: Box{N}
Type that represents a hyperrectangle.
Expand All @@ -24,7 +24,7 @@ Cartesian product of one-dimensional intervals.
- `radius` -- radius of the ball as a real vector, i.e., half of its width along
each coordinate direction
"""
struct Hyperrectangle{N<:Real} <: LazySet
struct Hyperrectangle{N<:Real} <: Box{N}
center::Vector{N}
radius::Vector{N}

Expand Down
15 changes: 12 additions & 3 deletions src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Abstract type for a lazy set.
### Notes
Every concrete `LazySet` must define a function `σ(d, X)`, representing the
support vector of `X` in a given direction `d`, and `dim`, the ambient dimension
of the set `X`.
Every concrete `LazySet` must define a function `σ(d, S)`, representing the
support vector of `S` in a given direction `d`, and `dim`, the ambient dimension
of the set `S`.
`LazySet` types should be parameterized with a type `N`, typically `N<:Real`, to
support computations with different numeric types.
Expand All @@ -38,6 +38,15 @@ include("helper_functions.jl")
# ===============================
# Types that inherit from LazySet
# ===============================
# abstract types
include("Polytopic.jl")
include("PointSymmetric.jl")
include("PointSymmetric_Polytopic.jl")
include("Box.jl")
include("Polygonal.jl")
include("HPolygonal.jl")
include("SingleSet.jl")
# concrete types
include("EmptySet.jl")
include("ZeroSet.jl")
include("Singleton.jl")
Expand Down
39 changes: 39 additions & 0 deletions src/PointSymmetric.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export PointSymmetric

"""
PointSymmetric{N<:Real} <: LazySet
Abstract type for point symmetric sets.
### Notes
Every concrete `PointSymmetric` must define the following functions:
- `center(::PointSymmetric{N})::Vector{N}` -- return the center point
```jldoctest
subtypes(PointSymmetric)
3-element Array{Union{DataType, UnionAll},1}:
LazySets.Ball2
LazySets.Ballp
LazySets.PointSymmetric_Polytopic
```
"""
abstract type PointSymmetric{N<:Real} <: LazySet end


"""
dim(S::PointSymmetric)::Int
Return the ambient dimension of a point symmetric, polytopic set.
### Input
- `S` -- set
### Output
The ambient dimension of the set.
"""
@inline function dim(S::PointSymmetric)::Int
return length(center(S))
end
27 changes: 27 additions & 0 deletions src/PointSymmetric_Polytopic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export PointSymmetric_Polytopic

"""
PointSymmetric_Polytopic{N<:Real} <: PointSymmetric{N}
Abstract type for point symmetric, polytopic sets.
It combines the `PointSymmetric` and `Polytopic` abstract types.
Such a type combination is necessary as long as Julia does not support
[multiple inheritance](https://github.com/JuliaLang/julia/issues/5).
This type arbitrarily inherits from `PointSymmetric`.
### Notes
Every concrete `PointSymmetric_Polytopic` must define the following functions
from `Polytopic`:
- `vertices_list(::PointSymmetric_Polytopic{N})::Vector{Vector{N}}` -- return a
list of all vertices
```jldoctest
subtypes(PointSymmetric_Polytopic)
3-element Array{Union{DataType, UnionAll},1}:
LazySets.Ball1
LazySets.Box
LazySets.Zonotope
```
"""
abstract type PointSymmetric_Polytopic{N<:Real} <: PointSymmetric{N} end
39 changes: 39 additions & 0 deletions src/Polygonal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export Polygonal

"""
Polygonal{N<:Real} <: Polytopic{N}
Abstract type for polygons (i.e., 2D polytopes).
### Notes
Every concrete `Polygonal` must define the following functions:
- `tovrep(::Polygonal{N})::VPolygon{N}` -- transform into V-representation
- `tohrep(::Polygonal{N})::HPolygonal{N}` -- transform into H-representation
```jldoctest
subtypes(Polygonal)
2-element Array{Union{DataType, UnionAll},1}:
LazySets.HPolygonal
LazySets.VPolygon
```
"""
abstract type Polygonal{N<:Real} <: Polytopic{N} end


"""
dim(P::Polygonal)::Int
Return the ambient dimension of a polygon.
### Input
- `P` -- polygon
### Output
The ambient dimension of the polygon, which is 2.
"""
@inline function dim(P::Polygonal)::Int
return 2
end
4 changes: 2 additions & 2 deletions src/Polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export Polyhedron,
constraints_list

"""
Polyhedron{N<:Real} <: LazySet
Polyhedron{N<:Real} <: Polytopic{N}
Type that represents a convex polyhedron in H-representation.
### Fields
- `constraints` -- vector of linear constraints
"""
struct Polyhedron{N<:Real} <: LazySet
struct Polyhedron{N<:Real} <: Polytopic{N}
constraints::Vector{LinearConstraint{N}}
end
# constructor for a Polyhedron with no constraints
Expand Down
22 changes: 22 additions & 0 deletions src/Polytopic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export Polytopic

"""
Polytopic{N<:Real} <: LazySet
Abstract type for polytopic sets, i.e., sets with finitely many flat facets, or
equivalently, sets defined as an intersection of a finite number of halfspaces,
or equivalently, sets with finitely many vertices.
### Notes
Every concrete `Polytopic` must define the following functions:
- `vertices_list(::Polytopic{N})::Vector{Vector{N}}` -- return a list of all
vertices
```jldoctest
subtypes(Polytopic)
1-element Array{Union{DataType, UnionAll},1}:
LazySets.Polygonal
```
"""
abstract type Polytopic{N<:Real} <: LazySet end
22 changes: 22 additions & 0 deletions src/SingleSet.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export SingleSet

"""
SingleSet{N<:Real} <: Box{N}
Abstract type for sets with a single value.
### Notes
Every concrete `SingleSet` must define the following functions:
- `element(::SingleSet{N})::Vector{N}` -- return the single element
- `element(::SingleSet{N}, i::Int)::N` -- return the single element's entry in
the `i`-th dimension
```jldoctest
subtypes(SingleSet)
2-element Array{Union{DataType, UnionAll},1}:
LazySets.Singleton
LazySets.ZeroSet
```
"""
abstract type SingleSet{N<:Real} <: Box{N} end
4 changes: 2 additions & 2 deletions src/Singleton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import Base.∈
export Singleton

"""
Singleton{N<:Real} <: LazySet
Singleton{N<:Real} <: SingleSet{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} <: SingleSet{N}
element::Vector{N}
end

Expand Down
Loading

0 comments on commit 62b01bb

Please sign in to comment.