Skip to content

Commit

Permalink
docs, constructors, restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Feb 9, 2018
1 parent 8e9f0b8 commit 9348d4a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 36 deletions.
29 changes: 17 additions & 12 deletions src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The Cartesian product of three elements is obtained recursively.
See also `CartesianProductArray` for an implementation of a Cartesian product of
many sets without recursion, instead using an array.
The `EmptySet` is the absorbing element for `CartesianProduct`.
Constructors:
- `CartesianProduct{N<:Real, S1<:LazySet{N}, S2<:LazySet{N}}(X1::S1, X2::S2)`
-- default constructor
Expand All @@ -45,6 +49,9 @@ CartesianProduct(Xarr::Vector{S}) where {S<:LazySet{N}} where {N<:Real} =
: CartesianProduct(Xarr[1],
CartesianProduct(Xarr[2:length(Xarr)])))

# EmptySet is the absorbing element for CartesianProduct
@commutative_absorbing(CartesianProduct, EmptySet)

"""
```
*(X::LazySet, Y::LazySet)
Expand All @@ -70,9 +77,6 @@ Alias for the binary Cartesian product.
"""
×(X::LazySet, Y::LazySet) = *(X, Y)

# EmptySet is the absorbing element for CartesianProduct
@commutative_absorbing(CartesianProduct, EmptySet)

"""
dim(cp::CartesianProduct)::Int
Expand Down Expand Up @@ -146,24 +150,25 @@ Type that represents the Cartesian product of a finite number of convex sets.
### Notes
- `CartesianProductArray(array::Vector{<:LazySet})` -- default constructor
The `EmptySet` is the absorbing element for `CartesianProductArray`.
Constructors:
- `CartesianProductArray()` -- constructor for an empty Cartesian product
- `CartesianProductArray(array::Vector{<:LazySet})` -- default constructor
- `CartesianProductArray(n::Int, [N]::Type=Float64)`
-- constructor for an empty Cartesian product with size hint and numeric type
- `CartesianProductArray([n]::Int=0, [N]::Type=Float64)`
-- constructor for an empty product with optional size hint and numeric type
"""
struct CartesianProductArray{N<:Real, S<:LazySet{N}} <: LazySet{N}
array::Vector{S}
end

# type-less convenience constructor
CartesianProductArray(arr::Vector{S}) where {S<:LazySet{N}} where {N<:Real} =
CartesianProductArray{N, S}(arr)
# constructor for an empty Cartesian product of floats
CartesianProductArray() =
CartesianProductArray{Float64, LazySet{Float64}}(Vector{LazySet{Float64}}(0))
# constructor for an empty Cartesian product with size hint and numeric type
function CartesianProductArray(n::Int, N::Type=Float64)::CartesianProductArray

# constructor for an empty product with optional size hint and numeric type
function CartesianProductArray(n::Int=0, N::Type=Float64)::CartesianProductArray
arr = Vector{LazySet{N}}(0)
sizehint!(arr, n)
return CartesianProductArray(arr)
Expand Down
32 changes: 23 additions & 9 deletions src/ConvexHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Type that represents the convex hull of the union of two convex sets.
- `X` -- convex set
- `Y` -- convex set
### Notes
The `EmptySet` is the neutral element for `ConvexHull`.
### Examples
Convex hull of two 100-dimensional Euclidean balls:
Expand All @@ -42,16 +46,16 @@ end
ConvexHull(X::S1, Y::S2) where {S1<:LazySet{N}, S2<:LazySet{N}} where {N<:Real} =
ConvexHull{N, S1, S2}(X, Y)

# EmptySet is the neutral element for ConvexHull
@commutative_neutral(ConvexHull, EmptySet)

"""
CH
Alias for `ConvexHull`.
"""
const CH = ConvexHull

# EmptySet is the neutral element for ConvexHull
@commutative_neutral(ConvexHull, EmptySet)

"""
dim(ch::ConvexHull)::Int
Expand Down Expand Up @@ -100,6 +104,17 @@ Type that represents the symbolic convex hull of a finite number of convex sets.
- `array` -- array of sets
### Notes
The `EmptySet` is the neutral element for `ConvexHullArray`.
Constructors:
- `ConvexHullArray(array::Vector{<:LazySet})` -- default constructor
- `ConvexHullArray([n]::Int=0, [N]::Type=Float64)`
-- constructor for an empty hull with optional size hint and numeric type
### Examples
Convex hull of 100 two-dimensional balls whose centers follows a sinusoidal:
Expand All @@ -113,14 +128,13 @@ julia> c = ConvexHullArray(b);
struct ConvexHullArray{N<:Real, S<:LazySet{N}} <: LazySet{N}
array::Vector{S}
end
# type-less convenience constructor
ConvexHullArray(a::Vector{S}) where {S<:LazySet{N}} where {N<:Real} = ConvexHullArray{N, S}(a)

# constructor for an empty convex hull array
ConvexHullArray() = ConvexHullArray{Float64, LazySet{Float64}}(Vector{LazySet{Float64}}(0))
# type-less convenience constructor
ConvexHullArray(a::Vector{S}) where {S<:LazySet{N}} where {N<:Real} =
ConvexHullArray{N, S}(a)

# constructor for an empty convex hull array with size hint and numeric type
function ConvexHullArray(n::Int, N::Type=Float64)::ConvexHullArray
# constructor for an empty hull with optional size hint and numeric type
function ConvexHullArray(n::Int=0, N::Type=Float64)::ConvexHullArray
a = Vector{LazySet{N}}(0)
sizehint!(a, n)
return ConvexHullArray(a)
Expand Down
36 changes: 21 additions & 15 deletions src/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Type that represents the Minkowski sum of two convex sets.
- `X` -- first convex set
- `Y` -- second convex set
### Notes
The `ZeroSet` is the neutral element and the `EmptySet` is the absorbing element
for `MinkowskiSum`.
"""
struct MinkowskiSum{N<:Real, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N}
X::S1
Expand All @@ -27,6 +32,10 @@ end
MinkowskiSum(X::S1, Y::S2) where {S1<:LazySet{N}, S2<:LazySet{N}} where {N<:Real} =
MinkowskiSum{N, S1, S2}(X, Y)

# ZeroSet is the neutral element and EmptySet is the absorbing element for
# MinkowskiSum
@commutative_neutral_absorbing(MinkowskiSum, ZeroSet, EmptySet)

"""
X + Y
Expand All @@ -50,10 +59,6 @@ Unicode alias constructor `\oplus` for the Minkowski sum operator `+(X, Y)`.
"""
(X::LazySet, Y::LazySet) = +(X, Y)

# ZeroSet is the neutral element and EmptySet is the absorbing element for
# MinkowskiSum
@commutative_neutral_absorbing(MinkowskiSum, ZeroSet, EmptySet)

"""
dim(ms::MinkowskiSum)::Int
Expand Down Expand Up @@ -107,24 +112,26 @@ Type that represents the Minkowski sum of a finite number of convex sets.
This type assumes that the dimensions of all elements match.
- `MinkowskiSumArray(array::Vector{<:LazySet})` -- default constructor
The `ZeroSet` is the neutral element and the `EmptySet` is the absorbing element
for `MinkowskiSumArray`.
- `MinkowskiSumArray()` -- constructor for an empty sum
Constructors:
- `MinkowskiSumArray(array::Vector{<:LazySet})` -- default constructor
- `MinkowskiSumArray(n::Int, [N]::Type=Float64)`
-- constructor for an empty sum with size hint and numeric type
- `MinkowskiSumArray([n]::Int=0, [N]::Type=Float64)`
-- constructor for an empty sum with optional size hint and numeric type
"""
struct MinkowskiSumArray{N<:Real, S<:LazySet{N}} <: LazySet{N}
array::Vector{S}
end

# type-less convenience constructor
MinkowskiSumArray(arr::Vector{S}) where {S<:LazySet{N}} where {N<:Real} =
MinkowskiSumArray{N, S}(arr)
# constructor for an empty sum of float type
MinkowskiSumArray() =
MinkowskiSumArray{Float64, LazySet{Float64}}(Vector{LazySet{Float64}}(0))
# constructor for an empty sum with size hint and numeric type
function MinkowskiSumArray(n::Int, N::Type=Float64)::MinkowskiSumArray

# constructor for an empty sum with optional size hint and numeric type
function MinkowskiSumArray(n::Int=0, N::Type=Float64)::MinkowskiSumArray
arr = Vector{LazySet{N}}(0)
sizehint!(arr, n)
return MinkowskiSumArray(arr)
Expand Down Expand Up @@ -168,8 +175,7 @@ The modified Minkowski sum of a finite number of convex sets.
"""
function MinkowskiSumArray(S::LazySet,
msa::MinkowskiSumArray)::MinkowskiSumArray
push!(msa.array, S)
return msa
return MinkowskiSumArray(msa, S)
end

"""
Expand Down

0 comments on commit 9348d4a

Please sign in to comment.