44import LazySets. Approximations: project
55using LazySets. Approximations: overapproximate
66
7- # add a "time" variable by taking the cartesian product of the flowpipe ℱ with each time lapse
8- function add_time (ℱ:: Vector{ReachSet{Hyperrectangle{Float64}}} )
9- ℱ_with_time = Vector {ReachSet{Hyperrectangle{Float64}}} (undef, length (ℱ))
7+ # add a "time" variable by taking the cartesian product of the flowpipe ℱ with
8+ # each time lapse, given by an interval
9+ function add_time (ℱ:: Vector{ReachSet{Hyperrectangle{T, VC, VR}}} ) where {T, VC, VR}
10+ HT = Hyperrectangle{T, VC, VR}
11+ ST = CartesianProduct{T, HT, Interval{T, IA. Interval{T}}}
12+ ℱ_with_time = Vector {ReachSet{ST}} (undef, length (ℱ))
1013 @inbounds for i in eachindex (ℱ)
1114 t0, t1 = time_start (ℱ[i]), time_end (ℱ[i])
12- radius = (t1 - t0)/ 2.0
13- Xi = set (ℱ[i]) × Hyperrectangle ([t0 + radius], [radius])
14- Xi = convert (Hyperrectangle, Xi)
15- ℱ_with_time[i] = ReachSet {Hyperrectangle{Float64}} (Xi, t0, t1)
15+ Xi = set (ℱ[i]) × Interval (t0, t1)
16+ ℱ_with_time[i] = ReachSet (Xi, t0, t1)
1617 end
1718 return ℱ_with_time
1819end
1920
20- function project (sol:: ReachSolution{Hyperrectangle{Float64 }} )
21+ function project (sol:: ReachSolution{Hyperrectangle{T, VC, VR }} ) where {T, VC, VR}
2122 N = length (sol. Xk) # number of reach sets
2223 n = dim (set (first (sol. Xk))) # state space dimension
24+
2325 options = copy (sol. options)
24- πℱ = Vector {ReachSet{Hyperrectangle{Float64}}} (undef, N) # preallocated projected reachsets
2526 πvars = sol. options[:plot_vars ] # variables for plotting
2627 @assert length (πvars) == 2
2728
28- if 0 ∈ πvars
29- # add the time variable to the flowpipe (assuming it's not already
30- # part of the model)
29+ if 0 ∈ πvars # if we want to project along time
3130 ℱ = add_time (sol. Xk)
3231 n += 1
3332 options[:n ] += 1 # TODO : remove when option is removed
@@ -37,11 +36,15 @@ function project(sol::ReachSolution{Hyperrectangle{Float64}})
3736 ℱ = sol. Xk
3837 end
3938
39+ HT = Hyperrectangle{T, Vector{T}, Vector{T}} # we hardcode dense vectors here,
40+ # as using VC and VR would require to adapt overapproximate
41+ πℱ = Vector {ReachSet{HT}} (undef, N) # preallocate projected reachsets
42+
4043 M = sparse ([1 , 2 ], πvars, [1.0 , 1.0 ], 2 , n)
4144 for i in eachindex (ℱ)
4245 t0, t1 = time_start (ℱ[i]), time_end (ℱ[i])
4346 πℱ_i = overapproximate (M * set (ℱ[i]), Hyperrectangle)
44- πℱ[i] = ReachSet {Hyperrectangle{Float64}} (πℱ_i, t0, t1)
47+ πℱ[i] = ReachSet (πℱ_i, t0, t1)
4548 end
4649 return ReachSolution (πℱ, options)
4750end
0 commit comments