/
SparseReachSet.jl
70 lines (57 loc) · 2.64 KB
/
SparseReachSet.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ================================================================
# Sparse reach set
# ================================================================
"""
SparseReachSet{N, ST<:LazySet{N}, D} <: AbstractReachSet{N}
Type that wraps a reach-set using a `LazySet` as underlying representation,
together with a tuple of variables associated to this reach-set.
### Fields
- `X` -- set
- `Δt` -- time interval
- `vars` -- tuple of variable indices represented by the set `X`
### Notes
A `SparseReachSet` is a struct representing (an approximation of) the reachable
states for a given time interval. The type of the representation is `ST`, which
may be any subtype of `LazySet` (ideally, concrete). Moreover, this type also
stores information about the variables (also named coordinates, or by abuse of
notation, *dimensions*) corresponding to the set `X`.
For instance in the ambient space `n=5`, one may have a `SparseReachSet` whose
variables tuple is `vars = (4, 5, 6)`, i.e. representing a three-dimensional
projection of the full-dimensional reach-set. In consequence, the dimension of
`X` doesn't match the length of `vars`, in general
In this type, the parameter `N` represents the numerical type of the `LazySet`
(typically, `Float64`), the type `ST` represents the set representation used,
and `D` denotes the dimension of this sparse reach set. Note that, in contrast
to `ReachSet`, for `SparseReachSet` the number of dimensions is part of the type
information.
"""
struct SparseReachSet{N,ST<:LazySet{N},D} <: AbstractLazyReachSet{N}
X::ST
Δt::IA.Interval{Float64}
vars::NTuple{D,Int}
# TODO: inner constructor that the dimension of vars matches that of X ?
end
# interface functions
set(R::SparseReachSet) = R.X
setrep(::SparseReachSet{N,ST}) where {N,ST<:LazySet{N}} = ST
setrep(::Type{<:SparseReachSet{N,ST}}) where {N,ST<:LazySet{N}} = ST
tstart(R::SparseReachSet) = inf(R.Δt)
tend(R::SparseReachSet) = sup(R.Δt)
tspan(R::SparseReachSet) = R.Δt
dim(R::SparseReachSet{N,ST,D}) where {N,ST<:LazySet{N},D} = D
vars(R::SparseReachSet) = R.vars
# constructor from vector of dimensions
function SparseReachSet(X::ST, Δt::IA.Interval{Float64},
vars::AbstractVector) where {N,ST<:LazySet{N}}
return SparseReachSet(X, Δt, Tuple(vars))
end
function shift(R::SparseReachSet, t0::Number)
return SparseReachSet(set(R), tspan(R) + t0, vars(R))
end
function reconstruct(R::SparseReachSet, Y::LazySet)
return SparseReachSet(Y, tspan(R), vars(R))
end
# constructor with a time point
function SparseReachSet(X::ST, t::Real, vars::AbstractVector) where {N,ST<:LazySet{N}}
return SparseReachSet(X, interval(t), vars)
end