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 Zonotope to its own module #3594

Merged
merged 7 commits into from
Jul 18, 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
1 change: 1 addition & 0 deletions docs/src/lib/concrete_binary_operations/intersection.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ intersection(::LineSegment, ::Line2D)
intersection(::AbstractZonotope{N}, ::HalfSpace{N}) where {N}
intersection(::Star, ::HalfSpace)
intersection!(::Star, ::HalfSpace)
LazySets._bound_intersect_2D(::Zonotope, ::Line2D)
```
45 changes: 27 additions & 18 deletions docs/src/lib/sets/Zonotope.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
```@meta
CurrentModule = LazySets
CurrentModule = LazySets.ZonotopeModule
```

# [Zonotope](@id def_Zonotope)

```@docs
Zonotope
```

## Operations

```@docs
center(::Zonotope)
rand(::Type{Zonotope})
generators(::Zonotope)
genmat(::Zonotope)
scale!(::Real, Z::Zonotope)
ngens(::Zonotope)
togrep(::Zonotope)
low(::Zonotope, ::Int)
high(::Zonotope, ::Int)
low(::Zonotope, ::Int)
ngens(::Zonotope)
rand(::Type{Zonotope})
remove_redundant_generators(Z::Zonotope{N}) where {N}
remove_zero_generators(::Zonotope)
togrep(::Zonotope)
linear_map!(::Zonotope, ::AbstractMatrix, ::Zonotope)
LazySets._bound_intersect_2D(::Zonotope, ::Line2D)
remove_redundant_generators(Z::Zonotope{N}) where {N}
scale!(::Real, Z::Zonotope)
translate!(::Zonotope, ::AbstractVector)
```

```@meta
CurrentModule = LazySets
```

Inherited from [`LazySet`](@ref):
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`high`](@ref high(::LazySet))
* [`low`](@ref low(::LazySet))
* [`norm`](@ref norm(::LazySet, ::Real))
* [`radius`](@ref radius(::LazySet, ::Real))
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Expand All @@ -36,20 +45,20 @@ Inherited from [`AbstractPolytope`](@ref):
* [`volume`](@ref volume(::AbstractPolytope))

Inherited from [`AbstractCentrallySymmetricPolytope`](@ref):
* [`an_element`](@ref an_element(::AbstractCentrallySymmetricPolytope))
* [`dim`](@ref dim(::AbstractCentrallySymmetricPolytope))
* [`isempty`](@ref isempty(::AbstractCentrallySymmetricPolytope))
* [`an_element`](@ref an_element(::AbstractCentrallySymmetricPolytope))

Inherited from [`AbstractZonotope`](@ref):
* [`ρ`](@ref ρ(::AbstractVector, ::AbstractZonotope))
* [`σ`](@ref σ(::AbstractVector, ::AbstractZonotope))
* [`∈`](@ref ∈(::AbstractVector, ::AbstractZonotope))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`split`](@ref split(::AbstractZonotope, ::Int))
* [`split`](@ref split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int}))
* [`constraints_list`](@ref constraints_list(::AbstractZonotope))
* [`constraints_list`](@ref constraints_list(::AbstractZonotope{N}; ::Bool=true) where {N<:AbstractFloat})
* [`vertices_list`](@ref vertices_list(::AbstractZonotope))
* [`order`](@ref order(::AbstractZonotope))
* [`reduce_order`](@ref reduce_order(::AbstractZonotope, ::Real, ::AbstractReductionMethod=GIR05()))
* [`reflect`](@ref reflect(::AbstractZonotope))
* [`vertices_list`](@ref vertices_list(::AbstractZonotope))
* [`∈`](@ref ∈(::AbstractVector, ::AbstractZonotope))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`reduce_order`](@ref reduce_order(::AbstractZonotope, ::Real, ::AbstractReductionMethod=GIR05()))
* [`split`](@ref split(::AbstractZonotope, ::Int))
* [`split`](@ref split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int}))
* [`ρ`](@ref ρ(::AbstractVector, ::AbstractZonotope))
* [`σ`](@ref σ(::AbstractVector, ::AbstractZonotope))
58 changes: 58 additions & 0 deletions src/ConcreteOperations/intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1116,3 +1116,61 @@ end
PT<:Union{HPoly,HPolygon,HPolygonOpt}}
return intersection!(copy(X), H)
end

"""
_bound_intersect_2D(Z::Zonotope, L::Line2D)

Evaluate the support function in the direction [0, 1] of the intersection
between the given zonotope and line.

### Input

- `Z` -- zonotope
- `L` -- vertical 2D line

### Output

The support function in the direction [0, 1] of the intersection between the
given zonotope and line.

### Notes

The algorithm assumes that the given line is vertical and that the intersection
between the given sets is not empty.

### Algorithm

This function implements [Algorithm 8.2, 1].

[1] *Colas Le Guernic. Reachability Analysis of Hybrid Systems with Linear
Continuous Dynamics. Computer Science [cs]. Université Joseph-Fourier - Grenoble
I, 2009. English. fftel-00422569v2f*
"""
function _bound_intersect_2D(Z::Zonotope, L::Line2D)
c = center(Z)
P = copy(c)
G = genmat(Z)
r = ngens(Z)
g(x) = view(G, :, x)
for i in 1:r
gi = g(i)
if !isupwards(gi)
gi .= -gi
end
P .= P - gi
end
G = sortslices(G; dims=2, by=x -> atan(x[2], x[1])) # sort gens
if P[1] < L.b
G .= G[:, end:-1:1]
end
j = 1
while isdisjoint(LineSegment(P, P + 2g(j)), L)
P .= P + 2g(j)
j += 1
if j > size(G, 2)
error("got an unexpected error; check that the sets intersect")
end
end
singleton = intersection(LineSegment(P, P + 2g(j)), L)
return element(singleton)[2]
end
2 changes: 0 additions & 2 deletions src/Initialization/init_StaticArraysCore.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using StaticArraysCore: SMatrix, SVector, MMatrix, MVector

eval(load_split_static())
eval(load_genmat_2D_static())
eval(load_reduce_order_static())
eval(load_reduce_order_static_zonotope())
4 changes: 2 additions & 2 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export AbstractZonotope,
ngens,
order,
togrep,
split!,
reduce_order
reduce_order,
remove_redundant_generators

"""
AbstractZonotope{N} <: AbstractCentrallySymmetricPolytope{N}
Expand Down
7 changes: 6 additions & 1 deletion src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ include("Sets/Tetrahedron/TetrahedronModule.jl")
include("Sets/ZeroSet/ZeroSetModule.jl")
@reexport using ..ZeroSetModule: ZeroSet

include("Sets/Zonotope.jl")
include("Sets/Zonotope/ZonotopeModule.jl")
@reexport using ..ZonotopeModule: Zonotope,
remove_zero_generators,
linear_map!,
split!
using ..ZonotopeModule: _split

include("Sets/SparsePolynomialZonotope/SparsePolynomialZonotopeModule.jl")
@reexport using ..SparsePolynomialZonotopeModule: SparsePolynomialZonotope, SPZ,
Expand Down
Loading
Loading