Skip to content

Commit

Permalink
Merge pull request #809 from JuliaReach/schillic/tm_zono
Browse files Browse the repository at this point in the history
Support ntdiv splitting in TM-zonotope overapproximation
  • Loading branch information
schillic authored Mar 15, 2024
2 parents 79c2d49 + 0cd02ea commit 830a76f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/ReachSets/TaylorModelReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ end

LazySets.box_approximation(R::TaylorModelReachSet) = overapproximate(R, Hyperrectangle)

# overapproximate TaylorModelReachSet with several hyperrectangles, by splitting
# overapproximate TaylorModelReachSet with several sets by splitting
# in space (with either nsdiv for uniform partitions or by specifying a
# partition (vector of integers); the version not used should be set to
# `nothing`) and/or in time (ntdiv)
# e.g. if the partition is uniform for each dimension, the number of returned
# sets is nsdiv^D * ntdiv
function overapproximate(R::TaylorModelReachSet{N}, ::Type{<:Hyperrectangle};
function overapproximate(R::TaylorModelReachSet{N}, T::Type{<:Union{Hyperrectangle,Zonotope}};
partition=nothing, nsdiv=nothing, ntdiv=1,
Δt::TimeInterval=tspan(R), dom=symBox(dim(R)), kwargs...) where {N}
if !isnothing(partition) && !isnothing(nsdiv)
Expand All @@ -335,7 +335,7 @@ function overapproximate(R::TaylorModelReachSet{N}, ::Type{<:Hyperrectangle};

# no splitting
if isnothing(partition) && nsdiv == 1 && ntdiv == 1
return _overapproximate(R, Hyperrectangle; Δt=Δt, dom=dom, kwargs...)
return _overapproximate(R, T; Δt=Δt, dom=dom, kwargs...)
end

D = dim(R)
Expand All @@ -361,20 +361,23 @@ function overapproximate(R::TaylorModelReachSet{N}, ::Type{<:Hyperrectangle};
else
# TODO (also below) may use IA.mince directly
partition = fill(nsdiv, D)
Sdiv = LazySets.split(convert(Hyperrectangle, S), partition)
Sdiv = LazySets.split(convert(T, S), partition)
partition = convert.(IntervalBox, Sdiv)
end

else
Sdiv = LazySets.split(convert(Hyperrectangle, S), partition)
Sdiv = LazySets.split(convert(T, S), partition)
partition = convert.(IntervalBox, Sdiv)
end
nparts = length(partition)

# preallocate output vectors
ST = Hyperrectangle{N,SVector{D,N},SVector{D,N}}
X̂out = Vector{ST}(undef, nparts * ntdiv)
R̂out = Vector{ReachSet{N,ST}}(undef, nparts * ntdiv)
if T <: Hyperrectangle
ST = Hyperrectangle{N,SVector{D,N},SVector{D,N}}
R̂out = Vector{ReachSet{N,ST}}(undef, nparts * ntdiv)
else
R̂out = Vector{ReachSet{N}}(undef, nparts * ntdiv)
end

# evaluate the spatial variables in the symmetric box
@inbounds for k in 1:ntdiv
Expand All @@ -384,11 +387,14 @@ function overapproximate(R::TaylorModelReachSet{N}, ::Type{<:Hyperrectangle};
X̂ib = IntervalBox([evaluate(Xk[i], Bj) for i in 1:D])

idx = j + (k - 1) * nparts
X̂out[idx] = convert(Hyperrectangle, X̂ib)
X̂out = convert(T, convert(Hyperrectangle, X̂ib))

R̂out[idx] = ReachSet(X̂out[idx], tspdiv[k])
R̂out[idx] = ReachSet(X̂out, tspdiv[k])
end
end
if T <: Zonotope # concrete output vector
R̂out = [e for e in R̂out]
end

return R̂out
end
Expand Down

0 comments on commit 830a76f

Please sign in to comment.