Skip to content

Commit

Permalink
Merge pull request #318 from JuliaReach/dfcaporale/GeneralizeTimeShif…
Browse files Browse the repository at this point in the history
…tFlowpipes

Issue #316
  • Loading branch information
mforets authored Aug 31, 2020
2 parents ea1b948 + 3fca441 commit de32b5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Flowpipes/flowpipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function linear_map(M::AbstractMatrix, fp::Flowpipe)
end

"""
shift(fp::Flowpipe{N, ReachSet{N, ST}}, t0::Number) where {N, ST}
shift(fp::Flowpipe{N, <:AbstractReachSet}, t0::Number) where {N}
Return the time-shifted flowpipe by the given number.
Expand All @@ -387,7 +387,7 @@ shifted by `t0`.
See also `Shift` for the lazy counterpart.
"""
function shift(fp::Flowpipe{N, ReachSet{N, ST}}, t0::Number) where {N, ST}
function shift(fp::Flowpipe{N, <:AbstractReachSet}, t0::Number) where {N}
return Flowpipe([shift(X, t0) for X in array(fp)], fp.ext)
end

Expand Down Expand Up @@ -514,6 +514,11 @@ function project(fp::ShiftedFlowpipe, i::Int, vars::NTuple{D, M}) where {D, M<:I
return SparseReachSet(proj, tspan(R) + t0, vars)
end

# TODO: improve using mutable ShiftedFlowpipe struct (so that we can modify t0->t0+t1)
function shift(fp::ShiftedFlowpipe, t1::Number)
return ShiftedFlowpipe(shift(fp.F, t1), fp.t0)
end

# =====================================
# Flowpipe composition with a lazy map
# =====================================
Expand Down
4 changes: 4 additions & 0 deletions src/Flowpipes/solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ function project(sol::ReachSolution{<:AbstractFlowpipe}, dir::AbstractVector{<:A
return project(sol.F, dir; vars=vars)
end

function shift(sol::ReachSolution{<:AbstractFlowpipe}, t0::Number)
return ReachSolution(shift(sol.F, t0), sol.alg, sol.ext)
end

# LazySets interface falls back to the associated flowpipe
LazySets.dim(sol::ReachSolution) = dim(sol.F)
LazySets.ρ(d, sol::ReachSolution{FT}) where {FT<:AbstractFlowpipe} = ρ(d, sol.F)
Expand Down
2 changes: 2 additions & 0 deletions test/algorithms/ASB07.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ end
sol = solve(prob, alg=ASB07=1e-7, max_order=3), max_jumps=2)
@test dim(sol) == 4
@test flowpipe(sol) isa HybridFlowpipe

@test tspan(shift(sol[1],1.0))==tspan(sol[1])+1.0
end


Expand Down
2 changes: 2 additions & 0 deletions test/algorithms/GLGM06.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
sol = solve(prob, T=5.0, GLGM06=0.01))
@test dim(sol) == 5

@test tspan(shift(sol,1.0))==tspan(sol)+1.0

# use approx model for "discrete-time" reachability
sol = solve(prob, T=5.0, GLGM06=0.01, approx_model=NoBloating()))
end
2 changes: 2 additions & 0 deletions test/algorithms/TMJets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
sol = solve(prob, T=0.2, abstol=1e-11)
@test sol.alg isa TMJets && sol.alg.abs_tol == 1e-11

@test ReachabilityAnalysis.tspan(shift(sol,1.0))==ReachabilityAnalysis.tspan(sol)+1.0

# split initial conditions
X0, S = initial_state(prob), system(prob)
X0s = split(X0, [2, 1]) # split along direction x
Expand Down

0 comments on commit de32b5c

Please sign in to comment.