Skip to content

Commit

Permalink
#702 - MethodError in TMJets projection (#703)
Browse files Browse the repository at this point in the history
* remove output type annotationsin solve

* fix projection params
  • Loading branch information
mforets authored Oct 24, 2019
1 parent abaa2f8 commit cd2b03b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
29 changes: 16 additions & 13 deletions src/ReachSets/ContinuousPost/TMJets/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
import LazySets.Approximations: project
using LazySets.Approximations: overapproximate

# add a "time" variable by taking the cartesian product of the flowpipe ℱ with each time lapse
function add_time(ℱ::Vector{ReachSet{Hyperrectangle{Float64}}})
ℱ_with_time = Vector{ReachSet{Hyperrectangle{Float64}}}(undef, length(ℱ))
# add a "time" variable by taking the cartesian product of the flowpipe ℱ with
# each time lapse, given by an interval
function add_time(ℱ::Vector{ReachSet{Hyperrectangle{T, VC, VR}}}) where {T, VC, VR}
HT = Hyperrectangle{T, VC, VR}
ST = CartesianProduct{T, HT, Interval{T, IA.Interval{T}}}
ℱ_with_time = Vector{ReachSet{ST}}(undef, length(ℱ))
@inbounds for i in eachindex(ℱ)
t0, t1 = time_start(ℱ[i]), time_end(ℱ[i])
radius = (t1 - t0)/2.0
Xi = set(ℱ[i]) × Hyperrectangle([t0 + radius], [radius])
Xi = convert(Hyperrectangle, Xi)
ℱ_with_time[i] = ReachSet{Hyperrectangle{Float64}}(Xi, t0, t1)
Xi = set(ℱ[i]) × Interval(t0, t1)
ℱ_with_time[i] = ReachSet(Xi, t0, t1)
end
return ℱ_with_time
end

function project(sol::ReachSolution{Hyperrectangle{Float64}})
function project(sol::ReachSolution{Hyperrectangle{T, VC, VR}}) where {T, VC, VR}
N = length(sol.Xk) # number of reach sets
n = dim(set(first(sol.Xk))) # state space dimension

options = copy(sol.options)
πℱ = Vector{ReachSet{Hyperrectangle{Float64}}}(undef, N) # preallocated projected reachsets
πvars = sol.options[:plot_vars] # variables for plotting
@assert length(πvars) == 2

if 0 πvars
# add the time variable to the flowpipe (assuming it's not already
# part of the model)
if 0 πvars # if we want to project along time
= add_time(sol.Xk)
n += 1
options[:n] += 1 # TODO : remove when option is removed
Expand All @@ -37,11 +36,15 @@ function project(sol::ReachSolution{Hyperrectangle{Float64}})
= sol.Xk
end

HT = Hyperrectangle{T, Vector{T}, Vector{T}} # we hardcode dense vectors here,
# as using VC and VR would require to adapt overapproximate
πℱ = Vector{ReachSet{HT}}(undef, N) # preallocate projected reachsets

M = sparse([1, 2], πvars, [1.0, 1.0], 2, n)
for i in eachindex(ℱ)
t0, t1 = time_start(ℱ[i]), time_end(ℱ[i])
πℱ_i = overapproximate(M * set(ℱ[i]), Hyperrectangle)
πℱ[i] = ReachSet{Hyperrectangle{Float64}}(πℱ_i, t0, t1)
πℱ[i] = ReachSet(πℱ_i, t0, t1)
end
return ReachSolution(πℱ, options)
end
10 changes: 5 additions & 5 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ solve(system::AbstractSystem, options::Pair{Symbol,<:Any}...) =
function solve!(problem::InitialValueProblem,
options::Options;
op::ContinuousPost=default_operator(problem)
)::AbstractSolution
)

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

"""
solve(system::InitialValueProblem{<:HybridSystem},
options::Options)::AbstractSolution
options::Options)
Interface to reachability algorithms for a hybrid system PWA dynamics.
Expand All @@ -91,7 +91,7 @@ Interface to reachability algorithms for a hybrid system PWA dynamics.
function solve(system::InitialValueProblem{<:HybridSystem, <:LazySet},
options::Options,
opC::ContinuousPost=BFFPSV18(),
opD::DiscretePost=LazyDiscretePost())::AbstractSolution
opD::DiscretePost=LazyDiscretePost())
return solve!(distribute_initial_set(system), copy(options), opC, opD)
end

Expand All @@ -100,7 +100,7 @@ function solve(system::InitialValueProblem{<:HybridSystem,
<:Vector{<:Tuple{Int64,<:LazySet}}},
options::Options,
opC::ContinuousPost=BFFPSV18(),
opD::DiscretePost=LazyDiscretePost())::AbstractSolution
opD::DiscretePost=LazyDiscretePost())
return solve!(system, copy(options), opC, opD)
end

Expand All @@ -109,7 +109,7 @@ function solve!(system::InitialValueProblem{<:HybridSystem,
options_input::Options,
opC::ContinuousPost,
opD::DiscretePost
)::AbstractSolution where N<:Real
) where N<:Real
# update global variable
global discrete_post_operator = opD

Expand Down

0 comments on commit cd2b03b

Please sign in to comment.