Conversion between set representations
This section of the manual lists the conversion functions between set representations.
Base.convert
— Methodconvert(::Type{Interval}, X::LazySet)
Convert a one-dimensional convex set to an interval.
Input
Interval
– interval target typeX
– one-dimensional convex set
Output
An interval.
Examples
julia> convert(Interval, Hyperrectangle([0.5], [0.5]))
Interval{Float64, IntervalArithmetic.Interval{Float64}}([0, 1])
Base.convert
— Methodconvert(::Type{Interval}, r::Rectification{N, IN}) where {N, IN<:Interval}
Convert a rectification of an interval to an interval.
Input
Interval
– target typer
– rectification of an interval
Output
An Interval
.
Base.convert
— Methodconvert(::Type{Interval}, x::MinkowskiSum{N, IT, IT}) where {N, IT<:Interval}
Convert the Minkowski sum of two intervals to an interval.
Input
Interval
– target typex
– Minkowski sum of two intervals
Output
An interval.
Base.convert
— Methodconvert(::Type{Interval}, x::IntervalArithmetic.Interval)
Convert an Interval
from IntervalArithmetic
to an Interval
in LazySets
.
Input
Interval
– target typex
– interval (IntervalArithmetic.Interval
)
Output
A LazySets.Interval
.
Base.convert
— Methodconvert(::Type{IntervalArithmetic.Interval}, X::LazySet)
Convert a convex set to an Interval
from IntervalArithmetic
.
Input
Interval
– target type, fromIntervalArithmetic
X
– convex set
Output
An IntervalArithmetic.Interval
.
Base.convert
— Methodconvert(::Type{IntervalArithmetic.IntervalBox}, H::AbstractHyperrectangle)
Convert a hyperrectangular set to an IntervalBox
from IntervalArithmetic
.
Input
IntervalBox
– target typeH
– hyperrectangular set
Output
An IntervalBox
.
Base.convert
— Methodconvert(::Type{Hyperrectangle}, IB::IntervalArithmetic.IntervalBox)
Convert an IntervalBox
from IntervalArithmetic
to a hyperrectangular set.
Input
Hyperrectangle
– target typeIB
– interval box
Output
A Hyperrectangle
.
Notes
IntervalArithmetic.IntervalBox
uses static vectors to store each component interval; hence the resulting Hyperrectangle
has its center and radius represented as a static vector (SArray
).
Base.convert
— Methodconvert(::Type{Hyperrectangle}, H::AbstractHyperrectangle)
Convert a hyperrectangular set to a hyperrectangle.
Input
Hyperrectangle
– hyperrectangle target typeH
– hyperrectangular set
Output
A hyperrectangle.
Examples
julia> convert(Hyperrectangle, Interval(0.0, 1.0))
Hyperrectangle{Float64, Vector{Float64}, Vector{Float64}}([0.5], [0.5])
Base.convert
— Methodconvert(::Type{Hyperrectangle}, cp::CartesianProduct{N, HN1, HN2})
where {N, HN1<:AbstractHyperrectangle, HN2<:AbstractHyperrectangle}
Convert the Cartesian product of two hyperrectangular sets to a single hyperrectangle.
Input
Hyperrectangle
– target typeS
– Cartesian product of two hyperrectangular sets
Output
A hyperrectangle.
Algorithm
The result is obtained by concatenating the center and radius of each hyperrectangle. This implementation uses the center
and radius_hyperrectangle
methods.
Base.convert
— Methodconvert(::Type{Hyperrectangle}, cpa::CartesianProductArray{N, HN})
where {N, HN<:AbstractHyperrectangle}
Convert the Cartesian product of a finite number of hyperrectangular sets to a single hyperrectangle.
Input
Hyperrectangle
– target typeS
– Cartesian product array of hyperrectangular set
Output
A hyperrectangle.
Algorithm
This implementation uses the center
and radius_hyperrectangle
methods of AbstractHyperrectangle
.
Base.convert
— Methodconvert(::Type{Hyperrectangle},
cpa::CartesianProductArray{N, IN}) where {N, IN<:Interval}
Convert the Cartesian product of a finite number of intervals to a single hyperrectangle.
Input
Hyperrectangle
– target typeS
– Cartesian product array of intervals
Output
A hyperrectangle.
Algorithm
This implementation uses the min
and max
methods of Interval
to reduce the allocations and improve performance (see LazySets#1143).
Base.convert
— Methodconvert(::Type{Hyperrectangle}, r::Rectification{N, AH})
where {N, AH<:AbstractHyperrectangle}
Convert a rectification of a hyperrectangle to a hyperrectangle.
Input
Hyperrectangle
– target typer
– rectification of a hyperrectangle
Output
A Hyperrectangle
.
Base.convert
— Methodconvert(::Type{HPOLYGON}, X::LazySet; [check_boundedness]::Bool=true,
prune::Bool=true) where {HPOLYGON<:AbstractHPolygon}
Convert a two-dimensional polytope to a polygon in vertex representation.
Input
HPOLYGON
– target typeX
– two-dimensional polytopecheck_boundedness
– (optional, default!isboundedtype(typeof(X))
) iftrue
check whether the setX
is bounded before creating the polygonprune
– (optional, default:true
) flag for removing redundant constraints in the end
Output
A polygon in constraint representation.
Algorithm
We compute the list of constraints of X
, then instantiate the polygon.
Base.convert
— Methodconvert(T::Type{HPOLYGON}, P::VPolygon) where {HPOLYGON<:AbstractHPolygon}
Convert a polygon in vertex representation to a polygon in constraint representation.
Input
HPOLYGON
– target typeP
– polygon in vertex representation
Output
A polygon in constraint representation.
Base.convert
— Methodconvert(::Type{HPOLYGON}, L::LineSegment{N}
) where {N, HPOLYGON<:AbstractHPolygon}
Convert a line segment to a polygon in constraint representation.
Input
HPOLYGON
– target typeL
– line segmentprune
– (optional, default:false
) flag for removing redundant constraints in the end
Output
A flat polygon in constraint representation with the minimal number of constraints (four).
Base.convert
— Methodconvert(::Type{HPOLYGON}, S::AbstractSingleton{N}
) where {N, HPOLYGON<:AbstractHPolygon}
Convert a singleton to a polygon in constraint representation.
Input
HPOLYGON
– target typeS
– singleton
Output
A polygon in constraint representation with the minimal number of constraints (three).
Base.convert
— Methodconvert(::Type{HPolyhedron}, X::LazySet)
Convert a polyhedral set to a polyhedron in constraint representation.
Input
HPolyhedron
– target typeX
– polyhedral set
Output
The given set represented as a polyhedron in constraint representation.
Algorithm
This method uses constraints_list
.
Base.convert
— Method convert(::Type{HPolyhedron}, P::HRep{N}) where {N}
Convert an HRep
polyhedron from Polyhedra.jl
to a polyhedron in constraint representation .
Input
HPolyhedron
– target typeP
–HRep
polyhedron
Output
An HPolyhedron
.
Base.convert
— Methodconvert(::Type{HPolytope}, X::LazySet)
Convert a polytopic set to a polytope in constraint representation.
Input
HPolytope
– target typeX
– polytopic set
Output
The given polytope represented as a polytope in constraint representation.
Algorithm
This method uses constraints_list
.
Base.convert
— Methodconvert(::Type{VPolygon}, X::LazySet)
Convert a two-dimensional polytopic set to a polygon in vertex representation.
Input
VPolygon
– target typeX
– two-dimensional polytopic set
Output
The 2D set represented as a polygon.
Algorithm
This method uses vertices_list
.
Base.convert
— Methodconvert(::Type{VPolygon}, P::AbstractHPolygon)
Convert a polygon in constraint representation to a polygon in vertex representation.
Input
VPolygon
– target typeP
– polygon in constraint representation
Output
A polygon in vertex representation.
Base.convert
— Methodconvert(::Type{VPolytope}, X::LazySet; [prune]::Bool=true)
Convert a polytopic set to a polytope in vertex representation.
Input
VPolytope
– target typeX
– polytopic setprune
– (optional, default:true
) option to remove redundant vertices
Output
The given set represented as a polytope in vertex representation.
Algorithm
This method uses vertices_list
. Use the option prune
to select whether to remove redundant vertices before constructing the polytope.
Base.convert
— Methodconvert(::Type{Zonotope}, Z::AbstractZonotope)
Convert a zonotopic set to a zonotope.
Input
Zonotope
– target typeH
– zonotopic set
Output
A zonotope.
Base.convert
— Methodconvert(::Type{Zonotope}, S::LinearMap{N, ZN})
where {N, ZN<:AbstractZonotope}
Convert the lazy linear map of a zonotopic set to a zonotope.
Input
Zonotope
– target typeS
– linear map of a zonotopic set
Output
A zonotope.
Algorithm
This method first applies the (concrete) linear map to the zonotopic set and then converts the result to a Zonotope
type.
Base.convert
— Methodconvert(::Type{Zonotope}, S::LinearMap{N, CartesianProduct{N, HN1, HN2}}
) where {N, HN1<:AbstractHyperrectangle,
HN2<:AbstractHyperrectangle}
Convert the lazy linear map of the Cartesian product of two hyperrectangular sets to a zonotope.
Input
Zonotope
– target typeS
– linear map of the Cartesian product of hyperrectangular sets
Output
A zonotope.
Algorithm
This method first converts the Cartesian product to a zonotope, and then applies the (concrete) linear map to the zonotope.
Base.convert
— Methodconvert(::Type{Zonotope},S::LinearMap{N, CartesianProductArray{N, HN}})
where {N, HN<:AbstractHyperrectangle}
Convert the lazy linear map of the Cartesian product of a finite number of hyperrectangular sets to a zonotope.
Input
Zonotope
– target typeS
– linear map of aCartesianProductArray
of hyperrectangular sets
Output
A zonotope.
Algorithm
This method first converts the Cartesian product array to a zonotope, and then applies the (concrete) linear map to the zonotope.
Base.convert
— Methodconvert(::Type{Zonotope}, cp::CartesianProduct{N, ZN1, ZN2}
) where {N, ZN1<:AbstractZonotope, ZN2<:AbstractZonotope}
Convert the Cartesian product of two zonotopic sets to a new zonotope.
Input
Zonotope
– target typeS
– Cartesian product of two zonotopic sets
Output
A zonotope.
Algorithm
The Cartesian product is obtained by:
- Concatenating the centers of each input zonotope.
- Arranging the generators in block-diagonal fashion, and filled with zeros in the off-diagonal; for this reason, the generator matrix of the returned zonotope is built as a sparse matrix.
Base.convert
— Methodconvert(::Type{Zonotope}, cp::CartesianProduct{N, HN1, HN2}) where {N,
HN1<:AbstractHyperrectangle, HN2<:AbstractHyperrectangle}
Convert the Cartesian product of two hyperrectangular sets to a zonotope.
Input
Zonotope
– target typecp
– Cartesian product of two hyperrectangular sets
Output
This method falls back to the conversion of the Cartesian product to a single hyperrectangle, and then from a hyperrectangle to a zonotope.
Base.convert
— Methodconvert(::Type{Zonotope}, cpa::CartesianProductArray{N, AZ})
where {N, AZ<:AbstractZonotope}
Convert a Cartesian product array of zonotopic sets to a zonotope.
Input
Zonotope
– target typecpa
– Cartesian product array of zonotopic sets
Output
A zonotope with sparse matrix representation.
Base.convert
— Methodconvert(::Type{Zonotope}, cpa::CartesianProductArray{N, HN})
where {N, HN<:AbstractHyperrectangle}
Convert the Cartesian product array of hyperrectangular sets to a zonotope.
Input
Zonotope
– target typecpa
– Cartesian product array of hyperrectangular sets
Output
A zonotope.
Algorithm
This method falls back to the conversion of the Cartesian product to a single hyperrectangle, and then from a hyperrectangle to a zonotope.
Base.convert
— Methodconvert(::Type{CartesianProduct{N, Interval{N}, Interval{N}}},
H::AbstractHyperrectangle{N}) where {N}
Convert a two-dimensional hyperrectangle to the Cartesian product of two intervals.
Input
CartesianProduct
– target typeH
– hyperrectangle
Output
The Cartesian product of two intervals.
Base.convert
— Methodconvert(::Type{CartesianProductArray{N, Interval{N}}},
H::AbstractHyperrectangle{N}) where {N}
Convert a hyperrectangle to the Cartesian product array of intervals.
Input
CartesianProductArray
– target typeH
– hyperrectangle
Output
The Cartesian product of a finite number of intervals.
Base.convert
— Methodconvert(::Type{MinkowskiSumArray},
X::MinkowskiSum{N, ST, MinkowskiSumArray{N, ST}}) where {N, ST}
Convert the Minkowski sum of a Minkowski sum array to a Minkowski sum array.
Input
MinkowskiSumArray
– target typeX
– Minkowski sum of a Minkowski sum array
Output
A Minkowski sum array.
Base.convert
— Methodconvert(::Type{HParallelotope}, Z::AbstractZonotope{N}) where {N}
Convert a zonotopic set of order one to a parallelotope in constraint representation.
Input
HParallelotope
– target typeZ
– zonotopic set of order one
Output
A parallelotope in constraint representation.
Notes
This function requires that the list of constraints of Z
are obtained in the particular order returned from the constraints_list
function of a Zonotope
. Hence it first converts Z
to a Zonotope
.
Base.convert
— Methodconvert(::Type{STAR}, P::AbstractPolyhedron{N}) where {N}
Convert a polyhedral set to a star set represented as a lazy affine map.
Input
STAR
– target typeP
– polyhedral set
Output
A star set.
Base.convert
— Methodconvert(::Type{STAR}, X::Star)
Convert a star set to its equivalent representation as a lazy affine map.
Input
STAR
– target typeX
– star set
Output
A star set.
Base.convert
— Methodconvert(::Type{Star}, P::AbstractPolyhedron{N}) where {N}
Convert a polyhedral set to a star set.
Input
Star
– target typeP
– polyhedral set
Output
A star set.
Base.convert
— Methodconvert(::Type{SimpleSparsePolynomialZonotope}, Z::AbstractZonotope)
Convert a zonotope to a simple sparse polynomial zonotope.
Input
SimpleSparsePolynomialZonotope
– target typeZ
– zonotopic set
Output
A simple sparse polynomial zonotope.
Algorithm
This method implements Proposition 3 in [1].
[1] Kochdumper, Althoff. Sparse polynomial zonotopes - a novel set representation for reachability analysis. 2021
Base.convert
— Methodconvert(::Type{SimpleSparsePolynomialZonotope},
SPZ::SparsePolynomialZonotope)
Convert a sparse polynomial zonotope to simple sparse polynomial zonotope.
Input
SimpleSparsePolynomialZonotope
– target typeSPZ
– sparse polynomial zonotope
Output
A simple sparse polynomial zonotope.
Base.convert
— Methodconvert(::Type{SparsePolynomialZonotope}, Z::AbstractZonotope{N}) where {N}
Convert a zonotope to sparse polynomial zonotope.
Input
SparsePolynomialZonotope
– target typeZ
– zonotopic set
Output
A sparse polynomial zonotope.
Base.convert
— Methodconvert(::Type{SparsePolynomialZonotope},
SSPZ::SimpleSparsePolynomialZonotope)
Convert a simple sparse polynomial zonotope to a sparse polynomial zonotope.
Input
SparsePolynomialZonotope
– target typeSSPZ
– simple sparse polynomial zonotope
Output
A sparse polynomial zonotope.