Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outsource HPolyhedron to its own module #3589

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/src/lib/interfaces/AbstractPolyhedron.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ LazySets._isbounded_stiemke
LazySets._linear_map_polyhedron
```

Some common functions implemented by several subtypes:

```@docs
addconstraint!(::AbstractPolyhedron, ::HalfSpace)
is_hyperplanar(::AbstractPolyhedron)
```

Some common functions to work with linear constraints:

```@docs
Expand Down
45 changes: 25 additions & 20 deletions docs/src/lib/sets/HPolyhedron.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```@meta
CurrentModule = LazySets
CurrentModule = LazySets.HPolyhedronModule
```

# [Polyhedron in constraint representation (HPolyhedron)](@id def_HPolyhedron)
Expand All @@ -8,44 +8,49 @@ CurrentModule = LazySets
HPolyhedron
```

## Operations

The following methods are shared between `HPolytope` and `HPolyhedron`.

```@docs
dim(::HPoly)
ρ(::AbstractVector{M}, ::HPoly{N}) where {M, N}
σ(::AbstractVector{M}, ::HPoly{N}) where {M, N}
addconstraint!(::HPoly, ::HalfSpace)
constraints_list(::HPoly)
tohrep(::HPoly)
tovrep(::HPoly)
dim(::HPoly)
normalize(::HPoly{N}, p::Real=N(2)) where {N}
translate(::HPoly, ::AbstractVector)
remove_redundant_constraints(::HPoly)
remove_redundant_constraints!(::HPoly)
tohrep(::HPoly)
tovrep(::HPoly)
addconstraint!(::HPoly, ::HalfSpace)
ρ(::AbstractVector{M}, ::HPoly{N}) where {M, N}
σ(::AbstractVector{M}, ::HPoly{N}) where {M, N}
translate(::HPoly, ::AbstractVector)
```

The following methods are specific to `HPolyhedron`.

```@docs
rand(::Type{HPolyhedron})
```

```@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))
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`reflect`](@ref reflect(::LazySet))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`isempty`](@ref isempty(::LazySet{N}, ::Bool=false) where {N})
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet)
* [`reflect`](@ref reflect(::LazySet))

Inherited from [`AbstractPolyhedron`](@ref):
* [`∈`](@ref ∈(::AbstractVector, ::AbstractPolyhedron))
* [`an_element`](@ref an_element(::AbstractPolyhedron))
* [`constrained_dimensions`](@ref constrained_dimensions(::AbstractPolyhedron))

The following methods are specific to `HPolyhedron`.

```@docs
rand(::Type{HPolyhedron})
```

Inherited from [`AbstractPolyhedron`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolyhedron{N}) where {N})
* [`isuniversal`](@ref isuniversal(::AbstractPolyhedron{N}, ::Bool=false) where {N})
* [`vertices_list`](@ref vertices_list(::AbstractPolyhedron, ::Bool=false))
* [`∈`](@ref ∈(::AbstractVector, ::AbstractPolyhedron))
1 change: 0 additions & 1 deletion src/Initialization/init_Polyhedra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ function _is_polyhedra_backend(backend::Polyhedra.Library)
return true
end

eval(load_polyhedra_hpolyhedron())
eval(load_polyhedra_mesh())
eval(load_polyhedra_lazyset())
4 changes: 1 addition & 3 deletions src/Initialization/init_Symbolics.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using .Symbolics: gradient,
simplify,
using .Symbolics: simplify,
Num, # variable like, e.g. x[1]
Term, # term like, eg. x[1] + x[2] == 1
Symbolic,
Expand All @@ -20,4 +19,3 @@ end

eval(load_symbolics_hyperplane())
eval(load_symbolics_halfspace())
eval(load_symbolics_hpolyhedron())
43 changes: 42 additions & 1 deletion src/Interfaces/AbstractPolyhedron_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export constrained_dimensions,
tosimplehrep,
remove_redundant_constraints,
remove_redundant_constraints!,
isfeasible
isfeasible,
addconstraint!,
is_hyperplanar

isconvextype(::Type{<:AbstractPolyhedron}) = true

Expand Down Expand Up @@ -1254,3 +1256,42 @@ function isfeasible(constraints::AbstractVector{<:HalfSpace},
return !_isempty_polyhedron_lp(constraints, witness; solver=solver)
end
end

"""
addconstraint!(P::AbstractPolyhedron, constraint::HalfSpace)

Add a linear constraint to a set in constraint representation in-place.

### Input

- `P` -- set in constraint representation
- `constraint` -- linear constraint to add

### Notes

It is left to the user to guarantee that the dimension of all linear constraints
is the same.
"""
function addconstraint!(::AbstractPolyhedron, ::HalfSpace) end

"""
is_hyperplanar(P::AbstractPolyhedron)

Determine whether a polyhedron is equivalent to a hyperplane.

### Input

- `P` -- polyhedron

### Output

`true` iff `P` is hyperplanar, i.e., consists of two linear constraints
``a·x ≤ b`` and ``-a·x ≤ -b``.
"""
function is_hyperplanar(::AbstractPolyhedron) end

# internal function; defined here due to dependency SymEngine and submodules
function _is_halfspace() end

# internal function; defined here due to dependency SymEngine and submodules
function _is_hyperplane() end
4 changes: 3 additions & 1 deletion src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ include("Sets/HPolygonOpt.jl")
include("Sets/HPolytope/HPolytopeModule.jl")
@reexport using ..HPolytopeModule: HPolytope

include("Sets/HPolyhedron.jl")
include("Sets/HPolyhedron/HPolyhedronModule.jl")
@reexport using ..HPolyhedronModule: HPolyhedron
using ..HPolyhedronModule: HPoly

include("Sets/HParallelotope/HParallelotopeModule.jl")
@reexport using ..HParallelotopeModule: HParallelotope,
Expand Down
Loading
Loading