From 7f624986f9756b60b910467df2290bdce9b760ec Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 1 Oct 2018 14:06:38 -0300 Subject: [PATCH 1/6] add overapporimate cap --- src/Approximations/overapproximate.jl | 21 +++++++++++++++++++++ src/Intersection.jl | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 256fa2ecdf..9f4542bd7a 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -166,3 +166,24 @@ function overapproximate(S::LazySet{N}, ::Type{Interval}) where {N<:Real} hi = σ([one(N)], S)[1] return Interval(lo, hi) end + +# overapproximate an intersection with a polytope in H-representation given a +# set of template directions. +function overapproximate(cap::Intersection{N, <:LazySet, S}, + dir::AbstractDirections{N}; + kwargs...) where {N<:Real, S<:AbstractPolytope{N}} + + X = cap.X # compact set + P = cap.Y # polytope + + Q = HPolytope{N}() + + for Hi in constraints_list(P) + for di in dir + # can overwrite defaults through kwargs + ρ_X_Hi = ρ(di, X∩Hi, kwargs...) + addconstraint!(Q, HalfSpace(Hi.a, ρ_X_Hi)) + end + end + return Q +end diff --git a/src/Intersection.jl b/src/Intersection.jl index 005767f6f3..51ca312393 100644 --- a/src/Intersection.jl +++ b/src/Intersection.jl @@ -319,6 +319,8 @@ The scalar value of the support function of the set `cap` in the given direction ### Notes +It is assumed that the set `cap.X` is compact. + The `check_intersection` flag can be useful if you know in advance that the intersection is non-empty. @@ -349,7 +351,7 @@ function ρ(d::AbstractVector{N}, algorithm::String="line_search", check_intersection::Bool=true, kwargs...) where {N<:AbstractFloat, S<:Union{HalfSpace, Hyperplane}} - + X = cap.X # compact set H = cap.Y # halfspace or hyperplane From a5a2ede6da780bd002fc62d1b82b2dad255f4703 Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 1 Oct 2018 14:23:13 -0300 Subject: [PATCH 2/6] swap dir loop --- src/Approximations/overapproximate.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 9f4542bd7a..9d46e94422 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -176,14 +176,17 @@ function overapproximate(cap::Intersection{N, <:LazySet, S}, X = cap.X # compact set P = cap.Y # polytope + clist = constraints_list(P) + m = length(clist) Q = HPolytope{N}() + ρ_X_Hi = Vector{N}(undef, m) - for Hi in constraints_list(P) - for di in dir - # can overwrite defaults through kwargs - ρ_X_Hi = ρ(di, X∩Hi, kwargs...) - addconstraint!(Q, HalfSpace(Hi.a, ρ_X_Hi)) + for di in dir + for (i, Hi) in enumerate(clist) + ρ_X_Hi[i] = ρ(di, X∩Hi, kwargs...)) end + min_ρ_X_Hi = minimum(ρ_X_Hi) + addconstraint!(Q, HalfSpace(Hi.a, min_ρ_X_Hi)) end return Q end From 575dfcab6f2440d3d62cf0cce23e614b5342881c Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 1 Oct 2018 14:27:10 -0300 Subject: [PATCH 3/6] typo --- 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 9d46e94422..860adb88c3 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -183,7 +183,7 @@ function overapproximate(cap::Intersection{N, <:LazySet, S}, for di in dir for (i, Hi) in enumerate(clist) - ρ_X_Hi[i] = ρ(di, X∩Hi, kwargs...)) + ρ_X_Hi[i] = ρ(di, X∩Hi, kwargs...) end min_ρ_X_Hi = minimum(ρ_X_Hi) addconstraint!(Q, HalfSpace(Hi.a, min_ρ_X_Hi)) From 6c56da5c91b99de0fe07661ec53d751230b1a706 Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 1 Oct 2018 14:44:03 -0300 Subject: [PATCH 4/6] more fixes --- src/Approximations/overapproximate.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 860adb88c3..3fa3adf683 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -185,8 +185,8 @@ function overapproximate(cap::Intersection{N, <:LazySet, S}, for (i, Hi) in enumerate(clist) ρ_X_Hi[i] = ρ(di, X∩Hi, kwargs...) end - min_ρ_X_Hi = minimum(ρ_X_Hi) - addconstraint!(Q, HalfSpace(Hi.a, min_ρ_X_Hi)) + i_min = indmin(ρ_X_Hi) + addconstraint!(Q, HalfSpace(clist[i_min].a, ρ_X_Hi[i_min])) end return Q end From b9c9aa455c1c97c7a670ffc223f25616898fea1a Mon Sep 17 00:00:00 2001 From: mforets Date: Tue, 2 Oct 2018 04:22:08 -0300 Subject: [PATCH 5/6] fix di, docstring, comparison inside loop --- src/Approximations/overapproximate.jl | 59 +++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 3fa3adf683..8bbdfac5ea 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -167,8 +167,47 @@ function overapproximate(S::LazySet{N}, ::Type{Interval}) where {N<:Real} return Interval(lo, hi) end -# overapproximate an intersection with a polytope in H-representation given a -# set of template directions. +""" + overapproximate(cap::Intersection{N, <:LazySet, S}, + dir::AbstractDirections{N}; + kwargs...) where {N<:Real, S<:AbstractPolytope{N}} + +Return the overapproximation of the intersection between a compact set and a +polytope given a set of template directions. + +### Input + +- `cap` -- intersection of a compact set and a polytope +- `dir` -- template directions +- `kwargs` -- additional arguents that are passed to the support fumction algorithm + +### Output + +A polytope in H-representation such that the normal direction of each half-space +is given by an element of `dir`. + +### Algorithm + +Let `di` be a direction drawn from the set of template directions `dir`. +Let `X` be the compact set and let `P` be the polytope; that we would like +to overapproximate the set `X ∩ H`. + +Solving the univariate optimization problem `ρ(di, X ∩ Hi)` for each +half-space in the set `P` and then taking the minimum gives an overapproximation +of the exact support function. + +This algorithm is inspired from [G. Frehse, R. Ray. Flowpipe-Guard Intersection +for Reachability Computations with Support +Functions](https://www.sciencedirect.com/science/article/pii/S1474667015371809). + +### Notes + +This method relies on having available the `constraints_list` of the polytope +`P`. + +This method of overapproximations can return a non-empty set even if the original +intersection is empty. +""" function overapproximate(cap::Intersection{N, <:LazySet, S}, dir::AbstractDirections{N}; kwargs...) where {N<:Real, S<:AbstractPolytope{N}} @@ -176,17 +215,19 @@ function overapproximate(cap::Intersection{N, <:LazySet, S}, X = cap.X # compact set P = cap.Y # polytope - clist = constraints_list(P) - m = length(clist) + Hi = constraints_list(P) + m = length(Hi) Q = HPolytope{N}() - ρ_X_Hi = Vector{N}(undef, m) for di in dir - for (i, Hi) in enumerate(clist) - ρ_X_Hi[i] = ρ(di, X∩Hi, kwargs...) + ρ_X_Hi_min = ρ(di, X ∩ Hi[1], kwargs...) + for i in 2:m + ρ_X_Hi = ρ(di, X ∩ Hi[i], kwargs...) + if ρ_X_Hi < ρ_X_Hi_min + ρ_X_Hi_min = ρ_X_Hi + end end - i_min = indmin(ρ_X_Hi) - addconstraint!(Q, HalfSpace(clist[i_min].a, ρ_X_Hi[i_min])) + addconstraint!(Q, HalfSpace(di, ρ_X_Hi_min)) end return Q end From 1fa4e2407138dcc3362b37ebee25f859c0a8c129 Mon Sep 17 00:00:00 2001 From: mforets Date: Tue, 2 Oct 2018 09:34:13 -0300 Subject: [PATCH 6/6] revise docstring --- src/Approximations/overapproximate.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index 8bbdfac5ea..1b7fe24860 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -179,7 +179,7 @@ polytope given a set of template directions. - `cap` -- intersection of a compact set and a polytope - `dir` -- template directions -- `kwargs` -- additional arguents that are passed to the support fumction algorithm +- `kwargs` -- additional arguents that are passed to the support function algorithm ### Output @@ -189,14 +189,15 @@ is given by an element of `dir`. ### Algorithm Let `di` be a direction drawn from the set of template directions `dir`. -Let `X` be the compact set and let `P` be the polytope; that we would like -to overapproximate the set `X ∩ H`. +Let `X` be the compact set and let `P` be the polytope. We overapproximate the +set `X ∩ H` with a polytope in constraint representation using a given set of +template directions `dir`. -Solving the univariate optimization problem `ρ(di, X ∩ Hi)` for each -half-space in the set `P` and then taking the minimum gives an overapproximation +The idea is to solve the univariate optimization problem `ρ(di, X ∩ Hi)` for each +half-space in the set `P` and then take the minimum. This gives an overapproximation of the exact support function. -This algorithm is inspired from [G. Frehse, R. Ray. Flowpipe-Guard Intersection +This algorithm is inspired from [G. Frehse, R. Ray. Flowpipe-Guard Intersection for Reachability Computations with Support Functions](https://www.sciencedirect.com/science/article/pii/S1474667015371809).