Skip to content

Commit 4d1ef9c

Browse files
authored
Merge pull request #899 from JuliaReach/schillic/support_function
Fast support function for `TemplateReachSet`
2 parents 866387c + a0d8ef4 commit 4d1ef9c

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/Flowpipes/AbstractFlowpipe.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ In this fallback implementation, the flowpipe behaves like the union of the
3333
reach-sets, i.e. the implementation is analogue to that of a `LazySet.UnionSetArray`.
3434
"""
3535
function LazySets.ρ(d::AbstractVector, fp::AbstractFlowpipe)
36-
return maximum(map(Ri -> ρ(d, set(Ri)), array(fp)))
36+
return maximum(ρ(d, Ri) for Ri in array(fp))
3737
end
3838

3939
"""

src/Initialization/init.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using LazySets: Interval, radius, sample, ∅, dim, scale, scale!, ⊂, matrix
2828

2929
# JuliaReach internal functions
3030
using ReachabilityBase.Arrays: projection_matrix, SingleEntryVector,
31-
isinvertible, vector_type
31+
isinvertible, samedir, vector_type
3232
using ReachabilityBase.Comparison: _leq, _geq
3333
using ReachabilityBase.Require: @required
3434
using LazySets.Approximations: AbstractDirections

src/ReachSets/TemplateReachSet.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,23 @@ end
9393
function overapproximate(R::AbstractLazyReachSet, dirs::Vector{VN}) where {VN}
9494
return TemplateReachSet(CustomDirections(dirs), R)
9595
end
96+
97+
function LazySets.ρ(d::AbstractVector, R::TemplateReachSet)
98+
# efficient implementation when direction is identical with some template direction
99+
for (i, di) in enumerate(R.dirs)
100+
if d == di
101+
return support_functions(R, i)
102+
end
103+
end
104+
105+
# efficient implementation when direction is multiple of some template direction
106+
for (i, di) in enumerate(R.dirs)
107+
issamedir, factor = samedir(d, di)
108+
if issamedir
109+
return support_functions(R, i) * factor
110+
end
111+
end
112+
113+
# fall back to polyhedral support function
114+
return ρ(d, set(R))
115+
end

test/reachsets/reachsets.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ReachabilityAnalysis: zeroI
1+
using ReachabilityAnalysis: zeroI, TimeInterval
22
using TaylorModels: set_variables,
33
Taylor1,
44
TaylorModel1
@@ -19,6 +19,17 @@ using TaylorModels: set_variables,
1919
@test tspan(R) == interval(1.0)
2020
end
2121

22+
@testset "Reach-set support function" begin
23+
dirs = CustomDirections([[1.0, 0.0]])
24+
sf = [2.0]
25+
Δt = TimeInterval(0.0, 1.0)
26+
R = TemplateReachSet(dirs, sf, Δt)
27+
d = [1.0, 0.0]
28+
@test ρ(d, R) == 2.0
29+
d = 2 * d
30+
@test ρ(d, R) == 4.0
31+
end
32+
2233
@testset "Reach-set projections" begin
2334
X = BallInf(zeros(5), 1.0)
2435
B = BallInf(zeros(2), 1.0)

0 commit comments

Comments
 (0)