Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update templates #115

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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