diff --git a/docs/src/lib/concrete_binary_operations/convex_hull.md b/docs/src/lib/concrete_binary_operations/convex_hull.md index d54242d6ca..9081f60562 100644 --- a/docs/src/lib/concrete_binary_operations/convex_hull.md +++ b/docs/src/lib/concrete_binary_operations/convex_hull.md @@ -11,7 +11,6 @@ CurrentModule = LazySets ```@docs convex_hull(::LazySet, ::LazySet) -convex_hull(::HPoly, ::HPoly) convex_hull(::Vector{VN}) where {N, VN<:AbstractVector{N}} monotone_chain! ``` diff --git a/docs/src/lib/sets/HPolyhedron.md b/docs/src/lib/sets/HPolyhedron.md index 06504de396..920511bfd8 100644 --- a/docs/src/lib/sets/HPolyhedron.md +++ b/docs/src/lib/sets/HPolyhedron.md @@ -10,17 +10,38 @@ HPolyhedron ## Conversion -```@docs +```julia convert(::Type{HPolyhedron}, ::LazySet) convert(::Type{HPolyhedron}, ::HRep) ``` ## Operations +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +rand(::Type{LazySet}) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs +rand(::Type{HPolyhedron}) +``` + The following methods are shared between `HPolytope` and `HPolyhedron`. +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +dim(::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` ```@docs -constraints_list(::HPoly) dim(::HPoly) normalize(::HPoly{N}, p::Real=N(2)) where {N} remove_redundant_constraints(::HPoly) @@ -28,36 +49,113 @@ remove_redundant_constraints!(::HPoly) tohrep(::HPoly) tovrep(::HPoly) addconstraint!(::HPoly, ::HalfSpace) +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +ρ(::AbstractVector, ::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs ρ(::AbstractVector{M}, ::HPoly{N}) where {M, N} +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +σ(::AbstractVector, ::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs σ(::AbstractVector{M}, ::HPoly{N}) where {M, N} -translate(::HPoly, ::AbstractVector) ``` - -The following methods are specific to `HPolyhedron`. - +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +translate(::LazySet, ::AbstractVector) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` ```@docs -rand(::Type{HPolyhedron}) +translate(::HPoly, ::AbstractVector) +convex_hull(::HPoly, ::HPoly) ``` +Undocumented implementations: +* [`constraints_list`](@ref constraints_list(::LazySet)) +* [`isempty`](@ref isempty(::LazySet)) +`ishyperplanar(::HPolyhedron)` +* [`isoperationtype`](@ref isoperationtype(::Type{LazySet})) +* [`permute`](@ref permute(::LazySet, ::AbstractVector{Int})) +* [`minkowski_sum`](@ref minkowski_sum(::LazySet, ::LazySet)) + ```@meta CurrentModule = LazySets ``` Inherited from [`LazySet`](@ref): -* [`diameter`](@ref diameter(::LazySet, ::Real)) -* [`high`](@ref high(::LazySet)) -* [`isempty`](@ref isempty(::LazySet{N}, ::Bool=false) where {N}) -* [`low`](@ref low(::LazySet)) -* [`norm`](@ref norm(::LazySet, ::Real)) -* [`radius`](@ref radius(::LazySet, ::Real)) +* [`area`](@ref area(::LazySet)) +* [`complement`](@ref complement(::LazySet)) +* [`concretize`](@ref concretize(::LazySet)) +* [`constraints`](@ref constraints(::LazySet)) +* [`convex_hull`](@ref convex_hull(::LazySet)) +* `copy(::Type{LazySet})` +* [`diameter`](@ref diameter(::LazySet, ::Real=Inf)) +* [`eltype`](@ref eltype(::Type{<:LazySet})) +* [`eltype`](@ref eltype(::LazySet)) +* [`isboundedtype`](@ref isboundedtype(::Type{LazySet})) +* [`isoperation`](@ref isoperation(::LazySet)) +* [`norm`](@ref norm(::LazySet, ::Real=Inf)) +* [`radius`](@ref radius(::LazySet, ::Real=Inf)) +* [`rectify`](@ref rectify(::LazySet)) * [`reflect`](@ref reflect(::LazySet)) * [`singleton_list`](@ref singleton_list(::LazySet)) -* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet) +* [`surface`](@ref surface(::LazySet)) +* [`vertices`](@ref vertices(::LazySet)) +* [`volume`](@ref volume(::LazySet)) +* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector)) +* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet)) +* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet)) +* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet)) +* [`sample`](@ref sample(::LazySet, ::Int=1)) +* [`scale`](@ref scale(::Real, ::LazySet)) +* [`cartesian_product`](@ref cartesian_product(::LazySet, ::LazySet)) +* [`difference`](@ref difference(::LazySet, ::LazySet)) +* [`distance`](@ref distance(::LazySet, ::LazySet; ::Real=2.0)) +* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet)) +* [`≈`](@ref ≈(::LazySet, ::LazySet)) +* [`==`](@ref ==(::LazySet, ::LazySet)) +* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet)) +* [`⊂`](@ref ⊂(::LazySet, ::LazySet)) +* [`minkowski_difference`](@ref minkowski_difference(::LazySet, ::LazySet)) + +Inherited from [`ConvexSet`](@ref): +* [`linear_combination`](@ref linear_combination(::ConvexSet, ::ConvexSet)) Inherited from [`AbstractPolyhedron`](@ref): * [`an_element`](@ref an_element(::AbstractPolyhedron)) * [`constrained_dimensions`](@ref constrained_dimensions(::AbstractPolyhedron)) +* [`extrema`](@ref extrema(::AbstractPolyhedron)) +* [`extrema`](@ref extrema(::AbstractPolyhedron, ::Int)) +* [`high`](@ref high(::AbstractPolyhedron)) +* [`high`](@ref high(::AbstractPolyhedron, ::Int)) * [`isbounded`](@ref isbounded(::AbstractPolyhedron{N}) where {N}) +* [`isconvextype`](@ref isconvextype(::Type{AbstractPolyhedron})) +* [`ispolyhedral`](@ref ispolyhedral(::AbstractPolyhedron)) * [`isuniversal`](@ref isuniversal(::AbstractPolyhedron, ::Bool=false)) +* [`low`](@ref low(::AbstractPolyhedron)) +* [`low`](@ref low(::AbstractPolyhedron, ::Int)) * [`vertices_list`](@ref vertices_list(::AbstractPolyhedron, ::Bool=false)) * [`∈`](@ref ∈(::AbstractVector, ::AbstractPolyhedron)) +* [`project`](@ref project(::AbstractPolyhedron, ::AbstractVector{Int})) +* [`intersection`](@ref intersection(::AbstractPolyhedron, ::AbstractPolyhedron)) +* [`isdisjoint`](@ref isdisjoint(::AbstractPolyhedron, ::AbstractPolyhedron)) +* [`⊆`](@ref ⊆(::LazySet, ::AbstractPolyhedron)) +* [`minkowski_sum`](@ref minkowski_sum(::AbstractPolyhedron, ::AbstractPolyhedron)) diff --git a/docs/src/lib/sets/HPolytope.md b/docs/src/lib/sets/HPolytope.md index f23a12f88e..546f9a0439 100644 --- a/docs/src/lib/sets/HPolytope.md +++ b/docs/src/lib/sets/HPolytope.md @@ -19,33 +19,162 @@ HPolytope ## Conversion -```@docs +```julia convert(::Type{HPolytope}, ::LazySet) ``` ## Operations ```@meta -CurrentModule = LazySets +CurrentModule = LazySets.HPolytopeModule ``` -Most functionality is shared with [`HPolyhedron`](@ref). -Additional functionality specific to `HPolytope` is listed below. - +```@docs +isbounded(::HPolytope, ::Bool=true) +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +rand(::Type{LazySet}) +``` ```@meta CurrentModule = LazySets.HPolytopeModule ``` - ```@docs rand(::Type{HPolytope}) vertices_list(::HPolytope) -isbounded(::HPolytope, ::Bool=true) ``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` + +The following functionality is shared with [`HPolyhedron`](@ref). + +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +dim(::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs; canonical=false +dim(::HPoly) +normalize(::HPoly{N}, p::Real=N(2)) where {N} +remove_redundant_constraints(::HPoly) +remove_redundant_constraints!(::HPoly) +tohrep(::HPoly) +tovrep(::HPoly) +addconstraint!(::HPoly, ::HalfSpace) +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +ρ(::AbstractVector, ::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs; canonical=false +ρ(::AbstractVector{M}, ::HPoly{N}) where {M, N} +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +σ(::AbstractVector, ::LazySet) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs; canonical=false +σ(::AbstractVector{M}, ::HPoly{N}) where {M, N} +``` +```@meta +CurrentModule = LazySets.API +``` +```@docs; canonical=false +translate(::LazySet, ::AbstractVector) +``` +```@meta +CurrentModule = LazySets.HPolyhedronModule +``` +```@docs; canonical=false +translate(::HPoly, ::AbstractVector) +convex_hull(::HPoly, ::HPoly) +``` + +```@meta +CurrentModule = LazySets.API +``` + +Undocumented implementations: +* [`constraints_list`](@ref constraints_list(::LazySet)) +* [`isempty`](@ref isempty(::LazySet)) +* [`isoperationtype`](@ref isoperationtype(::Type{LazySet})) +* [`permute`](@ref permute(::LazySet, ::AbstractVector{Int})) +* [`minkowski_sum`](@ref minkowski_sum(::LazySet, ::LazySet)) + ```@meta CurrentModule = LazySets ``` +Inherited from [`LazySet`](@ref): +* [`area`](@ref area(::LazySet)) +* [`complement`](@ref complement(::LazySet)) +* [`concretize`](@ref concretize(::LazySet)) +* [`constraints`](@ref constraints(::LazySet)) +* [`convex_hull`](@ref convex_hull(::LazySet)) +* `copy(::Type{LazySet})` +* [`diameter`](@ref diameter(::LazySet, ::Real=Inf)) +* [`eltype`](@ref eltype(::Type{<:LazySet})) +* [`eltype`](@ref eltype(::LazySet)) +* [`isoperation`](@ref isoperation(::LazySet)) +* [`norm`](@ref norm(::LazySet, ::Real=Inf)) +* [`radius`](@ref radius(::LazySet, ::Real=Inf)) +* [`rectify`](@ref rectify(::LazySet)) +* [`reflect`](@ref reflect(::LazySet)) +* [`singleton_list`](@ref singleton_list(::LazySet)) +* [`surface`](@ref surface(::LazySet)) +* [`vertices`](@ref vertices(::LazySet)) +* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector)) +* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet)) +* [`∈`](@ref ∈(::AbstractVector, ::LazySet)) +* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet)) +* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet)) +* [`sample`](@ref sample(::LazySet, ::Int=1)) +* [`scale`](@ref scale(::Real, ::LazySet)) +* [`cartesian_product`](@ref cartesian_product(::LazySet, ::LazySet)) +* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet)) +* [`≈`](@ref ≈(::LazySet, ::LazySet)) +* [`==`](@ref ==(::LazySet, ::LazySet)) +* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet)) +* [`⊂`](@ref ⊂(::LazySet, ::LazySet)) +* [`minkowski_difference`](@ref minkowski_difference(::LazySet, ::LazySet)) + +Inherited from [`ConvexSet`](@ref): +* [`linear_combination`](@ref linear_combination(::ConvexSet, ::ConvexSet)) + +Inherited from [`AbstractPolyhedron`](@ref): +* [`an_element`](@ref an_element(::AbstractPolyhedron)) +* [`extrema`](@ref extrema(::AbstractPolyhedron)) +* [`extrema`](@ref extrema(::AbstractPolyhedron, ::Int)) +* [`high`](@ref high(::AbstractPolyhedron)) +* [`high`](@ref high(::AbstractPolyhedron, ::Int)) +* [`ispolyhedral`](@ref ispolyhedral(::AbstractPolyhedron)) +* [`low`](@ref low(::AbstractPolyhedron)) +* [`low`](@ref low(::AbstractPolyhedron, ::Int)) +* [`project`](@ref project(::AbstractPolyhedron, ::AbstractVector{Int})) +* [`intersection`](@ref intersection(::AbstractPolyhedron, ::AbstractPolyhedron)) +* [`isdisjoint`](@ref isdisjoint(::AbstractPolyhedron, ::AbstractPolyhedron)) + Inherited from [`AbstractPolytope`](@ref): +* [`isboundedtype`](@ref isboundedtype(::Type{AbstractPolytope})) +* [`isconvextype`](@ref isconvextype(::Type{AbstractPolytope})) * [`isuniversal`](@ref isuniversal(::AbstractPolytope, ::Bool=false)) * [`volume`](@ref volume(::AbstractPolytope)) +* [`⊆`](@ref ⊆(::AbstractPolytope, ::AbstractPolyhedron)) diff --git a/src/Sets/HPolyhedron/constraints_list.jl b/src/Sets/HPolyhedron/constraints_list.jl index cd7bda9c5a..18ed0e1ef4 100644 --- a/src/Sets/HPolyhedron/constraints_list.jl +++ b/src/Sets/HPolyhedron/constraints_list.jl @@ -1,17 +1,3 @@ -""" - constraints_list(P::HPoly) - -Return the list of constraints defining a polyhedron in constraint -representation. - -### Input - -- `P` -- polyhedron in constraint representation - -### Output - -The list of constraints of the polyhedron. -""" function constraints_list(P::HPoly) return P.constraints end diff --git a/src/Sets/HPolyhedron/convert.jl b/src/Sets/HPolyhedron/convert.jl index 003d4f4d1b..a260178454 100644 --- a/src/Sets/HPolyhedron/convert.jl +++ b/src/Sets/HPolyhedron/convert.jl @@ -1,21 +1,3 @@ -""" - convert(::Type{HPolyhedron}, X::LazySet) - -Convert a polyhedral set to a polyhedron in constraint representation. - -### Input - -- `HPolyhedron` -- target type -- `X` -- polyhedral set - -### Output - -The given set represented as a polyhedron in constraint representation. - -### Algorithm - -This method uses `constraints_list`. -""" function convert(::Type{HPolyhedron}, X::LazySet) if !ispolyhedral(X) error("conversion to `HPolyhedron` requires a polyhedral set") @@ -37,21 +19,6 @@ function load_Polyhedra_convert_HPolyhedron() using .Polyhedra: HRep using ..HPolytopeModule: _convert_HPoly - """ - convert(::Type{HPolyhedron}, P::HRep) - - Convert an `HRep` polyhedron from `Polyhedra.jl` to a polyhedron in constraint - representation . - - ### Input - - - `HPolyhedron` -- target type - - `P` -- `HRep` polyhedron - - ### Output - - An `HPolyhedron`. - """ function convert(::Type{HPolyhedron}, P::HRep) return _convert_HPoly(HPolyhedron, P) end diff --git a/src/Sets/HPolyhedron/dim.jl b/src/Sets/HPolyhedron/dim.jl index 7aba4be608..98b7f5cb0f 100644 --- a/src/Sets/HPolyhedron/dim.jl +++ b/src/Sets/HPolyhedron/dim.jl @@ -1,16 +1,11 @@ """ - dim(P::HPoly) - -Return the dimension of a polyhedron in constraint representation. +# Extended help -### Input - -- `P` -- polyhedron in constraint representation + dim(P::HPoly) ### Output -The ambient dimension of the polyhedron in constraint representation. -If it has no constraints, the result is ``-1``. +If `P` has no constraints, the result is ``-1``. """ function dim(P::HPoly) return length(P.constraints) == 0 ? -1 : length(P.constraints[1].a) diff --git a/src/Sets/HPolyhedron/rand.jl b/src/Sets/HPolyhedron/rand.jl index 73d12e7088..5cc48a6586 100644 --- a/src/Sets/HPolyhedron/rand.jl +++ b/src/Sets/HPolyhedron/rand.jl @@ -1,21 +1,9 @@ """ +# Extended help + rand(::Type{HPolyhedron}; [N]::Type{<:Real}=Float64, [dim]::Int=2, [rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing) -Create a random polyhedron. - -### Input - -- `HPolyhedron` -- type for dispatch -- `N` -- (optional, default: `Float64`) numeric type -- `dim` -- (optional, default: 2) dimension (is ignored) -- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator -- `seed` -- (optional, default: `nothing`) seed for reseeding - -### Output - -A random polyhedron. - ### Algorithm We first create a random polytope and then for each constraint randomly (50%) diff --git a/src/Sets/HPolyhedron/support_function.jl b/src/Sets/HPolyhedron/support_function.jl index 914df40189..f5c6c3ee9d 100644 --- a/src/Sets/HPolyhedron/support_function.jl +++ b/src/Sets/HPolyhedron/support_function.jl @@ -1,22 +1,19 @@ """ +# Extended help + ρ(d::AbstractVector{M}, P::HPoly{N}; solver=default_lp_solver(M, N)) where {M, N} -Evaluate the support function of a polyhedron in constraint representation in a -given direction. - ### Input -- `d` -- direction -- `P` -- polyhedron in constraint representation - `solver` -- (optional, default: `default_lp_solver(M, N)`) the backend used to solve the linear program ### Output -The evaluation of the support function for the polyhedron. -If a polytope is unbounded in the given direction, we throw an error. -If a polyhedron is unbounded in the given direction, the result is `Inf`. +If `P` is unbounded in the given direction, there are two cases: +- If `P` is an `HPolytope`, we throw an error. +- If `P` is an `HPolyedron`, the result is `Inf`. """ function ρ(d::AbstractVector{M}, P::HPoly{N}; solver=default_lp_solver(M, N)) where {M,N} diff --git a/src/Sets/HPolyhedron/support_vector.jl b/src/Sets/HPolyhedron/support_vector.jl index 7fcb5c75dd..9b03d68c1f 100644 --- a/src/Sets/HPolyhedron/support_vector.jl +++ b/src/Sets/HPolyhedron/support_vector.jl @@ -1,23 +1,19 @@ """ +# Extended help + σ(d::AbstractVector{M}, P::HPoly{N}; solver=default_lp_solver(M, N) where {M, N} -Return a support vector of a polyhedron in constraint representation in a given -direction. - ### Input -- `d` -- direction -- `P` -- polyhedron in constraint representation - `solver` -- (optional, default: `default_lp_solver(M, N)`) the backend used to solve the linear program ### Output -The support vector in the given direction. -If a polytope is unbounded in the given direction, we throw an error. -If a polyhedron is unbounded in the given direction, the result contains `±Inf` -entries. +If `P` is unbounded in the given direction, there are two cases: +- If `P` is an `HPolytope`, we throw an error. +- If `P` is an `HPolyedron`, the result contains `±Inf` entries. """ function σ(d::AbstractVector{M}, P::HPoly{N}; solver=default_lp_solver(M, N)) where {M,N} diff --git a/src/Sets/HPolyhedron/translate.jl b/src/Sets/HPolyhedron/translate.jl index 50543c0e5c..1ed0adbbc8 100644 --- a/src/Sets/HPolyhedron/translate.jl +++ b/src/Sets/HPolyhedron/translate.jl @@ -1,28 +1,17 @@ """ - translate(P::HPoly, v::AbstractVector; [share]::Bool=false) +# Extended help -Translate (i.e., shift) a polyhedron in constraint representation by a given -vector. + translate(P::HPoly, v::AbstractVector; [share]::Bool=false) ### Input -- `P` -- polyhedron in constraint representation -- `v` -- translation vector - `share` -- (optional, default: `false`) flag for sharing unmodified parts of the original set representation -### Output - -A translated polyhedron in constraint representation. - ### Notes The normal vectors of the constraints (vector `a` in `a⋅x ≤ b`) are shared with the original constraints if `share == true`. - -### Algorithm - -We translate every constraint. """ function translate(P::HPoly, v::AbstractVector; share::Bool=false) @assert length(v) == dim(P) "cannot translate a $(dim(P))-dimensional " * diff --git a/src/Sets/HPolytope/convert.jl b/src/Sets/HPolytope/convert.jl index 0c566d97c0..b5ef13c09c 100644 --- a/src/Sets/HPolytope/convert.jl +++ b/src/Sets/HPolytope/convert.jl @@ -1,21 +1,3 @@ -""" - convert(::Type{HPolytope}, X::LazySet) - -Convert a polytopic set to a polytope in constraint representation. - -### Input - -- `HPolytope` -- target type -- `X` -- polytopic set - -### Output - -The given polytope represented as a polytope in constraint representation. - -### Algorithm - -This method uses `constraints_list`. -""" function convert(::Type{HPolytope}, X::LazySet) if !isboundedtype(typeof(X)) || !ispolyhedral(X) error("conversion to `HPolytope` requires a polytopic set") diff --git a/src/Sets/HPolytope/rand.jl b/src/Sets/HPolytope/rand.jl index 74b343f396..ee38e9feb0 100644 --- a/src/Sets/HPolytope/rand.jl +++ b/src/Sets/HPolytope/rand.jl @@ -1,23 +1,14 @@ """ +# Extended help + rand(::Type{HPolytope}; [N]::Type{<:Real}=Float64, [dim]::Int=2, [rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing) -Create a random polytope in constraint representation. - ### Input -- `HPolytope` -- type for dispatch -- `N` -- (optional, default: `Float64`) numeric type -- `dim` -- (optional, default: 2) dimension -- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator -- `seed` -- (optional, default: `nothing`) seed for reseeding - `num_vertices` -- (optional, default: `-1`) upper bound on the number of vertices of the polytope (see comment below) -### Output - -A random polytope in constraint representation. - ### Algorithm If `num_vertices == 0`, we create a fixed infeasible polytope (corresponding to