Skip to content

Commit

Permalink
Merge pull request #115 from JuliaReach/mforets/templates
Browse files Browse the repository at this point in the history
Update templates
  • Loading branch information
mforets authored Apr 15, 2020
2 parents 8ea237a + 5d8f445 commit a03b257
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/Flowpipes/reachsets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,24 @@ end
# Template reach set
# ================================================================

using LazySets.Approximations: AbstractDirections

"""
TemplateReachSet{N, VN<:AbstractVector{N}} <: AbstractReachSet{N}
TemplateReachSet{N, VN, TN<:AbstractDirections{N, VN}, SN<:AbstractVector{N}} <: AbstractLazyReachSet{N}
Reach set that stores the support function of a set at a give set of directions.
### Notes
The parameter `N` refers to the numerical type of the representation.
The struct has the following parameters:
- `N` -- refers to the numerical type of the representation.
- `VN` -- refers to the vector type of the template
- `TN` -- refers to the template type
- `SN` -- vector type that holds the support function evaluations
Concrete subtypes of `AbstractDirections` are defined in the `LazySets` library.
This reach-set implicitly represents a set by a set of directions and support
functions. `set(R::TemplateReachSet)` returns a polyhedron in half-space
representation.
Expand All @@ -624,29 +634,47 @@ the following methods are available:
- `sup_func(R)` -- return the vector of support function evaluations
- `sup_func(R, i)` -- return the `i`-th coordinate of the vector of support function evaluatons
"""
struct TemplateReachSet{N, VN<:AbstractVector{N}} <: AbstractReachSet{N}
dirs::Vector{VN} # TODO: consider more general types eg. AbstractDirections ?
sf::Vector{N}
struct TemplateReachSet{N, VN, TN<:AbstractDirections{N, VN}, SN<:AbstractVector{N}} <: AbstractLazyReachSet{N}
dirs::TN
sf::SN
Δt::TimeInterval
end

# constructor from a given set (may overapproximate)
function TemplateReachSet(dirs::AbstractDirections, X::LazySet, Δt::TimeInterval)
sfunc = [ρ(d, X) for d in dirs]
return TemplateReachSet(dirs, sfunc, Δt)
end

# constructor from a given reach-set (may overapproximate)
function TemplateReachSet(dirs::AbstractDirections, R::AbstractLazyReachSet)
return TemplateReachSet(dirs, set(R), tspan(R))
end

# implement abstract reachset interface
# TODO: use HPolyhedron or HPolytope if the set is bounded or not
set(R::TemplateReachSet) = HPolytope([HalfSpace(R.dirs[i], R.sf[i]) for i in eachindex(R.sf)])
set(R::TemplateReachSet) = HPolytope([HalfSpace(di, R.sf[i]) for (i, di) in enumerate(R.dirs)])
setrep(::Type{TemplateReachSet{N, VN}}) where {N, VN} = HPolyhedron{N, VN}
setrep(::TemplateReachSet{N, VN}) where {N, VN} = HPolyhedron{N, VN}
tspan(R::TemplateReachSet) = R.Δt
tstart(R::TemplateReachSet) = inf(R.Δt)
tend(R::TemplateReachSet) = sup(R.Δt)
dim(R::TemplateReachSet) = length(first(R.dirs))
vars_idx(R::TemplateReachSet) = Tuple(Base.OneTo(dim(R)),)
dim(R::TemplateReachSet) = dim(R.dirs)
vars_idx(R::TemplateReachSet) = Tuple(Base.OneTo(dim(R)),) # TODO rename to vars ?

directions(R::TemplateReachSet) = R.dirs
sup_func(R::TemplateReachSet) = R.sf
directions(R::TemplateReachSet) = R.dirs # TODO rename to dirs ?
sup_func(R::TemplateReachSet) = R.sf # TODO rename?
sup_func(R::TemplateReachSet, i) = R.sf[i]

# overapproximate a given reach set with the template, concretely
#= TODO: remove?
function overapproximate(R::AbstractLazyReachSet, dirs::Vector{VN}) where {VN}
Δt = tspan(R)
sup_func = map(d -> ρ(d, R), dirs)
return TemplateReachSet(dirs, sup_func, Δt)
end
=#

# convenience functions to get support directions of a given set
_getdirs(X::LazySet) = [c.a for c in constraints_list(X)]
LazySets.CustomDirections(X::LazySet) = CustomDirections(_getdirs(X), dim(X)) # TODO may use isboundedtype trait

0 comments on commit a03b257

Please sign in to comment.