Skip to content

Commit cd2b03b

Browse files
authored
#702 - MethodError in TMJets projection (#703)
* remove output type annotationsin solve * fix projection params
1 parent abaa2f8 commit cd2b03b

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/ReachSets/ContinuousPost/TMJets/project.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44
import LazySets.Approximations: project
55
using 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
1819
end
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)
4750
end

src/solve.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ solve(system::AbstractSystem, options::Pair{Symbol,<:Any}...) =
5959
function solve!(problem::InitialValueProblem,
6060
options::Options;
6161
op::ContinuousPost=default_operator(problem)
62-
)::AbstractSolution
62+
)
6363

6464
# normalize system to a canonical form if needed
6565
problem = IVP(normalize(problem.s), problem.x0)
@@ -79,7 +79,7 @@ end
7979

8080
"""
8181
solve(system::InitialValueProblem{<:HybridSystem},
82-
options::Options)::AbstractSolution
82+
options::Options)
8383
8484
Interface to reachability algorithms for a hybrid system PWA dynamics.
8585
@@ -91,7 +91,7 @@ Interface to reachability algorithms for a hybrid system PWA dynamics.
9191
function solve(system::InitialValueProblem{<:HybridSystem, <:LazySet},
9292
options::Options,
9393
opC::ContinuousPost=BFFPSV18(),
94-
opD::DiscretePost=LazyDiscretePost())::AbstractSolution
94+
opD::DiscretePost=LazyDiscretePost())
9595
return solve!(distribute_initial_set(system), copy(options), opC, opD)
9696
end
9797

@@ -100,7 +100,7 @@ function solve(system::InitialValueProblem{<:HybridSystem,
100100
<:Vector{<:Tuple{Int64,<:LazySet}}},
101101
options::Options,
102102
opC::ContinuousPost=BFFPSV18(),
103-
opD::DiscretePost=LazyDiscretePost())::AbstractSolution
103+
opD::DiscretePost=LazyDiscretePost())
104104
return solve!(system, copy(options), opC, opD)
105105
end
106106

@@ -109,7 +109,7 @@ function solve!(system::InitialValueProblem{<:HybridSystem,
109109
options_input::Options,
110110
opC::ContinuousPost,
111111
opD::DiscretePost
112-
)::AbstractSolution where N<:Real
112+
) where N<:Real
113113
# update global variable
114114
global discrete_post_operator = opD
115115

0 commit comments

Comments
 (0)