From b5ecc8573471a31aedd04565fc2d19516649ca80 Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 18 Nov 2019 11:05:13 -0300 Subject: [PATCH 1/4] generalize zonotope conversion for GLGM06 --- src/ReachSets/discretize.jl | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ReachSets/discretize.jl b/src/ReachSets/discretize.jl index abb57cb1..01308a17 100644 --- a/src/ReachSets/discretize.jl +++ b/src/ReachSets/discretize.jl @@ -701,8 +701,8 @@ end # version using concrete operations with zonotopes function _discretize_interpolation_homog(X0, ϕ, Einit, set_operations::Val{:zonotope}) - Einit = convert(Zonotope, Einit) - Z1 = convert(Zonotope, X0) + Einit = _convert_or_overapproximate(Zonotope, Einit) + Z1 = _convert_or_overapproximate(Zonotope, X0) Z2 = linear_map(ϕ, minkowski_sum(Z1, Einit)) Ω0 = overapproximate(ConvexHull(Z1, Z2), Zonotope) return Ω0 @@ -711,11 +711,11 @@ end # version using concrete operations with zonotopes function _discretize_interpolation_inhomog(δ, U0, U, X0, ϕ, Einit, Eψ0, A, sih, Phi2Aabs, set_operations::Val{:zonotope}) n = size(A, 1) - Einit = convert(Zonotope, Einit) - Eψ0 = convert(Zonotope, Eψ0) - Z1 = convert(Zonotope, X0) + Einit = _convert_or_overapproximate(Zonotope, Einit) + Eψ0 = _convert_or_overapproximate(Zonotope, Eψ0) + Z1 = _convert_or_overapproximate(Zonotope, X0) ϕX0 = linear_map(ϕ, Z1) - U0 = convert(Zonotope, U0) + U0 = _convert_or_overapproximate(Zonotope, U0) δI = Matrix(δ*I, n, n) δU0 = linear_map(δI, U0) Z2 = reduce(minkowski_sum, [ϕX0, δU0, Eψ0, Einit]) @@ -727,8 +727,8 @@ function _discretize_interpolation_inhomog(δ, U0, U, X0, ϕ, Einit, Eψ0, A, si elseif U isa VaryingInput Ud = Vector{LazySet}(undef, length(U)) for (k, Uk) in enumerate(U) - Eψk = convert(Zonotope, sih(Phi2Aabs * sih(A * Uk))) - Uk = convert(Zonotope, Uk) + Eψk = _convert_or_overapproximate(Zonotope, sih(Phi2Aabs * sih(A * Uk))) + Uk = _convert_or_overapproximate(Zonotope, Uk) δUk = linear_map(δI, Uk) Ud[k] = minkowski_sum(δUk, Eψk) end @@ -887,3 +887,14 @@ function _discretize_interval_matrix_inhomog(U, Ω0_homog, linear_maps, end return Ω0, Ud end + +# fallback implementation for conversion (if applicable) or overapproximation +function _convert_or_overapproximate(X::Type{<:Zonotope}, Y::LazySet) + if applicable(convert, X, Y) + return convert(X, Y) + elseif applicable(overapproximate, Y, X) + return overapproximate(Y, X) + else + return convert(Zonotope, overapproximate(Y, Hyperrectangle)) + end +end From 36dcb83d57e5b34a45a89795dc51758e4943f593 Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 18 Nov 2019 11:06:51 -0300 Subject: [PATCH 2/4] add test --- test/Reachability/solve_continuous.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Reachability/solve_continuous.jl b/test/Reachability/solve_continuous.jl index df3b43e2..d14fde41 100644 --- a/test/Reachability/solve_continuous.jl +++ b/test/Reachability/solve_continuous.jl @@ -173,6 +173,10 @@ s = solve(IVP(LCS(A), X0), Options(:T=>0.1), op=GLGM06(:max_order=>15)) # affine system, x' = Ax + Bu s = solve(IVP(CLCCS(A, B, nothing, U), X0), Options(:T=>0.1), op=GLGM06()) +# initial set which cannot be converted to a zonotope +X0 = Ball2(ones(4), 0.1) +s = solve(IVP(LCS(A), X0), Options(:T=>0.1), op=GLGM06()) + # ====================== # Unbounded-time setting # ====================== From bfcf866ba5175e408e96251ca1809fdf8b909e47 Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Wed, 20 Nov 2019 16:48:09 -0300 Subject: [PATCH 3/4] Update src/ReachSets/discretize.jl Co-Authored-By: Christian Schilling --- src/ReachSets/discretize.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReachSets/discretize.jl b/src/ReachSets/discretize.jl index 01308a17..6cbad9d1 100644 --- a/src/ReachSets/discretize.jl +++ b/src/ReachSets/discretize.jl @@ -889,7 +889,7 @@ function _discretize_interval_matrix_inhomog(U, Ω0_homog, linear_maps, end # fallback implementation for conversion (if applicable) or overapproximation -function _convert_or_overapproximate(X::Type{<:Zonotope}, Y::LazySet) +function _convert_or_overapproximate(X::Type{<:AbstractPolytope}, Y::LazySet) if applicable(convert, X, Y) return convert(X, Y) elseif applicable(overapproximate, Y, X) From cfd68b2413526a49ca6e1a9994cca9d751f62d51 Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Wed, 20 Nov 2019 16:48:16 -0300 Subject: [PATCH 4/4] Update src/ReachSets/discretize.jl Co-Authored-By: Christian Schilling --- src/ReachSets/discretize.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReachSets/discretize.jl b/src/ReachSets/discretize.jl index 6cbad9d1..ddc7dc60 100644 --- a/src/ReachSets/discretize.jl +++ b/src/ReachSets/discretize.jl @@ -895,6 +895,6 @@ function _convert_or_overapproximate(X::Type{<:AbstractPolytope}, Y::LazySet) elseif applicable(overapproximate, Y, X) return overapproximate(Y, X) else - return convert(Zonotope, overapproximate(Y, Hyperrectangle)) + return convert(X, overapproximate(Y, Hyperrectangle)) end end