From d13c88106572bc2b1b597af86c06cf4a2e46f48c Mon Sep 17 00:00:00 2001 From: mforets Date: Wed, 16 Jan 2019 16:42:46 -0300 Subject: [PATCH 1/3] add faster zonotope interval box approximation --- src/Approximations/overapproximate.jl | 31 +++++++++++++++++++++++++++ test/unit_overapproximate.jl | 8 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index a17b2a734f..3e3ec4b9a8 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -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. an `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)[:] + return Hyperrectangle(Z.center, r) +end + """ overapproximate(X::LazySet{N}, dir::AbstractDirections{N})::HPolytope{N} where {N} diff --git a/test/unit_overapproximate.jl b/test/unit_overapproximate.jl index 345a7ac2c2..7c5486be98 100644 --- a/test/unit_overapproximate.jl +++ b/test/unit_overapproximate.jl @@ -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 @@ -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} From 3000a515c8a4ae9d42ca67735bb1252b379bfa32 Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Wed, 16 Jan 2019 17:00:13 -0300 Subject: [PATCH 2/3] Update src/Approximations/overapproximate.jl Co-Authored-By: mforets --- src/Approximations/overapproximate.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 3e3ec4b9a8..82660a65b9 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -151,7 +151,7 @@ A hyperrectangle. 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. an `Hyperrectangle`) such that its center is ``c`` and the radius along +(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``. From 293cffdc8c3fdc3edb5aa676658cdcfd467ffe3c Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Thu, 17 Jan 2019 07:56:36 -0300 Subject: [PATCH 3/3] Update src/Approximations/overapproximate.jl --- src/Approximations/overapproximate.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 82660a65b9..975186e67e 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -160,7 +160,7 @@ hybrid systems using a combination of zonotopes and polytopes. Nonlinear analysi hybrid systems, 4(2), 233-249.* """ function overapproximate(Z::Zonotope, ::Type{<:Hyperrectangle})::Hyperrectangle - r = sum(abs.(Z.generators), dims=2)[:] + r = Compat.sum(abs.(Z.generators), dims=2)[:] return Hyperrectangle(Z.center, r) end