Conversion between set representations
This section of the manual lists the conversion functions between set representations.
Base.convert
— Method.convert(::Type{HPOLYGON1},
P::HPOLYGON2) where {HPOLYGON1<:AbstractHPolygon,
HPOLYGON2<:AbstractHPolygon}
Convert between polygon types in H-representation.
Input
type
– target typeP
– source polygon
Output
The polygon represented as the target type.
Notes
We need the Union
type for HPOLYGON1
because the target type must be concrete.
Base.convert
— Method.convert(T::Type{HPOLYGON}, P::VPolygon) where {HPOLYGON<:AbstractHPolygon}
Converts a polygon in vertex representation to a polygon in constraint representation.
Input
HPOLYGON
– type used for dispatchP
– polygon in vertex representation
Output
A polygon in constraint representation.
Base.convert
— Method.convert(::Type{Hyperrectangle}, H::AbstractHyperrectangle)
Convert a hyperrectangular set to a hyperrectangle.
Input
Hyperrectangle
– hyperrectangle type, used for dispatchH
– hyperrectangular set
Output
A hyperrectangle.
Examples
julia> convert(Hyperrectangle, Interval(0.0, 1.0))
Hyperrectangle{Float64}([0.5], [0.5])
Base.convert
— Method.convert(::Type{Interval}, H::AbstractHyperrectangle)
Converts a hyperrectangular set to an interval.
Input
Interval
– interval type, used for dispatchH
– hyperrectangular set
Output
An interval.
Examples
julia> convert(Interval, Hyperrectangle{Float64}([0.5], [0.5]))
Interval{Float64,IntervalArithmetic.Interval{Float64}}([0, 1])
Base.convert
— Method.convert(::Type{Interval}, S::LazySet{N}) where {N<:Real}
Converts a convex set to an interval.
Input
Interval
– interval type, used for dispatchS
– convex set
Output
An interval.
Base.convert
— Method.convert(::Type{Hyperrectangle},
cpa::CartesianProductArray{N, HN}) where {N<:Real, HN<:AbstractHyperrectangle{N}}
Converts the cartesian product of a finite number of hyperrectangular sets to a single hyperrectangle.
Input
Hyperrectangle
– type used for dispatchS
– cartesian product array of hyperrectangular set
Output
A hyperrectangle.
Algorithm
This implementation uses the center
and radius_hyperrectangle
methods of AbstractHyperrectangle
.
Base.convert
— Method.convert(::Type{Hyperrectangle},
cpa::CartesianProductArray{N, Interval{N}}) where {N<:Real}
Converts the cartesian product of a finite number of intervals to a single hyperrectangle.
Input
Hyperrectangle
– type used for dispatchS
– cartesian product array of intervals
Output
A hyperrectangle.
Algorithm
This implementation uses the min
and max
methods of Interval
to reduce the allocatons and improve performance (see LazySets#1143).
Base.convert
— Method.convert(::Type{HPOLYGON}, H::AbstractHyperrectangle) where
{HPOLYGON<:AbstractHPolygon}
Converts a hyperrectangular set to a polygon in constraint representation.
Input
HPOLYGON
– type used for dispatchH
– hyperrectangular set
Output
A polygon in constraint representation.
Base.convert
— Method.convert(::Type{HPOLYGON}, P::HPolytope{N}) where
{N<:Real, HPOLYGON<:AbstractHPolygon}
Convert from 2D polytope in H-representation to polygon in H-representation.
Input
type
– target typeP
– source polytope (must be 2D)
Output
The 2D polytope represented as polygon.
Base.convert
— Method.convert(::Type{HPOLYGON}, S::AbstractSingleton{N}
) where {N<:Real, HPOLYGON<:AbstractHPolygon}
Convert from singleton to polygon in H-representation.
Input
type
– target typeS
– singleton
Output
A polygon in constraint representation with the minimal number of constraints (three).
Base.convert
— Method.convert(::Type{HPOLYGON}, L::LineSegment{N}
) where {N<:Real, HPOLYGON<:AbstractHPolygon}
Convert from line segment to polygon in H-representation.
Input
type
– target typeL
– line segment
Output
A flat polygon in constraint representation with the minimal number of constraints (four).
Base.convert
— Method.convert(::Type{HPolyhedron}, P::AbstractPolytope)
Convert a polytopic set to a polyhedron in H-representation.
Input
type
– target typeP
– source polytope
Output
The given polytope represented as a polyhedron in constraint representation.
Base.convert
— Method.convert(::Type{HPolytope}, P::AbstractHPolygon)
Convert from polygon in H-representation to polytope in H-representation.
Input
type
– target typeP
– source polygon
Output
The polygon represented as 2D polytope.
Base.convert
— Method.convert(::Type{HPolytope}, H::AbstractHyperrectangle)
Converts a hyperrectangular set to a polytope in constraint representation.
Input
HPolytope
– type used for dispatchH
– hyperrectangular set
Output
A polytope in constraint representation.
Base.convert
— Method.convert(::Type{HPolytope}, P::AbstractPolytope)
Convert a polytopic set to a polytope in H-representation.
Input
type
– target typeP
– source polytope
Output
The given polytope represented as a polytope in constraint representation.
Algorithm
First the list of constraints of P
is computed, then the corresponding HPolytope
is created.
Base.convert
— Method.convert(::Type{HPolytope}, P::VPolytope)
Convert from polytope in V-representation to polytope in H-representation.
Input
type
– target typeP
– source polytope
Output
The polytope in the dual representation.
Algorithm
The tohrep
function is invoked. It requires the Polyhedra
package.
Base.convert
— Method.convert(::Type{VPolygon}, P::AbstractHPolygon)
Converts a polygon in constraint representation to a polygon in vertex representation.
Input
VPolygon
– type used for dispatchP
– polygon in constraint representation
Output
A polygon in vertex representation.
Base.convert
— Method.convert(::Type{VPolygon}, P::AbstractPolytope)
Convert polytopic set to polygon in V-representation.
Input
type
– target typeP
– source polytope
Output
The 2D polytope represented as a polygon.
Base.convert
— Method.convert(::Type{VPolytope}, P::AbstractPolytope)
Convert polytopic type to polytope in V-representation.
Input
type
– target typeP
– source polytope
Output
The set P
represented as a VPolytope
.
Base.convert
— Method.convert(::Type{VPolytope}, P::HPolytope)
Convert from polytope in H-representation to polytope in V-representation.
Input
type
– target typeP
– source polytope
Output
The polytope in the dual representation.
Algorithm
The tovrep
function is invoked. It requires the Polyhedra
package.
Base.convert
— Method.convert(::Type{Zonotope}, H::AbstractHyperrectangle)
Converts a hyperrectangular set to a zonotope.
Input
Zonotope
H
– hyperrectangular set
Output
A zonotope.
Base.convert
— Method.convert(::Type{IntervalArithmetic.IntervalBox}, H::AbstractHyperrectangle)
Converts a hyperrectangular set to an IntervalBox
from IntervalArithmetic
.
Input
IntervalBox
– type used for dispatchH
– hyperrectangular set
Output
An IntervalBox
.
Base.convert
— Method.convert(::Type{Hyperrectangle}, IB::IntervalArithmetic.IntervalBox)
Converts an IntervalBox
from IntervalArithmetic
to a hyperrectangular set.
Input
Hyperrectangle
– type used for dispatchIB
– interval box
Output
A Hyperrectangle
.
Base.convert
— Method.convert(::Type{Zonotope}, cp::CartesianProduct{N, Zonotope{N}, Zonotope{N}}) where {N<:Real}
Converts the cartesian product of two zonotopes to a new zonotope.
Input
Zonotope
– type used for dispatchS
– cartesian product of two zonotopes
Output
A zonotope.
Algorithm
The cartesian product is obtained by:
- Concatenating the centers of each input zonotope.
- Arranging the generators in block-diagional 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
— Method.convert(::Type{Hyperrectangle},
cp::CartesianProduct{N, HN1, HN2}) where {N<:Real, HN1<:AbstractHyperrectangle{N}, HN2<:AbstractHyperrectangle{N}}
Converts the cartesian product of two hyperrectangular sets to a single hyperrectangle.
Input
Hyperrectangle
– type used for dispatchS
– 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 of AbstractHyperrectangle
.
Base.convert
— Method.convert(::Type{Zonotope}, cp::CartesianProduct{N, HN1, HN2}) where {N<:Real,
HN1<:AbstractHyperrectangle{N}, HN2<:AbstractHyperrectangle{N}}
Converts the cartesian product of two hyperrectangular sets to a zonotope.
Input
Zonotope
– type, used for dispatchcp
– 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
— Method.convert(::Type{Zonotope}, cpa::CartesianProductArray{N, HN})
where {N<:Real, HN<:AbstractHyperrectangle{N}}
Converts the cartesian product array of hyperrectangular sets to a zonotope.
Input
Zonotope
– type, used for dispatchcpa
– 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
— Method.convert(::Type{Zonotope},
S::LinearMap{N, SN}
) where {N, SN<:AbstractHyperrectangle{N}}
Converts the lazy linear map of a hyperrectangular set to a zonotope.
Input
Zonotope
– type, used for dispatchS
– linear map of a hyperrectangular set
Output
A zonotope.
Algorithm
This method first converts the hyperrectangular set to a zonotope, and then applies the (concrete) linear map to the zonotope.
Base.convert
— Method.convert(::Type{Zonotope}, S::LinearMap{N, CartesianProduct{N, HN1, HN2}}
) where {N, HN1<:AbstractHyperrectangle{N},
HN2<:AbstractHyperrectangle{N}}
Converts the lazy linear map of the cartesian product of two hyperrectangular sets to a zonotope.
Input
Zonotope
– type, used for dispatchS
– 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
— Method.convert(::Type{Zonotope},S::LinearMap{N, CartesianProductArray{N, HN}}
) where {N, HN<:AbstractHyperrectangle{N}}
Converts the lazy linear map of the cartesian product of a finite number of hyperrectangular sets to a zonotope.
Input
Zonotope
– type, used for dispatchS
– 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.