Skip to content

Commit

Permalink
fix unbound args
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Mar 10, 2024
1 parent 79c2d49 commit 02d7f42
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/src/lib/reachsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ shift(::AbstractReachSet)

```@docs
AbstractLazyReachSet
project(::AbstractLazyReachSet, ::NTuple{D,M}; check_vars::Bool=true) where {D,M<:Integer}
project(::AbstractLazyReachSet, ::NTuple{D,Int}; check_vars::Bool=true) where {D}
```

## Reachable set
Expand Down
6 changes: 3 additions & 3 deletions src/Flowpipes/Flowpipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function (fp::Flowpipe)(dt::TimeInterval)
end

# concrete projection of a flowpipe along variables `vars`
function project(fp::Flowpipe, vars::NTuple{D,T}) where {D,T<:Integer}
function project(fp::Flowpipe, vars::NTuple{D,Int}) where {D}
Xk = array(fp)
πfp = map(X -> project(X, vars), Xk)
return Flowpipe(πfp, fp.ext)
Expand Down Expand Up @@ -243,13 +243,13 @@ Base.:⊆(F::Flowpipe, X::LazySet) = all(R ⊆ X for R in F)
Base.:(F::Flowpipe, Y::AbstractLazyReachSet) = all(R set(Y) for R in F)

# lazy projection of a flowpipe
function Projection(F::Flowpipe, vars::NTuple{D,T}) where {D,T<:Integer}
function Projection(F::Flowpipe, vars::NTuple{D,Int}) where {D}
Xk = array(F)
out = map(X -> Projection(X, vars), Xk)
return Flowpipe(out)
end
Projection(F::Flowpipe; vars) = Projection(F, Tuple(vars))
Projection(F::Flowpipe, vars::AbstractVector{M}) where {M<:Integer} = Projection(F, Tuple(vars))
Projection(F::Flowpipe, vars::AbstractVector{Int}) = Projection(F, Tuple(vars))

# membership test
function (x::AbstractVector{N}, fp::Flowpipe{N,<:AbstractLazyReachSet{N}}) where {N}
Expand Down
4 changes: 2 additions & 2 deletions src/Flowpipes/MappedFlowpipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct MappedFlowpipe{FT<:AbstractFlowpipe,ST} <: AbstractFlowpipe
end

"""
Projection(fp::AbstractFlowpipe, vars::NTuple{D, T}) where {D, T<:Integer}
Projection(fp::AbstractFlowpipe, vars::NTuple{D,Int}) where {D}
Return the lazy projection of a flowpipe.
Expand All @@ -30,7 +30,7 @@ The projection is lazy, and consists of mapping each set
`X` in the flowpipe to `MX`, where `M` is the projection matrix associated with
the given variables `vars`.
"""
function LazySets.Projection(fp::AbstractFlowpipe, vars::NTuple{D,T}) where {D,T<:Integer}
function LazySets.Projection(fp::AbstractFlowpipe, vars::NTuple{D,Int}) where {D}
# TODO: assert that vars belong to the variables of the flowpipe
M = projection_matrix(collect(vars), dim(F), Float64)
func = @map(x -> M * x)
Expand Down
4 changes: 2 additions & 2 deletions src/Flowpipes/ShiftedFlowpipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
project(fp::ShiftedFlowpipe, vars::AbstractVector) = project(fp, Tuple(vars))
project(fp::ShiftedFlowpipe; vars) = project(fp, Tuple(vars))

function project(fp::ShiftedFlowpipe, vars::NTuple{D,T}) where {D,T<:Integer}
function project(fp::ShiftedFlowpipe, vars::NTuple{D,Int}) where {D}
Xk = array(fp)
# TODO: use projection of the reachsets
if 0 vars # projection includes "time"
Expand All @@ -60,7 +60,7 @@ end

# this method is analogue to project(::AbstractLazyReachSet, vars; check_vars=true)
# TODO add check_vars ?
function project(fp::ShiftedFlowpipe, i::Int, vars::NTuple{D,M}) where {D,M<:Integer}
function project(fp::ShiftedFlowpipe, i::Int, vars::NTuple{D,Int}) where {D}
t0 = time_shift(fp)
R = fp[i]
if 0 vars
Expand Down
36 changes: 16 additions & 20 deletions src/Flowpipes/clustering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ the third to tenth reach-sets in another cluster.
"""
abstract type AbstractClusteringMethod{P} end

_partition(method::AbstractClusteringMethod{Missing}, idx) = nfolds(idx, 1)
_partition(method::AbstractClusteringMethod{<:Integer}, idx) = nfolds(idx, partition(method))
function _partition(method::AbstractClusteringMethod{VT},
idx) where {D<:Integer,VTi<:AbstractVector{D},VT<:AbstractVector{VTi}}
_partition(::AbstractClusteringMethod{Missing}, idx) = nfolds(idx, 1)

_partition(method::AbstractClusteringMethod{Int}, idx) = nfolds(idx, partition(method))

function _partition(method::AbstractClusteringMethod{<:AbstractVector{<:AbstractVector{Int}}}, idx)
return [idx[vi] for vi in partition(method)]
end

Expand Down Expand Up @@ -95,11 +96,10 @@ end
partition(method::LazyClustering) = method.partition

LazyClustering(; convex::Bool=true) = LazyClustering(missing, Val(convex))
function LazyClustering(nchunks::D; convex::Bool=true) where {D<:Integer}
return LazyClustering{D,typeof(Val(convex))}(nchunks, Val(convex))
function LazyClustering(nchunks::Int; convex::Bool=true)
return LazyClustering{Int,typeof(Val(convex))}(nchunks, Val(convex))
end
function LazyClustering(partition::VT) where {D<:Integer,VTi<:AbstractVector{D},
VT<:AbstractVector{VTi}}
function LazyClustering(partition::VT) where {VT<:AbstractVector{<:AbstractVector{Int}}}
return LazyClustering{VT,typeof(Val(convex))}(partition, Val(convex))
end

Expand Down Expand Up @@ -156,18 +156,16 @@ end
partition(method::BoxClustering) = method.inpartition

BoxClustering() = BoxClustering(missing, missing)
BoxClustering(nchunks::D) where {D<:Integer} = BoxClustering{D,Missing}(nchunks, missing)
function BoxClustering(partition::VT) where {D<:Integer,VTi<:AbstractVector{D},
VT<:AbstractVector{VTi}}
BoxClustering(nchunks::Int) = BoxClustering{Int,Missing}(nchunks, missing)
function BoxClustering(partition::VT) where {VT<:AbstractVector{<:AbstractVector{Int}}}
return BoxClustering{VT,Missing}(partition, missing)
end

_out_partition(method::BoxClustering{PI,Missing}, idx, n) where {PI} = fill(1, n)
function _out_partition(method::BoxClustering{PI,<:Integer}, idx, n) where {PI}
_out_partition(::BoxClustering{PI,Missing}, idx, n) where {PI} = fill(1, n)
function _out_partition(method::BoxClustering{PI,Int}, idx, n) where {PI}
return fill(method.outpartition, n)
end
function _out_partition(method::BoxClustering{PI,VT}, idx,
n) where {PI,D<:Integer,VT<:AbstractVector{D}}
function _out_partition(method::BoxClustering{PI,<:AbstractVector{Int}}, idx, n) where {PI}
return method.outpartition
end

Expand Down Expand Up @@ -350,14 +348,12 @@ end
partition(method::UnionClustering) = method.partition

UnionClustering() = UnionClustering(missing)
UnionClustering(nchunks::D) where {D<:Integer} = UnionClustering{D}(nchunks)
function UnionClustering(partition::VT) where {D<:Integer,VTi<:AbstractVector{D},
VT<:AbstractVector{VTi}}
UnionClustering(nchunks::Int) = UnionClustering{Int}(nchunks)
function UnionClustering(partition::VT) where {VT<:AbstractVector{<:AbstractVector{Int}}}
return UnionClustering{VT}(partition)
end

function cluster(F::Flowpipe{N,<:AbstractLazyReachSet}, idx,
method::UnionClustering{Missing}) where {N}
function cluster(F::Flowpipe{N,<:AbstractLazyReachSet}, idx, ::UnionClustering{Missing}) where {N}
Fidx = view(F, idx)
Δt = tspan(Fidx)
Uidx = UnionSetArray([set(R) for R in Fidx])
Expand Down
33 changes: 14 additions & 19 deletions src/Flowpipes/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ end

# TODO use LazySets._plot_singleton_list_1D if the reach-sets are stored as a struct
# array. Otherwise, we could use pass the list through x -> set(x)
function _plot_singleton_list_1D(list::Union{Flowpipe{N},AbstractVector{RN}}) where {N,
RN<:AbstractReachSet{N}}
function _plot_singleton_list_1D(list::Union{Flowpipe{N},AbstractVector{<:AbstractReachSet{N}}}) where {N}
m = length(list)

x = Vector{N}(undef, m)
Expand All @@ -191,8 +190,7 @@ function _plot_singleton_list_1D(list::Union{Flowpipe{N},AbstractVector{RN}}) wh
return x, y
end

function _plot_singleton_list_2D(list::Union{Flowpipe{N},AbstractVector{RN}}) where {N,
RN<:AbstractReachSet{N}}
function _plot_singleton_list_2D(list::Union{Flowpipe{N},AbstractVector{<:AbstractReachSet{N}}}) where {N}
m = length(list)
x = Vector{N}(undef, m)
y = Vector{N}(undef, m)
Expand Down Expand Up @@ -256,10 +254,10 @@ end
# Flowpipe plot recipes
# ========================

@recipe function plot_list(list::Union{Flowpipe{N},AbstractVector{RN}};
@recipe function plot_list(list::Union{Flowpipe{N},AbstractVector{<:AbstractReachSet{N}}};
vars=nothing,
ε=N(PLOT_PRECISION),
=PLOT_POLAR_DIRECTIONS) where {N,RN<:AbstractReachSet{N}}
=PLOT_POLAR_DIRECTIONS) where {N}
_check_vars(vars)

label --> DEFAULT_LABEL
Expand All @@ -280,11 +278,10 @@ end
end

# composite flowpipes
@recipe function plot_list(fp::Union{HF,MF};
@recipe function plot_list(fp::Union{<:HybridFlowpipe{N},<:MixedFlowpipe{N}};
vars=nothing,
ε=Float64(PLOT_PRECISION),
=PLOT_POLAR_DIRECTIONS) where {N,HF<:HybridFlowpipe{N},
MF<:MixedFlowpipe{N}}
=PLOT_POLAR_DIRECTIONS) where {N}
_check_vars(vars)

label --> DEFAULT_LABEL
Expand Down Expand Up @@ -313,10 +310,10 @@ end
# Solution plot recipes
# ========================

@recipe function plot_list(sol::ReachSolution{FT};
@recipe function plot_list(sol::ReachSolution{<:Flowpipe{N}};
vars=nothing,
ε=Float64(PLOT_PRECISION),
=PLOT_POLAR_DIRECTIONS) where {N,FT<:Flowpipe{N}}
=PLOT_POLAR_DIRECTIONS) where {N}
_check_vars(vars)

label --> DEFAULT_LABEL
Expand All @@ -338,13 +335,11 @@ end
end

# compound solution flowpipes
@recipe function plot_list(sol::Union{SMF,SHF};
@recipe function plot_list(sol::Union{ReachSolution{<:MixedFlowpipe{N}},
ReachSolution{<:HybridFlowpipe{N}}};
vars=nothing,
ε=Float64(PLOT_PRECISION),
=PLOT_POLAR_DIRECTIONS) where {N,MF<:MixedFlowpipe{N},
HF<:HybridFlowpipe{N},
SMF<:ReachSolution{MF},
SHF<:ReachSolution{HF}}
=PLOT_POLAR_DIRECTIONS) where {N}
_check_vars(vars)

label --> DEFAULT_LABEL
Expand Down Expand Up @@ -435,15 +430,15 @@ end
# plot each variable vs time
@recipe function plot_reachset(R::AbstractLazyReachSet{N};
ε::N=N(PLOT_PRECISION)
) where {N<:Real, D, M<:Integer}
) where {N}
error("not implemented yet")
end
@recipe function plot_list(list::AbstractVector{RN};
@recipe function plot_list(list::AbstractVector{<:AbstractReachSet{N}};
ε::N=N(PLOT_PRECISION),
Nφ::Int=PLOT_POLAR_DIRECTIONS,
fast::Bool=true
) where {N<:Real, RN<:AbstractReachSet{N}}
) where {N}
error("not implemented yet")
end
=#
Expand Down
4 changes: 2 additions & 2 deletions src/Flowpipes/setops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ end
# =========================

# extend LazySets concrete projection for other arguments
LazySets.project(X::LazySet, vars::NTuple{D,<:Integer}) where {D} = project(X, collect(vars))
LazySets.project(X::LazySet, vars::NTuple{D,Int}) where {D} = project(X, collect(vars))
LazySets.project(X::LazySet; vars) = project(X, vars)

# extend LazySets lazy projection for other arguments
LazySets.Projection(X::LazySet, vars::NTuple{D,<:Integer}) where {D} = Projection(X, collect(vars))
LazySets.Projection(X::LazySet, vars::NTuple{D,Int}) where {D} = Projection(X, collect(vars))
LazySets.Projection(X::LazySet; vars) = Projection(X, vars)

# ===============================
Expand Down
14 changes: 5 additions & 9 deletions src/Hybrid/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,10 @@ end

# the initial states are passed as a vector-of-tuples, each tuple being of the form
# (loc, X) where loc is an integer that corresponds to the mode and X is a set
function _distribute(ivp::InitialValueProblem{HS,Vector{Tuple{M,ST}}};
function _distribute(ivp::InitialValueProblem{<:HybridSystem,Vector{Tuple{Int,ST}}};
intersection_method=nothing,
check_invariant=false,
intersect_invariant=false) where {HS<:HybridSystem,M<:Integer,
ST<:AdmissibleSet}
intersect_invariant=false) where {ST<:AdmissibleSet}
H = system(ivp)
X0vec = initial_state(ivp) # distributed initial states

Expand All @@ -342,7 +341,6 @@ function _distribute(ivp::InitialValueProblem{HS,Vector{Tuple{M,ST}}};
STwl = ST
end

N = eltype(ST)
WL = WaitingList{TimeInterval,STwl,Int,StateInLocation{STwl,Int}}

if !check_invariant && !intersect_invariant
Expand All @@ -356,11 +354,10 @@ end

# "duck-typing" the initial states passed as a vector-of-tuples, each tuple being
# of the form (X, loc) where loc is an integer that corresponds to the mode and X is a set
function _distribute(ivp::InitialValueProblem{HS,Vector{Tuple{ST,M}}};
function _distribute(ivp::InitialValueProblem{HS,Vector{Tuple{ST,Int}}};
intersection_method=nothing,
check_invariant=false,
intersect_invariant=false) where {HS<:HybridSystem,ST<:AdmissibleSet,
M<:Integer}
intersect_invariant=false) where {HS<:HybridSystem,ST<:AdmissibleSet}
H = system(ivp)
X0vec = initial_state(ivp) # distributed initial states

Expand All @@ -371,7 +368,6 @@ function _distribute(ivp::InitialValueProblem{HS,Vector{Tuple{ST,M}}};
STwl = ST
end

N = eltype(ST)
WL = WaitingList{TimeInterval,STwl,Int,StateInLocation{STwl,Int}}

if !check_invariant && !intersect_invariant
Expand Down Expand Up @@ -414,7 +410,7 @@ end
# optionally it is checked that each set has a non-empty intersction with loc_i's invariant
function _distribute(ivp::InitialValueProblem{HS, VQT};
check_invariant=false) where {HS<:HybridSystem,
ST, QT<:Tuple{<:Integer, ST}, VQT<:AbstractVector{QT}}
ST, QT<:Tuple{Int}, ST}, VQT<:AbstractVector{QT}}
initial_states = WaitingList{Int, ST}()
for loc in states(S)
if check_invariant
Expand Down
6 changes: 3 additions & 3 deletions src/Hybrid/waiting_list.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# =====================================

"""
StateInLocation{ST, M<:Integer}
StateInLocation{ST,M}
Struct that associates a set with a hybrid automaton's location index,
usually an integer.
Expand Down Expand Up @@ -135,7 +135,7 @@ end

# conversion from vector-of-tuples to waiting list
function Base.convert(::Type{TW},
Q::Vector{Tuple{M,ST}}) where {TW<:WaitingList,M<:Integer,ST<:AdmissibleSet}
Q::Vector{Tuple{Int,ST}}) where {TW<:WaitingList,ST<:AdmissibleSet}
waiting_list = TW()
for Qi in Q # no intersection chcks
q, Xi = Qi
Expand All @@ -146,7 +146,7 @@ end

# "duck-typing" conversion from vector-of-tuples to waiting list
function Base.convert(::Type{TW},
Q::Vector{Tuple{ST,M}}) where {TW<:WaitingList,ST<:AdmissibleSet,M<:Integer}
Q::Vector{Tuple{ST,Int}}) where {TW<:WaitingList,ST<:AdmissibleSet}
waiting_list = TW()
for Qi in Q # no intersection chcks
Xi, q = Qi
Expand Down
16 changes: 8 additions & 8 deletions src/ReachSets/AbstractLazyReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ end
# ------------------------------------

"""
project(R::AbstractLazyReachSet, variables::NTuple{D, M};
check_vars::Bool=true) where {D, M<:Integer}
project(R::AbstractLazyReachSet, variables::NTuple{D,Int};
check_vars::Bool=true) where {D}
Projects a reach-set onto the subspace spanned by the given variables.
Expand Down Expand Up @@ -129,8 +129,8 @@ associated with the given variables `vars`.
To project onto the time variable, use the index `0`. For instance, `(0, 1)` projects
onto the time variable and the first variable in `R`.
"""
function project(R::AbstractLazyReachSet, variables::NTuple{D,M};
check_vars::Bool=true) where {D,M<:Integer}
function project(R::AbstractLazyReachSet, variables::NTuple{D,Int};
check_vars::Bool=true) where {D}
vR = vars(R)
vRvec = collect(vR)

Expand Down Expand Up @@ -162,7 +162,7 @@ function project(R::AbstractLazyReachSet, variable::Int; check_vars::Bool=true)
end

# concrete projection overloads
function project(R::AbstractLazyReachSet, vars::AbstractVector{M}) where {M<:Integer}
function project(R::AbstractLazyReachSet, vars::AbstractVector{Int})
return project(R, Tuple(vars))
end
project(R::AbstractLazyReachSet; vars) = project(R, Tuple(vars))
Expand All @@ -178,8 +178,8 @@ project(R::SubArray{<:AbstractLazyReachSet}; vars) = _project_vec(R, vars)
# Lazy projection of a reach-set
# -------------------------------

function Projection(R::AbstractLazyReachSet, variables::NTuple{D,M},
check_vars::Bool=true) where {D,M<:Integer}
function Projection(R::AbstractLazyReachSet, variables::NTuple{D,Int},
check_vars::Bool=true) where {D}
vR = vars(R)
vRvec = collect(vR)

Expand All @@ -202,7 +202,7 @@ function Projection(R::AbstractLazyReachSet, variables::NTuple{D,M},
end

# handle generic vars vector
function Projection(R::AbstractLazyReachSet, vars::AbstractVector{M}) where {M<:Integer}
function Projection(R::AbstractLazyReachSet, vars::AbstractVector{Int})
return Projection(R, Tuple(vars))
end

Expand Down
2 changes: 1 addition & 1 deletion src/ReachSets/ReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end

#=
# specialized concrete projection of zonotopic set by removing zero generators
function linear_map(R::ReachSet{N, <:AbstractZonotope{N}}, variables::NTuple{D, M}; check_vars::Bool=true) where {D, M<:Integer}
function linear_map(R::ReachSet{N, <:AbstractZonotope{N}}, variables::NTuple{D,Int}; check_vars::Bool=true) where {D}
πR = linear(R, variables, check_vars)
X = remove_zero_generators(set(πR))
SparseReachSet(proj, tspan(R), variables)
Expand Down
Loading

0 comments on commit 02d7f42

Please sign in to comment.