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

#1016 - Add faster zonotope interval box approximation #1019

Merged
merged 3 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 31 additions & 0 deletions src/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@ function overapproximate(S::ConvexHull{N, Zonotope{N}, Zonotope{N}},
return Zonotope(center, generators)
end

"""
overapproximate(Z::Zonotope, ::Type{<:Hyperrectangle})::Hyperrectangle

Return a tight overapproximation of a zonotope with an axis-aligned box.

### Input

- `Z` -- zonotope
- `Hyperrectangle` -- type for dispatch

### Output

A hyperrectangle.

### Algorithm

This function implements the method in [Section 5.1.2, 1]. A zonotope
``Z = ⟨c, G⟩`` can be overapproximated tightly by an axis-aligned box
(i.e. a `Hyperrectangle`) such that its center is ``c`` and the radius along
dimension ``i`` is the column-sum of the absolute values of the ``i``-th row
of ``G`` for ``i = 1,…, p``, where ``p`` is the number of generators of ``Z``.

[1] *Althoff, M., Stursberg, O., & Buss, M. (2010). Computing reachable sets of
hybrid systems using a combination of zonotopes and polytopes. Nonlinear analysis:
hybrid systems, 4(2), 233-249.*
"""
function overapproximate(Z::Zonotope, ::Type{<:Hyperrectangle})::Hyperrectangle
r = sum(abs.(Z.generators), dims=2)[:]
mforets marked this conversation as resolved.
Show resolved Hide resolved
return Hyperrectangle(Z.center, r)
end

"""
overapproximate(X::LazySet{N}, dir::AbstractDirections{N})::HPolytope{N}
where {N}
Expand Down
8 changes: 7 additions & 1 deletion test/unit_overapproximate.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LazySets.Approximations.overapproximate
import LazySets.Approximations: overapproximate, box_approximation

for N in [Float64, Rational{Int}, Float32]
# overapproximating a set of type T1 with an unsupported type T2 is the
Expand Down Expand Up @@ -37,6 +37,12 @@ for N in [Float64, Rational{Int}, Float32]
for d in [N[1], N[-1]]
@test σ(d, p)[1] ≈ σ(d, b)[1]
end

# approximation with an axis-aligned hyperrectangle
Z = Zonotope(N[-1.0, -1.0], N[-1/2 0; -1.2 -1])
Zoa = overapproximate(Z, Hyperrectangle) # faster o.a.
Zba = box_approximation(Z) # default o.a. implementation that uses supp function
@test Zoa.center ≈ Zba.center && Zoa.radius ≈ Zba.radius
end

# tests that do not work with Rational{Int}
Expand Down