Common Set Operations
This section of the manual describes the basic symbolic types describing operations between sets.
Minkowski Sum
Binary Minkowski Sum
LazySets.MinkowskiSum
— Type.MinkowskiSum{T1<:LazySet, T2<:LazySet} <: LazySet
Type that represents the Minkowski sum of two convex sets.
Fields
X
– first convex setY
– second convex set
LazySets.dim
— Method.dim(ms::MinkowskiSum)::Int
Return the dimension of a Minkowski sum.
Input
ms
– Minkowski sum
Output
The ambient dimension of the Minkowski sum.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, ms::MinkowskiSum)::AbstractVector{<:Real}
Return the support vector of a Minkowski sum.
Input
d
– directionms
– Minkowski sum
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the summand sets.
Base.:+
— Method.X + Y
Convenience constructor for Minkowski sum.
Input
X
– a convex setY
– another convex set
Output
The symbolic Minkowski sum of $X$ and $Y$.
LazySets.:⊕
— Function.⊕(X::LazySet, Y::LazySet)
Unicode alias constructor oplus
for the Minkowski sum operator +(X, Y)
.
$n$-ary Minkowski Sum
LazySets.MinkowskiSumArray
— Type.MinkowskiSumArray{T<:LazySet} <: LazySet
Type that represents the Minkowski sum of a finite number of convex sets.
Fields
sfarray
– array of convex sets
Notes
This type assumes that the dimensions of all elements match.
MinkowskiSumArray(sfarray::Vector{<:LazySet})
– default constructorMinkowskiSumArray()
– constructor for an empty sumMinkowskiSumArray(n::Int)
– constructor for an empty sum with size hint
LazySets.dim
— Method.dim(msa::MinkowskiSumArray)::Int
Return the dimension of a Minkowski sum of a finite number of sets.
Input
msa
– Minkowski sum array
Output
The ambient dimension of the Minkowski sum of a finite number of sets.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, msa::MinkowskiSumArray)::Vector{<:Real}
Return the support vector of a Minkowski sum of a finite number of sets in a given direction.
Input
d
– directionmsa
– Minkowski sum array
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the summand sets.
Base.:+
— Method.+(msa::MinkowskiSumArray, S::LazySet)::MinkowskiSumArray
Add a convex set to a Minkowski sum of a finite number of convex sets from the right.
Input
msa
– Minkowski sum array (is modified)S
– convex set
Output
The modified Minkowski sum of a finite number of convex sets.
Base.:+
— Method.+(S::LazySet, msa::MinkowskiSumArray)::MinkowskiSumArray
Add a convex set to a Minkowski sum of a finite number of convex sets from the left.
Input
S
– convex setmsa
– Minkowski sum array (is modified)
Output
The modified Minkowski sum of a finite number of convex sets.
Base.:+
— Method.+(msa1::MinkowskiSumArray, msa2::MinkowskiSumArray)::MinkowskiSumArray
Add the elements of a finite Minkowski sum of convex sets to another finite Minkowski sum.
Input
msa1
– first Minkowski sum array (is modified)msa2
– second Minkowski sum array
Output
The modified first Minkowski sum of a finite number of convex sets.
Base.:+
— Method.+(msa::MinkowskiSumArray, Z::ZeroSet)::MinkowskiSumArray
Returns the original array because addition with an empty set is a no-op.
Input
msa
– Minkowski sum arrayZ
– a Zero set
Cartesian Product
Binary Cartesian Product
LazySets.CartesianProduct
— Type.CartesianProduct{S1<:LazySet,S2<:LazySet} <: LazySet
Type that represents a Cartesian product of two convex sets.
Fields
X
– first convex setY
– second convex set
Notes
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.
CartesianProduct{S1<:LazySet,S2<:LazySet}
– default constructorCartesianProduct(Xarr::Vector{S}) where {S<:LazySet}
– constructor from an array of convex sets
LazySets.dim
— Method.dim(cp::CartesianProduct)::Int
Return the dimension of a Cartesian product.
Input
cp
– Cartesian product
Output
The ambient dimension of the Cartesian product.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, cp::CartesianProduct)::AbstractVector{<:Real}
Return the support vector of a Cartesian product.
Input
d
– directioncp
– Cartesian product
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the product sets.
Base.:*
— Method. *(X::LazySet, Y::LazySet)::CartesianProduct
Return the Cartesian product of two convex sets.
Input
X
– convex setY
– convex set
Output
The Cartesian product of the two convex sets.
Base.:∈
— Method.∈(x::AbstractVector{<:Real}, cp::CartesianProduct)::Bool
Check whether a given point is contained in a Cartesian product set.
Input
x
– point/vectorcp
– Cartesian product
Output
true
iff $x ∈ cp$.
$n$-ary Cartesian Product
LazySets.CartesianProductArray
— Type.CartesianProductArray{S<:LazySet} <: LazySet
Type that represents the Cartesian product of a finite number of convex sets.
Fields
sfarray
– array of sets
Notes
CartesianProductArray(sfarray::Vector{<:LazySet})
– default constructorCartesianProductArray()
– constructor for an empty Cartesian productCartesianProductArray(n::Int)
– constructor for an empty Cartesian product with size hint
LazySets.dim
— Method.dim(cpa::CartesianProductArray)::Int
Return the dimension of a Cartesian product of a finite number of convex sets.
Input
cpa
– Cartesian product array
Output
The ambient dimension of the Cartesian product of a finite number of convex sets.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, cpa::CartesianProductArray)::AbstractVector{<:Real}
Support vector of a Cartesian product.
Input
d
– directioncpa
– Cartesian product array
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the product sets.
Base.:*
— Method. *(cpa::CartesianProductArray, S::LazySet)::CartesianProductArray
Multiply a convex set to a Cartesian product of a finite number of convex sets from the right.
Input
cpa
– Cartesian product array (is modified)S
– convex set
Output
The modified Cartesian product of a finite number of convex sets.
Base.:*
— Method. *(S::LazySet, cpa::CartesianProductArray)::CartesianProductArray
Multiply a convex set to a Cartesian product of a finite number of convex sets from the left.
Input
S
– convex setcpa
– Cartesian product array (is modified)
Output
The modified Cartesian product of a finite number of convex sets.
Base.:*
— Method. *(cpa1::CartesianProductArray, cpa2::CartesianProductArray)::CartesianProductArray
Multiply a finite Cartesian product of convex sets to another finite Cartesian product.
Input
cpa1
– first Cartesian product array (is modified)cpa2
– second Cartesian product array
Output
The modified first Cartesian product.
Base.:∈
— Method.∈(x::AbstractVector{<:Real}, cpa::CartesianProductArray)::Bool
Check whether a given point is contained in a Cartesian product of a finite number of sets.
Input
x
– point/vectorcpa
– Cartesian product array
Output
true
iff $x ∈ \text{cpa}$.
Maps
Linear Map
LazySets.LinearMap
— Type.LinearMap{S<:LazySet, N<:Real} <: LazySet
Type that represents a linear transformation $M⋅S$ of a convex set $S$.
Fields
M
– matrix/linear mapsf
– convex set
LazySets.dim
— Method.dim(lm::LinearMap)::Int
Return the dimension of a linear map.
Input
lm
– linear map
Output
The ambient dimension of the linear map.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, lm::LinearMap)::AbstractVector{<:Real}
Return the support vector of the linear map.
Input
d
– directionlm
– linear map
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the wrapped set.
Notes
If $L = M⋅S$, where $M$ is a matrix and $S$ is a convex set, it follows that $σ(d, L) = M⋅σ(M^T d, S)$ for any direction $d$.
Base.:*
— Method. *(M::AbstractMatrix{<:Real}, S::LazySet)
Return the linear map of a convex set.
Input
M
– matrix/linear mapS
– convex set
Output
If the matrix is null, a ZeroSet
is returned; otherwise a lazy linear map.
Base.:*
— Method. *(a::Real, S::LazySet)::LinearMap
Return a linear map of a convex set by a scalar value.
Input
a
– real scalarS
– convex set
Output
The linear map of the convex set.
Base.:∈
— Method.∈(x::AbstractVector{N}, lm::LinearMap{<:LazySet, N})::Bool where {N<:Real}
Check whether a given point is contained in a linear map of a convex set.
Input
x
– point/vectorlm
– linear map of a convex set
Output
true
iff $x ∈ lm$.
Algorithm
Note that $x ∈ M⋅S$ iff $M^{-1}⋅x ∈ S$. This implementation does not explicitly invert the matrix, which is why it also works for non-square matrices.
Examples
julia> lm = LinearMap([2.0 0.0; 0.0 1.0], BallInf([1., 1.], 1.));
julia> ∈([5.0, 1.0], lm)
false
julia> ∈([3.0, 1.0], lm)
true
An example with non-square matrix:
julia> B = BallInf(zeros(4), 1.);
julia> M = [1. 0 0 0; 0 1 0 0]/2;
julia> ∈([0.5, 0.5], M*B)
true
Exponential Map
LazySets.ExponentialMap
— Type.ExponentialMap{S<:LazySet} <: LazySet
Type that represents the action of an exponential map on a convex set.
Fields
spmexp
– sparse matrix exponentialX
– convex set
LazySets.dim
— Method.dim(em::ExponentialMap)::Int
Return the dimension of an exponential map.
Input
em
– an ExponentialMap
Output
The ambient dimension of the exponential map.
LazySets.σ
— Method.σ(d::AbstractVector{Float64}, em::ExponentialMap)::AbstractVector{Float64}
Return the support vector of the exponential map.
Input
d
– directionem
– exponential map
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the wrapped set.
Notes
If $E = \exp(M)⋅S$, where $M$ is a matrix and $S$ is a convex set, it follows that $σ(d, E) = \exp(M)⋅σ(\exp(M)^T d, S)$ for any direction $d$.
Base.:∈
— Method.∈(x::AbstractVector{<:Real}, em::ExponentialMap{<:LazySet})::Bool
Check whether a given point is contained in an exponential map of a convex set.
Input
x
– point/vectorem
– linear map of a convex set
Output
true
iff $x ∈ em$.
Algorithm
This implementation exploits that $x ∈ \exp(M)⋅S$ iff $\exp(-M)⋅x ∈ S$. This follows from $\exp(-M)⋅\exp(M) = I$ for any $M$.
Examples
julia> em = ExponentialMap(SparseMatrixExp(SparseMatrixCSC([2.0 0.0; 0.0 1.0])),
BallInf([1., 1.], 1.));
julia> ∈([5.0, 1.0], em)
false
julia> ∈([1.0, 1.0], em)
true
ExponentialProjectionMap{S<:LazySet} <: LazySet
Type that represents the application of a projection of a sparse matrix exponential to a convex set.
Fields
spmexp
– projection of a sparse matrix exponentialX
– convex set
LazySets.dim
— Method.dim(eprojmap::ExponentialProjectionMap)::Int
Return the dimension of a projection of an exponential map.
Input
eprojmap
– projection of an exponential map
Output
The ambient dimension of the projection of an exponential map.
LazySets.σ
— Method.σ(d::AbstractVector{Float64}, eprojmap::ExponentialProjectionMap)::AbstractVector{Float64}
Return the support vector of a projection of an exponential map.
Input
d
– directioneprojmap
– projection of an exponential map
Output
The support vector in the given direction. If the direction has norm zero, the result depends on the wrapped set.
Notes
If $S = (L⋅M⋅R)⋅X$, where $L$ and $R$ are matrices, $M$ is a matrix exponential, and $X$ is a set, it follows that $σ(d, S) = L⋅M⋅R⋅σ(R^T⋅M^T⋅L^T⋅d, X)$ for any direction $d$.
LazySets.SparseMatrixExp
— Type.SparseMatrixExp{N<:Real}
Type that represents the matrix exponential, $\exp(M)$, of a sparse matrix.
Fields
M
– sparse matrix
Notes
This type is provided for use with very large and very sparse matrices. The evaluation of the exponential matrix action over vectors relies on the Expokit package.
Base.:*
— Method. *(spmexp::SparseMatrixExp, X::LazySet)::ExponentialMap
Return the exponential map of a convex set from a sparse matrix exponential.
Input
spmexp
– sparse matrix exponentialX
– convex set
Output
The exponential map of the convex set.
ProjectionSparseMatrixExp{N<:Real}
Type that represents the projection of a sparse matrix exponential, i.e., $L⋅\exp(M)⋅R$ for a given sparse matrix $M$.
Fields
L
– left multiplication matrixE
– sparse matrix exponentialR
– right multiplication matrix
Base.:*
— Method. *(projspmexp::ProjectionSparseMatrixExp, X::LazySet)::ExponentialProjectionMap
Return the application of a projection of a sparse matrix exponential to a convex set.
Input
projspmexp
– projection of a sparse matrix exponentialX
– convex set
Output
The application of the projection of a sparse matrix exponential to the convex set.
Convex Hull
LazySets.ConvexHull
— Type.ConvexHull{S1<:LazySet, S2<:LazySet} <: LazySet
Type that represents the convex hull of the union of two convex sets.
Fields
X
– convex setY
– convex set
LazySets.CH
— Type.CH
Alias for ConvexHull
.
LazySets.dim
— Method.dim(ch::ConvexHull)::Int
Return the dimension of a convex hull of two convex sets.
Input
ch
– convex hull of two convex sets
Output
The ambient dimension of the convex hull of two convex sets.
LazySets.σ
— Method.σ(d::AbstractVector{<:Real}, ch::ConvexHull)::AbstractVector{<:Real}
Return the support vector of a convex hull of two convex sets in a given direction.
Input
d
– directionch
– convex hull of two convex sets
Convex Hull Algorithms
LazySets.convex_hull
— Function.convex_hull(points::Vector{S}; [algorithm]::String="monotone_chain"
)::Vector{S} where {S<:AbstractVector{N}} where {N<:Real}
Compute the convex hull of points in the plane.
Input
points
– list of 2D vectorsalgorithm
– (optional, default:"monotone_chain"
) the convex hull algorithm, valid options are:"monotone_chain"
"monotone_chain_sorted"
Output
The convex hull as a list of 2D vectors with the coordinates of the points.
Examples
Compute the convex hull of a random set of points:
julia> points = [randn(2) for i in 1:30]; # 30 random points in 2D
julia> hull = convex_hull(points);
julia> typeof(hull)
Array{Array{Float64,1},1}
Plot both the random points and the computed convex hull polygon:
julia> using Plots;
julia> plot([Tuple(pi) for pi in points], seriestype=:scatter);
julia> plot!(VPolygon(hull), alpha=0.2);
LazySets.convex_hull!
— Function.convex_hull!(points::Vector{S}; [algorithm]::String="monotone_chain"
)::Vector{S} where {S<:AbstractVector{N}} where {N<:Real}
Compute the convex hull of points in the plane, in-place.
Input
points
– list of 2D vectors (is modified)algorithm
– (optional, default:"monotone_chain"
) the convex hull algorithm; valid options are:"monotone_chain"
"monotone_chain_sorted"
Output
The convex hull as a list of 2D vectors with the coordinates of the points.
Notes
See the non-modifying version convex_hull
for more details.
LazySets.right_turn
— Function.right_turn(O::AbstractVector{N}, A::AbstractVector{N}, B::AbstractVector{N}
)::N where {N<:Real}
Determine if the acute angle defined by the three points O
, A
, B
in the plane is a right turn (counter-clockwise) with respect to the center O
.
Input
O
– 2D center pointA
– 2D one pointB
– 2D another point
Output
Scalar representing the rotation.
Algorithm
The cross product is used to determine the sense of rotation. If the result is 0, the points are collinear; if it is positive, the three points constitute a positive angle of rotation around O
from A
to B
; otherwise they constitute a negative angle.
LazySets.monotone_chain!
— Function.monotone_chain!(points::Vector{S}; sort::Bool=true
)::Vector{S} where {S<:AbstractVector{N}} where {N<:Real}
Compute the convex hull of points in the plane using Andrew's monotone chain method.
Input
points
– list of 2D vectors; is sorted in-place inside this functionsort
– (optional, default:true
) flag for sorting the vertices lexicographically; sortedness is required for correctness
Output
List of vectors containing the 2D coordinates of the corner points of the convex hull.
Notes
For large sets of points, it is convenient to use static vectors to get maximum performance. For information on how to convert usual vectors into static vectors, see the type SVector
provided by the StaticArrays package.
Algorithm
This function implements Andrew's monotone chain convex hull algorithm to construct the convex hull of a set of $n$ points in the plane in $O(n \log n)$ time. For further details see Monotone chain