diff --git a/docs/src/about.md b/docs/src/about.md index 3079c3b9a9..dda92b72b5 100644 --- a/docs/src/about.md +++ b/docs/src/about.md @@ -62,11 +62,11 @@ New functions and types should be documented according to the You can view the source code documentation from inside the REPL by typing `?` followed by the name of the type or function. -For example, the following command will print the documentation of the `LazySet` +For example, the following command will print the documentation of the `ConvexSet` type: ```julia -julia> ?LazySet +julia> ?ConvexSet ``` The documentation you are currently reading is written in [Markdown](https://en.wikipedia.org/wiki/Markdown), and it diff --git a/docs/src/assets/interfaces.graphml b/docs/src/assets/interfaces.graphml index 750f5c45b6..ef21ef09a1 100755 --- a/docs/src/assets/interfaces.graphml +++ b/docs/src/assets/interfaces.graphml @@ -21,7 +21,7 @@ - LazySet + ConvexSet diff --git a/docs/src/index.md b/docs/src/index.md index 322e1a293a..9799db9297 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -30,7 +30,7 @@ common convex set class or operation between sets. Concrete information is obtained through evaluating the set in specific directions. More precisely, each concrete subtype $\mathcal{X}$ of the abstract type -`LazySet` exports a method to calculate its support vector +`ConvexSet` exports a method to calculate its support vector $σ(d, \mathcal{X})$ in a given (arbitrary) direction $d \in \mathbb{R}^n$. Representing sets exactly but lazily has the advantage of being able to perform only the required operations on-demand. diff --git a/docs/src/lib/approximations.md b/docs/src/lib/approximations.md index cdbd3e6f5f..32d03a36b0 100644 --- a/docs/src/lib/approximations.md +++ b/docs/src/lib/approximations.md @@ -64,12 +64,12 @@ box_approximation_helper ```@docs LocalApproximation PolygonalOverapproximation -new_approx(S::LazySet, p1::VN, d1::VN, +new_approx(S::ConvexSet, p1::VN, d1::VN, p2::VN, d2::VN) where {N<:AbstractFloat, VN<:AbstractVector{N}} addapproximation!(Ω::PolygonalOverapproximation, p1::VN, d1::VN, p2::VN, d2::VN) where {N<:Real, VN<:AbstractVector{N}} -refine(::LocalApproximation, ::LazySet) +refine(::LocalApproximation, ::ConvexSet) tohrep(::PolygonalOverapproximation) -_approximate(S::LazySet{N}, ε::Real) where {N<:AbstractFloat} +_approximate(S::ConvexSet{N}, ε::Real) where {N<:AbstractFloat} constraint(::LocalApproximation) ``` @@ -79,7 +79,7 @@ constraint(::LocalApproximation) AbstractDirections isbounding isnormalized -project(::LazySet, ::AbstractVector{Int}, ::Type{<:AbstractDirections}) +project(::ConvexSet, ::AbstractVector{Int}, ::Type{<:AbstractDirections}) BoxDirections DiagDirections OctDirections @@ -89,7 +89,7 @@ SphericalDirections CustomDirections ``` -See also `overapproximate(X::LazySet, dir::AbstractDirections)::HPolytope`. +See also `overapproximate(X::ConvexSet, dir::AbstractDirections)::HPolytope`. ## Hausdorff distance diff --git a/docs/src/lib/binary_functions.md b/docs/src/lib/binary_functions.md index c81e1b65e3..c2baac21c9 100644 --- a/docs/src/lib/binary_functions.md +++ b/docs/src/lib/binary_functions.md @@ -15,7 +15,7 @@ CurrentModule = LazySets ```@docs cartesian_product(::VPolytope, ::VPolytope) -cartesian_product(::LazySet, ::LazySet) +cartesian_product(::ConvexSet, ::ConvexSet) ``` ## Check for emptiness of intersection @@ -24,22 +24,22 @@ cartesian_product(::LazySet, ::LazySet) `is_intersection_empty` can be used as an alternative name to `isdisjoint`. ```@docs -isdisjoint(::LazySet, ::LazySet, ::Bool=false) +isdisjoint(::ConvexSet, ::ConvexSet, ::Bool=false) isdisjoint(::AbstractHyperrectangle, ::AbstractHyperrectangle, ::Bool=false) -isdisjoint(::LazySet, ::AbstractSingleton, ::Bool=false) +isdisjoint(::ConvexSet, ::AbstractSingleton, ::Bool=false) isdisjoint(::AbstractHyperrectangle, ::AbstractSingleton, ::Bool=false) isdisjoint(::AbstractSingleton, ::AbstractSingleton, ::Bool=false) isdisjoint(::AbstractZonotope, ::Union{Hyperplane, Line2D}, ::Bool=false) isdisjoint(::Ball2, ::Ball2, ::Bool=false) isdisjoint(::LineSegment, ::LineSegment, ::Bool=false) -isdisjoint(::LazySet, ::Union{Hyperplane, Line2D}, ::Bool=false) -isdisjoint(::LazySet, ::HalfSpace, ::Bool=false) +isdisjoint(::ConvexSet, ::Union{Hyperplane, Line2D}, ::Bool=false) +isdisjoint(::ConvexSet, ::HalfSpace, ::Bool=false) isdisjoint(::HalfSpace, ::HalfSpace, ::Bool=false) -isdisjoint(::AbstractPolyhedron, ::LazySet, ::Bool=false) -isdisjoint(::UnionSet, ::LazySet, ::Bool=false) -isdisjoint(::UnionSetArray, ::LazySet, ::Bool=false) -isdisjoint(::Universe, ::LazySet, ::Bool=false) -isdisjoint(::Complement, ::LazySet, ::Bool=false) +isdisjoint(::AbstractPolyhedron, ::ConvexSet, ::Bool=false) +isdisjoint(::UnionSet, ::ConvexSet, ::Bool=false) +isdisjoint(::UnionSetArray, ::ConvexSet, ::Bool=false) +isdisjoint(::Universe, ::ConvexSet, ::Bool=false) +isdisjoint(::Complement, ::ConvexSet, ::Bool=false) isdisjoint(::AbstractZonotope, ::AbstractZonotope, ::Bool=false) isdisjoint(::Interval, ::Interval, ::Bool=false) isdisjoint(::CartesianProductArray, ::AbstractPolyhedron) @@ -51,7 +51,7 @@ isdisjoint(::Line2D, ::Line2D, ::Bool=false) ## Convex hull ```@docs -convex_hull(::LazySet{N}, ::LazySet{N}) where {N} +convex_hull(::ConvexSet{N}, ::ConvexSet{N}) where {N} convex_hull(::HPoly, ::HPoly) convex_hull(::VPolytope, ::VPolytope) convex_hull(::VPolygon, ::VPolygon) @@ -63,23 +63,23 @@ monotone_chain! ## Intersection of two sets ```@docs -intersection(::AbstractSingleton, ::LazySet) +intersection(::AbstractSingleton, ::ConvexSet) intersection(::Line2D, ::Line2D) intersection(::AbstractHyperrectangle, ::AbstractHyperrectangle) intersection(::Interval, ::Interval) intersection(::Interval, ::HalfSpace) intersection(::Interval, ::Hyperplane) -intersection(::Interval, ::LazySet) +intersection(::Interval, ::ConvexSet) intersection(::AbstractHPolygon, ::AbstractHPolygon) intersection(::AbstractPolyhedron{N}, ::AbstractPolyhedron{N}) where {N} intersection(::Union{VPolytope, VPolygon}, ::Union{VPolytope, VPolygon}) intersection(::VPolygon, ::VPolygon; ::Bool=true) -intersection(::UnionSet, ::LazySet) -intersection(::UnionSetArray, ::LazySet) -intersection(::Universe, ::LazySet) +intersection(::UnionSet, ::ConvexSet) +intersection(::UnionSetArray, ::ConvexSet) +intersection(::Universe, ::ConvexSet) intersection(::AbstractPolyhedron, ::ResetMap) intersection(::CartesianProductArray, ::CartesianProductArray) -intersection(::LinearMap, ::LazySet) +intersection(::LinearMap, ::ConvexSet) intersection(::CartesianProductArray, ::AbstractPolyhedron) intersection(::LineSegment, ::Line2D) intersection(::LineSegment, ::LineSegment) @@ -89,7 +89,7 @@ intersection(::AbstractZonotope{N}, ::HalfSpace{N}) where {N} ## Minkowski sum ```@docs -minkowski_sum(::LazySet, ::LazySet) +minkowski_sum(::ConvexSet, ::ConvexSet) minkowski_sum(::AbstractPolyhedron, ::AbstractPolyhedron) minkowski_sum(::VPolytope, ::VPolytope) minkowski_sum(::AbstractHyperrectangle, ::AbstractHyperrectangle) @@ -102,7 +102,7 @@ minkowski_sum(::AbstractSingleton, ::AbstractSingleton) ## Minkowski difference ```@docs -minkowski_difference(::LazySet, ::LazySet) +minkowski_difference(::ConvexSet, ::ConvexSet) pontryagin_difference ``` @@ -110,29 +110,29 @@ pontryagin_difference ```@docs issubset -⊆(::LazySet, ::LazySet, ::Bool=false) -⊆(::LazySet, ::AbstractHyperrectangle, ::Bool=false) -⊆(::AbstractPolytope, ::LazySet, ::Bool=false) +⊆(::ConvexSet, ::ConvexSet, ::Bool=false) +⊆(::ConvexSet, ::AbstractHyperrectangle, ::Bool=false) +⊆(::AbstractPolytope, ::ConvexSet, ::Bool=false) ⊆(::AbstractPolytope, ::AbstractHyperrectangle, ::Bool=false) ⊆(::AbstractZonotope, ::AbstractHyperrectangle) ⊆(::AbstractHyperrectangle, ::AbstractHyperrectangle, ::Bool=false) -⊆(::LazySet, ::AbstractPolyhedron, ::Bool=false) -⊆(::AbstractSingleton, ::LazySet, ::Bool=false) +⊆(::ConvexSet, ::AbstractPolyhedron, ::Bool=false) +⊆(::AbstractSingleton, ::ConvexSet, ::Bool=false) ⊆(::AbstractSingleton, ::AbstractHyperrectangle, ::Bool=false) ⊆(::AbstractSingleton, ::AbstractSingleton, ::Bool=false) ⊆(::Ball2, ::Ball2, ::Bool=false) ⊆(::Union{Ball2, Ballp}, ::AbstractSingleton, ::Bool=false) -⊆(::LineSegment, ::LazySet, ::Bool=false) +⊆(::LineSegment, ::ConvexSet, ::Bool=false) ⊆(::LineSegment, ::AbstractHyperrectangle, ::Bool=false) ⊆(::Interval{N}, ::Interval, ::Bool=false) where {N} ⊆(::Interval, ::UnionSet, ::Bool=false) -⊆(::EmptySet, ::LazySet, ::Bool=false) -⊆(::LazySet, ::EmptySet, ::Bool=false) -⊆(::UnionSet, ::LazySet, ::Bool=false) -⊆(::UnionSetArray, ::LazySet, ::Bool=false) -⊆(::LazySet, ::Universe, ::Bool=false) -⊆(::Universe, ::LazySet, ::Bool=false) -⊆(::LazySet, ::Complement, ::Bool=false) +⊆(::EmptySet, ::ConvexSet, ::Bool=false) +⊆(::ConvexSet, ::EmptySet, ::Bool=false) +⊆(::UnionSet, ::ConvexSet, ::Bool=false) +⊆(::UnionSetArray, ::ConvexSet, ::Bool=false) +⊆(::ConvexSet, ::Universe, ::Bool=false) +⊆(::Universe, ::ConvexSet, ::Bool=false) +⊆(::ConvexSet, ::Complement, ::Bool=false) ⊆(::CartesianProduct, ::CartesianProduct, ::Bool=false) ⊆(::CartesianProductArray, ::CartesianProductArray, ::Bool=false) ⊆(::AbstractZonotope, ::AbstractHyperrectangle, ::Bool=false) @@ -142,7 +142,7 @@ issubset ## Set difference ```@docs -\(::LazySet, ::LazySet) +\(::ConvexSet, ::ConvexSet) difference(::IN, ::IN) where {N, IN<:Interval{N}} difference(::AbstractHyperrectangle{N}, ::AbstractHyperrectangle{N}) where {N} ``` @@ -150,6 +150,6 @@ difference(::AbstractHyperrectangle{N}, ::AbstractHyperrectangle{N}) where {N} ## Distance ```@docs -distance(::AbstractSingleton, ::LazySet; ::Real=2.0) +distance(::AbstractSingleton, ::ConvexSet; ::Real=2.0) distance(::AbstractHyperrectangle, ::AbstractHyperrectangle; ::Real=2.0) ``` diff --git a/docs/src/lib/conversion.md b/docs/src/lib/conversion.md index c94b7afe84..4bf1f110a5 100644 --- a/docs/src/lib/conversion.md +++ b/docs/src/lib/conversion.md @@ -16,21 +16,21 @@ CurrentModule = LazySets convert(::Type{HPOLYGON}, ::VPolygon) where {HPOLYGON<:AbstractHPolygon} convert(::Type{Hyperrectangle}, ::AbstractHyperrectangle) convert(::Type{Interval}, ::AbstractHyperrectangle) -convert(::Type{Interval}, ::LazySet{N}) where {N<:Real} +convert(::Type{Interval}, ::ConvexSet{N}) where {N<:Real} convert(::Type{Hyperrectangle}, cpa::CartesianProductArray{N, HN}) where {N<:Real, HN<:AbstractHyperrectangle{N}} convert(::Type{Hyperrectangle}, cpa::CartesianProductArray{N, Interval{N}}) where {N<:Real} convert(::Type{HPOLYGON}, ::AbstractHyperrectangle) where {HPOLYGON<:AbstractHPolygon} convert(::Type{HPOLYGON}, ::HPolytope{N, VN}) where {N<:Real, VN<:AbstractVector{N}, HPOLYGON<:AbstractHPolygon} convert(::Type{HPOLYGON}, ::AbstractSingleton{N}) where {N<:Real, HPOLYGON<:AbstractHPolygon} convert(::Type{HPOLYGON}, ::LineSegment{N}) where {N<:Real, HPOLYGON<:AbstractHPolygon} -convert(::Type{HPOLYGON}, ::LazySet) where {HPOLYGON<:AbstractHPolygon} +convert(::Type{HPOLYGON}, ::ConvexSet) where {HPOLYGON<:AbstractHPolygon} convert(::Type{HPolyhedron}, ::AbstractPolytope) convert(::Type{HPolytope}, ::AbstractHPolygon) convert(::Type{HPolytope}, ::AbstractHyperrectangle) convert(::Type{HPolytope}, ::AbstractPolytope) convert(::Type{HPolytope}, ::VPolytope) convert(::Type{VPolygon}, ::AbstractHPolygon) -convert(::Type{VPolytope}, ::LazySet) +convert(::Type{VPolytope}, ::ConvexSet) convert(::Type{VPolytope}, ::AbstractPolytope) convert(::Type{VPolytope}, ::HPolytope) convert(::Type{Zonotope}, ::AbstractZonotope) @@ -50,7 +50,7 @@ convert(::Type{Interval}, ::Rectification{N, IN}) where {N<:Real, IN<:Interval{N convert(::Type{IntervalArithmetic.Interval}, ::Interval) convert(::Type{Interval}, ::IntervalArithmetic.Interval) convert(::Type{VPolytope}, ::ConvexHullArray{N, Singleton{N, VT}}) where {N, VT} -convert(::Type{VPolygon}, ::LazySet) +convert(::Type{VPolygon}, ::ConvexSet) convert(::Type{MinkowskiSumArray}, ::MinkowskiSum{N, ST, MinkowskiSumArray{N, ST}}) where {N, ST} convert(::Type{Interval}, ::MinkowskiSum{N, IT, IT}) where {N, IT<:Interval{N}} convert(::Type{HParallelotope}, Z::AbstractZonotope{N}) where {N} diff --git a/docs/src/lib/interfaces.md b/docs/src/lib/interfaces.md index 2d59999670..9d6c1fa6d5 100644 --- a/docs/src/lib/interfaces.md +++ b/docs/src/lib/interfaces.md @@ -13,7 +13,7 @@ the respective sections. !!! note The naming convention is such that all interface names (with the exception - of the main abstract type `LazySet`) should be preceded by `Abstract`. + of the main abstract type `ConvexSet`) should be preceded by `Abstract`. The following diagram shows the interface hierarchy. @@ -28,26 +28,34 @@ Depth = 3 CurrentModule = LazySets ``` -## [General sets (LazySet)](@id def_LazySet) +## [General set (LazySet)](@id def_LazySet) -Every convex set in this library implements this interface. +Every set in this library is a subtype of the abstract type `LazySet`. ```@docs LazySet ``` +## [General sets (ConvexSet)](@id def_ConvexSet) + +Every convex set in this library implements this interface. + +```@docs +ConvexSet +``` + ### Support function and support vector -Every `LazySet` type must define a function `σ` to compute the support vector. +Every `ConvexSet` type must define a function `σ` to compute the support vector. ```@docs support_vector -ρ(::AbstractVector, ::LazySet) +ρ(::AbstractVector, ::ConvexSet) support_function σ -singleton_list(::LazySet) -constraints(::LazySet) -vertices(::LazySet) +singleton_list(::ConvexSet) +constraints(::ConvexSet) +vertices(::ConvexSet) delaunay ``` @@ -55,50 +63,50 @@ delaunay ```@docs basetype -norm(::LazySet, ::Real=Inf) -radius(::LazySet, ::Real=Inf) -diameter(::LazySet, ::Real=Inf) -isboundedtype(::Type{<:LazySet}) -isbounded(::LazySet) -_isbounded_unit_dimensions(::LazySet{N}) where {N} -is_polyhedral(::LazySet) -an_element(::LazySet{N}) where {N} -tosimplehrep(::LazySet) -isuniversal(::LazySet{N}, ::Bool=false) where {N} -affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector) -exponential_map(::AbstractMatrix, ::LazySet) -reflect(::LazySet) -is_interior_point(::AbstractVector{N}, ::LazySet{N}; p=Inf, ε=_rtol(N)) where {N<:Real} -isoperationtype(::Type{<:LazySet}) -isoperation(::LazySet) -isequivalent(::LazySet, ::LazySet) -isconvextype(::Type{<:LazySet}) -low(::LazySet{N}, ::Int) where {N} -high(::LazySet{N}, ::Int) where {N} -extrema(::LazySet, ::Int) -low(::LazySet) -high(::LazySet) -extrema(::LazySet) -surface(::LazySet{N}) where {N} -area(::LazySet{N}) where {N} -concretize(::LazySet) -complement(::LazySet) -project(::LazySet{N}, ::AbstractVector{Int}, ::Nothing=nothing, ::Int=dim(S)) where {N} -project(::LazySet, ::AbstractVector{Int}, ::Type{TS}, ::Int=dim(S)) where {TS<:LazySet} -project(::LazySet, ::AbstractVector{Int}, ::Pair{T, N}, ::Int=dim(S)) where {T<:UnionAll, N<:Real} -project(::LazySet, ::AbstractVector{Int}, ::Real, ::Int=dim(S)) -rectify(::LazySet, ::Bool=false) +norm(::ConvexSet, ::Real=Inf) +radius(::ConvexSet, ::Real=Inf) +diameter(::ConvexSet, ::Real=Inf) +isboundedtype(::Type{<:ConvexSet}) +isbounded(::ConvexSet) +_isbounded_unit_dimensions(::ConvexSet{N}) where {N} +is_polyhedral(::ConvexSet) +an_element(::ConvexSet{N}) where {N} +tosimplehrep(::ConvexSet) +isuniversal(::ConvexSet{N}, ::Bool=false) where {N} +affine_map(::AbstractMatrix, ::ConvexSet, ::AbstractVector) +exponential_map(::AbstractMatrix, ::ConvexSet) +reflect(::ConvexSet) +is_interior_point(::AbstractVector{N}, ::ConvexSet{N}; p=Inf, ε=_rtol(N)) where {N<:Real} +isoperationtype(::Type{<:ConvexSet}) +isoperation(::ConvexSet) +isequivalent(::ConvexSet, ::ConvexSet) +isconvextype(::Type{<:ConvexSet}) +low(::ConvexSet{N}, ::Int) where {N} +high(::ConvexSet{N}, ::Int) where {N} +extrema(::ConvexSet, ::Int) +low(::ConvexSet) +high(::ConvexSet) +extrema(::ConvexSet) +surface(::ConvexSet{N}) where {N} +area(::ConvexSet{N}) where {N} +concretize(::ConvexSet) +complement(::ConvexSet) +project(::ConvexSet{N}, ::AbstractVector{Int}, ::Nothing=nothing, ::Int=dim(S)) where {N} +project(::ConvexSet, ::AbstractVector{Int}, ::Type{TS}, ::Int=dim(S)) where {TS<:ConvexSet} +project(::ConvexSet, ::AbstractVector{Int}, ::Pair{T, N}, ::Int=dim(S)) where {T<:UnionAll, N<:Real} +project(::ConvexSet, ::AbstractVector{Int}, ::Real, ::Int=dim(S)) +rectify(::ConvexSet, ::Bool=false) permute -rationalize(::Type{T}, ::LazySet{N}, ::Real) where {T<:Integer, N<:AbstractFloat} +rationalize(::Type{T}, ::ConvexSet{N}, ::Real) where {T<:Integer, N<:AbstractFloat} ``` -Plotting is available for general one- or two-dimensional `LazySet`s, provided +Plotting is available for general one- or two-dimensional `ConvexSet`s, provided that the overapproximation using iterative refinement is available: ```@docs -plot_recipe(::LazySet{N}, ::Any=zero(N)) where {N} -RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::LazySet{N}, ::N=N(1e-3)) where {N} -RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::AbstractVector{VN}, ::N=N(1e-3), ::Int=40; ::Bool=false) where {N, VN<:LazySet{N}} +plot_recipe(::ConvexSet{N}, ::Any=zero(N)) where {N} +RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::ConvexSet{N}, ::N=N(1e-3)) where {N} +RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::AbstractVector{VN}, ::N=N(1e-3), ::Int=40; ::Bool=false) where {N, VN<:ConvexSet{N}} ``` For three-dimensional sets, we support `Makie`: @@ -111,9 +119,9 @@ plot3d! ### Set functions that override Base functions ```@docs -==(::LazySet, ::LazySet) -≈(::LazySet, ::LazySet) -copy(::LazySet) +==(::ConvexSet, ::ConvexSet) +≈(::ConvexSet, ::ConvexSet) +copy(::ConvexSet) eltype ``` diff --git a/docs/src/lib/lazy_operations/AffineMap.md b/docs/src/lib/lazy_operations/AffineMap.md index 71c4c4fe33..dc97c55d47 100644 --- a/docs/src/lib/lazy_operations/AffineMap.md +++ b/docs/src/lib/lazy_operations/AffineMap.md @@ -20,5 +20,5 @@ Inherited from [`AbstractAffineMap`](@ref): * [`constraints_list`](@ref constraints_list(::AbstractAffineMap)) * [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/Bloating.md b/docs/src/lib/lazy_operations/Bloating.md index b9cb0b7903..8340b66884 100644 --- a/docs/src/lib/lazy_operations/Bloating.md +++ b/docs/src/lib/lazy_operations/Bloating.md @@ -16,5 +16,5 @@ constraints_list(::Bloating) center(::Bloating) ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/CartesianProduct.md b/docs/src/lib/lazy_operations/CartesianProduct.md index 6860edf631..6d3eabd011 100644 --- a/docs/src/lib/lazy_operations/CartesianProduct.md +++ b/docs/src/lib/lazy_operations/CartesianProduct.md @@ -8,8 +8,8 @@ CurrentModule = LazySets ```@docs CartesianProduct -×(::LazySet, ::LazySet) -*(::LazySet, ::LazySet) +×(::ConvexSet, ::ConvexSet) +*(::ConvexSet, ::ConvexSet) swap(::CartesianProduct) dim(::CartesianProduct) ρ(::AbstractVector, ::CartesianProduct) @@ -25,12 +25,12 @@ project(::CartesianProduct{N, IT, HT}, ::AbstractVector{Int}) where {N, IT<:Inte project(::CartesianProduct{N, IT, ZT}, ::AbstractVector{Int}) where {N, IT<:Interval, ZT<:AbstractZonotope{N}} project(::CartesianProduct{N, IT, Union{VP1, VP2}}, ::AbstractVector{Int}) where {N, IT<:Interval, VP1<:VPolygon{N}, VP2<:VPolytope{N}} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## [``n``-ary Cartesian product (CartesianProductArray)](@id def_CartesianProductArray) @@ -51,9 +51,9 @@ block_structure(cpa::CartesianProductArray) block_to_dimension_indices(cpa::CartesianProductArray, vars::Vector{Int}) substitute_blocks(low_dim_cpa::CartesianProductArray{N}, orig_cpa::CartesianProductArray{N}, blocks::Vector{Tuple{Int,Int}}) where{N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/Complement.md b/docs/src/lib/lazy_operations/Complement.md index 960b52932c..2c2a6c022d 100644 --- a/docs/src/lib/lazy_operations/Complement.md +++ b/docs/src/lib/lazy_operations/Complement.md @@ -5,7 +5,7 @@ CurrentModule = LazySets # [Complement](@id def_Complement) Note that the complement of a convex set is generally not convex. -Hence this set type is not part of the convex-set family `LazySet`. +Hence this set type is not part of the convex-set family `ConvexSet`. ```@docs Complement diff --git a/docs/src/lib/lazy_operations/ConvexHull.md b/docs/src/lib/lazy_operations/ConvexHull.md index ca3a69205b..00e899da0e 100644 --- a/docs/src/lib/lazy_operations/ConvexHull.md +++ b/docs/src/lib/lazy_operations/ConvexHull.md @@ -17,12 +17,12 @@ isbounded(::ConvexHull) isempty(::ConvexHull) vertices_list(::ConvexHull) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## [``n``-ary convex hull (ConvexHullArray)](@id def_ConvexHullArray) @@ -37,9 +37,9 @@ array(::ConvexHullArray) isempty(::ConvexHullArray) vertices_list(::ConvexHullArray) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/ExponentialMap.md b/docs/src/lib/lazy_operations/ExponentialMap.md index bb7c584669..eed543c193 100644 --- a/docs/src/lib/lazy_operations/ExponentialMap.md +++ b/docs/src/lib/lazy_operations/ExponentialMap.md @@ -21,17 +21,17 @@ Inherited from [`AbstractAffineMap`](@ref): * [`constraints_list`](@ref constraints_list(::AbstractAffineMap)) * [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ### Sparse matrix exponential ```@docs SparseMatrixExp -*(::SparseMatrixExp, ::LazySet) +*(::SparseMatrixExp, ::ConvexSet) get_row(::SparseMatrixExp, ::Int) ``` @@ -51,15 +51,15 @@ Inherited from [`AbstractAffineMap`](@ref): * [`constraints_list`](@ref constraints_list(::AbstractAffineMap)) * [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ### Projection of a sparse matrix exponential ```@docs ProjectionSparseMatrixExp -*(::ProjectionSparseMatrixExp, ::LazySet) +*(::ProjectionSparseMatrixExp, ::ConvexSet) ``` diff --git a/docs/src/lib/lazy_operations/Intersection.md b/docs/src/lib/lazy_operations/Intersection.md index a19bface31..ae4796cd0a 100644 --- a/docs/src/lib/lazy_operations/Intersection.md +++ b/docs/src/lib/lazy_operations/Intersection.md @@ -8,11 +8,11 @@ CurrentModule = LazySets ```@docs Intersection -∩(::LazySet, ::LazySet) +∩(::ConvexSet, ::ConvexSet) dim(::Intersection) ρ(::AbstractVector, ::Intersection) -ρ(::AbstractVector, ::Intersection{N, S1, S2}) where {N, S1<:LazySet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} -ρ(::AbstractVector, ::Intersection{N, S1, S2}) where {N, S1<:LazySet{N}, S2<:AbstractPolyhedron{N}} +ρ(::AbstractVector, ::Intersection{N, S1, S2}) where {N, S1<:ConvexSet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} +ρ(::AbstractVector, ::Intersection{N, S1, S2}) where {N, S1<:ConvexSet{N}, S2<:AbstractPolyhedron{N}} ρ(::AbstractVector, ::Intersection{N, S1, S2}) where {N, S1<:AbstractPolyhedron{N}, S2<:AbstractPolyhedron{N}} σ(::AbstractVector, ::Intersection) isbounded(::Intersection) @@ -31,12 +31,12 @@ plot_recipe(::Intersection{N}, ::N=zero(N), ::Int=40) where {N<:Real} RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::Intersection{N}, ::N=zero(N), ::Int=40) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ### Intersection cache @@ -55,9 +55,9 @@ isbounded(::IntersectionArray) array(::IntersectionArray) constraints_list(::IntersectionArray{N}) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/InverseLinearMap.md b/docs/src/lib/lazy_operations/InverseLinearMap.md index 82c3369df1..9a35e86089 100644 --- a/docs/src/lib/lazy_operations/InverseLinearMap.md +++ b/docs/src/lib/lazy_operations/InverseLinearMap.md @@ -20,8 +20,8 @@ Inherited from [`AbstractAffineMap`](@ref): * [`isempty`](@ref isempty(::AbstractAffineMap)) * [`isbounded`](@ref isbounded(::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/LinearMap.md b/docs/src/lib/lazy_operations/LinearMap.md index 16ad351ee0..21448c66a3 100644 --- a/docs/src/lib/lazy_operations/LinearMap.md +++ b/docs/src/lib/lazy_operations/LinearMap.md @@ -6,7 +6,7 @@ CurrentModule = LazySets ```@docs LinearMap -*(::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, ::LazySet) +*(::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, ::ConvexSet) dim(::LinearMap) ρ(::AbstractVector, ::LinearMap) σ(::AbstractVector, ::LinearMap) @@ -15,17 +15,17 @@ an_element(::LinearMap) vertices_list(::LinearMap) constraints_list(::LinearMap) linear_map(::AbstractMatrix, ::LinearMap) -project(S::LazySet{N}, ::AbstractVector{Int}, ::Type{LM}, ::Int=dim(S)) where {N, LM<:LinearMap} +project(S::ConvexSet{N}, ::AbstractVector{Int}, ::Type{LM}, ::Int=dim(S)) where {N, LM<:LinearMap} ``` Inherited from [`AbstractAffineMap`](@ref): * [`isempty`](@ref isempty(::AbstractAffineMap)) * [`isbounded`](@ref isbounded(::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) The lazy projection of a set can be conveniently constructed using `Projection`. diff --git a/docs/src/lib/lazy_operations/MinkowskiSum.md b/docs/src/lib/lazy_operations/MinkowskiSum.md index 73af77c538..f2e00036ef 100644 --- a/docs/src/lib/lazy_operations/MinkowskiSum.md +++ b/docs/src/lib/lazy_operations/MinkowskiSum.md @@ -8,8 +8,8 @@ CurrentModule = LazySets ```@docs MinkowskiSum -⊕(::LazySet, ::LazySet) -+(::LazySet, ::LazySet) +⊕(::ConvexSet, ::ConvexSet) ++(::ConvexSet, ::ConvexSet) swap(::MinkowskiSum) dim(::MinkowskiSum) ρ(::AbstractVector, ::MinkowskiSum) @@ -18,15 +18,15 @@ isbounded(::MinkowskiSum) isempty(::MinkowskiSum) center(::MinkowskiSum) constraints_list(::MinkowskiSum) -∈(::AbstractVector, ::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:LazySet} +∈(::AbstractVector, ::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:ConvexSet} vertices_list(::MinkowskiSum) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## [``n``-ary Minkowski sum (MinkowskiSumArray)](@id def_MinkowskiSumArray) @@ -40,12 +40,12 @@ isempty(::MinkowskiSumArray) array(::MinkowskiSumArray) center(::MinkowskiSumArray) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet{N}) where {N}) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet{N}) where {N}) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## [``n``-ary Minkowski sum with cache (CachedMinkowskiSumArray)](@id def_CachedMinkowskiSumArray) @@ -58,9 +58,9 @@ isempty(::CachedMinkowskiSumArray) array(::CachedMinkowskiSumArray) forget_sets!(::CachedMinkowskiSumArray) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`an_element`](@ref an_element(::LazySet)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`an_element`](@ref an_element(::ConvexSet)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/Rectification.md b/docs/src/lib/lazy_operations/Rectification.md index f1cdd83a10..3adff2b506 100644 --- a/docs/src/lib/lazy_operations/Rectification.md +++ b/docs/src/lib/lazy_operations/Rectification.md @@ -5,7 +5,7 @@ CurrentModule = LazySets # [Rectification](@id def_Rectification) Note that the rectification of a convex set is generally not convex. -Hence this set type is not part of the convex-set family `LazySet`. +Hence this set type is not part of the convex-set family `ConvexSet`. ```@docs Rectification @@ -23,8 +23,8 @@ isbounded(::Rectification{N}) where {N} to_union_of_projections(::Rectification, ::Bool=false) ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## Rectification cache diff --git a/docs/src/lib/lazy_operations/ResetMap.md b/docs/src/lib/lazy_operations/ResetMap.md index d117d19cc9..5f5c018881 100644 --- a/docs/src/lib/lazy_operations/ResetMap.md +++ b/docs/src/lib/lazy_operations/ResetMap.md @@ -22,8 +22,8 @@ Inherited from [`AbstractAffineMap`](@ref): * [`vertices_list`](@ref vertices_list(::AbstractAffineMap)) * [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/SymmetricIntervalHull.md b/docs/src/lib/lazy_operations/SymmetricIntervalHull.md index f7dfe4e897..e010ea98a4 100644 --- a/docs/src/lib/lazy_operations/SymmetricIntervalHull.md +++ b/docs/src/lib/lazy_operations/SymmetricIntervalHull.md @@ -14,9 +14,9 @@ center(::SymmetricIntervalHull{N}) where {N} radius_hyperrectangle(::SymmetricIntervalHull) radius_hyperrectangle(::SymmetricIntervalHull, ::Int) ``` -Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/lazy_operations/Translation.md b/docs/src/lib/lazy_operations/Translation.md index 66a7ab83eb..e87c909b0f 100644 --- a/docs/src/lib/lazy_operations/Translation.md +++ b/docs/src/lib/lazy_operations/Translation.md @@ -6,8 +6,8 @@ CurrentModule = LazySets ```@docs Translation -+(X::LazySet, v::AbstractVector) -⊕(X::LazySet, v::AbstractVector) ++(X::ConvexSet, v::AbstractVector) +⊕(X::ConvexSet, v::AbstractVector) ρ(::AbstractVector, ::Translation) σ(::AbstractVector, ::Translation) an_element(::Translation) @@ -22,8 +22,8 @@ Inherited from [`AbstractAffineMap`](@ref): * [`isbounded`](@ref isbounded(::AbstractAffineMap)) * [`vertices_list`](@ref vertices_list(::AbstractAffineMap)) -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/lazy_operations/UnionSet.md b/docs/src/lib/lazy_operations/UnionSet.md index 5ee27d9023..cc0ecbfccf 100644 --- a/docs/src/lib/lazy_operations/UnionSet.md +++ b/docs/src/lib/lazy_operations/UnionSet.md @@ -5,13 +5,13 @@ CurrentModule = LazySets # Union Note that the union of convex sets is generally not convex. -Hence these set types are not part of the convex-set family `LazySet`. +Hence these set types are not part of the convex-set family `ConvexSet`. ## [Binary set union (UnionSet)](@id def_UnionSet) ```@docs UnionSet -∪(::LazySet, ::LazySet) +∪(::ConvexSet, ::ConvexSet) swap(::UnionSet) dim(::UnionSet) σ(::AbstractVector, ::UnionSet; algorithm="support_vector") @@ -23,8 +23,8 @@ isbounded(::UnionSet) vertices_list(::UnionSet) ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) ## [``n``-ary set union (UnionSetArray)](@id def_UnionSetArray) @@ -41,5 +41,5 @@ isbounded(::UnionSetArray) vertices_list(::UnionSetArray) ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/sets/Ball1.md b/docs/src/lib/sets/Ball1.md index 4448f2beda..63c0da2d3c 100644 --- a/docs/src/lib/sets/Ball1.md +++ b/docs/src/lib/sets/Ball1.md @@ -16,11 +16,11 @@ translate(::Ball1, ::AbstractVector) translate!(::Ball1, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Ball2.md b/docs/src/lib/sets/Ball2.md index f3df268281..6d122b2877 100644 --- a/docs/src/lib/sets/Ball2.md +++ b/docs/src/lib/sets/Ball2.md @@ -17,10 +17,10 @@ translate!(::Ball2, ::AbstractVector) chebyshev_center(::Ball2) volume(::Ball2) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) Inherited from [`AbstractCentrallySymmetric`](@ref): * [`dim`](@ref dim(::AbstractCentrallySymmetric)) diff --git a/docs/src/lib/sets/BallInf.md b/docs/src/lib/sets/BallInf.md index 58a6a12f31..db6b646095 100644 --- a/docs/src/lib/sets/BallInf.md +++ b/docs/src/lib/sets/BallInf.md @@ -17,9 +17,9 @@ rand(::Type{BallInf}) translate(::BallInf, ::AbstractVector) translate!(::BallInf, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Ballp.md b/docs/src/lib/sets/Ballp.md index 71fbec26ac..d20c7be177 100644 --- a/docs/src/lib/sets/Ballp.md +++ b/docs/src/lib/sets/Ballp.md @@ -13,10 +13,10 @@ rand(::Type{Ballp}) translate(::Ballp, ::AbstractVector) translate!(::Ballp, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) Inherited from [`AbstractCentrallySymmetric`](@ref): * [`dim`](@ref dim(::AbstractCentrallySymmetric)) diff --git a/docs/src/lib/sets/Ellipsoid.md b/docs/src/lib/sets/Ellipsoid.md index dde763e2de..71a06808c5 100644 --- a/docs/src/lib/sets/Ellipsoid.md +++ b/docs/src/lib/sets/Ellipsoid.md @@ -15,10 +15,10 @@ shape_matrix(::Ellipsoid) translate(::Ellipsoid, ::AbstractVector) translate!(::Ellipsoid, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) Inherited from [`AbstractCentrallySymmetric`](@ref): * [`dim`](@ref dim(::AbstractCentrallySymmetric)) diff --git a/docs/src/lib/sets/EmptySet.md b/docs/src/lib/sets/EmptySet.md index 33f5332ac5..21a60630e0 100644 --- a/docs/src/lib/sets/EmptySet.md +++ b/docs/src/lib/sets/EmptySet.md @@ -27,5 +27,5 @@ plot_recipe(::EmptySet{N}, ::Any=zero(N)) where {N} RecipesBase.apply_recipe(::AbstractDict{Symbol,Any}, ::EmptySet{N}, ::N=zero(N)) where {N} area(::EmptySet{N}) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) diff --git a/docs/src/lib/sets/HParallelotope.md b/docs/src/lib/sets/HParallelotope.md index 05842c075b..883b5f85ae 100644 --- a/docs/src/lib/sets/HParallelotope.md +++ b/docs/src/lib/sets/HParallelotope.md @@ -18,11 +18,11 @@ constraints_list(::HParallelotope{N, VN}) where {N, VN} rand(::Type{HParallelotope}) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/HPolygon.md b/docs/src/lib/sets/HPolygon.md index 4ba8b298b9..d31d308bf2 100644 --- a/docs/src/lib/sets/HPolygon.md +++ b/docs/src/lib/sets/HPolygon.md @@ -9,11 +9,11 @@ HPolygon σ(::AbstractVector, ::HPolygon) translate(::HPolygon, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolyhedron`](@ref): * [`linear_map`](@ref linear_map(::AbstractMatrix{NM}, ::AbstractPolyhedron{NP}) where {NM, NP}) diff --git a/docs/src/lib/sets/HPolygonOpt.md b/docs/src/lib/sets/HPolygonOpt.md index 8eda2915d3..ed8783c4c4 100644 --- a/docs/src/lib/sets/HPolygonOpt.md +++ b/docs/src/lib/sets/HPolygonOpt.md @@ -9,11 +9,11 @@ HPolygonOpt σ(::AbstractVector, ::HPolygonOpt) translate(::HPolygonOpt, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isempty`](@ref isempty(::AbstractPolytope)) diff --git a/docs/src/lib/sets/HPolyhedron.md b/docs/src/lib/sets/HPolyhedron.md index 7baeffe8f5..38c5b18047 100644 --- a/docs/src/lib/sets/HPolyhedron.md +++ b/docs/src/lib/sets/HPolyhedron.md @@ -27,11 +27,11 @@ remove_redundant_constraints!(::HPoly{N}) where {N} LazySets._isbounded_stiemke(::HPolyhedron{N}) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolyhedron`](@ref): * [`∈`](@ref ∈(::AbstractVector, ::AbstractPolyhedron)) diff --git a/docs/src/lib/sets/HalfSpace.md b/docs/src/lib/sets/HalfSpace.md index a444e47362..4d15cff615 100644 --- a/docs/src/lib/sets/HalfSpace.md +++ b/docs/src/lib/sets/HalfSpace.md @@ -30,7 +30,7 @@ complement(::HalfSpace) project(::HalfSpace{N}, ::AbstractVector{Int}) where {N} distance(::AbstractVector, ::HalfSpace{N}) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) diff --git a/docs/src/lib/sets/Hyperplane.md b/docs/src/lib/sets/Hyperplane.md index dbbcada6b2..e08936833e 100644 --- a/docs/src/lib/sets/Hyperplane.md +++ b/docs/src/lib/sets/Hyperplane.md @@ -23,7 +23,7 @@ distance(::AbstractVector, ::Hyperplane{N}) where {N} reflect(::AbstractVector, ::Hyperplane) project(::AbstractVector, ::Hyperplane) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) diff --git a/docs/src/lib/sets/Hyperrectangle.md b/docs/src/lib/sets/Hyperrectangle.md index 7c5ffd6478..f013735b1f 100644 --- a/docs/src/lib/sets/Hyperrectangle.md +++ b/docs/src/lib/sets/Hyperrectangle.md @@ -12,9 +12,9 @@ radius_hyperrectangle(::Hyperrectangle) radius_hyperrectangle(::Hyperrectangle, ::Int) translate(::Hyperrectangle, ::AbstractVector) ``` -Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Interval.md b/docs/src/lib/sets/Interval.md index 4b88e9ea5d..00ea3b0c11 100644 --- a/docs/src/lib/sets/Interval.md +++ b/docs/src/lib/sets/Interval.md @@ -34,8 +34,8 @@ rectify(::Interval{N}) where {N} diameter(::Interval, ::Real=Inf) split(::Interval, ::AbstractVector{Int}) ``` -Inherited from [`LazySet`](@ref): -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Line.md b/docs/src/lib/sets/Line.md index 01b487719f..cdf7573f47 100644 --- a/docs/src/lib/sets/Line.md +++ b/docs/src/lib/sets/Line.md @@ -24,7 +24,7 @@ normalize!(::Line, ::Real=2.0) distance(::AbstractVector, ::Line; ::Real=2.0) linear_map(::AbstractMatrix, ::Line) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) diff --git a/docs/src/lib/sets/Line2D.md b/docs/src/lib/sets/Line2D.md index d5b2740397..980be31cc1 100644 --- a/docs/src/lib/sets/Line2D.md +++ b/docs/src/lib/sets/Line2D.md @@ -19,7 +19,7 @@ constraints_list(::Line2D) translate(::Line2D, ::AbstractVector) project(::AbstractVector, ::Line2D) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) diff --git a/docs/src/lib/sets/LineSegment.md b/docs/src/lib/sets/LineSegment.md index 71c6050e9e..5f15e0794b 100644 --- a/docs/src/lib/sets/LineSegment.md +++ b/docs/src/lib/sets/LineSegment.md @@ -20,11 +20,11 @@ translate(::LineSegment, ::AbstractVector) generators(::LineSegment{N}) where {N} genmat(::LineSegment) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/RotatedHyperrectangle.md b/docs/src/lib/sets/RotatedHyperrectangle.md index cc63cafe22..2ab01fdba2 100644 --- a/docs/src/lib/sets/RotatedHyperrectangle.md +++ b/docs/src/lib/sets/RotatedHyperrectangle.md @@ -17,11 +17,11 @@ vertices_list(::RotatedHyperrectangle) constraints_list(::RotatedHyperrectangle) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Singleton.md b/docs/src/lib/sets/Singleton.md index 8ed3d9452e..e7726da483 100644 --- a/docs/src/lib/sets/Singleton.md +++ b/docs/src/lib/sets/Singleton.md @@ -14,9 +14,9 @@ translate!(::Singleton, ::AbstractVector) rectify(S::Singleton) project(::Singleton, ::AbstractVector{Int}) ``` -Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/VPolygon.md b/docs/src/lib/sets/VPolygon.md index fc8da375f0..4c45ceda21 100644 --- a/docs/src/lib/sets/VPolygon.md +++ b/docs/src/lib/sets/VPolygon.md @@ -19,11 +19,11 @@ translate!(::VPolygon, ::AbstractVector) remove_redundant_vertices(::VPolygon; ::String="monotone_chain") remove_redundant_vertices!(::VPolygon; ::String="monotone_chain") ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolyhedron`](@ref): * [`linear_map`](@ref linear_map(::AbstractMatrix{NM}, ::AbstractPolyhedron{NP}) where {NM, NP}) diff --git a/docs/src/lib/sets/VPolytope.md b/docs/src/lib/sets/VPolytope.md index 19730746e0..59b9d2ab6f 100644 --- a/docs/src/lib/sets/VPolytope.md +++ b/docs/src/lib/sets/VPolytope.md @@ -20,11 +20,11 @@ tovrep(::VPolytope) polyhedron(::VPolytope) linear_map(::AbstractMatrix, ::VPolytope) ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolyhedron`](@ref): * [`linear_map`](@ref linear_map(::AbstractMatrix{NM}, ::AbstractPolyhedron{NP}) where {NM, NP}) diff --git a/docs/src/lib/sets/ZeroSet.md b/docs/src/lib/sets/ZeroSet.md index 97f0f476bd..d63011ca62 100644 --- a/docs/src/lib/sets/ZeroSet.md +++ b/docs/src/lib/sets/ZeroSet.md @@ -18,9 +18,9 @@ translate(::ZeroSet, ::AbstractVector) center(::ZeroSet{N}, ::Int) where {N} rectify(Z::ZeroSet) ``` -Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/lib/sets/Zonotope.md b/docs/src/lib/sets/Zonotope.md index 1f14a6c7e5..c776684277 100644 --- a/docs/src/lib/sets/Zonotope.md +++ b/docs/src/lib/sets/Zonotope.md @@ -24,11 +24,11 @@ LazySets._bound_intersect_2D(::Zonotope, ::Line2D) remove_redundant_generators(Z::Zonotope{N}) where {N} ``` -Inherited from [`LazySet`](@ref): -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`singleton_list`](@ref singleton_list(::LazySet)) +Inherited from [`ConvexSet`](@ref): +* [`norm`](@ref norm(::ConvexSet, ::Real)) +* [`radius`](@ref radius(::ConvexSet, ::Real)) +* [`diameter`](@ref diameter(::ConvexSet, ::Real)) +* [`singleton_list`](@ref singleton_list(::ConvexSet)) Inherited from [`AbstractPolytope`](@ref): * [`isbounded`](@ref isbounded(::AbstractPolytope)) diff --git a/docs/src/man/interval_hulls.md b/docs/src/man/interval_hulls.md index 1d725c32fd..d1798cbb95 100644 --- a/docs/src/man/interval_hulls.md +++ b/docs/src/man/interval_hulls.md @@ -158,7 +158,7 @@ sparse vector: In this part we illustrate some functions to obtain metric properties of sets, applied to the sets `X`, `Y` and `Z` defined previously, in the infinity norm. -These functions apply generally to any `LazySet`. +These functions apply generally to any `ConvexSet`. For some types, specialized methods are triggered automatically through multiple-dispatch. diff --git a/docs/src/man/iterative_refinement.md b/docs/src/man/iterative_refinement.md index cbb3632714..3eac4b315a 100644 --- a/docs/src/man/iterative_refinement.md +++ b/docs/src/man/iterative_refinement.md @@ -210,7 +210,7 @@ h(1.), h(0.1), h(0.01) ``` !!! note - Actually, the plotting function for an arbitrary `LazySet` `plot(...)`, + Actually, the plotting function for an arbitrary `ConvexSet` `plot(...)`, called *recipe* in the context of [Plots.jl](https://github.com/JuliaPlots/Plots.jl), is such that it receives a numeric argument `ε` and the routine itself calls `overapproximate`. diff --git a/docs/src/man/reach_zonotopes.md b/docs/src/man/reach_zonotopes.md index dacf57e19d..7c760e15e7 100644 --- a/docs/src/man/reach_zonotopes.md +++ b/docs/src/man/reach_zonotopes.md @@ -56,8 +56,8 @@ function Algorithm1(A, X0, δ, μ, T; lazy::Bool=false) N = floor(Int, T / δ) # preallocate arrays - Q = Vector{LazySet{Float64}}(undef, N) - R = Vector{LazySet{Float64}}(undef, N) + Q = Vector{ConvexSet{Float64}}(undef, N) + R = Vector{ConvexSet{Float64}}(undef, N) # initial reach set in the time interval [0, δ] ϕp = (I+ϕ) / 2 diff --git a/docs/src/man/reach_zonotopes_hybrid.md b/docs/src/man/reach_zonotopes_hybrid.md index fbc8c85d27..227bf569be 100644 --- a/docs/src/man/reach_zonotopes_hybrid.md +++ b/docs/src/man/reach_zonotopes_hybrid.md @@ -43,7 +43,7 @@ function reach_hybrid(As, Ts, init, δ, μ, T, max_order, instant_transitions) queue = Vector{Tuple{Zonotope, Integer, Float64}}(undef, 1) queue[1] = (init[1], init[2], 0.0) - res = Tuple{LazySet, Int}[] + res = Tuple{ConvexSet, Int}[] while !isempty(queue) init, loc, t = pop!(queue) println("currently in location $loc at time $t") @@ -92,7 +92,7 @@ function reach_continuous(A, X0, δ, μ, T, max_order) N = floor(Int, T/δ) # preallocate array - R = Vector{LazySet}(undef, N) + R = Vector{ConvexSet}(undef, N) if N == 0 return R end diff --git a/docs/src/man/set_operations.md b/docs/src/man/set_operations.md index 0348eea189..a36ffba05d 100644 --- a/docs/src/man/set_operations.md +++ b/docs/src/man/set_operations.md @@ -65,7 +65,7 @@ The table entries have the following meaning. | type ↓ \ operation → | dim | ρ | σ | an_element | ∈ | isempty | isbounded | linear_map | translate | norm | radius | diameter | |------------------------------|-----|---|---|------------|---|---------|-----------|------------|-----------|------|--------|----------| | **Interfaces** | | | | | | | | | | | | | -| `LazySet` | | x | | x | | | x | | | | | x | +| `ConvexSet` | | x | | x | | | x | | | | | x | | `APolytope` | | i | | i | | x | x | x | | | | i | | `ACentrallySymmetric` | x | i | | x | | x | x | | | | | i | | `ACentrallySymmetricPolytope`| i | i | | i | | x | i | i | | | | i | @@ -233,7 +233,7 @@ The table entries consist of subsets of the following list of operations. | type ↓ \ type → |LazyS |APtop |ACSym |ACSPt |APgon |AHrec |AHPgn |ASing |Ball1 |Ball2 |BInf |Ballp |Ellip |Empty |HalfS |HPgon |HPhed |HPtop |Hplan |Hrect |Itrvl |Line2D |LineS |Singl |Universe |VPgon |VPtop |ZeroS |Zonot | CP | CPA | CH | CHA |EMap | EPM |Itsct |ItscA |LiMap | MS | MSA | CMS | ReMap | SIH | Transl | UnionSet | UnionSArr | Complem | |-------------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| | **Interfaces** | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -| `LazySet` | ⊎ |⊆ ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i |⊆ ⊎i |⊆i ⊎ |⊆i ⊎ ∩ |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i | ⊎i | ⊎i | ⊎i |⊆ ⊎ |⊆i ⊎i |⊆ ⊎ |⊆i ⊎ |⊆i ⊎ |⊆i ⊎i |⊆i ⊎i | ⊎ |⊆i ⊎i |⊆i ⊎i ∩i |⊆ ⊎ ∩ |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i |⊆i ⊎i | ⊎i | ⊎ ∩ | ⊎ ∩ |⊆ ⊎ | +| `ConvexSet` | ⊎ |⊆ ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i |⊆ ⊎i |⊆i ⊎ |⊆i ⊎ ∩ |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i | ⊎i | ⊎i | ⊎i |⊆ ⊎ |⊆i ⊎i |⊆ ⊎ |⊆i ⊎ |⊆i ⊎ |⊆i ⊎i |⊆i ⊎i | ⊎ |⊆i ⊎i |⊆i ⊎i ∩i |⊆ ⊎ ∩ |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i |⊆i ⊎i | ⊎i | ⊎ ∩ | ⊎ ∩ |⊆ ⊎ | | `APolytope` |⊆ ⊎i |⊆i ⊎i ∩ |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆ ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩ |⊆i ⊎i ∩ |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆ ⊎ ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i ∩i | ⊎i ∩i |⊆i ⊎i | | `ACentrallySymmetric` | ⊎i |⊆i ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i |⊆i ⊎i | ⊎i | ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i | ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i | ⊎i |⊆i ⊎i | ⊎i | ⊎i ∩i | ⊎i ∩i |⊆i ⊎i | | `ACentrallySymmetricPolytope` |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i ∩i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i |⊆i ⊎i ∩i |⊆i ⊎i | ⊎i ∩i | ⊎i ∩i |⊆i ⊎i | diff --git a/docs/src/man/tour.md b/docs/src/man/tour.md index 66dec4be51..e738fa15f3 100644 --- a/docs/src/man/tour.md +++ b/docs/src/man/tour.md @@ -300,7 +300,7 @@ sections of this manual for further examples. ## Exploring the type hierarchy Every set type in the library inherits from the parametric abstract type -`LazySet{N}`, where `N` is a parameter for the numeric type (typically, +`ConvexSet{N}`, where `N` is a parameter for the numeric type (typically, double-precision floating point numbers, `Float64`). This way one can easily choose between, e.g., floating point (`Float64`) and exact (`Rational`) precision with no additional performance penalty: @@ -319,7 +319,7 @@ using AbstractTrees AbstractTrees.children(x::Type) = LazySets.subtypes(x, false) -print_tree(LazySet) +print_tree(ConvexSet) ``` Since the list does not fit into the default size, some types are hidden. @@ -349,7 +349,7 @@ the interface level. Last but not least, we remark that one of the key design choices of LazySets (which, admittedly, may be confusing at first) is that -**both set representations and set operations subtype `LazySet`**. +**both set representations and set operations subtype `ConvexSet`**. In other words, an "operation between sets" and "a set" are on the same footing in terms of belonging to the same type hierarchy. One of the advantages of these two mathematical concepts to be "just types" is to conveniently @@ -358,14 +358,14 @@ compose representations and operations (existing and user-created ones). An overview of only the set operations can be obtained like so: ```@example tour -filter(isoperationtype, LazySets.subtypes(LazySet, true)) +filter(isoperationtype, LazySets.subtypes(ConvexSet, true)) ``` The total amount of available representations is larger (if we had used -`subtypes(LazySet)`, that would only show the direct subtypes of `LazySet`). +`subtypes(ConvexSet)`, that would only show the direct subtypes of `ConvexSet`). ```@example tour -length(LazySets.subtypes(LazySet, true)) +length(LazySets.subtypes(ConvexSet, true)) ``` diff --git a/src/Approximations/ballinf_approximation.jl b/src/Approximations/ballinf_approximation.jl index e457067d51..93f51172b5 100644 --- a/src/Approximations/ballinf_approximation.jl +++ b/src/Approximations/ballinf_approximation.jl @@ -3,7 +3,7 @@ # =========================================================== """ - ballinf_approximation(S::LazySet) + ballinf_approximation(S::ConvexSet) Overapproximate a set by a tight ball in the infinity norm. @@ -20,7 +20,7 @@ A tight ball in the infinity norm. The center and radius of the box are obtained by evaluating the support function of the given set along the canonical directions. """ -function ballinf_approximation(S::LazySet{N}) where {N} +function ballinf_approximation(S::ConvexSet{N}) where {N} n = dim(S) c = Vector{N}(undef, n) r = zero(N) diff --git a/src/Approximations/box_approximation.jl b/src/Approximations/box_approximation.jl index e93558e4ca..da0b181e2b 100644 --- a/src/Approximations/box_approximation.jl +++ b/src/Approximations/box_approximation.jl @@ -34,7 +34,7 @@ end end # quote / load_staticarrays_directions # ================================================ """ - box_approximation(S::LazySet{N}) where {N} + box_approximation(S::ConvexSet{N}) where {N} Overapproximate a set by a tight hyperrectangle. @@ -52,7 +52,7 @@ The center of the hyperrectangle is obtained by averaging the support function of the given set in the canonical directions, and the lengths of the sides can be recovered from the distance among support functions in the same directions. """ -function box_approximation(S::LazySet{N}) where {N} +function box_approximation(S::ConvexSet{N}) where {N} c, r = box_approximation_helper(S) if r[1] < 0 return EmptySet{N}(dim(S)) @@ -68,7 +68,7 @@ Alias for `box_approximation`. interval_hull = box_approximation """ - box_approximation_helper(S::LazySet{N}) where {N} + box_approximation_helper(S::ConvexSet{N}) where {N} Common code of `box_approximation` and `box_approximation_symmetric`. @@ -91,7 +91,7 @@ of the given set in the canonical directions. The lengths of the sides can be recovered from the distance among support functions in the same directions. """ -@inline function box_approximation_helper(S::LazySet{N}) where {N} +@inline function box_approximation_helper(S::ConvexSet{N}) where {N} n = dim(S) c = Vector{N}(undef, n) r = Vector{N}(undef, n) @@ -372,7 +372,7 @@ function box_approximation(ch::ConvexHull; algorithm::String="box") end end -function _box_approximation_chull_extrema(X::LazySet{N}, Y) where {N} +function _box_approximation_chull_extrema(X::ConvexSet{N}, Y) where {N} n = dim(X) c = Vector{N}(undef, n) r = Vector{N}(undef, n) @@ -388,7 +388,7 @@ function _box_approximation_chull_extrema(X::LazySet{N}, Y) where {N} return Hyperrectangle(c, r) end -function _box_approximation_chull_box(X::LazySet{N}, Y) where {N} +function _box_approximation_chull_box(X::ConvexSet{N}, Y) where {N} n = dim(X) H1 = box_approximation(X) H2 = box_approximation(Y) diff --git a/src/Approximations/decompositions.jl b/src/Approximations/decompositions.jl index 0233092819..7aa48576f1 100644 --- a/src/Approximations/decompositions.jl +++ b/src/Approximations/decompositions.jl @@ -67,7 +67,7 @@ julia> LazySets.Approximations.uniform_partition(10, 6) end """ - decompose(S::LazySet{N}, + decompose(S::ConvexSet{N}, partition::AbstractVector{<:AbstractVector{Int}}, block_options ) where {N} @@ -214,12 +214,12 @@ julia> typeof(res[1]), typeof(res[2]) (Hyperrectangle{Float64, Vector{Float64}, Vector{Float64}}, HPolygon{Float64, Vector{Float64}}) ``` """ -function decompose(S::LazySet{N}, +function decompose(S::ConvexSet{N}, partition::AbstractVector{<:AbstractVector{Int}}, block_options ) where {N} n = dim(S) - result = Vector{LazySet{N}}(undef, length(partition)) + result = Vector{ConvexSet{N}}(undef, length(partition)) @inbounds for (i, block) in enumerate(partition) result[i] = project(S, block, block_options[i], n) @@ -228,9 +228,9 @@ function decompose(S::LazySet{N}, end # convenience method with uniform block options -function decompose(S::LazySet{N}, +function decompose(S::ConvexSet{N}, partition::AbstractVector{<:AbstractVector{Int}}, - block_options::Union{Type{<:LazySet}, + block_options::Union{Type{<:ConvexSet}, Pair{<:UnionAll, <:Real}, Real, Type{<:AbstractDirections}, @@ -238,7 +238,7 @@ function decompose(S::LazySet{N}, } ) where {N} n = dim(S) - result = Vector{LazySet{N}}(undef, length(partition)) + result = Vector{ConvexSet{N}}(undef, length(partition)) @inbounds for (i, block) in enumerate(partition) result[i] = project(S, block, block_options, n) @@ -247,7 +247,7 @@ function decompose(S::LazySet{N}, end # convenience method with uniform block size -function decompose(S::LazySet, block_options; block_size::Int=1) +function decompose(S::ConvexSet, block_options; block_size::Int=1) partition = uniform_partition(dim(S), block_size) return decompose(S, partition, block_options) end diff --git a/src/Approximations/hausdorff_distance.jl b/src/Approximations/hausdorff_distance.jl index ef80551b5b..bbf5c4118d 100644 --- a/src/Approximations/hausdorff_distance.jl +++ b/src/Approximations/hausdorff_distance.jl @@ -1,7 +1,7 @@ export hausdorff_distance """ - hausdorff_distance(X::LazySet{N}, Y::LazySet{N}; [p]::N=N(Inf), + hausdorff_distance(X::ConvexSet{N}, Y::ConvexSet{N}; [p]::N=N(Inf), [ε]=N(1e-3)) where {N} Compute the Hausdorff distance between two convex sets up to a given threshold. @@ -51,7 +51,7 @@ Given a value ``δ``, to check whether the sets are within Hausdorff distance ``δ``, we simply check the inclusions given above, where on the right-hand side we use a lazy `Bloating`. """ -function hausdorff_distance(X::LazySet{N}, Y::LazySet{N}; p::N=N(Inf), +function hausdorff_distance(X::ConvexSet{N}, Y::ConvexSet{N}; p::N=N(Inf), ε=N(1e-3)) where {N} @assert ε > zero(N) "the value ε must be positive" @assert isbounded(X) && isbounded(Y) "the Hausdorff distance is only " * @@ -89,7 +89,7 @@ function _mutual_issubset_in_δ_bloating(X, Y, δ, n, p) _issubset_in_δ_bloating(Y, X, δ, n, p) end -function _issubset_in_δ_bloating(X::LazySet{N}, Y, δ, n, p) where {N} +function _issubset_in_δ_bloating(X::ConvexSet{N}, Y, δ, n, p) where {N} return X ⊆ Bloating(Y, δ, p) end diff --git a/src/Approximations/iterative_refinement.jl b/src/Approximations/iterative_refinement.jl index 1a0974545c..b5e7d6e72c 100644 --- a/src/Approximations/iterative_refinement.jl +++ b/src/Approximations/iterative_refinement.jl @@ -45,7 +45,7 @@ function constraint(approx::LocalApproximation) end """ - PolygonalOverapproximation{N, SN<:LazySet{N}, VN<:AbstractVector{N}} + PolygonalOverapproximation{N, SN<:ConvexSet{N}, VN<:AbstractVector{N}} Type that represents the polygonal approximation of a convex set. @@ -56,20 +56,20 @@ Type that represents the polygonal approximation of a convex set. - `constraints` -- vector of linear constraints that are already finalized (i.e., they satisfy the given error bound) """ -struct PolygonalOverapproximation{N, SN<:LazySet{N}, VN<:AbstractVector{N}} +struct PolygonalOverapproximation{N, SN<:ConvexSet{N}, VN<:AbstractVector{N}} S::SN approx_stack::Vector{LocalApproximation{N, VN}} constraints::Vector{LinearConstraint{N, VN}} end -function PolygonalOverapproximation(S::SN) where {N, SN<:LazySet{N}} +function PolygonalOverapproximation(S::SN) where {N, SN<:ConvexSet{N}} empty_local_approx = Vector{LocalApproximation{N, Vector{N}}}() empty_constraints = Vector{LinearConstraint{N,Vector{N}}}() return PolygonalOverapproximation(S, empty_local_approx, empty_constraints) end """ - new_approx(S::LazySet, p1::VN, d1::VN, + new_approx(S::ConvexSet, p1::VN, d1::VN, p2::VN, d2::VN) where {N<:AbstractFloat, VN<:AbstractVector{N}} Create a `LocalApproximation` instance for the given excerpt of a polygonal @@ -87,7 +87,7 @@ approximation. A local approximation of `S` in the given directions. """ -function new_approx(S::LazySet, p1::VN, d1::VN, +function new_approx(S::ConvexSet, p1::VN, d1::VN, p2::VN, d2::VN) where {N<:AbstractFloat, VN<:AbstractVector{N}} if norm(p1-p2, 2) <= _rtol(N) # this approximation cannot be refined and we set q = p1 by convention @@ -129,7 +129,7 @@ function addapproximation!(Ω::PolygonalOverapproximation, p1::VN, d1::VN, end """ - refine(approx::LocalApproximation, S::LazySet) + refine(approx::LocalApproximation, S::ConvexSet) Refine a given local approximation of the polygonal approximation of a convex set by splitting along the normal direction of the approximation. @@ -143,7 +143,7 @@ set by splitting along the normal direction of the approximation. The tuple consisting of the refined right and left local approximations. """ -function refine(approx::LocalApproximation, S::LazySet) +function refine(approx::LocalApproximation, S::ConvexSet) @assert approx.refinable ndir = normalize([approx.p2[2]-approx.p1[2], approx.p1[1]-approx.p2[1]]) s = σ(ndir, S) @@ -184,7 +184,7 @@ function tohrep(Ω::PolygonalOverapproximation) end """ - _approximate(S::LazySet{N}, ε::Real) where {N<:AbstractFloat} + _approximate(S::ConvexSet{N}, ε::Real) where {N<:AbstractFloat} Return an ε-close approximation of the given 2D convex set (in terms of Hausdorff distance) as an inner and an outer approximation composed by sorted @@ -199,7 +199,7 @@ local `Approximation2D`. An ε-close approximation of the given 2D convex set. """ -function _approximate(S::LazySet{N}, ε::Real) where {N<:AbstractFloat} +function _approximate(S::ConvexSet{N}, ε::Real) where {N<:AbstractFloat} # initialize box directions pe = σ(DIR_EAST(N), S) pn = σ(DIR_NORTH(N), S) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 27019dba8a..f1943285a9 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -6,7 +6,7 @@ using LazySets: block_to_dimension_indices, get_constrained_lowdimset """ - overapproximate(X::S, ::Type{S}, args...) where {S<:LazySet} + overapproximate(X::S, ::Type{S}, args...) where {S<:ConvexSet} Overapproximating a set of type `S` with type `S` is a no-op. @@ -20,42 +20,42 @@ Overapproximating a set of type `S` with type `S` is a no-op. The input set. """ -function overapproximate(X::S, ::Type{S}, args...) where {S<:LazySet} +function overapproximate(X::S, ::Type{S}, args...) where {S<:ConvexSet} return X end """ - overapproximate(S::LazySet) + overapproximate(S::ConvexSet) Alias for `overapproximate(S, Hyperrectangle)` resp. `box_approximation(S)`. """ -overapproximate(S::LazySet) = box_approximation(S) +overapproximate(S::ConvexSet) = box_approximation(S) """ - overapproximate(S::LazySet, ::Type{<:Hyperrectangle}) + overapproximate(S::ConvexSet, ::Type{<:Hyperrectangle}) Alias for `box_approximation(S)`. """ -function overapproximate(S::LazySet, ::Type{<:Hyperrectangle}) +function overapproximate(S::ConvexSet, ::Type{<:Hyperrectangle}) return box_approximation(S) end -# alias while Rectification is not a LazySet (#1895) +# alias while Rectification is not a ConvexSet (#1895) function overapproximate(r::Rectification, ::Type{<:Hyperrectangle}) return box_approximation(r) end """ - overapproximate(S::LazySet, ::Type{<:BallInf}) + overapproximate(S::ConvexSet, ::Type{<:BallInf}) Alias for `ballinf_approximation(S)`. """ -function overapproximate(S::LazySet, ::Type{<:BallInf}) +function overapproximate(S::ConvexSet, ::Type{<:BallInf}) return ballinf_approximation(S) end """ - overapproximate(S::LazySet{N}, + overapproximate(S::ConvexSet{N}, ::Type{<:HPolygon}, [ε]::Real=Inf) where {N} @@ -81,7 +81,7 @@ If no error tolerance ε is given, or is `Inf`, the result is a box-shaped polyg For convex input sets, the result is an ε-close approximation as a polygon, with respect to the Hausdorff distance. """ -function overapproximate(S::LazySet{N}, +function overapproximate(S::ConvexSet{N}, ::Type{<:HPolygon}, ε::Real=Inf; prune::Bool=true) where {N} @@ -104,7 +104,7 @@ function overapproximate(S::LazySet{N}, end # no-go functions for dispatch in HPolytope -function overapproximate(X::S, ::Type{<:HPolytope}) where {S<:LazySet} +function overapproximate(X::S, ::Type{<:HPolytope}) where {S<:ConvexSet} if dim(X) == 2 throw(ArgumentError("ε-close approximation is only available using " * "polygons in constraint representation; try `overapproximate(X, HPolygon)`")) @@ -117,11 +117,11 @@ function overapproximate(X::S, ::Type{<:HPolytope}) where {S<:LazySet} end """ - overapproximate(S::LazySet, ε::Real) + overapproximate(S::ConvexSet, ε::Real) Alias for `overapproximate(S, HPolygon, ε)`. """ -function overapproximate(S::LazySet, ε::Real) +function overapproximate(S::ConvexSet, ε::Real) return overapproximate(S, HPolygon, ε) end @@ -130,7 +130,7 @@ overapproximate(∅::EmptySet, options...) = ∅ # disambiguation overapproximate(∅::EmptySet) = ∅ -for ST in LazySets.subtypes(LazySet, true) +for ST in LazySets.subtypes(ConvexSet, true) if ST == HPolygon # must be defined separately below with extra argument continue end @@ -346,7 +346,7 @@ function overapproximate(lm::LinearMap{N, <:AbstractZonotope}, end """ - overapproximate(X::LazySet{N}, dir::AbstractDirections; [prune]::Bool=true) where {N} + overapproximate(X::ConvexSet{N}, dir::AbstractDirections; [prune]::Bool=true) where {N} Overapproximate a (possibly unbounded) set with template directions. @@ -363,7 +363,7 @@ A polyhedron overapproximating the set `X` with the directions from `dir`. The overapproximation is computed using support functions. If the obtained set is bounded, the result is an `HPolytope`. Otherwise the result is an `HPolyhedron`. """ -function overapproximate(X::LazySet{N}, dir::AbstractDirections{N, VN}; prune::Bool=true) where {N, VN} +function overapproximate(X::ConvexSet{N}, dir::AbstractDirections{N, VN}; prune::Bool=true) where {N, VN} n = dim(X) H = Vector{LinearConstraint{N, VN}}() sizehint!(H, length(dir)) @@ -388,7 +388,7 @@ function overapproximate(X::LazySet{N}, dir::AbstractDirections{N, VN}; prune::B end # alias with HPolytope type as second argument -function overapproximate(X::LazySet{N}, ::Type{<:HPolytope}, dirs::AbstractDirections{N}; prune::Bool=true) where {N} +function overapproximate(X::ConvexSet{N}, ::Type{<:HPolytope}, dirs::AbstractDirections{N}; prune::Bool=true) where {N} P = overapproximate(X, dirs, prune=prune) isbounded(P) || throw(ArgumentError("can't overapproximate with an `HPolytope` " * "because the set is unbounded; try using an `HPolyhedron`")) @@ -396,7 +396,7 @@ function overapproximate(X::LazySet{N}, ::Type{<:HPolytope}, dirs::AbstractDirec end # alias with HPolyhedron type as second argument -function overapproximate(X::LazySet{N}, ::Type{<:HPolyhedron}, dirs::AbstractDirections{N}; prune::Bool=true) where {N} +function overapproximate(X::ConvexSet{N}, ::Type{<:HPolyhedron}, dirs::AbstractDirections{N}; prune::Bool=true) where {N} return convert(HPolyhedron, overapproximate(X, dirs, prune=true)) end @@ -408,7 +408,7 @@ overapproximate(∅::EmptySet{N}, ::Type{<:HPolyhedron}, # this function overapproximates a bounded polyhedron with a list of directions # that define a bounded set (without checking these assumptions); the result is always bounded -function _overapproximate_bounded_polyhedron(X::LazySet{N}, dir::AbstractDirections{N, VN}; prune::Bool=true) where {N, VN} +function _overapproximate_bounded_polyhedron(X::ConvexSet{N}, dir::AbstractDirections{N, VN}; prune::Bool=true) where {N, VN} H = Vector{LinearConstraint{N, VN}}() sizehint!(H, length(dir)) for d in dir @@ -422,7 +422,7 @@ function _overapproximate_bounded_polyhedron(X::LazySet{N}, dir::AbstractDirecti end """ - overapproximate(X::LazySet{N}, dir::Type{<:AbstractDirections}) where {N} + overapproximate(X::ConvexSet{N}, dir::Type{<:AbstractDirections}) where {N} Overapproximating a set with template directions. @@ -437,7 +437,7 @@ A polyhedron overapproximating the set `X` with the directions from `dir`. If the directions are known to be bounded, the result is an `HPolytope`, otherwise the result is an `HPolyhedron`. """ -function overapproximate(X::LazySet{N}, +function overapproximate(X::ConvexSet{N}, dir::Type{<:AbstractDirections}; kwargs...) where {N} return overapproximate(X, dir{N}(dim(X)); kwargs...) end @@ -447,7 +447,7 @@ overapproximate(∅::EmptySet, dir::Type{<:AbstractDirections}; kwargs...) = ∅ overapproximate(∅::EmptySet, dir::AbstractDirections; prune::Bool=true) = ∅ """ - overapproximate(S::LazySet{N}, ::Type{<:Interval}) where {N} + overapproximate(S::ConvexSet{N}, ::Type{<:Interval}) where {N} Return the overapproximation of a unidimensional set with an interval. @@ -464,7 +464,7 @@ An interval. We use two support-function evaluations. """ -function overapproximate(S::LazySet{N}, ::Type{<:Interval}) where {N} +function overapproximate(S::ConvexSet{N}, ::Type{<:Interval}) where {N} @assert dim(S) == 1 "cannot overapproximate a $(dim(S))-dimensional set " * "with an `Interval`" return Interval(-ρ(N[-1], S), ρ(N[1], S)) @@ -531,7 +531,7 @@ function overapproximate(cap::IntersectionArray, ::Type{<:Interval}) return X end -function overapproximate_cap_helper(X::LazySet, # convex set +function overapproximate_cap_helper(X::ConvexSet, # convex set P::AbstractPolyhedron, # polyhedron dir::AbstractDirections; kwargs... @@ -562,7 +562,7 @@ function overapproximate_cap_helper(X::LazySet, # convex set end """ - overapproximate(cap::Intersection{N, <:LazySet, <:AbstractPolyhedron}, + overapproximate(cap::Intersection{N, <:ConvexSet, <:AbstractPolyhedron}, dir::AbstractDirections; kwargs... ) where {N} @@ -606,7 +606,7 @@ This method of overapproximations can return a non-empty set even if the origina intersection is empty. """ function overapproximate(cap::Intersection{N, - <:LazySet, + <:ConvexSet, <:AbstractPolyhedron}, dir::AbstractDirections; kwargs... @@ -617,7 +617,7 @@ end # symmetric method function overapproximate(cap::Intersection{N, <:AbstractPolyhedron, - <:LazySet}, + <:ConvexSet}, dir::AbstractDirections; kwargs... ) where {N} @@ -1198,7 +1198,7 @@ end end # quote / load_intervalmatrices_overapproximation() """ overapproximate(lm::LinearMap{N, <:CartesianProductArray}, ::Type{CartesianProductArray{N, S}} - ) where {N, S<:LazySet} + ) where {N, S<:ConvexSet} Decompose a lazy linear map of a Cartesian product array while keeping the original block structure. @@ -1214,7 +1214,7 @@ A `CartesianProductArray` representing the decomposed linear map. """ function overapproximate(lm::LinearMap{N, <:CartesianProductArray}, ::Type{CartesianProductArray{N, S}} - ) where {N, S<:LazySet} + ) where {N, S<:ConvexSet} cpa = array(lm.X) arr = Vector{S}(undef, length(cpa)) return _overapproximate_lm_cpa!(arr, lm.M, cpa, S) @@ -1249,7 +1249,7 @@ end """ overapproximate(lm::LinearMap{N, <:CartesianProductArray}, ::Type{<:CartesianProductArray}, - set_type::Type{<:LazySet}) where {N} + set_type::Type{<:ConvexSet}) where {N} Decompose a lazy linear map of a Cartesian product array with a given set type while keeping the original block structure. @@ -1266,7 +1266,7 @@ A `CartesianProductArray` representing the decomposed linear map. """ function overapproximate(lm::LinearMap{N, <:CartesianProductArray}, ::Type{<:CartesianProductArray}, - set_type::Type{<:LazySet}) where {N} + set_type::Type{<:ConvexSet}) where {N} cpa = array(lm.X) arr = Vector{set_type{N}}(undef, length(cpa)) return _overapproximate_lm_cpa!(arr, lm.M, cpa, set_type) @@ -1275,7 +1275,7 @@ end function _overapproximate_lm_cpa!(arr, M, cpa, overapprox_option) # construct Minkowski sum for block row function _block_row(cpa::Vector{S}, M::AbstractMatrix, - row_range::UnitRange{Int}) where {N, S<:LazySet{N}} + row_range::UnitRange{Int}) where {N, S<:ConvexSet{N}} arr_inner = Vector{LinearMap{N, <:S}}(undef, length(cpa)) col_start_ind, col_end_ind = 1, 0 @inbounds for (j, bj) in enumerate(cpa) @@ -1450,7 +1450,7 @@ function overapproximate(Z::Zonotope{N}, ::Type{<:Zonotope}, r::Union{Integer, R end """ - overapproximate(X::LazySet, ZT::Type{<:Zonotope}, + overapproximate(X::ConvexSet, ZT::Type{<:Zonotope}, dir::AbstractDirections; [algorithm]="vrep", kwargs...) @@ -1482,7 +1482,7 @@ Two algorithms are available: decomposition into two-dimensional blocks. See the docstring of [`_overapproximate_zonotope_cpa`](@ref) for further details. """ -function overapproximate(X::LazySet, ZT::Type{<:Zonotope}, +function overapproximate(X::ConvexSet, ZT::Type{<:Zonotope}, dir::AbstractDirections; algorithm="vrep", kwargs...) if algorithm == "vrep" @@ -1495,7 +1495,7 @@ function overapproximate(X::LazySet, ZT::Type{<:Zonotope}, end end -function overapproximate(X::LazySet, ZT::Type{<:Zonotope}, +function overapproximate(X::ConvexSet, ZT::Type{<:Zonotope}, dir::Type{<:AbstractDirections}; algorithm="vrep", kwargs...) overapproximate(X, ZT, dir(dim(X)), algorithm=algorithm, kwargs...) @@ -1514,7 +1514,7 @@ function overapproximate(∅::EmptySet, ZT::Type{<:Zonotope}, end """ - _overapproximate_zonotope_vrep(X::LazySet{N}, + _overapproximate_zonotope_vrep(X::ConvexSet{N}, dir::AbstractDirections; solver=default_lp_solver(N)) where {N} @@ -1563,7 +1563,7 @@ nonnegativity constraints (last type) are not stated explicitly in [1]. [1] Zonotopes as bounding volumes, L. J. Guibas et al, Proc. of Symposium on Discrete Algorithms, pp. 803-812. """ -function _overapproximate_zonotope_vrep(X::LazySet{N}, +function _overapproximate_zonotope_vrep(X::ConvexSet{N}, dir::AbstractDirections; solver=default_lp_solver(N)) where {N} # TODO "normalization" here involves two steps: removing opposite directions @@ -1637,14 +1637,14 @@ function _overapproximate_zonotope_vrep(X::LazySet{N}, end # overload on direction type -function _overapproximate_zonotope_vrep(X::LazySet{N}, +function _overapproximate_zonotope_vrep(X::ConvexSet{N}, dir::Type{<:AbstractDirections}; solver=default_lp_solver(N)) where {N} return _overapproximate_zonotope_vrep(X, dir(dim(X)), solver=solver) end """ - _overapproximate_zonotope_cpa(X::LazySet, dir::Type{<:AbstractDirections}) + _overapproximate_zonotope_cpa(X::ConvexSet, dir::Type{<:AbstractDirections}) Overapproximate a polytopic set with a zonotope using cartesian decomposition. @@ -1669,7 +1669,7 @@ The algorithm used is based on the section 8.2.4 of [1]. [1] Le Guernic, C. (2009). Reachability analysis of hybrid systems with linear continuous dynamics (Doctoral dissertation). """ -function _overapproximate_zonotope_cpa(X::LazySet, dir::Type{<:AbstractDirections}) +function _overapproximate_zonotope_cpa(X::ConvexSet, dir::Type{<:AbstractDirections}) n = dim(X) # overapproximate 2D blocks if n > 1 @@ -1695,7 +1695,7 @@ function _overapproximate_zonotope_cpa(X::LazySet, dir::Type{<:AbstractDirection end # overload on direction type -function _overapproximate_zonotope_cpa(X::LazySet, +function _overapproximate_zonotope_cpa(X::ConvexSet, dir::AbstractDirections) _overapproximate_zonotope_cpa(X, typeof(dir)) end diff --git a/src/Approximations/symmetric_interval_hull.jl b/src/Approximations/symmetric_interval_hull.jl index c6d561abf2..d67d44103e 100644 --- a/src/Approximations/symmetric_interval_hull.jl +++ b/src/Approximations/symmetric_interval_hull.jl @@ -3,7 +3,7 @@ # ================================ """ - symmetric_interval_hull(S::LazySet{N}) where {N} + symmetric_interval_hull(S::ConvexSet{N}) where {N} Overapproximate a set by a tight hyperrectangle centered in the origin. @@ -26,7 +26,7 @@ The result is a hyperrectangle and hence in particular convex. An alias for this function is `box_approximation_symmetric`. """ -function symmetric_interval_hull(S::LazySet{N}) where {N} +function symmetric_interval_hull(S::ConvexSet{N}) where {N} # fallback returns a hyperrectangular set (c, r) = box_approximation_helper(S) if r[1] < 0 diff --git a/src/Approximations/template_directions.jl b/src/Approximations/template_directions.jl index d6f069eeae..b6f8e5bb63 100644 --- a/src/Approximations/template_directions.jl +++ b/src/Approximations/template_directions.jl @@ -99,7 +99,7 @@ end isnormalized(::AD) where {AD<:AbstractDirections} = isnormalized(AD) """ - project(S::LazySet, + project(S::ConvexSet, block::AbstractVector{Int}, directions::Type{<:AbstractDirections}, [n]::Int; @@ -119,7 +119,7 @@ Project a high-dimensional set to a given block using template directions. The template direction approximation of the projection of `S`. """ -@inline function project(S::LazySet, +@inline function project(S::ConvexSet, block::AbstractVector{Int}, directions::Type{<:AbstractDirections}, n::Int=dim(S); diff --git a/src/Approximations/underapproximate.jl b/src/Approximations/underapproximate.jl index 3a49e00026..f168fe42a0 100644 --- a/src/Approximations/underapproximate.jl +++ b/src/Approximations/underapproximate.jl @@ -1,5 +1,5 @@ """ - underapproximate(X::LazySet{N}, dirs::AbstractDirections; + underapproximate(X::ConvexSet{N}, dirs::AbstractDirections; [apply_convex_hull]::Bool=false) where {N} Compute the underapproximation of a convex set by sampling support vectors. @@ -21,14 +21,14 @@ Since the support vectors are not always unique, this algorithm may return a strict underapproximation even if the set can be exactly approximated using the given template. """ -function underapproximate(X::LazySet{N}, dirs::AbstractDirections; +function underapproximate(X::ConvexSet{N}, dirs::AbstractDirections; apply_convex_hull::Bool=false) where {N} vinner = Vector{Vector{N}}(undef, length(dirs)) underapproximate!(vinner, X, dirs; apply_convex_hull=apply_convex_hull) end # in-place version -function underapproximate!(vinner, X::LazySet{N}, dirs::AbstractDirections; +function underapproximate!(vinner, X::ConvexSet{N}, dirs::AbstractDirections; apply_convex_hull::Bool=false) where {N} @assert dim(X) == dim(dirs) "the dimension of the set, $(dim(X)), doesn't match " * "the dimension of the template directions, $(dim(dirs))" @@ -42,6 +42,6 @@ function underapproximate!(vinner, X::LazySet{N}, dirs::AbstractDirections; return VPolytope(vinner) end -function underapproximate(X::LazySet, dirs::Type{<:AbstractDirections}; kwargs...) +function underapproximate(X::ConvexSet, dirs::Type{<:AbstractDirections}; kwargs...) return underapproximate(X, dirs(dim(X)), kwargs...) end diff --git a/src/ConcreteOperations/cartesian_product.jl b/src/ConcreteOperations/cartesian_product.jl index 033fb4de6b..eca7f91ee0 100644 --- a/src/ConcreteOperations/cartesian_product.jl +++ b/src/ConcreteOperations/cartesian_product.jl @@ -1,7 +1,7 @@ export cartesian_product """ - cartesian_product(X::LazySet, Y::LazySet; [backend]=nothing, [algorithm]::String="vrep") + cartesian_product(X::ConvexSet, Y::ConvexSet; [backend]=nothing, [algorithm]::String="vrep") Compute the Cartesian product of two sets. @@ -31,7 +31,7 @@ For further information on the supported backends see If `X` can be converted to a one-dimensional interval and the vertices of `Y` are available use `algorithm="vrep"`. """ -function cartesian_product(X::LazySet, Y::LazySet; backend=nothing, algorithm::String="hrep") +function cartesian_product(X::ConvexSet, Y::ConvexSet; backend=nothing, algorithm::String="hrep") if algorithm == "vrep" Yv = VPolytope(vertices_list(Y)) @@ -109,7 +109,7 @@ function cartesian_product(U1::Universe, U2::Universe) return Universe(dim(U1) + dim(U2)) end -function _cartesian_product_hrep(X::S1, Y::S2) where {S1<:LazySet{N}, S2<:LazySet} where {N} +function _cartesian_product_hrep(X::S1, Y::S2) where {S1<:ConvexSet{N}, S2<:ConvexSet} where {N} U1 = Universe{N}(dim(X)) clist1 = [cartesian_product(U1, c) for c in constraints_list(Y)] U2 = Universe{N}(dim(Y)) diff --git a/src/ConcreteOperations/convex_hull.jl b/src/ConcreteOperations/convex_hull.jl index d16d16c37d..23ed99d366 100644 --- a/src/ConcreteOperations/convex_hull.jl +++ b/src/ConcreteOperations/convex_hull.jl @@ -9,7 +9,7 @@ function default_convex_hull_algorithm(points) end """ - convex_hull(X::LazySet{N}, Y::LazySet{N}; [algorithm]=nothing, + convex_hull(X::ConvexSet{N}, Y::ConvexSet{N}; [algorithm]=nothing, [backend]=nothing, [solver]=nothing) where {N} Compute the convex hull of the given convex sets. @@ -37,7 +37,7 @@ One-dimensional sets are resolved by using `overapproximate` with an `Interval` For higher-dimensional sets, we compute the vertices of both `X` and `Y` using `vertices_list` and then compute the convex hull of the union of those vertices. """ -function convex_hull(X::LazySet{N}, Y::LazySet{N}; +function convex_hull(X::ConvexSet{N}, Y::ConvexSet{N}; algorithm=nothing, backend=nothing, solver=nothing @@ -592,8 +592,8 @@ function convex_hull(X::UnionSet) return convex_hull(X.X, X.Y) end -convex_hull(X::LazySet, ::EmptySet) = X -convex_hull(::EmptySet, X::LazySet) = X +convex_hull(X::ConvexSet, ::EmptySet) = X +convex_hull(::EmptySet, X::ConvexSet) = X convex_hull(∅::EmptySet, ::EmptySet) = ∅ """ diff --git a/src/ConcreteOperations/difference.jl b/src/ConcreteOperations/difference.jl index 3cc2e4c209..7fa3a49bfb 100644 --- a/src/ConcreteOperations/difference.jl +++ b/src/ConcreteOperations/difference.jl @@ -6,7 +6,7 @@ import Base: \ const IA = IntervalArithmetic """ - \\(X::LazySet, Y::LazySet) + \\(X::ConvexSet, Y::ConvexSet) Convenience alias for set difference. @@ -35,7 +35,7 @@ julia> X.dat \\ Y.dat # computing the left division [0.5, ∞] ``` """ -\(X::LazySet, Y::LazySet) = difference(X, Y) +\(X::ConvexSet, Y::ConvexSet) = difference(X, Y) # ================================= # Set difference between intervals diff --git a/src/ConcreteOperations/distance.jl b/src/ConcreteOperations/distance.jl index 56f7c88961..10669760a9 100644 --- a/src/ConcreteOperations/distance.jl +++ b/src/ConcreteOperations/distance.jl @@ -52,7 +52,7 @@ function distance(H1::AbstractHyperrectangle, H2::AbstractHyperrectangle; end """ - distance(S::AbstractSingleton, X::LazySet; [p]::Real=2.0) + distance(S::AbstractSingleton, X::ConvexSet; [p]::Real=2.0) Compute the distance between the singleton `S` and the set `X` with respect to the given `p`-norm. @@ -69,11 +69,11 @@ the given `p`-norm. A scalar representing the distance between the element wrapped by `S` and the set `X`. """ -function distance(S::AbstractSingleton, X::LazySet; p::Real=2.0) +function distance(S::AbstractSingleton, X::ConvexSet; p::Real=2.0) return distance(element(S), X; p=p) end -distance(X::LazySet, S::AbstractSingleton; p::Real=2.0) = distance(S, X; p=p) +distance(X::ConvexSet, S::AbstractSingleton; p::Real=2.0) = distance(S, X; p=p) distance(S1::AbstractSingleton, S2::AbstractSingleton; p::Real=2.0) = distance(element(S1), element(S2); p=p) diff --git a/src/ConcreteOperations/intersection.jl b/src/ConcreteOperations/intersection.jl index 1d4a9c16a4..4bb2505b24 100644 --- a/src/ConcreteOperations/intersection.jl +++ b/src/ConcreteOperations/intersection.jl @@ -2,7 +2,7 @@ export intersection -for T in [:LazySet, :AbstractSingleton, :Interval, :Universe, :LinearMap] +for T in [:ConvexSet, :AbstractSingleton, :Interval, :Universe, :LinearMap] @eval begin function intersection(∅::EmptySet, X::$T) @assert dim(∅) == dim(X) "cannot take the intersection between a " * @@ -27,7 +27,7 @@ function intersection(∅₁::EmptySet, ∅₂::EmptySet) end """ - intersection(S::AbstractSingleton, X::LazySet) + intersection(S::AbstractSingleton, X::ConvexSet) Return the intersection of a singleton with another set. @@ -41,7 +41,7 @@ Return the intersection of a singleton with another set. If the sets intersect, the result is `S`. Otherwise, the result is the empty set. """ -@commutative function intersection(S::AbstractSingleton, X::LazySet) +@commutative function intersection(S::AbstractSingleton, X::ConvexSet) return _intersection_singleton(S, X) end @@ -383,7 +383,7 @@ Otherwise the result is the singleton that describes the intersection. end """ - intersection(X::Interval, Y::LazySet) + intersection(X::Interval, Y::ConvexSet) Compute the intersection of an interval and a convex set. @@ -398,11 +398,11 @@ If the sets do not intersect, the result is the empty set. Otherwise the result is the interval that describes the intersection, which may be of type `Singleton` if the intersection is very small. """ -@commutative function intersection(X::Interval, Y::LazySet) +@commutative function intersection(X::Interval, Y::ConvexSet) return _intersection_interval(X, Y) end -function _intersection_interval(X::Interval, Y::LazySet) +function _intersection_interval(X::Interval, Y::ConvexSet) N = promote_type(eltype(X), eltype(Y)) lower = max(min(X), -ρ(N[-1], Y)) upper = min(max(X), ρ(N[1], Y)) @@ -777,7 +777,7 @@ function intersection(P1::VPolygon, P2::VPolygon; apply_convex_hull::Bool=true) end """ - intersection(cup::UnionSet, X::LazySet) + intersection(cup::UnionSet, X::ConvexSet) Return the intersection of a union of two convex sets and another convex set. @@ -791,7 +791,7 @@ Return the intersection of a union of two convex sets and another convex set. The union of the pairwise intersections, expressed as a `UnionSet`. If one of those sets is empty, only the other set is returned. """ -@commutative function intersection(cup::UnionSet, X::LazySet) +@commutative function intersection(cup::UnionSet, X::ConvexSet) return intersection(cup.X, X) ∪ intersection(cup.Y, X) end @@ -800,7 +800,7 @@ end _intersection_singleton(S, cup) """ - intersection(cup::UnionSetArray, X::LazySet) + intersection(cup::UnionSetArray, X::ConvexSet) Return the intersection of a union of a finite number of convex sets and another convex set. @@ -814,7 +814,7 @@ convex set. The union of the pairwise intersections, expressed as a `UnionSetArray`. """ -@commutative function intersection(cup::UnionSetArray, X::LazySet) +@commutative function intersection(cup::UnionSetArray, X::ConvexSet) return UnionSetArray([intersection(Y, X) for Y in array(cup)]) end @@ -823,7 +823,7 @@ end _intersection_singleton(S, cup) """ - intersection(L::LinearMap, S::LazySet) + intersection(L::LinearMap, S::ConvexSet) Return the intersection of a lazy linear map and a convex set. @@ -836,7 +836,7 @@ Return the intersection of a lazy linear map and a convex set. The polytope obtained by the intersection of `l.M * L.X` and `S`. """ -@commutative function intersection(L::LinearMap, S::LazySet) +@commutative function intersection(L::LinearMap, S::ConvexSet) return intersection(linear_map(L.M, L.X), S) end @@ -848,7 +848,7 @@ end _intersection_singleton(S, L) """ - intersection(U::Universe, X::LazySet) + intersection(U::Universe, X::ConvexSet) Return the intersection of a universe and a convex set. @@ -861,7 +861,7 @@ Return the intersection of a universe and a convex set. The set `X`. """ -@commutative function intersection(U::Universe, X::LazySet) +@commutative function intersection(U::Universe, X::ConvexSet) return X end diff --git a/src/ConcreteOperations/isdisjoint.jl b/src/ConcreteOperations/isdisjoint.jl index 4d54c607f6..16e43ef92d 100644 --- a/src/ConcreteOperations/isdisjoint.jl +++ b/src/ConcreteOperations/isdisjoint.jl @@ -5,7 +5,7 @@ export isdisjoint, is_intersection_empty # --- disjointness check for general sets --- """ - isdisjoint(X::LazySet, Y::LazySet, witness::Bool=false) + isdisjoint(X::ConvexSet, Y::ConvexSet, witness::Bool=false) Check whether two sets do not intersect, and otherwise optionally compute a witness. @@ -30,7 +30,7 @@ This is a fallback implementation that computes the concrete intersection, A witness is constructed using the `an_element` implementation of the result. """ -function isdisjoint(X::LazySet, Y::LazySet, witness::Bool=false) +function isdisjoint(X::ConvexSet, Y::ConvexSet, witness::Bool=false) cap = intersection(X, Y) empty_intersection = isempty(cap) if witness @@ -49,11 +49,11 @@ end const is_intersection_empty = isdisjoint # conversion for IA types -isdisjoint(X::LazySet, Y::IA.Interval) = isdisjoint(X, Interval(Y)) -isdisjoint(X::IA.Interval, Y::LazySet) = isdisjoint(Interval(X), Y) +isdisjoint(X::ConvexSet, Y::IA.Interval) = isdisjoint(X, Interval(Y)) +isdisjoint(X::IA.Interval, Y::ConvexSet) = isdisjoint(Interval(X), Y) -isdisjoint(X::LazySet, Y::IA.IntervalBox) = isdisjoint(X, convert(Hyperrectangle, Y)) -isdisjoint(X::IA.IntervalBox, Y::LazySet) = isdisjoint(convert(Hyperrectangle, X), Y) +isdisjoint(X::ConvexSet, Y::IA.IntervalBox) = isdisjoint(X, convert(Hyperrectangle, Y)) +isdisjoint(X::IA.IntervalBox, Y::ConvexSet) = isdisjoint(convert(Hyperrectangle, X), Y) # --- AbstractHyperrectangle --- @@ -175,7 +175,7 @@ end # common code for singletons @inline function isdisjoint_helper_singleton( - S::AbstractSingleton, X::LazySet, witness::Bool=false) + S::AbstractSingleton, X::ConvexSet, witness::Bool=false) empty_intersection = element(S) ∉ X if witness N = promote_type(eltype(S), eltype(X)) @@ -186,7 +186,7 @@ end end """ - isdisjoint(X::LazySet, S::AbstractSingleton, witness::Bool=false) + isdisjoint(X::ConvexSet, S::AbstractSingleton, witness::Bool=false) Check whether a convex set and a singleton do not intersect, and otherwise optionally compute a witness. @@ -209,7 +209,7 @@ optionally compute a witness. ``S ∩ X = ∅`` iff `element(S)` ``∉ X``. """ -@commutative function isdisjoint(X::LazySet, S::AbstractSingleton, +@commutative function isdisjoint(X::ConvexSet, S::AbstractSingleton, witness::Bool=false) return isdisjoint_helper_singleton(S, X, witness) end @@ -575,7 +575,7 @@ end @inline function isdisjoint_helper_hyperplane( hp::Union{Hyperplane, Line2D}, - X::LazySet, + X::ConvexSet, witness::Bool=false ) normal_hp = hp.a @@ -606,7 +606,7 @@ end """ - isdisjoint(X::LazySet, + isdisjoint(X::ConvexSet, hp::Union{Hyperplane, Line2D}, [witness]::Bool=false ) @@ -648,7 +648,7 @@ We follow [this algorithm](https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection#Algebraic_form) for the line-hyperplane intersection. """ -@commutative function isdisjoint(X::LazySet, +@commutative function isdisjoint(X::ConvexSet, hp::Union{Hyperplane, Line2D}, witness::Bool=false) return isdisjoint_helper_hyperplane(hp, X, witness) @@ -696,7 +696,7 @@ end @inline function isdisjoint_helper_halfspace( hs::HalfSpace, - X::LazySet, + X::ConvexSet, witness::Bool=false ) if !witness @@ -712,7 +712,7 @@ end end """ - isdisjoint(X::LazySet, hs::HalfSpace, [witness]::Bool=false) + isdisjoint(X::ConvexSet, hs::HalfSpace, [witness]::Bool=false) Check whether a compact set an a half-space do not intersect, and otherwise optionally compute a witness. @@ -745,7 +745,7 @@ The support vector is thus also a witness. Optional keyword arguments can be passed to the `ρ` function. In particular, if `X` is a lazy intersection, options can be passed to the line search algorithm. """ -@commutative function isdisjoint(X::LazySet, hs::HalfSpace, +@commutative function isdisjoint(X::ConvexSet, hs::HalfSpace, witness::Bool=false) return isdisjoint_helper_halfspace(hs, X, witness) end @@ -853,7 +853,7 @@ end """ isdisjoint(P::AbstractPolyhedron, - X::LazySet, + X::ConvexSet, witness::Bool=false; solver=nothing ) @@ -896,7 +896,7 @@ With the sufficiency algorithm, this function may return `false` even in the cas where the intersection is empty. On the other hand, if the algorithm returns `true`, then it is guaranteed that the intersection is empty. """ -@commutative function isdisjoint(P::AbstractPolyhedron, X::LazySet, +@commutative function isdisjoint(P::AbstractPolyhedron, X::ConvexSet, witness::Bool=false; solver=nothing, algorithm="exact") return _isdisjoint_polyhedron(P, X, witness; @@ -904,7 +904,7 @@ where the intersection is empty. On the other hand, if the algorithm returns end function _isdisjoint_polyhedron(P::AbstractPolyhedron, - X::LazySet, + X::ConvexSet, witness::Bool=false; solver=nothing, algorithm="exact" @@ -974,7 +974,7 @@ end """ - isdisjoint(cup::UnionSet, X::LazySet, [witness]::Bool=false) + isdisjoint(cup::UnionSet, X::ConvexSet, [witness]::Bool=false) Check whether a union of two convex sets and another set do not intersect. @@ -987,7 +987,7 @@ Check whether a union of two convex sets and another set do not intersect. `true` iff ``\\text{cup} ∩ X = ∅``. """ -@commutative function isdisjoint(cup::UnionSet, X::LazySet, +@commutative function isdisjoint(cup::UnionSet, X::ConvexSet, witness::Bool=false) return isdisjoint(UnionSetArray([cup.X, cup.Y]), X, witness) end @@ -1000,7 +1000,7 @@ function isdisjoint(cup1::UnionSet, cup2::UnionSet, end """ - isdisjoint(cup::UnionSetArray, X::LazySet, [witness]::Bool=false) + isdisjoint(cup::UnionSetArray, X::ConvexSet, [witness]::Bool=false) Check whether a union of a finite number of convex sets and another set do not intersect. @@ -1014,7 +1014,7 @@ intersect. `true` iff ``\\text{cup} ∩ X = ∅``. """ -@commutative function isdisjoint(cup::UnionSetArray, X::LazySet, +@commutative function isdisjoint(cup::UnionSetArray, X::ConvexSet, witness::Bool=false) result = true N = promote_type(eltype(cup), eltype(X)) @@ -1064,7 +1064,7 @@ end """ - isdisjoint(U::Universe, X::LazySet, [witness]::Bool=false) + isdisjoint(U::Universe, X::ConvexSet, [witness]::Bool=false) Check whether a universe and another set do not intersect. @@ -1077,7 +1077,7 @@ Check whether a universe and another set do not intersect. `true` iff ``X ≠ ∅``. """ -@commutative function isdisjoint(U::Universe, X::LazySet, +@commutative function isdisjoint(U::Universe, X::ConvexSet, witness::Bool=false) return _isdisjoint_universe(X, U, witness) end @@ -1101,21 +1101,21 @@ end @commutative function isdisjoint(P::AbstractPolyhedron, U::Universe, witness::Bool=false) return invoke(isdisjoint, - Tuple{Universe, LazySet, Bool}, + Tuple{Universe, ConvexSet, Bool}, U, P, witness) end @commutative function isdisjoint(S::AbstractSingleton, U::Universe, witness::Bool=false) return invoke(isdisjoint, - Tuple{Universe, LazySet, Bool}, + Tuple{Universe, ConvexSet, Bool}, U, S, witness) end @commutative function isdisjoint(hs::HalfSpace, U::Universe, witness::Bool=false) return invoke(isdisjoint, - Tuple{Universe, LazySet, Bool}, + Tuple{Universe, ConvexSet, Bool}, U, hs, witness) end @@ -1123,7 +1123,7 @@ end hp::Union{Hyperplane, Line2D}, witness::Bool=false) return invoke(isdisjoint, - Tuple{Universe, LazySet, Bool}, + Tuple{Universe, ConvexSet, Bool}, U, hp, witness) end @@ -1132,7 +1132,7 @@ end """ - isdisjoint(C::Complement, X::LazySet, [witness]::Bool=false) + isdisjoint(C::Complement, X::ConvexSet, [witness]::Bool=false) Check whether the complement of a convex set and another set do not intersect. @@ -1156,7 +1156,7 @@ We fall back to `X ⊆ C.X`, which can be justified as follows: X ∩ Y^C = ∅ ⟺ X ⊆ Y ``` """ -@commutative function isdisjoint(C::Complement, X::LazySet, +@commutative function isdisjoint(C::Complement, X::ConvexSet, witness::Bool=false) return ⊆(X, C.X, witness) end @@ -1300,7 +1300,7 @@ We perform these checks sequentially. return witness ? (false, w) : false end -@commutative function isdisjoint(::EmptySet, ::LazySet) +@commutative function isdisjoint(::EmptySet, ::ConvexSet) return true end @@ -1375,13 +1375,13 @@ end end for ST in (AbstractZonotope, AbstractSingleton) - @eval @commutative function isdisjoint(C::CartesianProduct{N, <:LazySet, <:Universe}, Z::$(ST)) where N + @eval @commutative function isdisjoint(C::CartesianProduct{N, <:ConvexSet, <:Universe}, Z::$(ST)) where N X = C.X Zp = project(Z, 1:dim(X)) return isdisjoint(X, Zp) end - @eval @commutative function isdisjoint(C::CartesianProduct{N, <:Universe, <:LazySet}, Z::$(ST)) where N + @eval @commutative function isdisjoint(C::CartesianProduct{N, <:Universe, <:ConvexSet}, Z::$(ST)) where N Y = C.Y Zp = project(Z, dim(C.X)+1:dim(C)) return isdisjoint(Y, Zp) diff --git a/src/ConcreteOperations/isstrictsubset.jl b/src/ConcreteOperations/isstrictsubset.jl index 57c16f8d05..0764edfb8a 100644 --- a/src/ConcreteOperations/isstrictsubset.jl +++ b/src/ConcreteOperations/isstrictsubset.jl @@ -1,5 +1,5 @@ """ - ⊂(X::LazySet{N}, Y::LazySet, [witness]::Bool=false) where {N} + ⊂(X::ConvexSet{N}, Y::ConvexSet, [witness]::Bool=false) where {N} Strict inclusion check. @@ -24,7 +24,7 @@ We check inclusion of `X` in `Y` and then check inclusion of `Y` in `X`: X ⊂ Y \\Leftrightarrow X ⊆ Y \\land ¬ (Y ⊆ X) ``` """ -function ⊂(X::LazySet{N}, Y::LazySet, witness::Bool=false) where {N} +function ⊂(X::ConvexSet{N}, Y::ConvexSet, witness::Bool=false) where {N} if witness res, w = ⊆(X, Y, witness) if res diff --git a/src/ConcreteOperations/issubset.jl b/src/ConcreteOperations/issubset.jl index 62dffc7d86..1dc1f477bf 100644 --- a/src/ConcreteOperations/issubset.jl +++ b/src/ConcreteOperations/issubset.jl @@ -1,7 +1,7 @@ import Base.issubset """ - issubset(X::LazySet, Y::LazySet, [witness]::Bool=false, args...) + issubset(X::ConvexSet, Y::ConvexSet, [witness]::Bool=false, args...) Alias for `⊆` (inclusion check). @@ -25,7 +25,7 @@ For more documentation see `⊆`. function issubset end # this operation is forbidden, but it is a common error so we give a detailed error message -function ⊆(::AbstractVector, ::LazySet) +function ⊆(::AbstractVector, ::ConvexSet) throw(ArgumentError("cannot make an inclusion check if the left-hand side " * "is a vector; either wrap it as a set with one element, as in " * "`Singleton(v) ⊆ X`, or check for set membership, as in `v ∈ X` " * @@ -33,16 +33,16 @@ function ⊆(::AbstractVector, ::LazySet) end # conversion for IA types -⊆(X::LazySet, Y::IA.Interval) = ⊆(X, Interval(Y)) -⊆(X::IA.Interval, Y::LazySet) = ⊆(Interval(X), Y) +⊆(X::ConvexSet, Y::IA.Interval) = ⊆(X, Interval(Y)) +⊆(X::IA.Interval, Y::ConvexSet) = ⊆(Interval(X), Y) -⊆(X::LazySet, Y::IA.IntervalBox) = ⊆(X, convert(Hyperrectangle, Y)) -⊆(X::IA.IntervalBox, Y::LazySet) = ⊆(convert(Hyperrectangle, X), Y) +⊆(X::ConvexSet, Y::IA.IntervalBox) = ⊆(X, convert(Hyperrectangle, Y)) +⊆(X::IA.IntervalBox, Y::ConvexSet) = ⊆(convert(Hyperrectangle, X), Y) # --- fall-back with constraints_list of rhs --- """ - ⊆(X::LazySet, P::LazySet, [witness]::Bool=false) + ⊆(X::ConvexSet, P::ConvexSet, [witness]::Bool=false) Check whether a set is contained in a polyhedral set, and if not, optionally compute a witness. @@ -68,7 +68,7 @@ We require that `constraints_list(P)` is available. We check inclusion of `X` in every constraint of `P`. """ -function ⊆(X::LazySet, P::LazySet, witness::Bool=false) +function ⊆(X::ConvexSet, P::ConvexSet, witness::Bool=false) if applicable(constraints_list, P) return _issubset_constraints_list(X, P, witness) else @@ -82,7 +82,7 @@ end """ - ⊆(S::LazySet, H::AbstractHyperrectangle, [witness]::Bool=false) + ⊆(S::ConvexSet, H::AbstractHyperrectangle, [witness]::Bool=false) Check whether a convex set is contained in a hyperrectangular set, and if not, optionally compute a witness. @@ -105,7 +105,7 @@ optionally compute a witness. ``S ⊆ H`` iff ``\\operatorname{ihull}(S) ⊆ H``, where ``\\operatorname{ihull}`` is the interval hull operator. """ -function ⊆(S::LazySet, H::AbstractHyperrectangle, witness::Bool=false) +function ⊆(S::ConvexSet, H::AbstractHyperrectangle, witness::Bool=false) return _issubset_in_hyperrectangle(S, H, witness) end @@ -177,7 +177,7 @@ end """ - ⊆(P::AbstractPolytope, S::LazySet, [witness]::Bool=false; + ⊆(P::AbstractPolytope, S::ConvexSet, [witness]::Bool=false; algorithm=_default_issubset(P, S)) Check whether a polytope is contained in a convex set, and if not, optionally @@ -210,7 +210,7 @@ compute a witness. Since ``S`` is convex, ``P ⊆ S`` iff ``v_i ∈ S`` for all vertices ``v_i`` of ``P``. """ -function ⊆(P::AbstractPolytope, S::LazySet, witness::Bool=false; +function ⊆(P::AbstractPolytope, S::ConvexSet, witness::Bool=false; algorithm=_default_issubset(P, S)) @assert dim(P) == dim(S) @@ -250,7 +250,7 @@ function _issubset_vertices_list(P, S, witness) end """ - ⊆(X::LazySet, P::AbstractPolyhedron, [witness]::Bool=false) + ⊆(X::ConvexSet, P::AbstractPolyhedron, [witness]::Bool=false) Check whether a convex set is contained in a polyhedron, and if not, optionally compute a witness. @@ -276,13 +276,13 @@ each direction of the constraints of ``P``. For witness generation, we use the support vector in the first direction where the above check fails. """ -function ⊆(X::LazySet, P::AbstractPolyhedron, witness::Bool=false) +function ⊆(X::ConvexSet, P::AbstractPolyhedron, witness::Bool=false) return _issubset_constraints_list(X, P, witness) end # for documentation see -# ⊆(X::LazySet, P::AbstractPolyhedron, witness::Bool=false) -function _issubset_constraints_list(S::LazySet, P::LazySet, witness::Bool=false) +# ⊆(X::ConvexSet, P::AbstractPolyhedron, witness::Bool=false) +function _issubset_constraints_list(S::ConvexSet, P::ConvexSet, witness::Bool=false) @assert dim(S) == dim(P) @inbounds for H in constraints_list(P) @@ -306,7 +306,7 @@ end # --- AbstractSingleton --- """ - ⊆(S::AbstractSingleton, X::LazySet, [witness]::Bool=false) + ⊆(S::AbstractSingleton, X::ConvexSet, [witness]::Bool=false) Check whether a given set with a single value is contained in a convex set, and if not, optionally compute a witness. @@ -324,7 +324,7 @@ if not, optionally compute a witness. * `(true, [])` iff ``S ⊆ X`` * `(false, v)` iff ``S ⊈ X`` and ``v ∈ S \\setminus X`` """ -function ⊆(S::AbstractSingleton, X::LazySet, witness::Bool=false) +function ⊆(S::AbstractSingleton, X::ConvexSet, witness::Bool=false) return _issubset_singleton(S, X, witness) end @@ -466,7 +466,7 @@ end """ - ⊆(L::LineSegment, S::LazySet, witness::Bool=false) + ⊆(L::LineSegment, S::ConvexSet, witness::Bool=false) Check whether a line segment is contained in a convex set, and if not, optionally compute a witness. @@ -489,8 +489,13 @@ optionally compute a witness. Since ``S`` is convex, ``L ⊆ S`` iff ``p ∈ S`` and ``q ∈ S``, where ``p, q`` are the end points of ``L``. """ +function ⊆(L::LineSegment, S::ConvexSet, witness::Bool=false) + return _issubset_line_segment(L, S, witness) +end + function ⊆(L::LineSegment, S::LazySet, witness::Bool=false) - return _issubset_line_segment(L, S) + throw(ArgumentError("this function requires the set type to be convex, but " * + "it is not the case for a $(typeof(S))")) end function _issubset_line_segment(L, S, witness) @@ -648,7 +653,7 @@ end """ - ⊆(∅::EmptySet, X::LazySet, witness::Bool=false) + ⊆(∅::EmptySet, X::ConvexSet, witness::Bool=false) Check whether an empty set is contained in another set. @@ -663,7 +668,7 @@ Check whether an empty set is contained in another set. `true`. """ -function ⊆(∅::EmptySet, X::LazySet, witness::Bool=false) +function ⊆(∅::EmptySet, X::ConvexSet, witness::Bool=false) return _issubset_emptyset(∅, X, witness) end @@ -677,7 +682,7 @@ end ⊆(∅::EmptySet, H::AbstractHyperrectangle, witness::Bool=false) = _issubset_emptyset(∅, H, witness) """ - ⊆(X::LazySet, ∅::EmptySet, [witness]::Bool=false) + ⊆(X::ConvexSet, ∅::EmptySet, [witness]::Bool=false) Check whether a set is contained in an empty set. @@ -696,7 +701,7 @@ Check whether a set is contained in an empty set. We rely on `isempty(X)` for the emptiness check and on `an_element(X)` for witness production. """ -function ⊆(X::LazySet, ∅::EmptySet, witness::Bool=false) +function ⊆(X::ConvexSet, ∅::EmptySet, witness::Bool=false) return _issubset_in_emptyset(X, ∅, witness) end @@ -730,7 +735,7 @@ end """ - ⊆(cup::UnionSet, X::LazySet, [witness]::Bool=false) + ⊆(cup::UnionSet, X::ConvexSet, [witness]::Bool=false) Check whether a union of two convex sets is contained in another set. @@ -748,12 +753,12 @@ Check whether a union of two convex sets is contained in another set. * `(false, v)` iff ``\\text{cup} \\not\\subseteq X`` and ``v ∈ \\text{cup} \\setminus X`` """ -function ⊆(cup::UnionSet, X::LazySet, witness::Bool=false) +function ⊆(cup::UnionSet, X::ConvexSet, witness::Bool=false) return ⊆(UnionSetArray([cup.X, cup.Y]), X, witness) # TODO implement here end """ - ⊆(cup::UnionSetArray, X::LazySet, [witness]::Bool=false) + ⊆(cup::UnionSetArray, X::ConvexSet, [witness]::Bool=false) Check whether a union of a finite number of convex sets is contained in another set. @@ -772,7 +777,7 @@ set. * `(false, v)` iff ``\\text{cup} \\not\\subseteq X`` and ``v ∈ \\text{cup} \\setminus X`` """ -function ⊆(cup::UnionSetArray, X::LazySet, witness::Bool=false) +function ⊆(cup::UnionSetArray, X::ConvexSet, witness::Bool=false) result = true N = promote_type(eltype(cup), eltype(X)) w = N[] @@ -794,7 +799,7 @@ end """ - ⊆(X::LazySet, U::Universe, [witness]::Bool=false) + ⊆(X::ConvexSet, U::Universe, [witness]::Bool=false) Check whether a convex set is contained in a universe. @@ -809,7 +814,7 @@ Check whether a convex set is contained in a universe. * If `witness` option is deactivated: `true` * If `witness` option is activated: `(true, [])` """ -function ⊆(X::LazySet, U::Universe, witness::Bool=false) +function ⊆(X::ConvexSet, U::Universe, witness::Bool=false) return _issubset_universe(X, U, witness) end @@ -824,7 +829,7 @@ for ST in [AbstractPolytope, AbstractHyperrectangle, AbstractSingleton, LineSegm end """ - ⊆(U::Universe, X::LazySet, [witness]::Bool=false) + ⊆(U::Universe, X::ConvexSet, [witness]::Bool=false) Check whether a universe is contained in another convex set, and otherwise optionally compute a witness. @@ -847,7 +852,7 @@ optionally compute a witness. We fall back to `isuniversal(X)`. """ -function ⊆(U::Universe, X::LazySet, witness::Bool=false) +function ⊆(U::Universe, X::ConvexSet, witness::Bool=false) return isuniversal(X, witness) end @@ -866,7 +871,7 @@ end """ - ⊆(X::LazySet, C::Complement, [witness]::Bool=false) + ⊆(X::ConvexSet, C::Complement, [witness]::Bool=false) Check whether a convex set is contained in the complement of another convex set, and otherwise optionally compute a witness. @@ -893,7 +898,7 @@ We fall back to `isdisjoint(X, C.X)`, which can be justified as follows. X ⊆ Y^C ⟺ X ∩ Y = ∅ ``` """ -function ⊆(X::LazySet, C::Complement, witness::Bool=false) +function ⊆(X::ConvexSet, C::Complement, witness::Bool=false) return isdisjoint(X, C.X, witness) end @@ -1093,13 +1098,13 @@ function ⊆(Z::AbstractZonotope, H::AbstractHyperrectangle, witness::Bool=false end for ST in (AbstractZonotope, AbstractSingleton, LineSegment) - @eval function ⊆(Z::$(ST), C::CartesianProduct{N, <:LazySet, <:Universe}) where N + @eval function ⊆(Z::$(ST), C::CartesianProduct{N, <:ConvexSet, <:Universe}) where N X = C.X Zp = project(Z, 1:dim(X)) return ⊆(Zp, X) end - @eval function ⊆(Z::$(ST), C::CartesianProduct{N, <:Universe, <:LazySet}) where N + @eval function ⊆(Z::$(ST), C::CartesianProduct{N, <:Universe, <:ConvexSet}) where N Y = C.Y Zp = project(Z, dim(C.X)+1:dim(C)) return ⊆(Zp, Y) diff --git a/src/ConcreteOperations/minkowski_difference.jl b/src/ConcreteOperations/minkowski_difference.jl index 558959225e..bf4e2b5241 100644 --- a/src/ConcreteOperations/minkowski_difference.jl +++ b/src/ConcreteOperations/minkowski_difference.jl @@ -1,7 +1,7 @@ export minkowski_difference, pontryagin_difference """ - minkowski_difference(P::LazySet, Q::LazySet) + minkowski_difference(P::ConvexSet, Q::ConvexSet) Concrete Minkowski difference (geometric difference) for a pair of convex sets. @@ -45,7 +45,7 @@ of disturbance invariant sets for discrete-time linear systems.* [Mathematical Problems in Engineering Volume 4, Issue 4, Pages 317-367.](http://dx.doi.org/10.1155/S1024123X98000866) """ -function minkowski_difference(P::LazySet, Q::LazySet) +function minkowski_difference(P::ConvexSet, Q::ConvexSet) @assert applicable(constraints_list, P) "this function " * "requires that the list of constraints of its first argument is applicable, but it is not; " * @@ -62,7 +62,7 @@ function minkowski_difference(P::LazySet, Q::LazySet) end """ - pontryagin_difference(P::LazySet, Q::LazySet) + pontryagin_difference(P::ConvexSet, Q::ConvexSet) An alias for the function `minkowski_difference`. @@ -75,5 +75,5 @@ Due to inconsistent naming conventions, both the name *Minkowski difference* and const pontryagin_difference = minkowski_difference # concrete minkowski difference with singleton -minkowski_difference(X::LazySet, S::AbstractSingleton) = translate(X, -element(S)) -minkowski_difference(X::LazySet, ::ZeroSet) = X +minkowski_difference(X::ConvexSet, S::AbstractSingleton) = translate(X, -element(S)) +minkowski_difference(X::ConvexSet, ::ZeroSet) = X diff --git a/src/ConcreteOperations/minkowski_sum.jl b/src/ConcreteOperations/minkowski_sum.jl index 0de21ea800..9e41debcc9 100644 --- a/src/ConcreteOperations/minkowski_sum.jl +++ b/src/ConcreteOperations/minkowski_sum.jl @@ -1,7 +1,7 @@ export minkowski_sum """ - minkowski_sum(P::LazySet, Q::LazySet; + minkowski_sum(P::ConvexSet, Q::ConvexSet; [backend]=nothing, [algorithm]=nothing, [prune]=true) @@ -42,7 +42,7 @@ julia> ... julia> minkowski_sum(P, Q) ``` """ -function minkowski_sum(P::LazySet, Q::LazySet; +function minkowski_sum(P::ConvexSet, Q::ConvexSet; backend=nothing, algorithm=nothing, prune=true) @@ -502,7 +502,7 @@ and whose generators are the concatenation of the generators of `PZ` and `Z`. return DensePolynomialZonotope(c, PZ.E, PZ.F, G) end -@commutative minkowski_sum(::ZeroSet, X::LazySet) = X +@commutative minkowski_sum(::ZeroSet, X::ConvexSet) = X @commutative minkowski_sum(::ZeroSet, P::AbstractPolyhedron) = P @commutative minkowski_sum(::ZeroSet, P::AbstractPolytope) = P @commutative minkowski_sum(::ZeroSet, Z::AbstractZonotope) = Z diff --git a/src/Initialization/init_Javis.jl b/src/Initialization/init_Javis.jl index f1beefedb8..5bcc65be74 100644 --- a/src/Initialization/init_Javis.jl +++ b/src/Initialization/init_Javis.jl @@ -13,7 +13,7 @@ end # convert a lazysets to a polygonal overapproximation with the given tolerance, # and then to the function `poly` from Luxor.jl that receives array of points -function luxify(X::LazySet; tol=1e-3) +function luxify(X::ConvexSet; tol=1e-3) # ε-close outer polygonal approximation of X P = overapproximate(X, HPolygon, tol) @@ -41,7 +41,7 @@ end # animate an array of sets using Javis.jl # TODO pass colors, eg. with default cols = Javis.distinguishable_colors(length(X)) -function Javis.animate(X::AbstractVector{ST}; kwargs...) where {N, ST<:LazySet{N}} +function Javis.animate(X::AbstractVector{ST}; kwargs...) where {N, ST<:ConvexSet{N}} # size of the animation sz = get(kwargs, :size, (500, 500)) diff --git a/src/Initialization/init_Polyhedra.jl b/src/Initialization/init_Polyhedra.jl index 1b78945677..38bb8eb6d5 100644 --- a/src/Initialization/init_Polyhedra.jl +++ b/src/Initialization/init_Polyhedra.jl @@ -4,7 +4,7 @@ eval(quote using .Polyhedra: HRep, VRep, removehredundancy!, removevredundancy! - function default_polyhedra_backend(P::LazySet{N}) where {N} + function default_polyhedra_backend(P::ConvexSet{N}) where {N} if LazySets.dim(P) == 1 return default_polyhedra_backend_1d(N) else diff --git a/src/Interfaces/AbstractAffineMap.jl b/src/Interfaces/AbstractAffineMap.jl index 4aac4bcd8f..543ce92e38 100644 --- a/src/Interfaces/AbstractAffineMap.jl +++ b/src/Interfaces/AbstractAffineMap.jl @@ -4,7 +4,7 @@ export AbstractAffineMap, matrix, vector, set """ - AbstractAffineMap{N, S<:LazySet{N}} <: LazySet{N} + AbstractAffineMap{N, S<:ConvexSet{N}} <: ConvexSet{N} Abstract type for affine maps. @@ -29,7 +29,7 @@ julia> subtypes(AbstractAffineMap) Translation ``` """ -abstract type AbstractAffineMap{N, S<:LazySet{N}} <: LazySet{N} end +abstract type AbstractAffineMap{N, S<:ConvexSet{N}} <: ConvexSet{N} end isoperationtype(::Type{<:AbstractAffineMap}) = true isconvextype(::Type{<:AbstractAffineMap{N, S}}) where {N, S} = isconvextype(S) diff --git a/src/Interfaces/AbstractCentrallySymmetric.jl b/src/Interfaces/AbstractCentrallySymmetric.jl index 046b8a4da6..fc08654d25 100644 --- a/src/Interfaces/AbstractCentrallySymmetric.jl +++ b/src/Interfaces/AbstractCentrallySymmetric.jl @@ -5,7 +5,7 @@ export AbstractCentrallySymmetric, an_element """ - AbstractCentrallySymmetric{N} <: LazySet{N} + AbstractCentrallySymmetric{N} <: ConvexSet{N} Abstract type for centrally symmetric sets. @@ -24,7 +24,7 @@ julia> subtypes(AbstractCentrallySymmetric) Ellipsoid ``` """ -abstract type AbstractCentrallySymmetric{N} <: LazySet{N} end +abstract type AbstractCentrallySymmetric{N} <: ConvexSet{N} end isconvextype(::Type{<:AbstractCentrallySymmetric}) = false diff --git a/src/Interfaces/AbstractHPolygon.jl b/src/Interfaces/AbstractHPolygon.jl index b1601d3c47..a7163c8265 100644 --- a/src/Interfaces/AbstractHPolygon.jl +++ b/src/Interfaces/AbstractHPolygon.jl @@ -187,7 +187,7 @@ function constraints_list(P::AbstractHPolygon) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Interfaces/AbstractHyperrectangle.jl b/src/Interfaces/AbstractHyperrectangle.jl index 8a112a6499..080e8eac1d 100644 --- a/src/Interfaces/AbstractHyperrectangle.jl +++ b/src/Interfaces/AbstractHyperrectangle.jl @@ -261,7 +261,7 @@ function constraints_list(H::AbstractHyperrectangle{N}) where {N} return constraints end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Interfaces/AbstractPolygon.jl b/src/Interfaces/AbstractPolygon.jl index ba8d1782da..1a3a3b5bee 100644 --- a/src/Interfaces/AbstractPolygon.jl +++ b/src/Interfaces/AbstractPolygon.jl @@ -28,7 +28,7 @@ abstract type AbstractPolygon{N} <: AbstractPolytope{N} end isconvextype(::Type{<:AbstractPolygon}) = true -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Interfaces/AbstractPolyhedron.jl b/src/Interfaces/AbstractPolyhedron.jl index bf45187814..c479cc11b1 100644 --- a/src/Interfaces/AbstractPolyhedron.jl +++ b/src/Interfaces/AbstractPolyhedron.jl @@ -1,7 +1,7 @@ export AbstractPolyhedron """ - AbstractPolyhedron{N} <: LazySet{N} + AbstractPolyhedron{N} <: ConvexSet{N} Abstract type for compact convex polyhedral sets. @@ -29,7 +29,7 @@ half-spaces. As such, polyhedra are closed and convex but not necessarily bounded. Bounded polyhedra are called *polytopes* (see [`AbstractPolytope`](@ref)). """ -abstract type AbstractPolyhedron{N} <: LazySet{N} end +abstract type AbstractPolyhedron{N} <: ConvexSet{N} end isconvextype(::Type{<:AbstractPolyhedron}) = true diff --git a/src/Interfaces/AbstractPolyhedron_functions.jl b/src/Interfaces/AbstractPolyhedron_functions.jl index cb30a75636..858314a7ba 100644 --- a/src/Interfaces/AbstractPolyhedron_functions.jl +++ b/src/Interfaces/AbstractPolyhedron_functions.jl @@ -25,7 +25,7 @@ function default_lp_solver(M::Type{<:Number}, N::Type{<:Number}) end # Polyhedra backend (fallback method) -function default_polyhedra_backend(P::LazySet{N}) where {N} +function default_polyhedra_backend(P::ConvexSet{N}) where {N} require(:Polyhedra; fun_name="default_polyhedra_backend") error("no default backend for numeric type $N") end @@ -1157,7 +1157,7 @@ function _check_constrained_dimensions(c::HalfSpace, block) return status end -function _project_polyhedron(P::LazySet{N}, block; kwargs...) where {N} +function _project_polyhedron(P::ConvexSet{N}, block; kwargs...) where {N} M = projection_matrix(block, dim(P), N) πP = linear_map(M, P; kwargs...) return constraints_list(πP) diff --git a/src/Interfaces/AbstractPolynomialZonotope.jl b/src/Interfaces/AbstractPolynomialZonotope.jl index 5f2ba6db59..d6c5da58ce 100644 --- a/src/Interfaces/AbstractPolynomialZonotope.jl +++ b/src/Interfaces/AbstractPolynomialZonotope.jl @@ -1,5 +1,5 @@ """ - AbstractPolynomialZonotope{N} <: LazySet{N} + AbstractPolynomialZonotope{N} <: ConvexSet{N} Abstract type for polynomial zonotope sets. diff --git a/src/Interfaces/AbstractSingleton.jl b/src/Interfaces/AbstractSingleton.jl index 02c122240f..27988a1ccc 100644 --- a/src/Interfaces/AbstractSingleton.jl +++ b/src/Interfaces/AbstractSingleton.jl @@ -281,7 +281,7 @@ function linear_map(M::AbstractMatrix, S::AbstractSingleton) return T(M * element(S)) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -345,7 +345,7 @@ function ∈(x::AbstractVector, S::AbstractSingleton) end # this operation is forbidden, but it is a common error -function ∈(S::AbstractSingleton, X::LazySet) +function ∈(S::AbstractSingleton, X::ConvexSet) throw(ArgumentError("cannot make a point-in-set check if the left-hand side is " * "a set; either check for set inclusion, as in `S ⊆ X`, or check for " * "membership, as in `element(S) ∈ X` (the results are equivalent but " * diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 09dec543ad..21622875ae 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -222,7 +222,7 @@ function order(Z::AbstractZonotope) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Interfaces/ConvexSet.jl b/src/Interfaces/ConvexSet.jl new file mode 100644 index 0000000000..0b6c2d688c --- /dev/null +++ b/src/Interfaces/ConvexSet.jl @@ -0,0 +1,1542 @@ +import Base: ==, ≈, copy, eltype, rationalize, extrema +import Random.rand + +export ConvexSet, + basetype, + ρ, support_function, + σ, support_vector, + complement, + dim, + norm, + radius, + diameter, + an_element, + isbounded, + isboundedtype, + neutral, + absorbing, + tosimplehrep, + isuniversal, + translate, + affine_map, + exponential_map, + reflect, + is_interior_point, + isoperation, + isoperationtype, + isequivalent, + isconvextype, + is_polyhedral, + area, + surface, + singleton_list, + concretize, + constraints, + vertices, + project, + rectify, + permute + +""" + ConvexSet{N} <: LazySet{N} + +Abstract type for convex sets, i.e., sets characterized by a (possibly infinite) +intersection of halfspaces, or equivalently, sets ``S`` such that for any two +elements ``x, y ∈ S`` and ``0 ≤ λ ≤ 1`` it holds that ``λ·x + (1-λ)·y ∈ S``. + +### Notes + +`ConvexSet` types should be parameterized with a type `N`, typically `N<:Real`, +for using different numeric types. + +Every concrete `ConvexSet` must define the following functions: +- `σ(d::AbstractVector, S::ConvexSet)` -- the support vector of `S` in a given + direction `d` +- `dim(S::ConvexSet)` -- the ambient dimension of `S` + +The function +- `ρ(d::AbstractVector, S::ConvexSet)` -- the support function of `S` in a given + direction `d` +is optional because there is a fallback implementation relying on `σ`. +However, for unbounded sets (which includes most lazy set types) this fallback +cannot be used and an explicit method must be implemented. +""" +abstract type ConvexSet{N} <: LazySet{N} end + + +# --- common ConvexSet functions --- + +""" + eltype(::Type{<:ConvexSet{N}}) where {N} + +Return the numeric type (`N`) of the given set type. + +### Input + +- `T` -- set type, used for dispatch + +### Output + +The numeric type of `T`. +""" +eltype(::Type{<:ConvexSet{N}}) where {N} = N + +""" + eltype(::ConvexSet{N}) where {N} + +Return the numeric type (`N`) of the given set. + +### Input + +- `X` -- set instance, used for dispatch + +### Output + +The numeric type of `X`. +""" +eltype(::ConvexSet{N}) where {N} = N + +""" + basetype(T::Type{<:ConvexSet}) + +Return the base type of the given set type (i.e., without type parameters). + +### Input + +- `T` -- set type, used for dispatch + +### Output + +The base type of `T`. +""" +basetype(T::Type{<:ConvexSet}) = Base.typename(T).wrapper + +""" + basetype(S::ConvexSet) + +Return the base type of the given set (i.e., without type parameters). + +### Input + +- `S` -- set instance, used for dispatch + +### Output + +The base type of `S`. + +### Examples + +```jldoctest +julia> z = rand(Zonotope); + +julia> basetype(z) +Zonotope + +julia> basetype(z + z) +MinkowskiSum + +julia> basetype(LinearMap(rand(2, 2), z + z)) +LinearMap +``` +""" +basetype(S::ConvexSet) = Base.typename(typeof(S)).wrapper + +""" + ρ(d::AbstractVector, S::ConvexSet) + +Evaluate the support function of a set in a given direction. + +### Input + +- `d` -- direction +- `S` -- convex set + +### Output + +The support function of the set `S` for the direction `d`. +""" +function ρ(d::AbstractVector, S::ConvexSet) + return dot(d, σ(d, S)) +end + +""" + support_function + +Alias for the support function ρ. +""" +const support_function = ρ + +""" + σ + +Function to compute the support vector σ. +""" +function σ end + +""" + support_vector + +Alias for the support vector σ. +""" +const support_vector = σ + +""" + isboundedtype(::Type{<:ConvexSet}) + +Determine whether a set type only represents bounded sets. + +### Input + +- `ConvexSet` -- set type for dispatch + +### Output + +`true` if the set type only represents bounded sets. +Note that some sets may still represent an unbounded set even though their type +actually does not (example: [`HPolytope`](@ref), because the construction with +non-bounding linear constraints is allowed). + +### Notes + +By default this function returns `false`. +All set types that can determine boundedness should override this behavior. +""" +function isboundedtype(::Type{T}) where {T<:ConvexSet} + return false +end + +""" + isbounded(S::ConvexSet) + +Determine whether a set is bounded. + +### Input + +- `S` -- set +- `algorithm` -- (optional, default: `"support_function"`) algorithm choice, + possible options are `"support_function"` and `"stiemke"` + +### Output + +`true` iff the set is bounded. + +### Algorithm + +See the documentation of `_isbounded_unit_dimensions` or `_isbounded_stiemke` +for details. +""" +function isbounded(S::ConvexSet; algorithm="support_function") + if algorithm == "support_function" + return _isbounded_unit_dimensions(S) + elseif algorithm == "stiemke" + return _isbounded_stiemke(S) + else + throw(ArgumentError("unknown algorithm $algorithm")) + end +end + +""" + _isbounded_unit_dimensions(S::ConvexSet{N}) where {N} + +Determine whether a set is bounded in each unit dimension. + +### Input + +- `S` -- set + +### Output + +`true` iff the set is bounded in each unit dimension. + +### Algorithm + +This function performs ``2n`` support function checks, where ``n`` is the +ambient dimension of `S`. +""" +function _isbounded_unit_dimensions(S::ConvexSet{N}) where {N} + n = dim(S) + @inbounds for i in 1:n + for o in [one(N), -one(N)] + d = SingleEntryVector(i, n, o) + if ρ(d, S) == N(Inf) + return false + end + end + end + return true +end + +""" + is_polyhedral(S::ConvexSet) + +Trait for polyhedral sets. + +### Input + +- `S` -- set + +### Output + +`true` only if the set behaves like an [`AbstractPolyhedron`](@ref). +The answer is conservative, i.e., may sometimes be `false` even if the set is +polyhedral. +""" +function is_polyhedral(S::ConvexSet) + return false +end + +""" + norm(S::ConvexSet, [p]::Real=Inf) + +Return the norm of a convex set. +It is the norm of the enclosing ball (of the given ``p``-norm) of minimal volume +that is centered in the origin. + +### Input + +- `S` -- convex set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the norm. +""" +function norm(S::ConvexSet, p::Real=Inf) + if p == Inf + return norm(box_approximation(S), p) + elseif applicable(vertices_list, S) + return maximum(norm(v, p) for v in vertices_list(S)) + else + error("the norm for this value of p=$p is not implemented") + end +end + +""" + radius(S::ConvexSet, [p]::Real=Inf) + +Return the radius of a convex set. +It is the radius of the enclosing ball (of the given ``p``-norm) of minimal +volume with the same center. + +### Input + +- `S` -- convex set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the radius. +""" +function radius(S::ConvexSet, p::Real=Inf) + if p == Inf + return radius(Approximations.ballinf_approximation(S), p) + else + error("the radius for this value of p=$p is not implemented") + end +end + +""" + diameter(S::ConvexSet, [p]::Real=Inf) + +Return the diameter of a convex set. +It is the maximum distance between any two elements of the set, or, +equivalently, the diameter of the enclosing ball (of the given ``p``-norm) of +minimal volume with the same center. + +### Input + +- `S` -- convex set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the diameter. +""" +function diameter(S::ConvexSet, p::Real=Inf) + return radius(S, p) * 2 +end + +""" + affine_map(M::AbstractMatrix, X::ConvexSet, v::AbstractVector; kwargs...) + +Compute a concrete affine map. + +### Input + +- `M` -- linear map +- `X` -- convex set +- `v` -- translation vector + +### Output + +A set representing the affine map of `X`. + +### Algorithm + +The implementation applies the functions `linear_map` and `translate`. +""" +function affine_map(M::AbstractMatrix, X::ConvexSet, v::AbstractVector; kwargs...) + return translate(linear_map(M, X; kwargs...), v) +end + +""" + exponential_map(M::AbstractMatrix, X::ConvexSet) + +Compute the concrete exponential map of `M` and `X`, i.e., `exp(M) * X`. + +### Input + +- `M` -- matrix +- `X` -- set + +### Output + +A set representing the exponential map of `M` and `X`. + +### Algorithm + +The implementation applies the functions `exp` and `linear_map`. +""" +function exponential_map(M::AbstractMatrix, X::ConvexSet) + return linear_map(exp(M), X) +end + +""" + an_element(S::ConvexSet{N}) where {N} + +Return some element of a convex set. + +### Input + +- `S` -- convex set + +### Output + +An element of a convex set. + +### Algorithm + +An element of the set is obtained by evaluating its support vector along +direction ``[1, 0, …, 0]``. +""" +function an_element(S::ConvexSet{N}) where {N} + e₁ = SingleEntryVector(1, dim(S), one(N)) + return σ(e₁, S) +end + +""" + ==(X::ConvexSet, Y::ConvexSet) + +Return whether two LazySets of the same type are exactly equal. + +### Input + +- `X` -- any `ConvexSet` +- `Y` -- another `ConvexSet` of the same type as `X` + +### Output + +- `true` iff `X` is equal to `Y`. + +### Notes + +The check is purely syntactic and the sets need to have the same base type. +For instance, `X::VPolytope == Y::HPolytope` returns `false` even if `X` and `Y` +represent the same polytope. +However `X::HPolytope{Int64} == Y::HPolytope{Float64}` is a valid comparison. + +### Algorithm + +We recursively compare the fields of `X` and `Y` until a mismatch is found. + +### Examples + +```jldoctest +julia> HalfSpace([1], 1) == HalfSpace([1], 1) +true + +julia> HalfSpace([1], 1) == HalfSpace([1.0], 1.0) +true + +julia> Ball1([0.], 1.) == Ball2([0.], 1.) +false +``` +""" +function ==(X::ConvexSet, Y::ConvexSet) + # if the common supertype of X and Y is abstract, they cannot be compared + if isabstracttype(promote_type(typeof(X), typeof(Y))) + return false + end + + for f in fieldnames(typeof(X)) + if getfield(X, f) != getfield(Y, f) + return false + end + end + + return true +end +""" + ≈(X::ConvexSet, Y::ConvexSet) + +Return whether two LazySets of the same type are approximately equal. + +### Input + +- `X` -- any `ConvexSet` +- `Y` -- another `ConvexSet` of the same type as `X` + +### Output + +- `true` iff `X` is equal to `Y`. + +### Notes + +The check is purely syntactic and the sets need to have the same base type. +For instance, `X::VPolytope ≈ Y::HPolytope` returns `false` even if `X` and `Y` +represent the same polytope. +However `X::HPolytope{Int64} ≈ Y::HPolytope{Float64}` is a valid comparison. + +### Algorithm + +We recursively compare the fields of `X` and `Y` until a mismatch is found. + +### Examples + +```jldoctest +julia> HalfSpace([1], 1) ≈ HalfSpace([1], 1) +true + +julia> HalfSpace([1], 1) ≈ HalfSpace([1.00000001], 0.99999999) +true + +julia> HalfSpace([1], 1) ≈ HalfSpace([1.0], 1.0) +true + +julia> Ball1([0.], 1.) ≈ Ball2([0.], 1.) +false +``` +""" +function ≈(X::ConvexSet, Y::ConvexSet) + # if the common supertype of X and Y is abstract, they cannot be compared + if isabstracttype(promote_type(typeof(X), typeof(Y))) + return false + end + + for f in fieldnames(typeof(X)) + if !_isapprox(getfield(X, f), getfield(Y, f)) + return false + end + end + + return true +end + +# hook into random API +function rand(rng::AbstractRNG, ::SamplerType{T}) where T<:ConvexSet + rand(T, rng=rng) +end + +""" + copy(S::ConvexSet) + +Return a copy of the given set by copying its values recursively. + +### Input + +- `S` -- any `ConvexSet` + +### Output + +A copy of `S`. + +### Notes + +This function performs a `copy` of each field in `S`. +See the documentation of `?copy` for further details. +""" +function copy(S::T) where {T<:ConvexSet} + args = [copy(getfield(S, f)) for f in fieldnames(T)] + BT = basetype(S) + return BT(args...) +end + +""" + tosimplehrep(S::ConvexSet) + +Return the simple H-representation ``Ax ≤ b`` of a set from its list of linear +constraints. + +### Input + +- `S` -- set + +### Output + +The tuple `(A, b)` where `A` is the matrix of normal directions and `b` is the +vector of offsets. + +### Notes + +This function only works for sets that can be represented exactly by a finite +list of linear constraints. +This fallback implementation relies on `constraints_list(S)`. +""" +tosimplehrep(S::ConvexSet) = tosimplehrep(constraints_list(S)) + +""" + reflect(P::ConvexSet) + +Concrete reflection of a convex set `P`, resulting in the reflected set `-P`. + +### Note + +This function requires that the list of constraints of the set `P` is +available, i.e. such that it can be written as +``P = \\{z ∈ ℝⁿ: ⋂ sᵢᵀz ≤ rᵢ, i = 1, ..., N\\}.`` + +This function can be used to implement the alternative definition of the +Minkowski Difference, which writes as +```math +A ⊖ B = \\{a − b | a ∈ A, b ∈ B\\} = A ⊕ (-B) +``` +by calling `minkowski_sum(A, reflect(B))`. +""" +function reflect(P::ConvexSet) + @assert applicable(constraints_list, P) "this function " * + "requires that the list of constraints is available, but it is not; " * + "if the set is bounded, try overapproximating with an `HPolytope` first" + + F, g = tosimplehrep(P) + T = isbounded(P) ? HPolytope : HPolyhedron + return T(-F, g) +end + +""" + isuniversal(X::ConvexSet{N}, [witness]::Bool=false) where {N} + +Check whether a given convex set is universal, and otherwise optionally compute +a witness. + +### Input + +- `X` -- convex set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If `witness` option is deactivated: `true` iff ``X`` is universal +* If `witness` option is activated: + * `(true, [])` iff ``X`` is universal + * `(false, v)` iff ``X`` is not universal and ``v ∉ X`` + +### Notes + +This is a naive fallback implementation. +""" +function isuniversal(X::ConvexSet{N}, witness::Bool=false) where {N} + if isbounded(X) + result = false + else + error("cannot determine universality of the set") + end + + if result + return witness ? (true, N[]) : true + elseif witness + error("witness production is currently not supported") + else + return false + end +end + +""" + is_interior_point(d::AbstractVector{N}, P::ConvexSet{N}; + p=N(Inf), ε=_rtol(N)) where {N<:Real} + +Check if the point `d` is contained in the interior of the convex set `P`. + +### Input + +- `d` -- point +- `P` -- set +- `p` -- (optional; default: `N(Inf)`) norm of the ball used to apply the error + tolerance +- `ε` -- (optional; default: `_rtol(N)`) error tolerance of check + +### Output + +Boolean which indicates if the point `d` is contained in `P`. + +### Algorithm + +The implementation checks if a `Ballp` of norm `p` with center `d` and radius +`ε` is contained in the set `P`. +This is a numerical check for `d ∈ interior(P)` with error tolerance `ε`. +""" +function is_interior_point(d::AbstractVector{N}, P::ConvexSet{N}; + p=N(Inf), ε=_rtol(N)) where {N<:Real} + return Ballp(p, d, ε) ⊆ P +end + +""" + plot_recipe(X::ConvexSet{N}, [ε]=N(PLOT_PRECISION)) where {N} + +Convert a convex set to a pair `(x, y)` of points for plotting. + +### Input + +- `X` -- convex set +- `ε` -- (optional, default: `PLOT_PRECISION`) approximation error bound + +### Output + +A pair `(x, y)` of points that can be plotted. + +### Algorithm + +We first assert that `X` is bounded. + +One-dimensional sets are converted to an `Interval`. +We do not support three-dimensional or higher-dimensional sets at the moment. + +For two-dimensional sets, we first compute a polygonal overapproximation. +The second argument, `ε`, corresponds to the error in Hausdorff distance between +the overapproximating set and `X`. +The default value `PLOT_PRECISION` is chosen such that the unit ball in the +2-norm is approximated with reasonable accuracy. +On the other hand, if you only want to produce a fast box-overapproximation of +`X`, pass `ε=Inf`. +Finally, we use the plot recipe for polygons. +""" +function plot_recipe(X::ConvexSet{N}, ε=N(PLOT_PRECISION)) where {N} + @assert dim(X) <= 2 "cannot plot a $(dim(X))-dimensional $(typeof(X))" + @assert isbounded(X) "cannot plot an unbounded $(typeof(X))" + + if dim(X) == 1 + Y = convert(Interval, X) + else + Y = overapproximate(X, ε) + end + return plot_recipe(Y, ε) +end + +""" + isoperation(X::ConvexSet) + +Check whether the given `ConvexSet` is an instance of a set operation or not. + +### Input + +- `X` -- a `ConvexSet` + +### Output + +`true` if `X` is an instance of a set-based operation and `false` otherwise. + +### Notes + +The fallback implementation returns whether the set type of the input is an +operation or not using `isoperationtype`. + +See also [`isoperationtype(X::Type{<:ConvexSet})`](@ref). + +### Examples + +```jldoctest +julia> B = BallInf([0.0, 0.0], 1.0); + +julia> isoperation(B) +false + +julia> isoperation(B ⊕ B) +true +``` +""" +function isoperation(X::ConvexSet) + return isoperationtype(typeof(X)) +end + +isoperation(::Type{<:ConvexSet}) = error("`isoperation` cannot be applied to a set " * + "type; use `isoperationtype` instead") + +""" + isoperationtype(X::Type{<:ConvexSet}) + +Check whether the given `ConvexSet` type is an operation or not. + +### Input + +- `X` -- subtype of `ConvexSet` + +### Output + +`true` if the given set type is a set-based operation and `false` otherwise. + +### Notes + +The fallback for this function returns an error that `isoperationtype` is not +implemented. Subtypes of `ConvexSet` should dispatch on this function as required. + +See also [`isoperation(X<:ConvexSet)`](@ref). + +### Examples + +```jldoctest +julia> isoperationtype(BallInf) +false + +julia> isoperationtype(LinearMap) +true +``` +""" +function isoperationtype(X::Type{<:ConvexSet}) + error("`isoperationtype` is not implemented for type $X") +end + +isoperationtype(::ConvexSet) = error("`isoperationtype` cannot be applied to " * + "a set instance; use `isoperation` instead") + +""" + isequivalent(X::ConvexSet, Y::ConvexSet) + +Return whether two LazySets are equal in the mathematical sense, i.e. equivalent. + +### Input + +- `X` -- any `ConvexSet` +- `Y` -- another `ConvexSet` + +### Output + +`true` iff `X` is equivalent to `Y`. + +## Algorithm + +First we check `X ≈ Y`, which returns `true` if and only if `X` and `Y` have the +same type and approximately the same values (checked with `LazySets._isapprox`). +If that fails, we check the double inclusion `X ⊆ Y && Y ⊆ X`. + +### Examples + +```jldoctest +julia> X = BallInf([0.1, 0.2], 0.3); + +julia> Y = convert(HPolytope, X); + +julia> X == Y +false + +julia> isequivalent(X, Y) +true +``` +""" +function isequivalent(X::ConvexSet, Y::ConvexSet) + try # TODO temporary try-catch construct until ≈ is fixed for all set types + if X ≈ Y + return true + end + catch e + end + return _isequivalent_inclusion(X, Y) +end + +function _isequivalent_inclusion(X::ConvexSet, Y::ConvexSet) + return X ⊆ Y && Y ⊆ X +end + +""" + isconvextype(X::Type{<:ConvexSet}) + +Check whether the given `ConvexSet` type is convex. + +### Input + +- `X` -- subtype of `ConvexSet` + +### Output + +`true` if the given set type is guaranteed to be convex by using only type +information, and `false` otherwise. + +### Notes + +Since this operation only acts on types (not on values), it can return false +negatives, i.e. there may be instances where the set is convex, even though the +answer of this function is `false`. The examples below illustrate this point. + +### Examples + +A ball in the infinity norm is always convex, hence we get: + +```jldoctest convex_types +julia> isconvextype(BallInf) +true +``` + +For instance, the union (`UnionSet`) of two sets may in general be either convex +or not, since convexity cannot be decided by just using type information. +Hence, `isconvextype` returns `false` if `X` is `Type{<:UnionSet}`. + +```jldoctest convex_types +julia> isconvextype(UnionSet) +false +``` + +However, the type parameters from the set operations allow to decide convexity +in some cases, by falling back to the convexity of the type of its arguments. +Consider for instance the lazy intersection. The intersection of two convex sets +is always convex, hence we can get: + +```jldoctest convex_types +julia> isconvextype(Intersection{Float64, BallInf{Float64}, BallInf{Float64}}) +true +``` +""" +isconvextype(X::Type{<:ConvexSet}) = false + +""" + surface(X::ConvexSet{N}) where {N} + +Compute the surface area of a set. + +### Input + +- `X` -- set + +### Output + +A number representing the surface area of `X`. +""" +function surface(X::ConvexSet{N}) where {N} + if dim(X) == 2 + return area(X) + else + throw(ArgumentError("the surface function is only implemented for " * + "two-dimensional sets, but the given set is $(dim(X))-dimensional")) + end +end + +""" + area(X::ConvexSet{N}) where {N} + +Compute the area of a two-dimensional polytopic set using the Shoelace formula. + +### Input + +- `X` -- two-dimensional set + +### Output + +A number representing the area of `X`. + +### Notes + +This algorithm is applicable to any lazy set `X` such that its list of vertices, +`vertices_list`, can be computed. + +### Algorithm + +Let `m` be the number of vertices of `X`. The following instances are considered: + +- `m = 0, 1, 2`: the output is zero. +- `m = 3`: the triangle case is computed using the Shoelace formula with 3 points. +- `m = 4`: the quadrilateral case is obtained by the factored version of the Shoelace + formula with 4 points. + +Otherwise, the general Shoelace formula is used; for detals see the wikipedia +article [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula). +""" +function area(X::ConvexSet{N}) where {N} + @assert dim(X) == 2 "this function only applies to two-dimensional sets, " * + "but the given set is $(dim(X))-dimensional" + + Xpoly = convert(VPolygon, X) + vlist = vertices_list(Xpoly) + m = length(vlist) + + if m <= 2 + return zero(N) + end + + if m == 3 # triangle + res = _area_triangle(vlist) + + elseif m == 4 # quadrilateral + res = _area_quadrilateral(vlist) + + else # general case + res = _area_polygon(vlist) + end + + return res +end + +function _area_triangle(v::Vector{VN}) where {N, VN<:AbstractVector{N}} + A = v[1] + B = v[2] + C = v[3] + res = A[1] * (B[2] - C[2]) + B[1] * (C[2] - A[2]) + C[1] * (A[2] - B[2]) + return abs(res/2) +end + +function _area_quadrilateral(v::Vector{VN}) where {N, VN<:AbstractVector{N}} + A = v[1] + B = v[2] + C = v[3] + D = v[4] + res = A[1] * (B[2] - D[2]) + B[1] * (C[2] - A[2]) + C[1] * (D[2] - B[2]) + D[1] * (A[2] - C[2]) + return abs(res/2) +end + +function _area_polygon(v::Vector{VN}) where {N, VN<:AbstractVector{N}} + m = length(v) + @inbounds res = v[m][1] * v[1][2] - v[1][1] * v[m][2] + for i in 1:m-1 + @inbounds res += v[i][1] * v[i+1][2] - v[i+1][1] * v[i][2] + end + return abs(res/2) +end + +""" + singleton_list(P::ConvexSet) + +Return the vertices of a polytopic set as a list of singletons. + +### Input + +- `P` -- polytopic set + +### Output + +The list of vertices of `P`, as `Singleton`. + +### Notes + +This function relies on `vertices_list`, which raises an error if the set is +not polytopic (e.g., unbounded). +""" +function singleton_list(P::ConvexSet) + return [Singleton(x) for x in vertices_list(P)] +end + +""" + concretize(X::ConvexSet) + +Construct a concrete representation of a (possibly lazy) set. + +### Input + +- `X` -- set + +### Output + +A concrete representation of `X` (as far as possible). + +### Notes + +Since not every lazy set has a concrete set representation in this library, the +result may be partially lazy. +""" +function concretize(X::ConvexSet) + return X +end + +""" + constraints(X::ConvexSet) + +Construct an iterator over the constraints of a polyhedral set. + +### Input + +- `X` -- polyhedral set + +### Output + +An iterator over the constraints of `X`. +""" +function constraints(X::ConvexSet) + return _constraints_fallback(X) +end + +""" + vertices(X::ConvexSet) + +Construct an iterator over the vertices of a polyhedral set. + +### Input + +- `X` -- polyhedral set + +### Output + +An iterator over the vertices of `X`. +""" +function vertices(X::ConvexSet) + return _vertices_fallback(X) +end + +function _constraints_fallback(X::ConvexSet) + return VectorIterator(constraints_list(X)) +end + +function _vertices_fallback(X::ConvexSet) + return VectorIterator(vertices_list(X)) +end + +# ========================= +# Code requiring MiniQhull +# ========================= + +function load_delaunay_MiniQhull() +return quote + +import .MiniQhull: delaunay +export delaunay + +""" + delaunay(X::ConvexSet) + +Compute the Delaunay triangulation of the given convex set. + +### Input + +- `X` -- set + +### Output + +A union of polytopes in vertex representation. + +### Notes + +This function requires that you have properly installed the package +[MiniQhull.jl](https://github.com/gridap/MiniQhull.jl), including the library +[Qhull](http://www.qhull.org/). + +The method works in arbitrary dimension and the requirement is that the list of +vertices of `X` can be obtained. +""" +function delaunay(X::ConvexSet) + n = dim(X) + v = vertices_list(X) + m = length(v) + coordinates = vcat(v...) + connectivity_matrix = delaunay(n, m, coordinates) + nelements = size(connectivity_matrix, 2) + elements = [VPolytope(v[connectivity_matrix[:, i]]) for i in 1:nelements] + return UnionSetArray(elements) +end + +end end # load_delaunay_MiniQhull + +""" + complement(X::ConvexSet) + +Return the complement of a set. + +### Input + +- `X` -- set + +### Output + +A `UnionSetArray` of half-spaces, i.e. the output is the union of the linear +constraints which are obtained by complementing each constraint of `X`. + +### Algorithm + +The principle used in this function is that if ``X`` and ``Y`` are any pair of sets, +then ``(X ∩ Y)^C = X^C ∪ Y^C``. In particular, we can apply this rule for each constraint +that defines a polyhedral set, hence the concrete complement can be represented as the set +union of the complement of each constraint. +""" +function complement(X::ConvexSet) + return UnionSetArray(constraints_list(Complement(X))) +end + +# -- concrete projection -- + +""" + project(S::ConvexSet{N}, + block::AbstractVector{Int}, + [::Nothing=nothing], + [n]::Int=dim(S); + [kwargs...] + ) where {N} + +Project a high-dimensional set to a given block by using a concrete linear map. + +### Input + +- `S` -- set +- `block` -- block structure - a vector with the dimensions of interest +- `nothing` -- (default: `nothing`) used for dispatch +- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` + +### Output + +A set representing the projection of the set `S` to block `block`. + +### Algorithm + +We apply the function `linear_map`. +""" +@inline function project(S::ConvexSet{N}, + block::AbstractVector{Int}, + ::Nothing=nothing, + n::Int=dim(S); + kwargs... + ) where {N} + return _project_linear_map(S, block, n; kwargs...) +end + +@inline function _project_linear_map(S::ConvexSet{N}, + block::AbstractVector{Int}, + n::Int=dim(S); + kwargs... + ) where {N} + M = projection_matrix(block, n, N) + return linear_map(M, S) +end + +""" + project(S::ConvexSet, + block::AbstractVector{Int}, + set_type::Type{TS}, + [n]::Int=dim(S); + [kwargs...] + ) where {TS<:ConvexSet} + +Project a high-dimensional set to a given block and set type, possibly involving +an overapproximation. + +### Input + +- `S` -- set +- `block` -- block structure - a vector with the dimensions of interest +- `set_type` -- target set type +- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` + +### Output + +A set of type `set_type` representing an overapproximation of the projection of +`S`. + +### Algorithm + +1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +coordinates and zero otherwise. +2. Overapproximate the projected lazy set using `overapproximate` and +`set_type`. +""" +@inline function project(S::ConvexSet, + block::AbstractVector{Int}, + set_type::Type{TS}, + n::Int=dim(S); + kwargs... + ) where {TS<:ConvexSet} + lm = project(S, block, LinearMap, n) + return overapproximate(lm, set_type) +end + +""" + project(S::ConvexSet, + block::AbstractVector{Int}, + set_type_and_precision::Pair{T, N}, + [n]::Int=dim(S); + [kwargs...] + ) where {T<:UnionAll, N<:Real} + +Project a high-dimensional set to a given block and set type with a certified +error bound. + +### Input + +- `S` -- set +- `block` -- block structure - a vector with the dimensions of interest +- `set_type_and_precision` -- pair `(T, ε)` of a target set type `T` and an + error bound `ε` for approximation +- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` + +### Output + +A set representing the epsilon-close approximation of the projection of `S`. + +### Notes + +Currently we only support `HPolygon` as set type, which implies that the set +must be two-dimensional. + +### Algorithm + +1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +coordinates and zero otherwise. +2. Overapproximate the projected lazy set with the given error bound `ε`. +""" +@inline function project(S::ConvexSet, + block::AbstractVector{Int}, + set_type_and_precision::Pair{T, N}, + n::Int=dim(S); + kwargs... + ) where {T<:UnionAll, N<:Real} + set_type = set_type_and_precision[1] + ε = set_type_and_precision[2] + @assert length(block) == 2 && set_type == HPolygon "currently only 2D " * + "HPolygon decomposition is supported" + + lm = project(S, block, LinearMap, n) + return overapproximate(lm, set_type, ε) +end + +""" + project(S::ConvexSet, + block::AbstractVector{Int}, + ε::Real, + [n]::Int=dim(S); + [kwargs...] + ) + +Project a high-dimensional set to a given block and set type with a certified +error bound. + +### Input + +- `S` -- set +- `block` -- block structure - a vector with the dimensions of interest +- `ε` -- error bound for approximation +- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` + +### Output + +A set representing the epsilon-close approximation of the projection of `S`. + +### Algorithm + +1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +coordinates and zero otherwise. +2. Overapproximate the projected lazy set with the given error bound `ε`. +The target set type is chosen automatically. +""" +@inline function project(S::ConvexSet, + block::AbstractVector{Int}, + ε::Real, + n::Int=dim(S); + kwargs... + ) + # currently we only support HPolygon + if length(block) == 2 + set_type = HPolygon + else + throw(ArgumentError("ε-close approximation is only supported for 2D " * + "blocks")) + end + return project(S, block, set_type => ε, n) +end + +""" + rectify(X::ConvexSet, [concrete_intersection]::Bool=false) + +Concrete rectification of a set. + +### Input + +- `X` -- set +- `concrete_intersection` -- (optional, default: `false`) flag to compute + concrete intersections for intermediate results + +### Output + +A set corresponding to the rectification of `X`, which is in general a union of +linear maps of intersections. + +### Algorithm + +For each dimension in which `X` is both positive and negative we split `X` into +these two parts. Additionally we project the negative part to zero. +""" +function rectify(X::ConvexSet, concrete_intersection::Bool=false) + return to_union_of_projections(Rectification(X), concrete_intersection) +end + +""" + low(X::ConvexSet, i::Int) + +Return the lower coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension of interest + +### Output + +The lower coordinate of the set in the given dimension. +""" +function low(X::ConvexSet{N}, i::Int) where {N} + n = dim(X) + d = SingleEntryVector(i, n, -one(N)) + return -ρ(d, X) +end + +""" + low(X::ConvexSet) + +Return a vector with the lowest coordinates of the set for each canonical direction. + +### Input + +- `X` -- set + +### Output + +A vector with the lower coordinate of the set for each dimension. + +### Notes + +See also [`low(X::ConvexSet, i::Int)`](@ref). +""" +function low(X::ConvexSet) + n = dim(X) + return [low(X, i) for i in 1:n] +end + +""" + high(X::ConvexSet, i::Int) + +Return the higher coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension of interest + +### Output + +The higher coordinate of the set in the given dimension. +""" +function high(X::ConvexSet{N}, i::Int) where {N} + n = dim(X) + d = SingleEntryVector(i, n, one(N)) + return ρ(d, X) +end + +""" + high(X::ConvexSet) + +Return a vector with the highest coordinate of the set for each canonical direction. + +### Input + +- `X` -- set + +### Output + +A vector with the highest coordinate of the set for each dimension. + +### Notes + +See also [`high(X::ConvexSet, i::Int)`](@ref). +""" +function high(X::ConvexSet) + n = dim(X) + return [high(X, i) for i in 1:n] +end + +""" + extrema(X::ConvexSet) + +Return two vectors with the lowest and highest coordinate of `X` for each +dimension. + +### Input + +- `X` -- set + +### Output + +Two vectors with the lowest and highest coordinates of `X` for each dimension. + +### Notes + +The result is equivalent to `(low(X), high(X))`, but sometimes it can be +computed more efficiently. +""" +function extrema(X::ConvexSet) + l = low(X) + h = high(X) + return (l, h) +end + +""" + extrema(X::ConvexSet, i::Int) + +Return the lower and higher coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension of interest + +### Output + +The lower and higher coordinate of the set in the given dimension. + +### Notes + +The result is equivalent to `(low(X, i), high(X, i))`, but sometimes it can be +computed more efficiently. +""" +function extrema(X::ConvexSet, i::Int) + l = low(X, i) + h = high(X, i) + return (l, h) +end + +""" + rationalize(::Type{T}, X::ConvexSet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} + +Approximate a ConvexSet of floating point numbers as a set whose entries are +rationals of the given integer type. + +### Input + +- `T` -- (optional, default: `Int`) integer type to represent the rationals +- `X` -- set which has floating-point components +- `tol` -- (optional, default: `eps(N)`) tolerance of the result; each rationalized + component will differ by no more than `tol` with respect to the floating-point value + +### Output + +A ConvexSet of the same base type of `X` where each numerical component is of +type `Rational{T}`. +""" +function rationalize(::Type{T}, X::ConvexSet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} + m = length(fieldnames(typeof(X))) + frat = ntuple(fi -> _rationalize(T, getfield(X, fi), tol), m) + ST = basetype(X) + return ST(frat...) +end + +rationalize(X::ConvexSet{N}; kwargs...) where {N<:AbstractFloat} = rationalize(Int, X; kwargs...) +rationalize(::Type{T}, X::ConvexSet{N}; tol::Real=eps(N)) where {T<:Integer, N<:AbstractFloat} = rationalize(T, X, tol) + +# method extension for lazy sets +_rationalize(::Type{T}, X::AbstractVector{<:ConvexSet{N}}, tol::Real) where {T<:Integer, N<:AbstractFloat} = rationalize.(Ref(T), X, Ref(tol)) +_rationalize(::Type{T}, X::ConvexSet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} = rationalize(T, X, tol) + +""" + permute(X::ConvexSet, p::AbstractVector{Int}) + +Permute the dimensions of a set according to a given permutation vector. + +### Input + +- `X` -- set +- `p` -- permutation vector + +### Output + +A new set corresponding to `X` where the dimensions have been permuted according +to `p`. +""" +function permute end diff --git a/src/Interfaces/LazySet.jl b/src/Interfaces/LazySet.jl index 570e415b60..9395c1e610 100644 --- a/src/Interfaces/LazySet.jl +++ b/src/Interfaces/LazySet.jl @@ -1,48 +1,9 @@ -import Base: ==, ≈, copy, eltype, rationalize, extrema -import Random.rand - -export LazySet, - basetype, - ρ, support_function, - σ, support_vector, - complement, - dim, - norm, - radius, - diameter, - an_element, - isbounded, - isboundedtype, - neutral, - absorbing, - tosimplehrep, - isuniversal, - translate, - affine_map, - exponential_map, - reflect, - is_interior_point, - isoperation, - isoperationtype, - isequivalent, - isconvextype, - is_polyhedral, - area, - surface, - singleton_list, - concretize, - constraints, - vertices, - project, - rectify, - permute +export LazySet """ LazySet{N} -Abstract type for convex sets, i.e., sets characterized by a (possibly infinite) -intersection of halfspaces, or equivalently, sets ``S`` such that for any two -elements ``x, y ∈ S`` and ``0 ≤ λ ≤ 1`` it holds that ``λ·x + (1-λ)·y ∈ S``. +Abstract type for the set types in LazySets.jl ### Notes @@ -65,21 +26,8 @@ The subtypes of `LazySet` (including abstract interfaces): ```jldoctest; setup = :(using LazySets: subtypes) julia> subtypes(LazySet, false) -14-element Vector{Any}: - AbstractAffineMap - AbstractCentrallySymmetric - AbstractPolyhedron - Bloating - CachedMinkowskiSumArray - CartesianProduct - CartesianProductArray - ConvexHull - ConvexHullArray - EmptySet - Intersection - IntersectionArray - MinkowskiSum - MinkowskiSumArray +1-element Vector{Any}: + ConvexSet ``` If we only consider *concrete* subtypes, then: @@ -135,1484 +83,7 @@ VPolygon VPolytope ZeroSet Zonotope -``` -""" -abstract type LazySet{N} end - - -# --- common LazySet functions --- - -""" - eltype(::Type{<:LazySet{N}}) where {N} - -Return the numeric type (`N`) of the given set type. - -### Input - -- `T` -- set type, used for dispatch - -### Output - -The numeric type of `T`. -""" -eltype(::Type{<:LazySet{N}}) where {N} = N - -""" - eltype(::LazySet{N}) where {N} - -Return the numeric type (`N`) of the given set. - -### Input - -- `X` -- set instance, used for dispatch - -### Output - -The numeric type of `X`. -""" -eltype(::LazySet{N}) where {N} = N - -""" - basetype(T::Type{<:LazySet}) - -Return the base type of the given set type (i.e., without type parameters). - -### Input - -- `T` -- set type, used for dispatch - -### Output - -The base type of `T`. -""" -basetype(T::Type{<:LazySet}) = Base.typename(T).wrapper - -""" - basetype(S::LazySet) - -Return the base type of the given set (i.e., without type parameters). - -### Input - -- `S` -- set instance, used for dispatch - -### Output - -The base type of `S`. - -### Examples - -```jldoctest -julia> z = rand(Zonotope); - -julia> basetype(z) -Zonotope - -julia> basetype(z + z) -MinkowskiSum - -julia> basetype(LinearMap(rand(2, 2), z + z)) -LinearMap -``` -""" -basetype(S::LazySet) = Base.typename(typeof(S)).wrapper - -""" - ρ(d::AbstractVector, S::LazySet) - -Evaluate the support function of a set in a given direction. - -### Input - -- `d` -- direction -- `S` -- convex set - -### Output - -The support function of the set `S` for the direction `d`. -""" -function ρ(d::AbstractVector, S::LazySet) - return dot(d, σ(d, S)) -end - -""" - support_function - -Alias for the support function ρ. -""" -const support_function = ρ - -""" - σ - -Function to compute the support vector σ. -""" -function σ end - -""" - support_vector - -Alias for the support vector σ. -""" -const support_vector = σ - -""" - isboundedtype(::Type{<:LazySet}) - -Determine whether a set type only represents bounded sets. - -### Input - -- `LazySet` -- set type for dispatch - -### Output - -`true` if the set type only represents bounded sets. -Note that some sets may still represent an unbounded set even though their type -actually does not (example: [`HPolytope`](@ref), because the construction with -non-bounding linear constraints is allowed). - -### Notes - -By default this function returns `false`. -All set types that can determine boundedness should override this behavior. -""" -function isboundedtype(::Type{T}) where {T<:LazySet} - return false -end - -""" - isbounded(S::LazySet) - -Determine whether a set is bounded. - -### Input - -- `S` -- set -- `algorithm` -- (optional, default: `"support_function"`) algorithm choice, - possible options are `"support_function"` and `"stiemke"` - -### Output - -`true` iff the set is bounded. - -### Algorithm - -See the documentation of `_isbounded_unit_dimensions` or `_isbounded_stiemke` -for details. -""" -function isbounded(S::LazySet; algorithm="support_function") - if algorithm == "support_function" - return _isbounded_unit_dimensions(S) - elseif algorithm == "stiemke" - return _isbounded_stiemke(S) - else - throw(ArgumentError("unknown algorithm $algorithm")) - end -end - -""" - _isbounded_unit_dimensions(S::LazySet{N}) where {N} - -Determine whether a set is bounded in each unit dimension. - -### Input - -- `S` -- set - -### Output - -`true` iff the set is bounded in each unit dimension. - -### Algorithm - -This function performs ``2n`` support function checks, where ``n`` is the -ambient dimension of `S`. -""" -function _isbounded_unit_dimensions(S::LazySet{N}) where {N} - n = dim(S) - @inbounds for i in 1:n - for o in [one(N), -one(N)] - d = SingleEntryVector(i, n, o) - if ρ(d, S) == N(Inf) - return false - end - end - end - return true -end - -""" - is_polyhedral(S::LazySet) - -Trait for polyhedral sets. - -### Input - -- `S` -- set - -### Output - -`true` only if the set behaves like an [`AbstractPolyhedron`](@ref). -The answer is conservative, i.e., may sometimes be `false` even if the set is -polyhedral. -""" -function is_polyhedral(S::LazySet) - return false -end - -""" - norm(S::LazySet, [p]::Real=Inf) - -Return the norm of a convex set. -It is the norm of the enclosing ball (of the given ``p``-norm) of minimal volume -that is centered in the origin. - -### Input - -- `S` -- convex set -- `p` -- (optional, default: `Inf`) norm - -### Output - -A real number representing the norm. -""" -function norm(S::LazySet, p::Real=Inf) - if p == Inf - return norm(box_approximation(S), p) - elseif applicable(vertices_list, S) - return maximum(norm(v, p) for v in vertices_list(S)) - else - error("the norm for this value of p=$p is not implemented") - end -end - -""" - radius(S::LazySet, [p]::Real=Inf) - -Return the radius of a convex set. -It is the radius of the enclosing ball (of the given ``p``-norm) of minimal -volume with the same center. - -### Input - -- `S` -- convex set -- `p` -- (optional, default: `Inf`) norm - -### Output - -A real number representing the radius. -""" -function radius(S::LazySet, p::Real=Inf) - if p == Inf - return radius(Approximations.ballinf_approximation(S), p) - else - error("the radius for this value of p=$p is not implemented") - end -end - -""" - diameter(S::LazySet, [p]::Real=Inf) - -Return the diameter of a convex set. -It is the maximum distance between any two elements of the set, or, -equivalently, the diameter of the enclosing ball (of the given ``p``-norm) of -minimal volume with the same center. - -### Input - -- `S` -- convex set -- `p` -- (optional, default: `Inf`) norm - -### Output -A real number representing the diameter. -""" -function diameter(S::LazySet, p::Real=Inf) - return radius(S, p) * 2 -end - -""" - affine_map(M::AbstractMatrix, X::LazySet, v::AbstractVector; kwargs...) - -Compute a concrete affine map. - -### Input - -- `M` -- linear map -- `X` -- convex set -- `v` -- translation vector - -### Output - -A set representing the affine map of `X`. - -### Algorithm - -The implementation applies the functions `linear_map` and `translate`. -""" -function affine_map(M::AbstractMatrix, X::LazySet, v::AbstractVector; kwargs...) - return translate(linear_map(M, X; kwargs...), v) -end - -""" - exponential_map(M::AbstractMatrix, X::LazySet) - -Compute the concrete exponential map of `M` and `X`, i.e., `exp(M) * X`. - -### Input - -- `M` -- matrix -- `X` -- set - -### Output - -A set representing the exponential map of `M` and `X`. - -### Algorithm - -The implementation applies the functions `exp` and `linear_map`. -""" -function exponential_map(M::AbstractMatrix, X::LazySet) - return linear_map(exp(M), X) -end - -""" - an_element(S::LazySet{N}) where {N} - -Return some element of a convex set. - -### Input - -- `S` -- convex set - -### Output - -An element of a convex set. - -### Algorithm - -An element of the set is obtained by evaluating its support vector along -direction ``[1, 0, …, 0]``. -""" -function an_element(S::LazySet{N}) where {N} - e₁ = SingleEntryVector(1, dim(S), one(N)) - return σ(e₁, S) -end - -""" - ==(X::LazySet, Y::LazySet) - -Return whether two LazySets of the same type are exactly equal. - -### Input - -- `X` -- any `LazySet` -- `Y` -- another `LazySet` of the same type as `X` - -### Output - -- `true` iff `X` is equal to `Y`. - -### Notes - -The check is purely syntactic and the sets need to have the same base type. -For instance, `X::VPolytope == Y::HPolytope` returns `false` even if `X` and `Y` -represent the same polytope. -However `X::HPolytope{Int64} == Y::HPolytope{Float64}` is a valid comparison. - -### Algorithm - -We recursively compare the fields of `X` and `Y` until a mismatch is found. - -### Examples - -```jldoctest -julia> HalfSpace([1], 1) == HalfSpace([1], 1) -true - -julia> HalfSpace([1], 1) == HalfSpace([1.0], 1.0) -true - -julia> Ball1([0.], 1.) == Ball2([0.], 1.) -false -``` -""" -function ==(X::LazySet, Y::LazySet) - # if the common supertype of X and Y is abstract, they cannot be compared - if isabstracttype(promote_type(typeof(X), typeof(Y))) - return false - end - - for f in fieldnames(typeof(X)) - if getfield(X, f) != getfield(Y, f) - return false - end - end - - return true -end -""" - ≈(X::LazySet, Y::LazySet) - -Return whether two LazySets of the same type are approximately equal. - -### Input - -- `X` -- any `LazySet` -- `Y` -- another `LazySet` of the same type as `X` - -### Output - -- `true` iff `X` is equal to `Y`. - -### Notes - -The check is purely syntactic and the sets need to have the same base type. -For instance, `X::VPolytope ≈ Y::HPolytope` returns `false` even if `X` and `Y` -represent the same polytope. -However `X::HPolytope{Int64} ≈ Y::HPolytope{Float64}` is a valid comparison. - -### Algorithm - -We recursively compare the fields of `X` and `Y` until a mismatch is found. - -### Examples - -```jldoctest -julia> HalfSpace([1], 1) ≈ HalfSpace([1], 1) -true - -julia> HalfSpace([1], 1) ≈ HalfSpace([1.00000001], 0.99999999) -true - -julia> HalfSpace([1], 1) ≈ HalfSpace([1.0], 1.0) -true - -julia> Ball1([0.], 1.) ≈ Ball2([0.], 1.) -false -``` -""" -function ≈(X::LazySet, Y::LazySet) - # if the common supertype of X and Y is abstract, they cannot be compared - if isabstracttype(promote_type(typeof(X), typeof(Y))) - return false - end - - for f in fieldnames(typeof(X)) - if !_isapprox(getfield(X, f), getfield(Y, f)) - return false - end - end - - return true -end - -# hook into random API -function rand(rng::AbstractRNG, ::SamplerType{T}) where T<:LazySet - rand(T, rng=rng) -end - -""" - copy(S::LazySet) - -Return a copy of the given set by copying its values recursively. - -### Input - -- `S` -- any `LazySet` - -### Output - -A copy of `S`. - -### Notes - -This function performs a `copy` of each field in `S`. -See the documentation of `?copy` for further details. -""" -function copy(S::T) where {T<:LazySet} - args = [copy(getfield(S, f)) for f in fieldnames(T)] - BT = basetype(S) - return BT(args...) -end - -""" - tosimplehrep(S::LazySet) - -Return the simple H-representation ``Ax ≤ b`` of a set from its list of linear -constraints. - -### Input - -- `S` -- set - -### Output - -The tuple `(A, b)` where `A` is the matrix of normal directions and `b` is the -vector of offsets. - -### Notes - -This function only works for sets that can be represented exactly by a finite -list of linear constraints. -This fallback implementation relies on `constraints_list(S)`. -""" -tosimplehrep(S::LazySet) = tosimplehrep(constraints_list(S)) - -""" - reflect(P::LazySet) - -Concrete reflection of a convex set `P`, resulting in the reflected set `-P`. - -### Note - -This function requires that the list of constraints of the set `P` is -available, i.e. such that it can be written as -``P = \\{z ∈ ℝⁿ: ⋂ sᵢᵀz ≤ rᵢ, i = 1, ..., N\\}.`` - -This function can be used to implement the alternative definition of the -Minkowski Difference, which writes as -```math -A ⊖ B = \\{a − b | a ∈ A, b ∈ B\\} = A ⊕ (-B) ``` -by calling `minkowski_sum(A, reflect(B))`. -""" -function reflect(P::LazySet) - @assert applicable(constraints_list, P) "this function " * - "requires that the list of constraints is available, but it is not; " * - "if the set is bounded, try overapproximating with an `HPolytope` first" - - F, g = tosimplehrep(P) - T = isbounded(P) ? HPolytope : HPolyhedron - return T(-F, g) -end - -""" - isuniversal(X::LazySet{N}, [witness]::Bool=false) where {N} - -Check whether a given convex set is universal, and otherwise optionally compute -a witness. - -### Input - -- `X` -- convex set -- `witness` -- (optional, default: `false`) compute a witness if activated - -### Output - -* If `witness` option is deactivated: `true` iff ``X`` is universal -* If `witness` option is activated: - * `(true, [])` iff ``X`` is universal - * `(false, v)` iff ``X`` is not universal and ``v ∉ X`` - -### Notes - -This is a naive fallback implementation. """ -function isuniversal(X::LazySet{N}, witness::Bool=false) where {N} - if isbounded(X) - result = false - else - error("cannot determine universality of the set") - end - - if result - return witness ? (true, N[]) : true - elseif witness - error("witness production is currently not supported") - else - return false - end -end - -""" - is_interior_point(d::AbstractVector{N}, P::LazySet{N}; - p=N(Inf), ε=_rtol(N)) where {N<:Real} - -Check if the point `d` is contained in the interior of the convex set `P`. - -### Input - -- `d` -- point -- `P` -- set -- `p` -- (optional; default: `N(Inf)`) norm of the ball used to apply the error - tolerance -- `ε` -- (optional; default: `_rtol(N)`) error tolerance of check - -### Output - -Boolean which indicates if the point `d` is contained in `P`. - -### Algorithm - -The implementation checks if a `Ballp` of norm `p` with center `d` and radius -`ε` is contained in the set `P`. -This is a numerical check for `d ∈ interior(P)` with error tolerance `ε`. -""" -function is_interior_point(d::AbstractVector{N}, P::LazySet{N}; - p=N(Inf), ε=_rtol(N)) where {N<:Real} - return Ballp(p, d, ε) ⊆ P -end - -""" - plot_recipe(X::LazySet{N}, [ε]=N(PLOT_PRECISION)) where {N} - -Convert a convex set to a pair `(x, y)` of points for plotting. - -### Input - -- `X` -- convex set -- `ε` -- (optional, default: `PLOT_PRECISION`) approximation error bound - -### Output - -A pair `(x, y)` of points that can be plotted. - -### Algorithm - -We first assert that `X` is bounded. - -One-dimensional sets are converted to an `Interval`. -We do not support three-dimensional or higher-dimensional sets at the moment. - -For two-dimensional sets, we first compute a polygonal overapproximation. -The second argument, `ε`, corresponds to the error in Hausdorff distance between -the overapproximating set and `X`. -The default value `PLOT_PRECISION` is chosen such that the unit ball in the -2-norm is approximated with reasonable accuracy. -On the other hand, if you only want to produce a fast box-overapproximation of -`X`, pass `ε=Inf`. -Finally, we use the plot recipe for polygons. -""" -function plot_recipe(X::LazySet{N}, ε=N(PLOT_PRECISION)) where {N} - @assert dim(X) <= 2 "cannot plot a $(dim(X))-dimensional $(typeof(X))" - @assert isbounded(X) "cannot plot an unbounded $(typeof(X))" - - if dim(X) == 1 - Y = convert(Interval, X) - else - Y = overapproximate(X, ε) - end - return plot_recipe(Y, ε) -end - -""" - isoperation(X::LazySet) - -Check whether the given `LazySet` is an instance of a set operation or not. - -### Input - -- `X` -- a `LazySet` - -### Output - -`true` if `X` is an instance of a set-based operation and `false` otherwise. - -### Notes - -The fallback implementation returns whether the set type of the input is an -operation or not using `isoperationtype`. - -See also [`isoperationtype(X::Type{<:LazySet})`](@ref). - -### Examples - -```jldoctest -julia> B = BallInf([0.0, 0.0], 1.0); - -julia> isoperation(B) -false - -julia> isoperation(B ⊕ B) -true -``` -""" -function isoperation(X::LazySet) - return isoperationtype(typeof(X)) -end - -isoperation(::Type{<:LazySet}) = error("`isoperation` cannot be applied to a set " * - "type; use `isoperationtype` instead") - -""" - isoperationtype(X::Type{<:LazySet}) - -Check whether the given `LazySet` type is an operation or not. - -### Input - -- `X` -- subtype of `LazySet` - -### Output - -`true` if the given set type is a set-based operation and `false` otherwise. - -### Notes - -The fallback for this function returns an error that `isoperationtype` is not -implemented. Subtypes of `LazySet` should dispatch on this function as required. - -See also [`isoperation(X<:LazySet)`](@ref). - -### Examples - -```jldoctest -julia> isoperationtype(BallInf) -false - -julia> isoperationtype(LinearMap) -true -``` -""" -function isoperationtype(X::Type{<:LazySet}) - error("`isoperationtype` is not implemented for type $X") -end - -isoperationtype(::LazySet) = error("`isoperationtype` cannot be applied to " * - "a set instance; use `isoperation` instead") - -""" - isequivalent(X::LazySet, Y::LazySet) - -Return whether two LazySets are equal in the mathematical sense, i.e. equivalent. - -### Input - -- `X` -- any `LazySet` -- `Y` -- another `LazySet` - -### Output - -`true` iff `X` is equivalent to `Y`. - -## Algorithm - -First we check `X ≈ Y`, which returns `true` if and only if `X` and `Y` have the -same type and approximately the same values (checked with `LazySets._isapprox`). -If that fails, we check the double inclusion `X ⊆ Y && Y ⊆ X`. - -### Examples - -```jldoctest -julia> X = BallInf([0.1, 0.2], 0.3); - -julia> Y = convert(HPolytope, X); - -julia> X == Y -false - -julia> isequivalent(X, Y) -true -``` -""" -function isequivalent(X::LazySet, Y::LazySet) - try # TODO temporary try-catch construct until ≈ is fixed for all set types - if X ≈ Y - return true - end - catch e - end - return _isequivalent_inclusion(X, Y) -end - -function _isequivalent_inclusion(X::LazySet, Y::LazySet) - return X ⊆ Y && Y ⊆ X -end - -""" - isconvextype(X::Type{<:LazySet}) - -Check whether the given `LazySet` type is convex. - -### Input - -- `X` -- subtype of `LazySet` - -### Output - -`true` if the given set type is guaranteed to be convex by using only type -information, and `false` otherwise. - -### Notes - -Since this operation only acts on types (not on values), it can return false -negatives, i.e. there may be instances where the set is convex, even though the -answer of this function is `false`. The examples below illustrate this point. - -### Examples - -A ball in the infinity norm is always convex, hence we get: - -```jldoctest convex_types -julia> isconvextype(BallInf) -true -``` - -For instance, the union (`UnionSet`) of two sets may in general be either convex -or not, since convexity cannot be decided by just using type information. -Hence, `isconvextype` returns `false` if `X` is `Type{<:UnionSet}`. - -```jldoctest convex_types -julia> isconvextype(UnionSet) -false -``` - -However, the type parameters from the set operations allow to decide convexity -in some cases, by falling back to the convexity of the type of its arguments. -Consider for instance the lazy intersection. The intersection of two convex sets -is always convex, hence we can get: - -```jldoctest convex_types -julia> isconvextype(Intersection{Float64, BallInf{Float64}, BallInf{Float64}}) -true -``` -""" -isconvextype(X::Type{<:LazySet}) = false - -""" - surface(X::LazySet{N}) where {N} - -Compute the surface area of a set. - -### Input - -- `X` -- set - -### Output - -A number representing the surface area of `X`. -""" -function surface(X::LazySet{N}) where {N} - if dim(X) == 2 - return area(X) - else - throw(ArgumentError("the surface function is only implemented for " * - "two-dimensional sets, but the given set is $(dim(X))-dimensional")) - end -end - -""" - area(X::LazySet{N}) where {N} - -Compute the area of a two-dimensional polytopic set using the Shoelace formula. - -### Input - -- `X` -- two-dimensional set - -### Output - -A number representing the area of `X`. - -### Notes - -This algorithm is applicable to any lazy set `X` such that its list of vertices, -`vertices_list`, can be computed. - -### Algorithm - -Let `m` be the number of vertices of `X`. The following instances are considered: - -- `m = 0, 1, 2`: the output is zero. -- `m = 3`: the triangle case is computed using the Shoelace formula with 3 points. -- `m = 4`: the quadrilateral case is obtained by the factored version of the Shoelace - formula with 4 points. - -Otherwise, the general Shoelace formula is used; for detals see the wikipedia -article [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula). -""" -function area(X::LazySet{N}) where {N} - @assert dim(X) == 2 "this function only applies to two-dimensional sets, " * - "but the given set is $(dim(X))-dimensional" - - Xpoly = convert(VPolygon, X) - vlist = vertices_list(Xpoly) - m = length(vlist) - - if m <= 2 - return zero(N) - end - - if m == 3 # triangle - res = _area_triangle(vlist) - - elseif m == 4 # quadrilateral - res = _area_quadrilateral(vlist) - - else # general case - res = _area_polygon(vlist) - end - - return res -end - -function _area_triangle(v::Vector{VN}) where {N, VN<:AbstractVector{N}} - A = v[1] - B = v[2] - C = v[3] - res = A[1] * (B[2] - C[2]) + B[1] * (C[2] - A[2]) + C[1] * (A[2] - B[2]) - return abs(res/2) -end - -function _area_quadrilateral(v::Vector{VN}) where {N, VN<:AbstractVector{N}} - A = v[1] - B = v[2] - C = v[3] - D = v[4] - res = A[1] * (B[2] - D[2]) + B[1] * (C[2] - A[2]) + C[1] * (D[2] - B[2]) + D[1] * (A[2] - C[2]) - return abs(res/2) -end - -function _area_polygon(v::Vector{VN}) where {N, VN<:AbstractVector{N}} - m = length(v) - @inbounds res = v[m][1] * v[1][2] - v[1][1] * v[m][2] - for i in 1:m-1 - @inbounds res += v[i][1] * v[i+1][2] - v[i+1][1] * v[i][2] - end - return abs(res/2) -end - -""" - singleton_list(P::LazySet) - -Return the vertices of a polytopic set as a list of singletons. - -### Input - -- `P` -- polytopic set - -### Output - -The list of vertices of `P`, as `Singleton`. - -### Notes - -This function relies on `vertices_list`, which raises an error if the set is -not polytopic (e.g., unbounded). -""" -function singleton_list(P::LazySet) - return [Singleton(x) for x in vertices_list(P)] -end - -""" - concretize(X::LazySet) - -Construct a concrete representation of a (possibly lazy) set. - -### Input - -- `X` -- set - -### Output - -A concrete representation of `X` (as far as possible). - -### Notes - -Since not every lazy set has a concrete set representation in this library, the -result may be partially lazy. -""" -function concretize(X::LazySet) - return X -end - -""" - constraints(X::LazySet) - -Construct an iterator over the constraints of a polyhedral set. - -### Input - -- `X` -- polyhedral set - -### Output - -An iterator over the constraints of `X`. -""" -function constraints(X::LazySet) - return _constraints_fallback(X) -end - -""" - vertices(X::LazySet) - -Construct an iterator over the vertices of a polyhedral set. - -### Input - -- `X` -- polyhedral set - -### Output - -An iterator over the vertices of `X`. -""" -function vertices(X::LazySet) - return _vertices_fallback(X) -end - -function _constraints_fallback(X::LazySet) - return VectorIterator(constraints_list(X)) -end - -function _vertices_fallback(X::LazySet) - return VectorIterator(vertices_list(X)) -end - -# ========================= -# Code requiring MiniQhull -# ========================= - -function load_delaunay_MiniQhull() -return quote - -import .MiniQhull: delaunay -export delaunay - -""" - delaunay(X::LazySet) - -Compute the Delaunay triangulation of the given convex set. - -### Input - -- `X` -- set - -### Output - -A union of polytopes in vertex representation. - -### Notes - -This function requires that you have properly installed the package -[MiniQhull.jl](https://github.com/gridap/MiniQhull.jl), including the library -[Qhull](http://www.qhull.org/). - -The method works in arbitrary dimension and the requirement is that the list of -vertices of `X` can be obtained. -""" -function delaunay(X::LazySet) - n = dim(X) - v = vertices_list(X) - m = length(v) - coordinates = vcat(v...) - connectivity_matrix = delaunay(n, m, coordinates) - nelements = size(connectivity_matrix, 2) - elements = [VPolytope(v[connectivity_matrix[:, i]]) for i in 1:nelements] - return UnionSetArray(elements) -end - -end end # load_delaunay_MiniQhull - -""" - complement(X::LazySet) - -Return the complement of a set. - -### Input - -- `X` -- set - -### Output - -A `UnionSetArray` of half-spaces, i.e. the output is the union of the linear -constraints which are obtained by complementing each constraint of `X`. - -### Algorithm - -The principle used in this function is that if ``X`` and ``Y`` are any pair of sets, -then ``(X ∩ Y)^C = X^C ∪ Y^C``. In particular, we can apply this rule for each constraint -that defines a polyhedral set, hence the concrete complement can be represented as the set -union of the complement of each constraint. -""" -function complement(X::LazySet) - return UnionSetArray(constraints_list(Complement(X))) -end - -# -- concrete projection -- - -""" - project(S::LazySet{N}, - block::AbstractVector{Int}, - [::Nothing=nothing], - [n]::Int=dim(S); - [kwargs...] - ) where {N} - -Project a high-dimensional set to a given block by using a concrete linear map. - -### Input - -- `S` -- set -- `block` -- block structure - a vector with the dimensions of interest -- `nothing` -- (default: `nothing`) used for dispatch -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` - -### Output - -A set representing the projection of the set `S` to block `block`. - -### Algorithm - -We apply the function `linear_map`. -""" -@inline function project(S::LazySet{N}, - block::AbstractVector{Int}, - ::Nothing=nothing, - n::Int=dim(S); - kwargs... - ) where {N} - return _project_linear_map(S, block, n; kwargs...) -end - -@inline function _project_linear_map(S::LazySet{N}, - block::AbstractVector{Int}, - n::Int=dim(S); - kwargs... - ) where {N} - M = projection_matrix(block, n, N) - return linear_map(M, S) -end - -""" - project(S::LazySet, - block::AbstractVector{Int}, - set_type::Type{TS}, - [n]::Int=dim(S); - [kwargs...] - ) where {TS<:LazySet} - -Project a high-dimensional set to a given block and set type, possibly involving -an overapproximation. - -### Input - -- `S` -- set -- `block` -- block structure - a vector with the dimensions of interest -- `set_type` -- target set type -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` - -### Output - -A set of type `set_type` representing an overapproximation of the projection of -`S`. - -### Algorithm - -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block -coordinates and zero otherwise. -2. Overapproximate the projected lazy set using `overapproximate` and -`set_type`. -""" -@inline function project(S::LazySet, - block::AbstractVector{Int}, - set_type::Type{TS}, - n::Int=dim(S); - kwargs... - ) where {TS<:LazySet} - lm = project(S, block, LinearMap, n) - return overapproximate(lm, set_type) -end - -""" - project(S::LazySet, - block::AbstractVector{Int}, - set_type_and_precision::Pair{T, N}, - [n]::Int=dim(S); - [kwargs...] - ) where {T<:UnionAll, N<:Real} - -Project a high-dimensional set to a given block and set type with a certified -error bound. - -### Input - -- `S` -- set -- `block` -- block structure - a vector with the dimensions of interest -- `set_type_and_precision` -- pair `(T, ε)` of a target set type `T` and an - error bound `ε` for approximation -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` - -### Output - -A set representing the epsilon-close approximation of the projection of `S`. - -### Notes - -Currently we only support `HPolygon` as set type, which implies that the set -must be two-dimensional. - -### Algorithm - -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block -coordinates and zero otherwise. -2. Overapproximate the projected lazy set with the given error bound `ε`. -""" -@inline function project(S::LazySet, - block::AbstractVector{Int}, - set_type_and_precision::Pair{T, N}, - n::Int=dim(S); - kwargs... - ) where {T<:UnionAll, N<:Real} - set_type = set_type_and_precision[1] - ε = set_type_and_precision[2] - @assert length(block) == 2 && set_type == HPolygon "currently only 2D " * - "HPolygon decomposition is supported" - - lm = project(S, block, LinearMap, n) - return overapproximate(lm, set_type, ε) -end - -""" - project(S::LazySet, - block::AbstractVector{Int}, - ε::Real, - [n]::Int=dim(S); - [kwargs...] - ) - -Project a high-dimensional set to a given block and set type with a certified -error bound. - -### Input - -- `S` -- set -- `block` -- block structure - a vector with the dimensions of interest -- `ε` -- error bound for approximation -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` - -### Output - -A set representing the epsilon-close approximation of the projection of `S`. - -### Algorithm - -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block -coordinates and zero otherwise. -2. Overapproximate the projected lazy set with the given error bound `ε`. -The target set type is chosen automatically. -""" -@inline function project(S::LazySet, - block::AbstractVector{Int}, - ε::Real, - n::Int=dim(S); - kwargs... - ) - # currently we only support HPolygon - if length(block) == 2 - set_type = HPolygon - else - throw(ArgumentError("ε-close approximation is only supported for 2D " * - "blocks")) - end - return project(S, block, set_type => ε, n) -end - -""" - rectify(X::LazySet, [concrete_intersection]::Bool=false) - -Concrete rectification of a set. - -### Input - -- `X` -- set -- `concrete_intersection` -- (optional, default: `false`) flag to compute - concrete intersections for intermediate results - -### Output - -A set corresponding to the rectification of `X`, which is in general a union of -linear maps of intersections. - -### Algorithm - -For each dimension in which `X` is both positive and negative we split `X` into -these two parts. Additionally we project the negative part to zero. -""" -function rectify(X::LazySet, concrete_intersection::Bool=false) - return to_union_of_projections(Rectification(X), concrete_intersection) -end - -""" - low(X::LazySet, i::Int) - -Return the lower coordinate of a set in a given dimension. - -### Input - -- `X` -- set -- `i` -- dimension of interest - -### Output - -The lower coordinate of the set in the given dimension. -""" -function low(X::LazySet{N}, i::Int) where {N} - n = dim(X) - d = SingleEntryVector(i, n, -one(N)) - return -ρ(d, X) -end - -""" - low(X::LazySet) - -Return a vector with the lowest coordinates of the set for each canonical direction. - -### Input - -- `X` -- set - -### Output - -A vector with the lower coordinate of the set for each dimension. - -### Notes - -See also [`low(X::LazySet, i::Int)`](@ref). -""" -function low(X::LazySet) - n = dim(X) - return [low(X, i) for i in 1:n] -end - -""" - high(X::LazySet, i::Int) - -Return the higher coordinate of a set in a given dimension. - -### Input - -- `X` -- set -- `i` -- dimension of interest - -### Output - -The higher coordinate of the set in the given dimension. -""" -function high(X::LazySet{N}, i::Int) where {N} - n = dim(X) - d = SingleEntryVector(i, n, one(N)) - return ρ(d, X) -end - -""" - high(X::LazySet) - -Return a vector with the highest coordinate of the set for each canonical direction. - -### Input - -- `X` -- set - -### Output - -A vector with the highest coordinate of the set for each dimension. - -### Notes - -See also [`high(X::LazySet, i::Int)`](@ref). -""" -function high(X::LazySet) - n = dim(X) - return [high(X, i) for i in 1:n] -end - -""" - extrema(X::LazySet) - -Return two vectors with the lowest and highest coordinate of `X` for each -dimension. - -### Input - -- `X` -- set - -### Output - -Two vectors with the lowest and highest coordinates of `X` for each dimension. - -### Notes - -The result is equivalent to `(low(X), high(X))`, but sometimes it can be -computed more efficiently. -""" -function extrema(X::LazySet) - l = low(X) - h = high(X) - return (l, h) -end - -""" - extrema(X::LazySet, i::Int) - -Return the lower and higher coordinate of a set in a given dimension. - -### Input - -- `X` -- set -- `i` -- dimension of interest - -### Output - -The lower and higher coordinate of the set in the given dimension. - -### Notes - -The result is equivalent to `(low(X, i), high(X, i))`, but sometimes it can be -computed more efficiently. -""" -function extrema(X::LazySet, i::Int) - l = low(X, i) - h = high(X, i) - return (l, h) -end - -""" - rationalize(::Type{T}, X::LazySet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} - -Approximate a LazySet of floating point numbers as a set whose entries are -rationals of the given integer type. - -### Input - -- `T` -- (optional, default: `Int`) integer type to represent the rationals -- `X` -- set which has floating-point components -- `tol` -- (optional, default: `eps(N)`) tolerance of the result; each rationalized - component will differ by no more than `tol` with respect to the floating-point value - -### Output - -A LazySet of the same base type of `X` where each numerical component is of -type `Rational{T}`. -""" -function rationalize(::Type{T}, X::LazySet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} - m = length(fieldnames(typeof(X))) - frat = ntuple(fi -> _rationalize(T, getfield(X, fi), tol), m) - ST = basetype(X) - return ST(frat...) -end - -rationalize(X::LazySet{N}; kwargs...) where {N<:AbstractFloat} = rationalize(Int, X; kwargs...) -rationalize(::Type{T}, X::LazySet{N}; tol::Real=eps(N)) where {T<:Integer, N<:AbstractFloat} = rationalize(T, X, tol) - -# method extension for lazy sets -_rationalize(::Type{T}, X::AbstractVector{<:LazySet{N}}, tol::Real) where {T<:Integer, N<:AbstractFloat} = rationalize.(Ref(T), X, Ref(tol)) -_rationalize(::Type{T}, X::LazySet{N}, tol::Real) where {T<:Integer, N<:AbstractFloat} = rationalize(T, X, tol) - -""" - permute(X::LazySet, p::AbstractVector{Int}) - -Permute the dimensions of a set according to a given permutation vector. - -### Input - -- `X` -- set -- `p` -- permutation vector - -### Output - -A new set corresponding to `X` where the dimensions have been permuted according -to `p`. -""" -function permute end +abstract type LazySet{N} end diff --git a/src/LazyOperations/AffineMap.jl b/src/LazyOperations/AffineMap.jl index ee3cc97631..1f17730003 100644 --- a/src/LazyOperations/AffineMap.jl +++ b/src/LazyOperations/AffineMap.jl @@ -1,7 +1,7 @@ export AffineMap """ - AffineMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}, + AffineMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}, VN<:AbstractVector{NM}} <: AbstractAffineMap{N, S} Type that represents an affine transformation ``M⋅X ⊕ v`` of a set ``X``, @@ -81,14 +81,14 @@ julia> AffineMap(A, EmptySet{Int}(2), b3) EmptySet{Int64}(2) ``` """ -struct AffineMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}, +struct AffineMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}, VN<:AbstractVector{NM}} <: AbstractAffineMap{N, S} M::MAT X::S v::VN # default constructor with dimension match check - function AffineMap(M::MAT, X::S, v::VN) where {N, S<:LazySet{N}, NM, + function AffineMap(M::MAT, X::S, v::VN) where {N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}, VN<:AbstractVector{NM}} @@ -107,12 +107,12 @@ isoperationtype(::Type{<:AffineMap}) = true isconvextype(::Type{<:AffineMap{N, S}}) where {N, S} = isconvextype(S) # convenience constructor from a UniformScaling -function AffineMap(M::UniformScaling, X::LazySet, v::AbstractVector) +function AffineMap(M::UniformScaling, X::ConvexSet, v::AbstractVector) return AffineMap(M.λ, X, v) end # convenience constructor from a scalar -function AffineMap(α::N, X::LazySet, v::AbstractVector) where {N<:Real} +function AffineMap(α::N, X::ConvexSet, v::AbstractVector) where {N<:Real} if α == one(N) return Translation(X, v) end @@ -163,7 +163,7 @@ function set(am::AffineMap) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- function concretize(am::AffineMap) diff --git a/src/LazyOperations/Bloating.jl b/src/LazyOperations/Bloating.jl index 333d70dcfb..af9b8ae9ec 100644 --- a/src/LazyOperations/Bloating.jl +++ b/src/LazyOperations/Bloating.jl @@ -1,7 +1,7 @@ export Bloating """ - Bloating{N, S<:LazySet{N}} <: LazySet{N} + Bloating{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents a uniform expansion of a set in a given norm (also known as *bloating*). @@ -21,12 +21,12 @@ of `X` and a ball in the `p`-norm of radius `ε` centered in the origin `O` The `Bloating` operation preserves convexity: if `X` is convex, then any bloating of `X` is convex as well. """ -struct Bloating{N, S<:LazySet{N}} <: LazySet{N} +struct Bloating{N, S<:ConvexSet{N}} <: ConvexSet{N} X::S ε::N p::N - function Bloating(X::S, ε::N, p::N=N(2)) where {N, S<:LazySet{N}} + function Bloating(X::S, ε::N, p::N=N(2)) where {N, S<:ConvexSet{N}} @assert p >= one(N) "bloating requires a norm >= 1, but $p was given" return new{N, S}(X, ε, p) diff --git a/src/LazyOperations/CachedMinkowskiSumArray.jl b/src/LazyOperations/CachedMinkowskiSumArray.jl index 9d694cd2d6..b1396de454 100644 --- a/src/LazyOperations/CachedMinkowskiSumArray.jl +++ b/src/LazyOperations/CachedMinkowskiSumArray.jl @@ -30,7 +30,7 @@ function getindex(cp::CachedPair, idx::Int) end """ - CachedMinkowskiSumArray{N, S<:LazySet{N}} <: LazySet{N} + CachedMinkowskiSumArray{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents the Minkowski sum of a finite number of sets. Support vector queries are cached. @@ -58,17 +58,17 @@ their Minkowski sum is convex as well. Constructors: -- `CachedMinkowskiSumArray(array::Vector{<:LazySet})` -- default constructor +- `CachedMinkowskiSumArray(array::Vector{<:ConvexSet})` -- default constructor - `CachedMinkowskiSumArray([n]::Int=0, [N]::Type=Float64)` -- constructor for an empty sum with optional size hint and numeric type """ -struct CachedMinkowskiSumArray{N, S<:LazySet{N}} <: LazySet{N} +struct CachedMinkowskiSumArray{N, S<:ConvexSet{N}} <: ConvexSet{N} array::Vector{S} cache::Dict{AbstractVector{N}, CachedPair{N}} # default constructor that initializes cache - CachedMinkowskiSumArray(arr::Vector{S}) where {N, S<:LazySet{N}} = + CachedMinkowskiSumArray(arr::Vector{S}) where {N, S<:ConvexSet{N}} = new{N, S}(arr, Dict{AbstractVector{N}, CachedPair{N}}()) end @@ -77,7 +77,7 @@ isconvextype(::Type{CachedMinkowskiSumArray{N, S}}) where {N, S} = isconvextype( # constructor for an empty sum with optional size hint and numeric type function CachedMinkowskiSumArray(n::Int=0, N::Type=Float64) - arr = Vector{LazySet{N}}() + arr = Vector{ConvexSet{N}}() sizehint!(arr, n) return CachedMinkowskiSumArray(arr) end diff --git a/src/LazyOperations/CartesianProduct.jl b/src/LazyOperations/CartesianProduct.jl index 7a96012f44..bcc53ab0d5 100644 --- a/src/LazyOperations/CartesianProduct.jl +++ b/src/LazyOperations/CartesianProduct.jl @@ -5,7 +5,7 @@ export CartesianProduct, swap """ - CartesianProduct{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} + CartesianProduct{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} Type that represents the Cartesian product of two sets, that is the set @@ -58,10 +58,10 @@ julia> convert(Hyperrectangle, I12) Hyperrectangle{Float64, Vector{Float64}, Vector{Float64}}([0.5, 3.0], [0.5, 1.0]) ``` """ -struct CartesianProduct{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} +struct CartesianProduct{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} X::S1 Y::S2 - function CartesianProduct(X::LazySet{N}, Y::LazySet{N}) where {N} + function CartesianProduct(X::ConvexSet{N}, Y::ConvexSet{N}) where {N} return new{N, typeof(X), typeof(Y)}(X, Y) end end @@ -75,12 +75,12 @@ is_polyhedral(cp::CartesianProduct) = is_polyhedral(cp.X) && is_polyhedral(cp.Y) """ ``` - *(X::LazySet, Y::LazySet) + *(X::ConvexSet, Y::ConvexSet) ``` Alias for the binary Cartesian product. """ -*(X::LazySet, Y::LazySet) = CartesianProduct(X, Y) +*(X::ConvexSet, Y::ConvexSet) = CartesianProduct(X, Y) """ × @@ -91,7 +91,7 @@ Unicode alias constructor × (`times`) for the binary Cartesian product operator Write `\\times[TAB]` to enter this symbol. """ -×(X::LazySet, Y::LazySet) = CartesianProduct(X, Y) +×(X::ConvexSet, Y::ConvexSet) = CartesianProduct(X, Y) """ swap(cp::CartesianProduct) diff --git a/src/LazyOperations/CartesianProductArray.jl b/src/LazyOperations/CartesianProductArray.jl index e895061872..c5a82c044b 100644 --- a/src/LazyOperations/CartesianProductArray.jl +++ b/src/LazyOperations/CartesianProductArray.jl @@ -5,7 +5,7 @@ export CartesianProductArray, same_block_structure """ - CartesianProductArray{N, S<:LazySet{N}} <: LazySet{N} + CartesianProductArray{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents the Cartesian product of a finite number of sets. @@ -22,18 +22,18 @@ their Cartesian product is convex as well. Constructors: -- `CartesianProductArray(array::Vector{<:LazySet})` -- default constructor +- `CartesianProductArray(array::Vector{<:ConvexSet})` -- default constructor - `CartesianProductArray([n]::Int=0, [N]::Type=Float64)` -- constructor for an empty product with optional size hint and numeric type """ -struct CartesianProductArray{N, S<:LazySet{N}} <: LazySet{N} +struct CartesianProductArray{N, S<:ConvexSet{N}} <: ConvexSet{N} array::Vector{S} end # constructor for an empty product with optional size hint and numeric type function CartesianProductArray(n::Int=0, N::Type=Float64) - arr = Vector{LazySet{N}}() + arr = Vector{ConvexSet{N}}() sizehint!(arr, n) return CartesianProductArray(arr) end @@ -402,7 +402,7 @@ end """ same_block_structure(x::AbstractVector{S1}, y::AbstractVector{S2} - ) where {S1<:LazySet, S2<:LazySet} + ) where {S1<:ConvexSet, S2<:ConvexSet} Check whether two vectors of sets have the same block structure, i.e., the ``i``-th entry in the vectors have the same dimension. @@ -417,7 +417,7 @@ Check whether two vectors of sets have the same block structure, i.e., the `true` iff the vectors have the same block structure. """ function same_block_structure(x::AbstractVector{S1}, y::AbstractVector{S2} - ) where {S1<:LazySet, S2<:LazySet} + ) where {S1<:ConvexSet, S2<:ConvexSet} if length(x) != length(y) return false end @@ -567,7 +567,7 @@ function substitute_blocks(low_dim_cpa::CartesianProductArray{N}, orig_cpa::CartesianProductArray{N}, blocks::Vector{Tuple{Int,Int}}) where {N} - array = Vector{LazySet{N}}(undef, length(orig_cpa.array)) + array = Vector{ConvexSet{N}}(undef, length(orig_cpa.array)) index = 1 for bi in 1:length(orig_cpa.array) start_ind, end_index = blocks[bi] @@ -607,7 +607,7 @@ function linear_map(M::AbstractMatrix, cpa::CartesianProductArray) end function project(cpa::CartesianProductArray, block::AbstractVector{Int}; kwargs...) - target_sets = LazySet[] + target_sets = ConvexSet[] m = length(block) # find first set diff --git a/src/LazyOperations/Complement.jl b/src/LazyOperations/Complement.jl index 3ac08ea53d..98ae233b48 100644 --- a/src/LazyOperations/Complement.jl +++ b/src/LazyOperations/Complement.jl @@ -5,7 +5,7 @@ export Complement, complement """ - Complement{N, S<:LazySet{N}} + Complement{N, S<:ConvexSet{N}} Type that represents the complement of a set, that is the set @@ -38,7 +38,7 @@ julia> Complement(C) BallInf{Float64, Vector{Float64}}([0.0, 0.0], 1.0) ``` """ -struct Complement{N, S<:LazySet{N}} +struct Complement{N, S<:ConvexSet{N}} X::S end diff --git a/src/LazyOperations/ConvexHull.jl b/src/LazyOperations/ConvexHull.jl index 9ea5d7eea7..170d9d0472 100644 --- a/src/LazyOperations/ConvexHull.jl +++ b/src/LazyOperations/ConvexHull.jl @@ -7,7 +7,7 @@ export ConvexHull, CH, swap """ - ConvexHull{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} + ConvexHull{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} Type that represents the convex hull of the union of two sets, that is the set @@ -39,12 +39,12 @@ julia> typeof(c) ConvexHull{Float64, Ball2{Float64, Vector{Float64}}, Ball2{Float64, Vector{Float64}}} ``` """ -struct ConvexHull{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} +struct ConvexHull{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} X::S1 Y::S2 # default constructor with dimension check - function ConvexHull(X::LazySet{N}, Y::LazySet{N}) where {N} + function ConvexHull(X::ConvexSet{N}, Y::ConvexSet{N}) where {N} @assert dim(X) == dim(Y) "sets in a convex hull must have the same dimension" return new{N, typeof(X), typeof(Y)}(X, Y) end diff --git a/src/LazyOperations/ConvexHullArray.jl b/src/LazyOperations/ConvexHullArray.jl index 50d3fc5b8c..1356214455 100644 --- a/src/LazyOperations/ConvexHullArray.jl +++ b/src/LazyOperations/ConvexHullArray.jl @@ -8,7 +8,7 @@ export ConvexHullArray, CHArray, # ================================ """ - ConvexHullArray{N, S<:LazySet{N}} <: LazySet{N} + ConvexHullArray{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents the symbolic convex hull of a finite number of sets. @@ -22,7 +22,7 @@ The `EmptySet` is the neutral element for `ConvexHullArray`. Constructors: -- `ConvexHullArray(array::Vector{<:LazySet})` -- default constructor +- `ConvexHullArray(array::Vector{<:ConvexSet})` -- default constructor - `ConvexHullArray([n]::Int=0, [N]::Type=Float64)` -- constructor for an empty hull with optional size hint and numeric type @@ -37,7 +37,7 @@ julia> b = [Ball2([2*pi*i/100, sin(2*pi*i/100)], 0.05) for i in 1:100]; julia> c = ConvexHullArray(b); ``` """ -struct ConvexHullArray{N, S<:LazySet{N}} <: LazySet{N} +struct ConvexHullArray{N, S<:ConvexSet{N}} <: ConvexSet{N} array::Vector{S} end @@ -46,7 +46,7 @@ isconvextype(::Type{<:ConvexHullArray}) = true # constructor for an empty hull with optional size hint and numeric type function ConvexHullArray(n::Int=0, N::Type=Float64) - a = Vector{LazySet{N}}() + a = Vector{ConvexSet{N}}() sizehint!(a, n) return ConvexHullArray(a) end diff --git a/src/LazyOperations/ExponentialMap.jl b/src/LazyOperations/ExponentialMap.jl index f70f84870b..652e1be04f 100644 --- a/src/LazyOperations/ExponentialMap.jl +++ b/src/LazyOperations/ExponentialMap.jl @@ -153,7 +153,7 @@ function get_rows(spmexp::SparseMatrixExp{N}, I::AbstractArray{Int}; end """ - ExponentialMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} + ExponentialMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} Type that represents the action of an exponential map on a set. @@ -201,7 +201,7 @@ julia> E * EmptySet(2) ∅(2) ``` """ -struct ExponentialMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} +struct ExponentialMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} spmexp::SparseMatrixExp{N} X::S end @@ -224,7 +224,7 @@ end """ ``` - *(spmexp::SparseMatrixExp, X::LazySet) + *(spmexp::SparseMatrixExp, X::ConvexSet) ``` Return the exponential map of a set from a sparse matrix exponential. @@ -238,7 +238,7 @@ Return the exponential map of a set from a sparse matrix exponential. The exponential map of the set. """ -function *(spmexp::SparseMatrixExp, X::LazySet) +function *(spmexp::SparseMatrixExp, X::ConvexSet) return ExponentialMap(spmexp, X) end @@ -259,7 +259,7 @@ function set(em::ExponentialMap) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -466,7 +466,7 @@ struct ProjectionSparseMatrixExp{N, MN1<:AbstractSparseMatrix{N}, end """ - ExponentialProjectionMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} + ExponentialProjectionMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} Type that represents the application of a projection of a sparse matrix exponential to a set. @@ -481,7 +481,7 @@ exponential to a set. The exponential projection preserves convexity: if `X` is convex, then any exponential projection of `X` is convex as well. """ -struct ExponentialProjectionMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} +struct ExponentialProjectionMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} projspmexp::ProjectionSparseMatrixExp X::S end @@ -491,7 +491,7 @@ isconvextype(::Type{ExponentialProjectionMap{N, S}}) where {N, S} = isconvextype """ ``` - *(projspmexp::ProjectionSparseMatrixExp, X::LazySet) + *(projspmexp::ProjectionSparseMatrixExp, X::ConvexSet) ``` Return the application of a projection of a sparse matrix exponential to a set. @@ -505,7 +505,7 @@ Return the application of a projection of a sparse matrix exponential to a set. The application of the projection of a sparse matrix exponential to the set. """ -function *(projspmexp::ProjectionSparseMatrixExp, X::LazySet) +function *(projspmexp::ProjectionSparseMatrixExp, X::ConvexSet) return ExponentialProjectionMap(projspmexp, X) end @@ -527,7 +527,7 @@ function set(epm::ExponentialProjectionMap) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/LazyOperations/Intersection.jl b/src/LazyOperations/Intersection.jl index b857de25dd..3c5e4f895d 100644 --- a/src/LazyOperations/Intersection.jl +++ b/src/LazyOperations/Intersection.jl @@ -44,7 +44,7 @@ function set_isempty!(c::IntersectionCache, isempty::Bool) end """ - Intersection{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} + Intersection{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} Type that represents the intersection of two sets. @@ -95,13 +95,13 @@ julia> W = intersection(X, Y) Hyperrectangle{Float64, Vector{Float64}, Vector{Float64}}([0.375, 0.0], [0.125, 0.5]) ``` """ -struct Intersection{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} +struct Intersection{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} X::S1 Y::S2 cache::IntersectionCache # default constructor with dimension check - function Intersection(X::LazySet{N}, Y::LazySet{N}; cache::IntersectionCache=IntersectionCache()) where {N} + function Intersection(X::ConvexSet{N}, Y::ConvexSet{N}; cache::IntersectionCache=IntersectionCache()) where {N} @assert dim(X) == dim(Y) "sets in an intersection must have the same dimension" return new{N, typeof(X), typeof(Y)}(X, Y, cache) end @@ -122,7 +122,7 @@ is_polyhedral(cap::Intersection) = is_polyhedral(cap.X) && is_polyhedral(cap.Y) Alias for `Intersection`. """ -∩(X::LazySet, Y::LazySet) = Intersection(X, Y) +∩(X::ConvexSet, Y::ConvexSet) = Intersection(X, Y) # --- simplifications --- @@ -189,7 +189,7 @@ function swap(cap::Intersection) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -257,7 +257,7 @@ function ρ_helper(d::AbstractVector{M}, cap::Intersection{N, S1, <:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}}, algorithm::String; - kwargs...) where {M, N, S1<:LazySet{N}} + kwargs...) where {M, N, S1<:ConvexSet{N}} if !isbounded(cap.X) raise(ArgumentError("the first set in the intersection must be bounded")) end @@ -315,7 +315,7 @@ end ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; algorithm::String="line_search", - kwargs...) where {N, S1<:LazySet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} + kwargs...) where {N, S1<:ConvexSet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} Return the support function of the intersection of a compact set and a half-space/hyperplane/line in a given direction. @@ -374,7 +374,7 @@ For additional information we refer to: function ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; algorithm::String="line_search", - kwargs...) where {N, S1<:LazySet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} + kwargs...) where {N, S1<:ConvexSet{N}, S2<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}} return ρ_helper(d, cap, algorithm; kwargs...) end @@ -382,13 +382,13 @@ end function ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; algorithm::String="line_search", - kwargs...) where {N, S1<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}, S2<:LazySet{N}} + kwargs...) where {N, S1<:Union{HalfSpace{N}, Hyperplane{N}, Line2D{N}}, S2<:ConvexSet{N}} return ρ_helper(d, swap(cap), algorithm; kwargs...) end """ ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; - kwargs...) where {N, S1<:LazySet{N}, S2<:AbstractPolyhedron{N}} + kwargs...) where {N, S1<:ConvexSet{N}, S2<:AbstractPolyhedron{N}} Return an upper bound on the support function of the intersection between a compact set and a polyhedron along a given direction. @@ -419,13 +419,13 @@ Functions](https://www.sciencedirect.com/science/article/pii/S1474667015371809). This method relies on the `constraints_list` of the polyhedron. """ function ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; - kwargs...) where {N, S1<:LazySet{N}, S2<:AbstractPolyhedron{N}} + kwargs...) where {N, S1<:ConvexSet{N}, S2<:AbstractPolyhedron{N}} return ρ_helper(d, cap; kwargs...) end # symmetric method function ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; kwargs... - ) where {N, S1<:AbstractPolyhedron{N}, S2<:LazySet{N}} + ) where {N, S1<:AbstractPolyhedron{N}, S2<:ConvexSet{N}} return ρ_helper(d, swap(cap); kwargs...) end @@ -436,7 +436,7 @@ function ρ(d::AbstractVector, cap::Intersection{N, S1, S2}; kwargs... end function ρ_helper(d::AbstractVector, cap::Intersection{N, S1, S2}; kwargs... - ) where {N, S1<:LazySet{N}, S2<:AbstractPolyhedron{N}} + ) where {N, S1<:ConvexSet{N}, S2<:AbstractPolyhedron{N}} if !use_precise_ρ(cap) use_simple_method = true else @@ -805,7 +805,7 @@ julia> v[1] ``` """ function _line_search(ℓ, X::S, H::Union{<:HalfSpace, <:Hyperplane, <:Line2D}; - kwargs...) where {S<:LazySet} + kwargs...) where {S<:ConvexSet} if !isconvextype(S) raise(ArgumentError("the first set in the intersection must be convex")) end @@ -905,7 +905,7 @@ function _projection(ℓ, X::S, H::Union{Hyperplane{N}, Line2D{N}}; lazy_linear_map=false, lazy_2d_intersection=true, algorithm_2d_intersection=nothing, - kwargs...) where {N, S<:LazySet} + kwargs...) where {N, S<:ConvexSet} if !isconvextype(S) raise(ArgumentError("the first set in the intersection must be convex")) end @@ -932,7 +932,7 @@ end """ get_constrained_lowdimset(cpa::CartesianProductArray{N, S}, P::AbstractPolyhedron{N} - ) where {N, S<:LazySet{N}} + ) where {N, S<:ConvexSet{N}} Preprocessing step for the intersection between a Cartesian product array and a polyhedron. @@ -958,7 +958,7 @@ the original `cpa` """ function get_constrained_lowdimset(cpa::CartesianProductArray{N, S}, P::AbstractPolyhedron{N} - ) where {N, S<:LazySet{N}} + ) where {N, S<:ConvexSet{N}} if isbounded(P) blocks, non_empty_length = block_to_dimension_indices(cpa) diff --git a/src/LazyOperations/IntersectionArray.jl b/src/LazyOperations/IntersectionArray.jl index 1be1c2a3e3..71969ed3f6 100644 --- a/src/LazyOperations/IntersectionArray.jl +++ b/src/LazyOperations/IntersectionArray.jl @@ -6,7 +6,7 @@ export IntersectionArray, # ================================ """ - IntersectionArray{N, S<:LazySet{N}} <: LazySet{N} + IntersectionArray{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents the intersection of a finite number of sets. @@ -25,12 +25,12 @@ their intersection is convex as well. Constructors: -- `IntersectionArray(array::Vector{<:LazySet})` -- default constructor +- `IntersectionArray(array::Vector{<:ConvexSet})` -- default constructor - `IntersectionArray([n]::Int=0, [N]::Type=Float64)` -- constructor for an empty sum with optional size hint and numeric type """ -struct IntersectionArray{N, S<:LazySet{N}} <: LazySet{N} +struct IntersectionArray{N, S<:ConvexSet{N}} <: ConvexSet{N} array::Vector{S} end @@ -39,7 +39,7 @@ isconvextype(::Type{IntersectionArray{N, S}}) where {N, S} = isconvextype(S) # constructor for an empty sum with optional size hint and numeric type function IntersectionArray(n::Int=0, N::Type=Float64) - arr = Vector{LazySet{N}}() + arr = Vector{ConvexSet{N}}() sizehint!(arr, n) return IntersectionArray(arr) end @@ -71,7 +71,7 @@ function array(ia::IntersectionArray) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/LazyOperations/InverseLinearMap.jl b/src/LazyOperations/InverseLinearMap.jl index 78b33f8607..343dda26c2 100644 --- a/src/LazyOperations/InverseLinearMap.jl +++ b/src/LazyOperations/InverseLinearMap.jl @@ -5,7 +5,7 @@ export InverseLinearMap, constraints_list """ - InverseLinearMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} + InverseLinearMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} Given a linear transformation ``M``, this type represents the linear transformation ``M⁻¹⋅X`` of a set ``X`` without actually computing ``M⁻¹``. @@ -54,12 +54,12 @@ julia> InverseLinearMap(A, ZeroSet{Int}(3)) ZeroSet{Int64}(3) ``` """ -struct InverseLinearMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} +struct InverseLinearMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} M::MAT X::S # default constructor with dimension match check - function InverseLinearMap(M::MAT, X::S; check_invertibility::Bool=false) where {N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} + function InverseLinearMap(M::MAT, X::S; check_invertibility::Bool=false) where {N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} @assert dim(X) == size(M, 1) "a linear map of size $(size(M)) cannot " * "be applied to a set of dimension $(dim(X))" if check_invertibility @@ -70,12 +70,12 @@ struct InverseLinearMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} <: Abstra end # convenience constructor from a UniformScaling -function InverseLinearMap(M::UniformScaling{N}, X::LazySet; check_invertibility::Bool=false) where {N} +function InverseLinearMap(M::UniformScaling{N}, X::ConvexSet; check_invertibility::Bool=false) where {N} return InverseLinearMap(M.λ, X, check_invertibility=check_invertibility) end # convenience constructor from a scalar -function InverseLinearMap(α::N, X::LazySet; check_invertibility::Bool=false) where {N<:Real} +function InverseLinearMap(α::N, X::ConvexSet; check_invertibility::Bool=false) where {N<:Real} if check_invertibility @assert !iszero(α) "the linear map is not invertible" end diff --git a/src/LazyOperations/LinearMap.jl b/src/LazyOperations/LinearMap.jl index da55f9cea5..cfb67b557a 100644 --- a/src/LazyOperations/LinearMap.jl +++ b/src/LazyOperations/LinearMap.jl @@ -6,7 +6,7 @@ export LinearMap, Projection """ - LinearMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} + LinearMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} Type that represents a linear transformation ``M⋅S`` of a set ``S``. @@ -95,13 +95,13 @@ julia> A * EmptySet{Int}(2) EmptySet{Int64}(2) ``` """ -struct LinearMap{N, S<:LazySet{N}, +struct LinearMap{N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} <: AbstractAffineMap{N, S} M::MAT X::S # default constructor with dimension match check - function LinearMap(M::MAT, X::S) where {N, S<:LazySet{N}, NM, + function LinearMap(M::MAT, X::S) where {N, S<:ConvexSet{N}, NM, MAT<:AbstractMatrix{NM}} @assert dim(X) == size(M, 2) "a linear map of size $(size(M)) cannot " * "be applied to a set of dimension $(dim(X))" @@ -114,7 +114,7 @@ isconvextype(::Type{<:LinearMap{N, S}}) where {N, S} = isconvextype(S) """ ``` - *(map::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, X::LazySet) + *(map::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, X::ConvexSet) ``` Alias to create a `LinearMap` object. @@ -128,17 +128,17 @@ Alias to create a `LinearMap` object. A lazy linear map, i.e., a `LinearMap` instance. """ -function *(map::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, X::LazySet) +function *(map::Union{AbstractMatrix, UniformScaling, AbstractVector, Real}, X::ConvexSet) return LinearMap(map, X) end # scaling from the right -function *(X::LazySet, map::Real) +function *(X::ConvexSet, map::Real) return LinearMap(map, X) end # convenience constructor from a vector -function LinearMap(v::AbstractVector, X::LazySet) +function LinearMap(v::AbstractVector, X::ConvexSet) n = dim(X) m = length(v) if n == m @@ -150,7 +150,7 @@ function LinearMap(v::AbstractVector, X::LazySet) end # convenience constructor from a UniformScaling -function LinearMap(M::UniformScaling{N}, X::LazySet) where {N} +function LinearMap(M::UniformScaling{N}, X::ConvexSet) where {N} if M.λ == one(N) return X end @@ -158,7 +158,7 @@ function LinearMap(M::UniformScaling{N}, X::LazySet) where {N} end # convenience constructor from a scalar -function LinearMap(α::Real, X::LazySet) +function LinearMap(α::Real, X::ConvexSet) n = dim(X) return LinearMap(sparse(α * I, n, n), X) end @@ -170,11 +170,11 @@ end # disambiguations function LinearMap(v::AbstractVector, lm::LinearMap) - return invoke(LinearMap, Tuple{AbstractVector, LazySet}, v, lm) + return invoke(LinearMap, Tuple{AbstractVector, ConvexSet}, v, lm) end function LinearMap(α::Real, lm::LinearMap) - return invoke(LinearMap, Tuple{Real, LazySet}, α, lm) + return invoke(LinearMap, Tuple{Real, ConvexSet}, α, lm) end # more efficient version @@ -215,7 +215,7 @@ function set(lm::LinearMap) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -259,7 +259,7 @@ function σ(d::AbstractVector, lm::LinearMap) return _σ_linear_map(d, lm.M, lm.X) end -function _σ_linear_map(d::AbstractVector, M::AbstractMatrix, X::LazySet) +function _σ_linear_map(d::AbstractVector, M::AbstractMatrix, X::ConvexSet) return M * σ(_At_mul_B(M, d), X) end @@ -289,7 +289,7 @@ function ρ(d::AbstractVector, lm::LinearMap; kwargs...) return _ρ_linear_map(d, lm.M, lm.X; kwargs...) end -function _ρ_linear_map(d::AbstractVector, M::AbstractMatrix, X::LazySet; kwargs...) +function _ρ_linear_map(d::AbstractVector, M::AbstractMatrix, X::ConvexSet; kwargs...) return ρ(_At_mul_B(M, d), X; kwargs...) end @@ -439,7 +439,7 @@ function concretize(lm::LinearMap) end """ - Projection(X::LazySet{N}, variables::AbstractVector{Int}) where {N<:Real} + Projection(X::ConvexSet{N}, variables::AbstractVector{Int}) where {N<:Real} Return the lazy projection of a set. @@ -468,13 +468,13 @@ julia> isequivalent(Bproj, BallInf(zeros(2), 1.0)) true ``` """ -function Projection(X::LazySet{N}, variables::AbstractVector{Int}) where {N} +function Projection(X::ConvexSet{N}, variables::AbstractVector{Int}) where {N} M = projection_matrix(variables, dim(X), N) return LinearMap(M, X) end """ - project(S::LazySet{N}, + project(S::ConvexSet{N}, block::AbstractVector{Int}, set_type::Type{LM}, [n]::Int=dim(S); @@ -494,7 +494,7 @@ Project a high-dimensional set to a given block by using a lazy linear map. A lazy `LinearMap` representing the projection of the set `S` to block `block`. """ -@inline function project(S::LazySet{N}, +@inline function project(S::ConvexSet{N}, block::AbstractVector{Int}, set_type::Type{LM}, n::Int=dim(S); diff --git a/src/LazyOperations/MinkowskiSum.jl b/src/LazyOperations/MinkowskiSum.jl index 7106a53689..ef093b517a 100644 --- a/src/LazyOperations/MinkowskiSum.jl +++ b/src/LazyOperations/MinkowskiSum.jl @@ -5,7 +5,7 @@ export MinkowskiSum, ⊕, swap """ - MinkowskiSum{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} + MinkowskiSum{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} Type that represents the Minkowski sum of two sets, i.e., the set @@ -26,12 +26,12 @@ for `MinkowskiSum`. The Minkowski sum preserves convexity: if the set arguments are convex, then their Minkowski sum is convex as well. """ -struct MinkowskiSum{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N} +struct MinkowskiSum{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} <: ConvexSet{N} X::S1 Y::S2 # default constructor with dimension check - function MinkowskiSum(X::LazySet{N}, Y::LazySet{N}) where {N} + function MinkowskiSum(X::ConvexSet{N}, Y::ConvexSet{N}) where {N} @assert dim(X) == dim(Y) "sets in a Minkowski sum must have the same dimension" return new{N, typeof(X), typeof(Y)}(X, Y) end @@ -62,10 +62,10 @@ Convenience constructor for Minkowski sum. The symbolic Minkowski sum of ``X`` and ``Y``. """ -+(X::LazySet, Y::LazySet) = MinkowskiSum(X, Y) ++(X::ConvexSet, Y::ConvexSet) = MinkowskiSum(X, Y) """ - ⊕(X::LazySet, Y::LazySet) + ⊕(X::ConvexSet, Y::ConvexSet) Unicode alias constructor ⊕ (`oplus`) for the lazy Minkowski sum operator. @@ -73,7 +73,7 @@ Unicode alias constructor ⊕ (`oplus`) for the lazy Minkowski sum operator. Write `\\oplus[TAB]` to enter this symbol. """ -⊕(X::LazySet, Y::LazySet) = MinkowskiSum(X, Y) +⊕(X::ConvexSet, Y::ConvexSet) = MinkowskiSum(X, Y) """ swap(ms::MinkowskiSum) @@ -236,7 +236,7 @@ function constraints_list(ms::MinkowskiSum) end """ - ∈(x::AbstractVector, ms::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:LazySet} + ∈(x::AbstractVector, ms::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:ConvexSet} Check whether a given point is contained in the Minkowski sum of a singleton and a set. @@ -255,12 +255,12 @@ and a set. Note that ``x ∈ (S ⊕ P)``, where ``S`` is a singleton set, ``S = \\{s\\}`` and ``P`` is a set, if and only if ``(x-s) ∈ P``. """ -function ∈(x::AbstractVector, ms::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:LazySet} +function ∈(x::AbstractVector, ms::MinkowskiSum{N, S1, S2}) where {N, S1<:AbstractSingleton, S2<:ConvexSet} return _in_singleton_msum(x, ms.X, ms.Y) end # symmetric method -function ∈(x::AbstractVector, ms::MinkowskiSum{N, <:LazySet, <:AbstractSingleton}) where {N} +function ∈(x::AbstractVector, ms::MinkowskiSum{N, <:ConvexSet, <:AbstractSingleton}) where {N} return _in_singleton_msum(x, ms.Y, ms.X) end diff --git a/src/LazyOperations/MinkowskiSumArray.jl b/src/LazyOperations/MinkowskiSumArray.jl index e83a4cc2f7..0cc05e48d0 100644 --- a/src/LazyOperations/MinkowskiSumArray.jl +++ b/src/LazyOperations/MinkowskiSumArray.jl @@ -6,7 +6,7 @@ export MinkowskiSumArray, # ================================== """ - MinkowskiSumArray{N, S<:LazySet{N}} <: LazySet{N} + MinkowskiSumArray{N, S<:ConvexSet{N}} <: ConvexSet{N} Type that represents the Minkowski sum of a finite number of sets. @@ -26,12 +26,12 @@ their Minkowski sum is convex as well. Constructors: -- `MinkowskiSumArray(array::Vector{<:LazySet})` -- default constructor +- `MinkowskiSumArray(array::Vector{<:ConvexSet})` -- default constructor - `MinkowskiSumArray([n]::Int=0, [N]::Type=Float64)` -- constructor for an empty sum with optional size hint and numeric type """ -struct MinkowskiSumArray{N, S<:LazySet{N}} <: LazySet{N} +struct MinkowskiSumArray{N, S<:ConvexSet{N}} <: ConvexSet{N} array::Vector{S} end @@ -40,7 +40,7 @@ isconvextype(::Type{MinkowskiSumArray{N, S}}) where {N, S} = isconvextype(S) # constructor for an empty sum with optional size hint and numeric type function MinkowskiSumArray(n::Int=0, N::Type=Float64) - arr = Vector{LazySet{N}}() + arr = Vector{ConvexSet{N}}() sizehint!(arr, n) return MinkowskiSumArray(arr) end @@ -110,7 +110,7 @@ function σ(d::AbstractVector, msa::MinkowskiSumArray) end @inline function _σ_msum_array(d::AbstractVector{N}, - array::AbstractVector{<:LazySet}) where {N} + array::AbstractVector{<:ConvexSet}) where {N} return sum(σ(d, Xi) for Xi in array) end diff --git a/src/LazyOperations/Rectification.jl b/src/LazyOperations/Rectification.jl index 780b6a997e..90596f8d53 100644 --- a/src/LazyOperations/Rectification.jl +++ b/src/LazyOperations/Rectification.jl @@ -15,18 +15,18 @@ Struct that is used as a cache for [`Rectification`](@ref)s. computations for the cached set """ mutable struct RectificationCache{N} - set::Union{LazySet{N}, UnionSetArray{N}, Nothing} + set::Union{ConvexSet{N}, UnionSetArray{N}, Nothing} use_support_vector::Bool # constructor without a set RectificationCache{N}(::Nothing) where {N} = new{N}(nothing, false) # constructor with a set - RectificationCache{N}(set::LazySet{N}) where {N} = new{N}(set, true) + RectificationCache{N}(set::ConvexSet{N}) where {N} = new{N}(set, true) end """ - Rectification{N, S<:LazySet{N}} + Rectification{N, S<:ConvexSet{N}} Type that represents the rectification of a set. @@ -88,12 +88,12 @@ containing the origin. The rectification of ``X ∩ O_2`` and ``X ∩ O_4`` both result in flat ``1``-dimensional line segments on the corresponding hyperplane of ``O_1``. """ -struct Rectification{N, S<:LazySet{N}} +struct Rectification{N, S<:ConvexSet{N}} X::S cache::RectificationCache{N} # default constructor that initializes cache - function Rectification(X::S) where {N, S<:LazySet{N}} + function Rectification(X::S) where {N, S<:ConvexSet{N}} if X isa AbstractHyperrectangle || X isa CartesianProduct || X isa CartesianProductArray || X isa EmptySet # set types with efficient support-vector computations @@ -113,7 +113,7 @@ end isoperationtype(::Type{<:Rectification}) = true isconvextype(::Type{<:Rectification}) = false -# redundant if Rectification <: LazySet +# redundant if Rectification <: ConvexSet eltype(::Type{<:Rectification{N}}) where {N} = N eltype(r::Rectification) = eltype(typeof(r)) @@ -543,7 +543,7 @@ end # identify dimensions where set is negative and mixed (positive/negative) and # also fill a bit vector for mixed dimensions -function compute_negative_and_mixed_dimensions(X::LazySet{N}, n) where {N} +function compute_negative_and_mixed_dimensions(X::ConvexSet{N}, n) where {N} negative_dimensions = Vector{Int}() mixed_dimensions = Vector{Int}() mixed_dimensions_enumeration = BitArray(undef, 0) @@ -574,7 +574,7 @@ function construct_constraints(indices, bits, n, ::Type{N}) where {N} end # project negative dimensions to zero (see `to_union_of_projections`) -function construct_projection(set::LazySet{N}, negative_dimensions, +function construct_projection(set::ConvexSet{N}, negative_dimensions, mixed_dimensions, mixed_dimensions_enumeration, n ) where {N} # initialize negative indices to zero and all other dimensions to one diff --git a/src/LazyOperations/ResetMap.jl b/src/LazyOperations/ResetMap.jl index 7b0c2b1136..f0e76fca95 100644 --- a/src/LazyOperations/ResetMap.jl +++ b/src/LazyOperations/ResetMap.jl @@ -4,7 +4,7 @@ import Base: isempty export ResetMap """ - ResetMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} + ResetMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} Type that represents a lazy reset map. A reset map is a special case of an affine map ``A x + b, x ∈ X`` where the @@ -81,7 +81,7 @@ julia> σ(ones(3), rm) 0.0 ``` """ -struct ResetMap{N, S<:LazySet{N}} <: AbstractAffineMap{N, S} +struct ResetMap{N, S<:ConvexSet{N}} <: AbstractAffineMap{N, S} X::S resets::Dict{Int, N} end @@ -167,7 +167,7 @@ function set(rm::ResetMap) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/LazyOperations/SymmetricIntervalHull.jl b/src/LazyOperations/SymmetricIntervalHull.jl index 63fd119866..3523598e50 100644 --- a/src/LazyOperations/SymmetricIntervalHull.jl +++ b/src/LazyOperations/SymmetricIntervalHull.jl @@ -2,7 +2,7 @@ export SymmetricIntervalHull, ⊡, an_element """ - SymmetricIntervalHull{N, S<:LazySet{N}} <: AbstractHyperrectangle{N} + SymmetricIntervalHull{N, S<:ConvexSet{N}} <: AbstractHyperrectangle{N} Type that represents the symmetric interval hull of a compact set. @@ -34,12 +34,12 @@ The symmetric inteval hull of a set is a hyperrectangle, hence in particular con An alias for this function is `⊡`. """ -struct SymmetricIntervalHull{N, S<:LazySet{N}} <: AbstractHyperrectangle{N} +struct SymmetricIntervalHull{N, S<:ConvexSet{N}} <: AbstractHyperrectangle{N} X::S cache::Vector{N} # default constructor that initializes cache - function SymmetricIntervalHull(X::S; check_boundedness::Bool=true) where {N, S<:LazySet{N}} + function SymmetricIntervalHull(X::S; check_boundedness::Bool=true) where {N, S<:ConvexSet{N}} @assert !check_boundedness || isbounded(X) "the symmetric interval hull is only defined for bounded sets" cache = fill(-one(N), dim(X)) return new{N, S}(X, cache) @@ -164,7 +164,7 @@ function center(sih::SymmetricIntervalHull{N}) where {N} end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/LazyOperations/Translation.jl b/src/LazyOperations/Translation.jl index 451e846583..3246bf4b39 100644 --- a/src/LazyOperations/Translation.jl +++ b/src/LazyOperations/Translation.jl @@ -7,7 +7,7 @@ export Translation, center """ - Translation{N, S<:LazySet{N}, VN<:AbstractVector{N}} <: AbstractAffineMap{N, S} + Translation{N, S<:ConvexSet{N}, VN<:AbstractVector{N}} <: AbstractAffineMap{N, S} Type that represents a lazy translation. @@ -146,12 +146,12 @@ julia> constraints_list(tr) HalfSpace{Float64, LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 0.0, -1.0], -1.0) ``` """ -struct Translation{N, S<:LazySet{N}, VN<:AbstractVector{N}} <: AbstractAffineMap{N, S} +struct Translation{N, S<:ConvexSet{N}, VN<:AbstractVector{N}} <: AbstractAffineMap{N, S} X::S v::VN # default constructor with dimension check - function Translation(X::S, v::VN) where {N, VN<:AbstractVector{N}, S<:LazySet{N}} + function Translation(X::S, v::VN) where {N, VN<:AbstractVector{N}, S<:ConvexSet{N}} @assert dim(X) == length(v) "cannot create a translation of a set of " * "dimension $(dim(X)) along a vector of length $(length(v))" @@ -166,7 +166,7 @@ isconvextype(::Type{Translation{N, S, VN}}) where {N, S, VN} = isconvextype(S) Translation(tr::Translation{N}, v::AbstractVector{N}) where {N} = Translation(tr.X, tr.v + v) """ - +(X::LazySet, v::AbstractVector) + +(X::ConvexSet, v::AbstractVector) Convenience constructor for a translation. @@ -179,20 +179,20 @@ Convenience constructor for a translation. The symbolic translation of ``X`` along vector ``v``. """ -+(X::LazySet, v::AbstractVector) = Translation(X, v) ++(X::ConvexSet, v::AbstractVector) = Translation(X, v) # translation from the left -+(v::AbstractVector, X::LazySet) = Translation(X, v) ++(v::AbstractVector, X::ConvexSet) = Translation(X, v) """ - ⊕(X::LazySet, v::AbstractVector) + ⊕(X::ConvexSet, v::AbstractVector) Unicode alias constructor ⊕ (`oplus`) for the lazy translation operator. """ -⊕(X::LazySet, v::AbstractVector) = Translation(X, v) +⊕(X::ConvexSet, v::AbstractVector) = Translation(X, v) # translation from the left -⊕(v::AbstractVector, X::LazySet) = Translation(X, v) +⊕(v::AbstractVector, X::ConvexSet) = Translation(X, v) # the translation of a lazy linear map is a (lazy) affine map Translation(lm::LinearMap, v::AbstractVector) = AffineMap(lm.M, lm.X, v) @@ -218,7 +218,7 @@ function set(tr::Translation) end # ============================ -# LazySet interface functions +# ConvexSet interface functions # ============================ """ @@ -312,7 +312,7 @@ function constraints_list(tr::Translation) return _constraints_list_translation(tr.X, tr.v) end -function _constraints_list_translation(X::LazySet, v::AbstractVector) +function _constraints_list_translation(X::ConvexSet, v::AbstractVector) @assert applicable(constraints_list, X) "this function requires that " * "the `constraints_list` method is applicable" diff --git a/src/LazyOperations/UnionSet.jl b/src/LazyOperations/UnionSet.jl index 7cb0c511c5..931158e4da 100644 --- a/src/LazyOperations/UnionSet.jl +++ b/src/LazyOperations/UnionSet.jl @@ -8,7 +8,7 @@ export UnionSet, # ======================================== """ - UnionSet{N, S1<:LazySet{N}, S2<:LazySet{N}} + UnionSet{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} Type that represents the set union of two sets. @@ -21,12 +21,12 @@ Type that represents the set union of two sets. The union of convex sets is typically not convex. """ -struct UnionSet{N, S1<:LazySet{N}, S2<:LazySet{N}} +struct UnionSet{N, S1<:ConvexSet{N}, S2<:ConvexSet{N}} X::S1 Y::S2 # default constructor with dimension check - function UnionSet(X::LazySet{N}, Y::LazySet{N}) where {N} + function UnionSet(X::ConvexSet{N}, Y::ConvexSet{N}) where {N} @assert dim(X) == dim(Y) "sets in a union must have the same dimension" return new{N, typeof(X), typeof(Y)}(X, Y) end @@ -47,7 +47,7 @@ is_polyhedral(U::UnionSet) = is_polyhedral(U.X) && is_polyhedral(U.Y) Alias for `UnionSet`. """ -∪(X::LazySet, Y::LazySet) = UnionSet(X, Y) +∪(X::ConvexSet, Y::ConvexSet) = UnionSet(X, Y) """ swap(cup::UnionSet) diff --git a/src/LazyOperations/UnionSetArray.jl b/src/LazyOperations/UnionSetArray.jl index 24e6c49df8..0390b2d2ba 100644 --- a/src/LazyOperations/UnionSetArray.jl +++ b/src/LazyOperations/UnionSetArray.jl @@ -6,7 +6,7 @@ export UnionSetArray, # ======================================== """ - UnionSetArray{N, S<:LazySet{N}} + UnionSetArray{N, S<:ConvexSet{N}} Type that represents the set union of a finite number of sets. @@ -18,7 +18,7 @@ Type that represents the set union of a finite number of sets. The union of convex sets is typically not convex. """ -struct UnionSetArray{N, S<:LazySet{N}} +struct UnionSetArray{N, S<:ConvexSet{N}} array::Vector{S} end @@ -27,7 +27,7 @@ isconvextype(::Type{<:UnionSetArray}) = false # constructor for an empty union with optional size hint and numeric type function UnionSetArray(n::Int=0, N::Type=Float64) - arr = Vector{LazySet{N}}() + arr = Vector{ConvexSet{N}}() sizehint!(arr, n) return UnionSetArray(arr) end diff --git a/src/LazySets.jl b/src/LazySets.jl index fd4b9b03c7..9ba35a6ca6 100644 --- a/src/LazySets.jl +++ b/src/LazySets.jl @@ -62,6 +62,7 @@ include("Utils/matrix_exponential.jl") # Abstract set types # ================== include("Interfaces/LazySet.jl") +include("Interfaces/ConvexSet.jl") include("Interfaces/AbstractStar.jl") include("Interfaces/AbstractPolynomialZonotope.jl") include("Interfaces/AbstractPolyhedron.jl") diff --git a/src/Parallel/box_approximations.jl b/src/Parallel/box_approximations.jl index 263e47e195..9daae516ea 100644 --- a/src/Parallel/box_approximations.jl +++ b/src/Parallel/box_approximations.jl @@ -3,7 +3,7 @@ export box_approximation, symmetric_interval_hull """ - box_approximation(S::LazySet{N}) where {N<:Real} + box_approximation(S::ConvexSet{N}) where {N<:Real} Overapproximation a convex set by a tight hyperrectangle using a parallel algorithm. @@ -22,7 +22,7 @@ The center of the hyperrectangle is obtained by averaging the support function of the given set in the canonical directions, and the lengths of the sides can be recovered from the distance among support functions in the same directions. """ -function box_approximation(S::LazySet{N}) where {N<:Real} +function box_approximation(S::ConvexSet{N}) where {N<:Real} (c, r) = box_approximation_helper_parallel(S) if r[1] < 0 return EmptySet{N}(dim(S)) @@ -31,7 +31,7 @@ function box_approximation(S::LazySet{N}) where {N<:Real} end """ - box_approximation_symmetric(S::LazySet{N}) where {N<:Real} + box_approximation_symmetric(S::ConvexSet{N}) where {N<:Real} Overapproximate a convex set by a tight hyperrectangle centered in the origin, using a parallel algorithm. @@ -49,13 +49,13 @@ A tight hyperrectangle centered in the origin. The center of the box is the origin, and the radius is obtained by computing the maximum value of the support function evaluated at the canonical directions. """ -function box_approximation_symmetric(S::LazySet{N}) where {N<:Real} +function box_approximation_symmetric(S::ConvexSet{N}) where {N<:Real} (c, r) = box_approximation_helper_parallel(S) return Hyperrectangle(zeros(N, length(c)), abs.(c) .+ r) end """ - box_approximation_helper_parallel(S::LazySet{N}) where {N<:Real} + box_approximation_helper_parallel(S::ConvexSet{N}) where {N<:Real} Parallel implementation for the common code of `box_approximation` and `box_approximation_symmetric`. @@ -82,7 +82,7 @@ functions in the same directions. The same load is distributed among all available workers, see [`distribute_task!`](@ref). """ -@inline function box_approximation_helper_parallel(S::LazySet{N}) where {N<:Real} +@inline function box_approximation_helper_parallel(S::ConvexSet{N}) where {N<:Real} n = dim(S) c = SharedVector{N}(n) r = SharedVector{N}(n) @@ -92,7 +92,7 @@ The same load is distributed among all available workers, see end """ - process_chunk!(S::LazySet{N}, + process_chunk!(S::ConvexSet{N}, irange::UnitRange{Int}, c::SharedVector{N}, r::SharedVector{N}) where {N<:Real} @@ -116,7 +116,7 @@ The load for each worker is passed through the `irange` argument. By default, the same load is distributed among all available workers. For details see `distribute_task!`. """ -function process_chunk!(S::LazySet{N}, +function process_chunk!(S::ConvexSet{N}, irange::UnitRange{Int}, c::SharedVector{N}, r::SharedVector{N}) where {N<:Real} diff --git a/src/Parallel/distribute.jl b/src/Parallel/distribute.jl index 22dccf0c30..be629002ff 100644 --- a/src/Parallel/distribute.jl +++ b/src/Parallel/distribute.jl @@ -2,7 +2,7 @@ export assign_chunk!, distribute_task! """ - distribute_task!(S::LazySet{N}, v::SharedVector{N}...) where {N<:Real} + distribute_task!(S::ConvexSet{N}, v::SharedVector{N}...) where {N<:Real} Distribute the assignment of each chunk among the available processes. @@ -27,7 +27,7 @@ contain one or more shared vectors in which the values of the task are written. Typically, the function `assign_chunk!` is a wrapper around some problem-specific `process_chunk!` function. """ -function distribute_task!(S::LazySet{N}, v::SharedVector{N}...) where {N<:Real} +function distribute_task!(S::ConvexSet{N}, v::SharedVector{N}...) where {N<:Real} @sync begin for p in procs(v[1]) @async remotecall_wait(assign_chunk!, p, S, v...) @@ -36,7 +36,7 @@ function distribute_task!(S::LazySet{N}, v::SharedVector{N}...) where {N<:Real} end """ - assign_chunk!(S::LazySet{N}, v::SharedVector{N}...) where {N<:Real} + assign_chunk!(S::ConvexSet{N}, v::SharedVector{N}...) where {N<:Real} Return the function that assigns the work for each process. @@ -56,7 +56,7 @@ of shared vectors. The tasks are equally distributed among the number of process See also [`distribute_task!`](@ref). """ -function assign_chunk!(S::LazySet{N}, v::SharedVector{N}...) where {N<:Real} +function assign_chunk!(S::ConvexSet{N}, v::SharedVector{N}...) where {N<:Real} return process_chunk!(S, _prange(v[1]), v...) end diff --git a/src/Plotting/mesh.jl b/src/Plotting/mesh.jl index c9578983d4..92f920a314 100644 --- a/src/Plotting/mesh.jl +++ b/src/Plotting/mesh.jl @@ -19,7 +19,7 @@ end end # quote / function load_makie() # helper function for 3D plotting; converts S to a polytope in H-representation -function _plot3d_helper(S::LazySet, backend) +function _plot3d_helper(S::ConvexSet, backend) @assert dim(S) <= 3 "plot3d can only be used to plot sets of dimension three (or lower); " * "but the given set is $(dim(S))-dimensional" @@ -36,7 +36,7 @@ function _plot3d_helper(S::LazySet, backend) end """ - plot3d(S::LazySet; backend=default_polyhedra_backend(S), + plot3d(S::ConvexSet; backend=default_polyhedra_backend(S), alpha=1.0, color=:blue, colormap=:viridis, colorrange=nothing, interpolate=false, linewidth=1, overdraw=false, shading=true, transparency=true, visible=true) @@ -114,7 +114,7 @@ julia> plot3d(10. * rand(Hyperrectangle, dim=3)) julia> plot3d!(10. * rand(Hyperrectangle, dim=3), color=:red) ``` """ -function plot3d(S::LazySet; backend=default_polyhedra_backend(S), +function plot3d(S::ConvexSet; backend=default_polyhedra_backend(S), alpha=1.0, color=:blue, colormap=:viridis, colorrange=nothing, interpolate=false, linewidth=1, overdraw=false, shading=true, transparency=true, visible=true) require(:Makie; fun_name="plot3d") @@ -129,7 +129,7 @@ function plot3d(S::LazySet; backend=default_polyhedra_backend(S), end """ - plot3d!(S::LazySet; backend=default_polyhedra_backend(S), + plot3d!(S::ConvexSet; backend=default_polyhedra_backend(S), alpha=1.0, color=:blue, colormap=:viridis, colorrange=nothing, interpolate=false, linewidth=1, overdraw=false, shading=true, transparency=true, visible=true) @@ -145,7 +145,7 @@ documentation](http://makie.juliaplots.org/stable/plot-attributes). See the documentation of `plot3d` for examples. """ -function plot3d!(S::LazySet; backend=default_polyhedra_backend(S), +function plot3d!(S::ConvexSet; backend=default_polyhedra_backend(S), alpha=1.0, color=:blue, colormap=:viridis, colorrange=nothing, interpolate=false, linewidth=1, overdraw=false, shading=true, transparency=true, visible=true) require(:Makie; fun_name="plot3d!") diff --git a/src/Plotting/paraview.jl b/src/Plotting/paraview.jl index 1a01a966f4..02d7f8a9f4 100644 --- a/src/Plotting/paraview.jl +++ b/src/Plotting/paraview.jl @@ -1,4 +1,4 @@ -function writevtk(X::LazySet{N}; file="output") where {N} +function writevtk(X::ConvexSet{N}; file="output") where {N} points, connec = triangulate(X) ntriangles = length(connec) cell = VTKPolyhedron(1:ntriangles, connec...) @@ -8,7 +8,7 @@ function writevtk(X::LazySet{N}; file="output") where {N} end end -function writevtk(X::AbstractVector{VT}; file="output") where {N, VT<:LazySet{N}} +function writevtk(X::AbstractVector{VT}; file="output") where {N, VT<:ConvexSet{N}} points_list = Vector{Matrix{Float32}}() cell_list = Vector{VTKPolyhedron}() count = 0 diff --git a/src/Plotting/plot_recipes.jl b/src/Plotting/plot_recipes.jl index 3c2430a40d..e52d562da2 100644 --- a/src/Plotting/plot_recipes.jl +++ b/src/Plotting/plot_recipes.jl @@ -52,7 +52,7 @@ function _extract_extrema(p::RecipesBase.AbstractPlot) return extrema end -function _update_plot_limits!(lims, X::LazySet) +function _update_plot_limits!(lims, X::ConvexSet) box = box_approximation(X) isempty(box) && return nothing # can happen if X is empty or flat @@ -101,7 +101,7 @@ end """ plot_list(list::AbstractVector{VN}, [ε]::N=N(PLOT_PRECISION), [Nφ]::Int=PLOT_POLAR_DIRECTIONS; [same_recipe]=false; ...) - where {N, VN<:LazySet{N}} + where {N, VN<:ConvexSet{N}} Plot a list of convex sets. @@ -150,7 +150,7 @@ julia> plot(Bs, 1e-2) # faster but less accurate than the previous call """ @recipe function plot_list(list::AbstractVector{VN}, ε::N=N(PLOT_PRECISION), Nφ::Int=PLOT_POLAR_DIRECTIONS; same_recipe=false - ) where {N, VN<:LazySet{N}} + ) where {N, VN<:ConvexSet{N}} if same_recipe label --> DEFAULT_LABEL grid --> DEFAULT_GRID @@ -173,7 +173,7 @@ julia> plot(Bs, 1e-2) # faster but less accurate than the previous call end function _plot_list_same_recipe(list::AbstractVector{VN}, ε::N=N(PLOT_PRECISION), - Nφ::Int=PLOT_POLAR_DIRECTIONS) where {N, VN<:LazySet{N}} + Nφ::Int=PLOT_POLAR_DIRECTIONS) where {N, VN<:ConvexSet{N}} first = true x = Vector{N}() y = Vector{N}() @@ -283,7 +283,7 @@ function _plot_singleton_list_2D(list::AbstractVector{SN}) where {N, SN<:Abstrac end """ - plot_lazyset(X::LazySet{N}, [ε]::N=N(PLOT_PRECISION); ...) where {N} + plot_lazyset(X::ConvexSet{N}, [ε]::N=N(PLOT_PRECISION); ...) where {N} Plot a convex set. @@ -294,7 +294,7 @@ Plot a convex set. ### Notes -See [`plot_recipe(::LazySet)`](@ref). +See [`plot_recipe(::ConvexSet)`](@ref). For polyhedral set types (subtypes of `AbstractPolyhedron`), the argument `ε` is ignored. @@ -309,7 +309,7 @@ julia> plot(B, 1e-3) # default accuracy value (explicitly given for clarity) julia> plot(B, 1e-2) # faster but less accurate than the previous call ``` """ -@recipe function plot_lazyset(X::LazySet{N}, ε::N=N(PLOT_PRECISION)) where {N} +@recipe function plot_lazyset(X::ConvexSet{N}, ε::N=N(PLOT_PRECISION)) where {N} label --> DEFAULT_LABEL grid --> DEFAULT_GRID if DEFAULT_ASPECT_RATIO != :none @@ -439,7 +439,7 @@ Plot a lazy intersection. ### Notes -This function is separated from the main `LazySet` plot recipe because iterative +This function is separated from the main `ConvexSet` plot recipe because iterative refinement is not available for lazy intersections (since it uses the support vector (but see [#1187](https://github.com/JuliaReach/LazySets.jl/issues/1187))). diff --git a/src/Sets/Ball1.jl b/src/Sets/Ball1.jl index 405d30d479..fcd2754e6b 100644 --- a/src/Sets/Ball1.jl +++ b/src/Sets/Ball1.jl @@ -116,7 +116,7 @@ function vertices_list(B::Ball1{N, VN}) where {N, VN<:AbstractVector} end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Ball2.jl b/src/Sets/Ball2.jl index 22d419c4bb..f8cb516486 100644 --- a/src/Sets/Ball2.jl +++ b/src/Sets/Ball2.jl @@ -88,7 +88,7 @@ function center(B::Ball2) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ ρ(d::AbstractVector, B::Ball2) diff --git a/src/Sets/BallInf.jl b/src/Sets/BallInf.jl index 85bab59ec8..87c7b99073 100644 --- a/src/Sets/BallInf.jl +++ b/src/Sets/BallInf.jl @@ -157,7 +157,7 @@ function center(B::BallInf) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Ballp.jl b/src/Sets/Ballp.jl index 9e19cfe4d4..0fbd249fe9 100644 --- a/src/Sets/Ballp.jl +++ b/src/Sets/Ballp.jl @@ -100,7 +100,7 @@ function center(B::Ballp) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Ellipsoid.jl b/src/Sets/Ellipsoid.jl index 7cf15422fe..a07991046d 100644 --- a/src/Sets/Ellipsoid.jl +++ b/src/Sets/Ellipsoid.jl @@ -162,7 +162,7 @@ function shape_matrix(E::Ellipsoid) return E.shape_matrix end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/EmptySet.jl b/src/Sets/EmptySet.jl index 36f038915b..6609ab9ccb 100644 --- a/src/Sets/EmptySet.jl +++ b/src/Sets/EmptySet.jl @@ -7,11 +7,11 @@ export EmptySet, ∅, linear_map """ - EmptySet{N} <: LazySet{N} + EmptySet{N} <: ConvexSet{N} Type that represents the empty set, i.e., the set with no elements. """ -struct EmptySet{N} <: LazySet{N} +struct EmptySet{N} <: ConvexSet{N} dim::Int end @@ -29,7 +29,7 @@ Alias for `EmptySet{Float64}`. const ∅ = EmptySet{Float64} -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/HPolygon.jl b/src/Sets/HPolygon.jl index e05181a191..5b6a95c238 100644 --- a/src/Sets/HPolygon.jl +++ b/src/Sets/HPolygon.jl @@ -98,7 +98,7 @@ HPolygon(A::AbstractMatrix, check_boundedness=check_boundedness, prune=prune) -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/HPolygonOpt.jl b/src/Sets/HPolygonOpt.jl index 0c7774b779..7bde32663f 100644 --- a/src/Sets/HPolygonOpt.jl +++ b/src/Sets/HPolygonOpt.jl @@ -107,7 +107,7 @@ HPolygonOpt(A::AbstractMatrix, check_boundedness=check_boundedness, prune=prune) -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/HPolyhedron.jl b/src/Sets/HPolyhedron.jl index fa6bd67093..c197aa9238 100644 --- a/src/Sets/HPolyhedron.jl +++ b/src/Sets/HPolyhedron.jl @@ -70,7 +70,7 @@ HPolyhedron(A::AbstractMatrix, b::AbstractVector) = const HPoly{N} = Union{HPolytope{N}, HPolyhedron{N}} -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -609,7 +609,7 @@ function polyhedron(P::HPoly; return Polyhedra.polyhedron(Polyhedra.hrep(A, b), backend) end -function triangulate(X::LazySet) +function triangulate(X::ConvexSet) dim(X) == 3 || throw(ArgumentError("the dimension of the set should be three, got $(dim(X))")) diff --git a/src/Sets/HPolytope.jl b/src/Sets/HPolytope.jl index 3c89f636b1..681d7aa80f 100644 --- a/src/Sets/HPolytope.jl +++ b/src/Sets/HPolytope.jl @@ -70,7 +70,7 @@ HPolytope(A::AbstractMatrix, b::AbstractVector; HPolytope(constraints_list(A, b); check_boundedness=check_boundedness) -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/HalfSpace.jl b/src/Sets/HalfSpace.jl index db1ff697b6..23cd039438 100644 --- a/src/Sets/HalfSpace.jl +++ b/src/Sets/HalfSpace.jl @@ -83,7 +83,7 @@ function _normalize_halfspace(H, p=2) return a, b end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -522,7 +522,7 @@ end # TODO: after #2032, #2041 remove use of this function _normal_Vector(c::LinearConstraint) = LinearConstraint(convert(Vector, c.a), c.b) _normal_Vector(C::Vector{<:LinearConstraint}) = [_normal_Vector(c) for c in C] -_normal_Vector(P::LazySet) = _normal_Vector(constraints_list(P)) +_normal_Vector(P::ConvexSet) = _normal_Vector(constraints_list(P)) # ============================================ # Functionality that requires Symbolics diff --git a/src/Sets/Hyperplane.jl b/src/Sets/Hyperplane.jl index fa2187cf34..11849c424f 100644 --- a/src/Sets/Hyperplane.jl +++ b/src/Sets/Hyperplane.jl @@ -79,7 +79,7 @@ function constraints_list(hp::Hyperplane) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Hyperrectangle.jl b/src/Sets/Hyperrectangle.jl index 62fa9451ab..c1d9950b91 100644 --- a/src/Sets/Hyperrectangle.jl +++ b/src/Sets/Hyperrectangle.jl @@ -201,7 +201,7 @@ function center(H::Hyperrectangle) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Line.jl b/src/Sets/Line.jl index c041ff0e6d..ac161f6b94 100644 --- a/src/Sets/Line.jl +++ b/src/Sets/Line.jl @@ -221,7 +221,7 @@ function constraints_list(L::Line{N, VN}) where {N, VN} return out end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Line2D.jl b/src/Sets/Line2D.jl index e85d28d541..87fc2e421d 100644 --- a/src/Sets/Line2D.jl +++ b/src/Sets/Line2D.jl @@ -107,7 +107,7 @@ function constraints_list(L::Line2D) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/LineSegment.jl b/src/Sets/LineSegment.jl index 42612ab2fc..a7e7109de4 100644 --- a/src/Sets/LineSegment.jl +++ b/src/Sets/LineSegment.jl @@ -68,7 +68,7 @@ isoperationtype(::Type{<:LineSegment}) = false isconvextype(::Type{<:LineSegment}) = true -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ @@ -263,7 +263,7 @@ function vertices_list(L::LineSegment) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Singleton.jl b/src/Sets/Singleton.jl index 63668c8d46..5a93219534 100644 --- a/src/Sets/Singleton.jl +++ b/src/Sets/Singleton.jl @@ -71,7 +71,7 @@ function element(S::Singleton, i::Int) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Universe.jl b/src/Sets/Universe.jl index 0efe442f52..69787adc95 100644 --- a/src/Sets/Universe.jl +++ b/src/Sets/Universe.jl @@ -74,7 +74,7 @@ function constrained_dimensions(U::Universe) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/VPolygon.jl b/src/Sets/VPolygon.jl index e72cd741f8..62e58571e8 100644 --- a/src/Sets/VPolygon.jl +++ b/src/Sets/VPolygon.jl @@ -256,7 +256,7 @@ function vertices_list(P::VPolygon) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/VPolytope.jl b/src/Sets/VPolytope.jl index 412e8bf986..58b218cee2 100644 --- a/src/Sets/VPolytope.jl +++ b/src/Sets/VPolytope.jl @@ -71,7 +71,7 @@ function VPolytope(vertices_matrix::MT) where {N, MT<:AbstractMatrix{N}} return VPolytope(vertices) end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ dim(P::VPolytope) diff --git a/src/Sets/ZeroSet.jl b/src/Sets/ZeroSet.jl index 029f274e88..a188cd2f2e 100644 --- a/src/Sets/ZeroSet.jl +++ b/src/Sets/ZeroSet.jl @@ -63,7 +63,7 @@ function element(S::ZeroSet{N}, ::Int) where {N} end -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Sets/Zonotope.jl b/src/Sets/Zonotope.jl index 4953451cf6..db2d048926 100644 --- a/src/Sets/Zonotope.jl +++ b/src/Sets/Zonotope.jl @@ -236,7 +236,7 @@ Integer representing the number of generators. ngens(Z::Zonotope) = size(Z.generators, 2) -# --- LazySet interface functions --- +# --- ConvexSet interface functions --- """ diff --git a/src/Utils/helper_functions.jl b/src/Utils/helper_functions.jl index a0ec9520d7..17a88f7d35 100644 --- a/src/Utils/helper_functions.jl +++ b/src/Utils/helper_functions.jl @@ -277,12 +277,12 @@ binary) concrete set operations. - `op` -- set operation (respectively its `Function` object) - `signature` -- (optional, default: `Type[]`) the type signature of the - function without the `LazySet` type(s) (see also the `index` + function without the `ConvexSet` type(s) (see also the `index` option and the `Examples` section below) - `index` -- (optional, default: `1`) index of the set type in the signature in the unary case (see the `binary` option) - `type_args` -- (optional, default: `Float64`) type arguments added to the - `LazySet`(s) when searching for available methods; valid + `ConvexSet`(s) when searching for available methods; valid inputs are a type or `nothing`, and in the unary case (see the `binary` option) it can also be a list of types - `binary` -- (optional, default: `false`) flag indicating whether `op` is a @@ -364,8 +364,8 @@ function implementing_sets(op::Function; "missing" => Vector{Tuple{Type, Type}}(), "specific" => Vector{Tuple{Type, Type}}()) signature_copy = copy(signature) - insert!(signature_copy, 1, LazySet) # insert a dummy type - for set_type in subtypes(LazySet, true) + insert!(signature_copy, 1, ConvexSet) # insert a dummy type + for set_type in subtypes(ConvexSet, true) augmented_set_type = set_type try if type_args isa Type @@ -376,7 +376,7 @@ function implementing_sets(op::Function; end catch e # type combination not available - push!(binary_dict["missing"], (set_type, LazySet)) + push!(binary_dict["missing"], (set_type, ConvexSet)) continue end signature_copy[1] = augmented_set_type # replace dummy type @@ -406,7 +406,7 @@ function _implementing_sets_unary!(dict, op, signature, index, type_args) return Tuple{new_signature...} end - for set_type in subtypes(LazySet, true) + for set_type in subtypes(ConvexSet, true) augmented_set_type = set_type try if type_args isa Type diff --git a/src/Utils/macros.jl b/src/Utils/macros.jl index 6f3ae53487..aded7eb75a 100644 --- a/src/Utils/macros.jl +++ b/src/Utils/macros.jl @@ -37,10 +37,10 @@ macro neutral(SET, NEUT) end # create functions to declare the neutral element - function $SET(X::LazySet{N}, ::$NEUT{N}) where {N} + function $SET(X::ConvexSet{N}, ::$NEUT{N}) where {N} return X end - function $SET(::$NEUT{N}, X::LazySet{N}) where {N} + function $SET(::$NEUT{N}, X::ConvexSet{N}) where {N} return X end function $SET(Y::$NEUT{N}, ::$NEUT{N}) where {N} @@ -107,10 +107,10 @@ macro absorbing(SET, ABS) end # create functions to declare the absorbing element - function $SET(::LazySet{N}, Y::$ABS{N}) where {N} + function $SET(::ConvexSet{N}, Y::$ABS{N}) where {N} return Y end - function $SET(Y::$ABS{N}, ::LazySet{N}) where {N} + function $SET(Y::$ABS{N}, ::ConvexSet{N}) where {N} return Y end function $SET(Y::$ABS{N}, ::$ABS{N}) where {N} @@ -185,15 +185,15 @@ macro declare_array_version(SET, SETARR) end # create in-place modification functions for array version - function $_SET!(X::LazySet{N}, Y::LazySet{N}) where {N} + function $_SET!(X::ConvexSet{N}, Y::ConvexSet{N}) where {N} # no array type: just use the lazy operation return $SET(X, Y) end - function $_SET!(X::LazySet{N}, arr::$SETARR{N}) where {N} + function $_SET!(X::ConvexSet{N}, arr::$SETARR{N}) where {N} push!(array(arr), X) return arr end - function $_SET!(arr::$SETARR{N}, X::LazySet{N}) where {N} + function $_SET!(arr::$SETARR{N}, X::ConvexSet{N}) where {N} push!(array(arr), X) return arr end diff --git a/src/Utils/samples.jl b/src/Utils/samples.jl index 124f4708bf..7262db0e14 100644 --- a/src/Utils/samples.jl +++ b/src/Utils/samples.jl @@ -1,5 +1,5 @@ # ======================== -# Sampling from a LazySet +# Sampling from a ConvexSet # ======================== """ @@ -16,7 +16,7 @@ set to be sampled, and the third argument is the sampler instance. abstract type AbstractSampler end """ - sample(X::LazySet{N}, num_samples::Int; + sample(X::ConvexSet{N}, num_samples::Int; [sampler]=_default_sampler(X), [rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing, @@ -52,7 +52,7 @@ If `include_vertices == true`, we include all vertices computed with `vertices`. Alternatively if a number ``k`` is passed, we plot the first ``k`` vertices returned by `vertices(X)`. """ -function sample(X::LazySet{N}, num_samples::Int; +function sample(X::ConvexSet{N}, num_samples::Int; sampler=_default_sampler(X), rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int, Nothing}=nothing, @@ -77,12 +77,12 @@ function sample(X::LazySet{N}, num_samples::Int; end # without argument, returns a single element (instead of a singleton) -function sample(X::LazySet; kwargs...) +function sample(X::ConvexSet; kwargs...) return sample(X, 1; kwargs...)[1] end # default sampling for LazySets -_default_sampler(::LazySet) = CombinedSampler() +_default_sampler(::ConvexSet) = CombinedSampler() _default_sampler(::LineSegment{N}) where {N} = RejectionSampler(DefaultUniform(zero(N), one(N)), true, Inf) _default_sampler(::HalfSpace) = HalfSpaceSampler() @@ -167,7 +167,7 @@ function RejectionSampler(distr::DefaultUniform; tight::Bool=false, maxiter=Inf) return RejectionSampler([distr], tight, maxiter) end -function RejectionSampler(X::LazySet, distribution=DefaultUniform; +function RejectionSampler(X::ConvexSet, distribution=DefaultUniform; tight::Bool=false, maxiter=Inf) # define the support of the distribution as the smallest box enclosing X n = dim(X) @@ -186,7 +186,7 @@ function RejectionSampler(X::AbstractHyperrectangle) return RejectionSampler(distr, true, Inf) end -function sample!(D::Vector{VN}, X::LazySet, sampler::RejectionSampler; +function sample!(D::Vector{VN}, X::ConvexSet, sampler::RejectionSampler; rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int, Nothing}=nothing) where {N, VN<:AbstractVector{N}} U = sampler.distribution @@ -271,7 +271,7 @@ end RandomWalkSampler() = RandomWalkSampler(true) -function sample!(D::Vector{VN}, X::LazySet, sampler::RandomWalkSampler; +function sample!(D::Vector{VN}, X::ConvexSet, sampler::RandomWalkSampler; rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int, Nothing}=nothing) where {N, VN<:AbstractVector{N}} rng = reseed(rng, seed) @@ -321,7 +321,7 @@ struct CombinedSampler <: AbstractSampler # end -function sample!(D::Vector{VN}, X::LazySet, sampler::CombinedSampler; +function sample!(D::Vector{VN}, X::ConvexSet, sampler::CombinedSampler; rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int, Nothing}=nothing) where {N, VN<:AbstractVector{N}} # try rejection sampling 100 times @@ -379,7 +379,7 @@ struct FaceSampler <: AbstractSampler dim::Int end -function sample!(D::Vector{VN}, X::LazySet, sampler::FaceSampler; +function sample!(D::Vector{VN}, X::ConvexSet, sampler::FaceSampler; rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int, Nothing}=nothing) where {N, VN<:AbstractVector{N}} n = dim(X) diff --git a/src/convert.jl b/src/convert.jl index f77fbd2b0a..489ea1161f 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -3,7 +3,7 @@ import Base.convert #= conversion between set types =# # convert methods for identity (no-ops) -for T in subtypes(LazySet, true) +for T in subtypes(ConvexSet, true) @eval begin Base.convert(::Type{$T}, X::$T) = X end @@ -28,7 +28,7 @@ function convert(T::Type{HPOLYGON}, P::VPolygon) where {HPOLYGON<:AbstractHPolyg end """ - convert(::Type{HPOLYGON}, X::LazySet; [check_boundedness]::Bool=true) where {HPOLYGON<:AbstractHPolygon} + convert(::Type{HPOLYGON}, X::ConvexSet; [check_boundedness]::Bool=true) where {HPOLYGON<:AbstractHPolygon} Converts a polyhedral set to a polygon in vertex representation. @@ -47,7 +47,7 @@ A polygon in constraint representation. We compute the list of constraints of `X`, then instantiate the polygon. """ -function convert(::Type{HPOLYGON}, X::LazySet; check_boundedness::Bool=true) where {HPOLYGON<:AbstractHPolygon} +function convert(::Type{HPOLYGON}, X::ConvexSet; check_boundedness::Bool=true) where {HPOLYGON<:AbstractHPolygon} @assert dim(X) == 2 "set must be two-dimensional for conversion, but it is of dimension $(dim(X))" PT = basetype(HPOLYGON) if check_boundedness && !isbounded(X) @@ -111,7 +111,7 @@ function convert(::Type{VPolytope}, P::AbstractPolytope) end """ - convert(::Type{VPolygon}, X::LazySet) + convert(::Type{VPolygon}, X::ConvexSet) Generic conversion to polygon in vertex representation. @@ -130,7 +130,7 @@ We compute the list of vertices of `X` and wrap the result in a polygon in vertex representation, which guarantees that the vertices are sorted in counter-clockwise fashion. """ -function convert(::Type{VPolygon}, X::LazySet) +function convert(::Type{VPolygon}, X::ConvexSet) @assert dim(X) == 2 "set must be two-dimensional for conversion" return VPolygon(vertices_list(X)) end @@ -186,7 +186,7 @@ function convert(::Type{HPolyhedron{N, Vector{N}}}, X::AbstractPolyhedron) where return HPolyhedron([HalfSpace(Vector(c.a), c.b) for c in clist]) end -function convert(::Type{HPolyhedron}, X::LazySet) +function convert(::Type{HPolyhedron}, X::ConvexSet) return HPolyhedron(constraints_list(X)) end @@ -212,12 +212,12 @@ function convert(::Type{HPolytope}, P::VPolytope) return tohrep(P) end -function convert(::Type{HPolytope}, X::LazySet) +function convert(::Type{HPolytope}, X::ConvexSet) return HPolytope(constraints_list(X)) end """ - convert(::Type{VPolytope}, X::LazySet; [prune]::Bool=true) + convert(::Type{VPolytope}, X::ConvexSet; [prune]::Bool=true) Generic conversion to polytope in vertex representation. @@ -237,7 +237,7 @@ We compute the list of vertices of `X` and wrap the result in a polytope in vertex representation, `VPolytope`. Use the option `prune` to select whether or not to remove redundant vertices before constructing the polytope. """ -function convert(::Type{VPolytope}, X::LazySet; prune::Bool=true) +function convert(::Type{VPolytope}, X::ConvexSet; prune::Bool=true) return VPolytope(vertices_list(X, prune=prune)) end @@ -617,7 +617,7 @@ function convert(::Type{Interval}, H::AbstractHyperrectangle) end """ - convert(::Type{Interval}, S::LazySet{N}) where {N<:Real} + convert(::Type{Interval}, S::ConvexSet{N}) where {N<:Real} Converts a convex set to an interval. @@ -630,7 +630,7 @@ Converts a convex set to an interval. An interval. """ -function convert(::Type{Interval}, S::LazySet{N}) where {N<:Real} +function convert(::Type{Interval}, S::ConvexSet{N}) where {N<:Real} @assert dim(S) == 1 "cannot convert a $(dim(S))-dimensional $(typeof(S)) to `Interval`" return Interval(-ρ(N[-1], S), ρ(N[1], S)) end diff --git a/test/Interfaces/LazySet.jl b/test/Interfaces/ConvexSet.jl similarity index 72% rename from test/Interfaces/LazySet.jl rename to test/Interfaces/ConvexSet.jl index 49ada8231e..2240f31182 100644 --- a/test/Interfaces/LazySet.jl +++ b/test/Interfaces/ConvexSet.jl @@ -1,4 +1,4 @@ -for ST in LazySets.subtypes(LazySet, true) +for ST in LazySets.subtypes(ConvexSet, true) # check that certain methods are implemented isconvextype(ST) isoperationtype(ST) diff --git a/test/Interfaces/interfaces.jl b/test/Interfaces/interfaces.jl index 20b1e6ad3f..a1eb3bf991 100644 --- a/test/Interfaces/interfaces.jl +++ b/test/Interfaces/interfaces.jl @@ -1,12 +1,12 @@ # check that all interace functions are provided -# --- LazySet --- +# --- ConvexSet --- # support vector -@test check_method_implementation(LazySet, σ, +@test check_method_implementation(ConvexSet, σ, Function[S -> (Vector{Float64}, S{Float64})]) # dimension -check_method_implementation(LazySet, dim, Function[S -> (S{Float64},)]) +check_method_implementation(ConvexSet, dim, Function[S -> (S{Float64},)]) # --- AbstractPolyhedron --- diff --git a/test/LazyOperations/CartesianProduct.jl b/test/LazyOperations/CartesianProduct.jl index 03f31d932e..49f8da1f99 100644 --- a/test/LazyOperations/CartesianProduct.jl +++ b/test/LazyOperations/CartesianProduct.jl @@ -265,7 +265,7 @@ for N in [Float64, Float32, Rational{Int}] # in-place modification b = BallInf(N[0, 0], N(2)) - cpa = CartesianProductArray(LazySet{N}[]) + cpa = CartesianProductArray(ConvexSet{N}[]) @test CartesianProduct!(b, b) isa CartesianProduct && length(array(cpa)) == 0 res = CartesianProduct!(b, cpa) diff --git a/test/LazyOperations/Complement.jl b/test/LazyOperations/Complement.jl index a7a67a1144..7665ec1102 100644 --- a/test/LazyOperations/Complement.jl +++ b/test/LazyOperations/Complement.jl @@ -50,7 +50,7 @@ for N in [Float64, Rational{Int}, Float32] H = HalfSpace(N[1, 0], N(1)) # x <= 1 @test complement(H) == HalfSpace(N[-1, 0], N(-1)) @test constraints_list(Complement(H)) == [HalfSpace(N[-1, 0], N(-1))] - # test fallback for <: LazySet + # test fallback for <: ConvexSet c = complement(N[0 1; 1 0] * H) @test c isa UnionSetArray && length(array(c)) == 1 @test first(array(c)) == HalfSpace(N[0, -1], N(-1)) # complement of y <= 1 is y >= 1 diff --git a/test/LazyOperations/ConvexHull.jl b/test/LazyOperations/ConvexHull.jl index 39c37ca19f..32ea07bc91 100644 --- a/test/LazyOperations/ConvexHull.jl +++ b/test/LazyOperations/ConvexHull.jl @@ -85,11 +85,11 @@ for N in [Float64, Rational{Int}, Float32] Singleton(N[7//5, 4//5])]) # array getter - v = Vector{LazySet{N}}() + v = Vector{ConvexSet{N}}() @test array(ConvexHullArray(v)) ≡ v # in-place modification - cha = ConvexHullArray(LazySet{N}[]) + cha = ConvexHullArray(ConvexSet{N}[]) @test ConvexHull!(b1, b1) isa ConvexHull && length(array(cha)) == 0 res = ConvexHull!(b1, cha) @test res isa ConvexHullArray && length(array(cha)) == 1 diff --git a/test/LazyOperations/Intersection.jl b/test/LazyOperations/Intersection.jl index 8fcc9e6761..3c3d1ad161 100644 --- a/test/LazyOperations/Intersection.jl +++ b/test/LazyOperations/Intersection.jl @@ -105,7 +105,7 @@ for N in [Float64, Rational{Int}, Float32] @test ones(N, 2) ∈ IArr && N[5, 5] ∉ IArr # array getter - v = Vector{LazySet{N}}() + v = Vector{ConvexSet{N}}() @test array(IntersectionArray(v)) ≡ v # constructor with size hint and type diff --git a/test/LazyOperations/MinkowskiSum.jl b/test/LazyOperations/MinkowskiSum.jl index 7f7aa257f2..028e61ae32 100644 --- a/test/LazyOperations/MinkowskiSum.jl +++ b/test/LazyOperations/MinkowskiSum.jl @@ -48,7 +48,7 @@ for N in [Float64, Rational{Int}, Float32] # center @test center(s) == N[0, 5] - # Sum of array of LazySet + # Sum of array of ConvexSet # 2-elements ms = MinkowskiSum(Singleton(N[1]), Singleton(N[2])) @test ρ(N[1], ms) == 3 @@ -110,14 +110,14 @@ for N in [Float64, Rational{Int}, Float32] @test LazySets.is_array_constructor(MinkowskiSumArray) # array getter - v = Vector{LazySet{N}}() + v = Vector{ConvexSet{N}}() @test array(MinkowskiSumArray(v)) ≡ v # constructor with size hint and type MinkowskiSumArray(10, N) # in-place modification - msa = MinkowskiSumArray(LazySet{N}[]) + msa = MinkowskiSumArray(ConvexSet{N}[]) @test MinkowskiSum!(b1, b1) isa MinkowskiSum && length(array(msa)) == 0 res = MinkowskiSum!(b1, msa) @test res isa MinkowskiSumArray && length(array(msa)) == 1 @@ -206,8 +206,8 @@ for N in [Float64, Rational{Int}, Float32] # neutral element z = ZeroSet{N}(2) - msa = MinkowskiSumArray(LazySet{N}[]) - cms = CachedMinkowskiSumArray(LazySet{N}[]) + msa = MinkowskiSumArray(ConvexSet{N}[]) + cms = CachedMinkowskiSumArray(ConvexSet{N}[]) @test neutral(MinkowskiSum) == neutral(MinkowskiSumArray) == neutral(CachedMinkowskiSumArray) == ZeroSet @test b1 + z == z + b1 == b1 diff --git a/test/Sets/Ball2.jl b/test/Sets/Ball2.jl index a793501bd0..c8b6958199 100644 --- a/test/Sets/Ball2.jl +++ b/test/Sets/Ball2.jl @@ -94,7 +94,7 @@ for N in [Float64, Float32] subset, point = ⊆(b1, b3, true) @test b1 ⊈ b3 && !subset && point ∈ b1 && point ∉ b3 @test b3 ⊆ b1 && ⊆(b3, b1, true)[1] - # inclusion of a Ball2 in a polyhedral LazySet + # inclusion of a Ball2 in a polyhedral ConvexSet b = Ball2(zeros(N, 4), N(1)) p = BallInf(zeros(N, 2), N(1)) × BallInf(zeros(N, 2), N(1)) subset, point = ⊆(b, p, true) diff --git a/test/Sets/EmptySet.jl b/test/Sets/EmptySet.jl index 1ac82ffa3d..75da6a60df 100644 --- a/test/Sets/EmptySet.jl +++ b/test/Sets/EmptySet.jl @@ -104,7 +104,7 @@ end @test EmptySet(2) == ∅(2) == EmptySet{Float64}(2) # intersection -for X in LazySets.subtypes(LazySet, true) +for X in LazySets.subtypes(ConvexSet, true) if X <: RotatedHyperrectangle || isoperationtype(X) # TODO #2391 continue end diff --git a/test/Utils/check_method_implementation.jl b/test/Utils/check_method_implementation.jl index 69eeb1006b..15d3b3e7cf 100644 --- a/test/Utils/check_method_implementation.jl +++ b/test/Utils/check_method_implementation.jl @@ -33,7 +33,7 @@ This function can also print all intermediate results to STDOUT. ### Examples ```jldoctest -julia> check_method_implementation(LazySet, σ, +julia> check_method_implementation(ConvexSet, σ, Function[S -> (AbstractVector{Float64}, S)]) true ``` diff --git a/test/runtests.jl b/test/runtests.jl index dbfe15e23b..817eb65231 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -84,9 +84,9 @@ if test_suite_basic @time @testset "LazySets.CDDLib" begin include("Interfaces/CDDLib.jl") end # ======================================= - # Testing types that inherit from LazySet + # Testing types that inherit from ConvexSet # ======================================= - @time @testset "LazySets.LazySet" begin include("Interfaces/LazySet.jl") end + @time @testset "LazySets.ConvexSet" begin include("Interfaces/ConvexSet.jl") end @time @testset "LazySets.Singleton" begin include("Sets/Singleton.jl") end @time @testset "LazySets.Ball1" begin include("Sets/Ball1.jl") end @time @testset "LazySets.Ball2" begin include("Sets/Ball2.jl") end @@ -133,7 +133,7 @@ if test_suite_basic @time @testset "LazySets.CompactSet" begin include("Interfaces/CompactSet.jl") end # ========================================================= - # Testing other set types that do not inherit from LazySet + # Testing other set types that do not inherit from ConvexSet # ========================================================= @time @testset "LazySets.Complement" begin include("LazyOperations/Complement.jl") end @time @testset "LazySets.DensePolynomialZonotope" begin include("Sets/DensePolynomialZonotope.jl") end