From 7dbebf97fc207723b4f8b1b988c0670af5866da7 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 10 Mar 2024 17:47:49 +0100 Subject: [PATCH 1/2] fix ambiguities --- src/Algorithms/BFFPSV18/reach_homog.jl | 13 ++++--- src/Algorithms/BFFPSV18/reach_inhomog.jl | 25 ++++++------- src/Flowpipes/setops.jl | 10 ++++-- src/ReachSets/AbstractLazyReachSet.jl | 6 ++-- src/ReachSets/AbstractReachSet.jl | 14 ++++---- src/ReachSets/TaylorModelReachSet.jl | 45 +++++++----------------- 6 files changed, 44 insertions(+), 69 deletions(-) diff --git a/src/Algorithms/BFFPSV18/reach_homog.jl b/src/Algorithms/BFFPSV18/reach_homog.jl index e4ebdd14b..f38f38da2 100644 --- a/src/Algorithms/BFFPSV18/reach_homog.jl +++ b/src/Algorithms/BFFPSV18/reach_homog.jl @@ -5,8 +5,8 @@ # Set representation: Interval # Matrix operations: Dense # Invariant: No -function reach_homog_BFFPSV18!(F, Xhat0, Φ::AbstractMatrix{NM}, NSTEPS, δ, X::Universe, - ST::Type{<:Interval{N}}, vars, block_indices, +function reach_homog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::AbstractMatrix{NM}, NSTEPS, δ, + X::Universe, ST::Type{<:Interval{N}}, vars, block_indices, row_blocks, column_blocks, Δt0, viewval::Val{true}) where {NM,N} @@ -44,8 +44,8 @@ end # Set representation: Generic # Matrix operations: Dense # Invariant: No -function reach_homog_BFFPSV18!(F, Xhat0, Φ::MT, NSTEPS, δ::N, X::Universe, - ST, vars, block_indices, +function reach_homog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ::N, + X::Universe, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, @@ -86,9 +86,8 @@ end # Set representation: Generic # Matrix operations: Sparse # Invariant: No -function reach_homog_BFFPSV18!(F, Xhat0, Φ::MT, NSTEPS, δ::N, X::Universe, - ST, vars, - block_indices, +function reach_homog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ::N, + X::Universe, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, diff --git a/src/Algorithms/BFFPSV18/reach_inhomog.jl b/src/Algorithms/BFFPSV18/reach_inhomog.jl index 41be52db2..feeff1b8a 100644 --- a/src/Algorithms/BFFPSV18/reach_inhomog.jl +++ b/src/Algorithms/BFFPSV18/reach_inhomog.jl @@ -5,9 +5,8 @@ # Set representation: Interval # Matrix operations: Dense # Invariant: No -function reach_inhomog_BFFPSV18!(F, Xhat0::LazySet{N}, Φ::MT, NSTEPS, δ, X::Universe, U, - ST::Type{<:Interval{N}}, vars, - block_indices, +function reach_inhomog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ, + X::Universe, U, ST::Type{<:Interval{N}}, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, @@ -60,8 +59,8 @@ end # Set representation: Generic # Matrix operations: Dense # Invariant: No -function reach_inhomog_BFFPSV18!(F, Xhat0::LazySet{N}, Φ::MT, NSTEPS, δ, X::Universe, U, - ST, vars, block_indices, +function reach_inhomog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ, + X::Universe, U, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, @@ -114,10 +113,8 @@ end # Set representation: Generic # Matrix operations: Sparse # Invariant: No -function reach_inhomog_BFFPSV18!(F, Xhat0, Φ::MT, NSTEPS, δ::N, - X::Universe, U, - ST, vars, - block_indices, +function reach_inhomog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ::N, + X::Universe, U, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, @@ -170,10 +167,8 @@ function reach_inhomog_BFFPSV18!(F, Xhat0, Φ::MT, NSTEPS, δ::N, return F end -function reach_inhomog_BFFPSV18!(F, Xhat0, Φ::MT, NSTEPS, δ::N, - X::Universe, U, - ST, vars, - block_indices, +function reach_inhomog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ::N, + X::Universe, U, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, @@ -233,8 +228,8 @@ end # Set representation: Generic # Matrix operations: Dense # Invariant: LazySet -function reach_inhomog_BFFPSV18!(F, Xhat0::LazySet{N}, Φ::MT, NSTEPS, δ, X::LazySet, U, - ST, vars, block_indices, +function reach_inhomog_BFFPSV18!(F, Xhat0::CartesianProductArray{N}, Φ::MT, NSTEPS, δ, + X::LazySet, U, ST, vars, block_indices, row_blocks::AbstractVector{<:RBLKi}, column_blocks::AbstractVector{<:CBLKj}, Δt0, diff --git a/src/Flowpipes/setops.jl b/src/Flowpipes/setops.jl index 274c6743e..531bd3dd4 100644 --- a/src/Flowpipes/setops.jl +++ b/src/Flowpipes/setops.jl @@ -53,6 +53,7 @@ function _reconvert(Ω0::Hyperrectangle{N,Vector{N},Vector{N}}, static::Val{true return nodim_msg() end _reconvert(Ω0::Hyperrectangle{N,<:SVector,<:SVector}, static::Val{true}, dim) where {N} = Ω0 +_reconvert(Ω0::Hyperrectangle{N,<:SVector,<:SVector}, static::Val{true}, dim::Val) where {N} = Ω0 # convert any Hyperrectangle to be represented with regular arrays function _reconvert(Ω0::Hyperrectangle, static::Val{false}, dim::Missing) @@ -60,8 +61,7 @@ function _reconvert(Ω0::Hyperrectangle, static::Val{false}, dim::Missing) end # convert any Hyperrectangle to be represented with static arrays -function _reconvert(Ω0::Hyperrectangle{N,VNC,VNR}, static::Val{true}, - dim::Val{n}) where {N,VNC,VNR,n} +function _reconvert(Ω0::Hyperrectangle{N}, static::Val{true}, dim::Val{n}) where {N,n} #n = length(Ω0.center) # dimension return Ω0 = Hyperrectangle(SVector{n,N}(Ω0.center), SVector{n,N}(Ω0.radius); check_bounds=false) end @@ -71,6 +71,8 @@ _reconvert(Φ::Matrix{N}, static::Val{false}, dim) where {N} = Φ _reconvert(Φ::IntervalMatrix{N}, static::Val{false}, dim) where {N} = Φ _reconvert(Φ::AbstractMatrix, static::Val{false}, dim) = Matrix(Φ) _reconvert(Φ::SMatrix, static::Val{true}, dim) = Φ +_reconvert(Φ::SMatrix, static::Val{true}, dim::Val) = Φ +_reconvert(Φ::SMatrix, static::Val{true}, dim::Missing) = Φ function _reconvert(Φ::AbstractMatrix, static::Val{true}, dim::Missing) return _reconvert(Φ, static, Val(size(Φ, 1))) end @@ -92,6 +94,8 @@ const VPOLY{N,VN} = Union{VPolygon{N,VN},VPolytope{N,VN}} # no-op _reconvert(V::VPOLY{N,VN}, static::Val{false}, dim) where {N,VN<:AbstractVector{N}} = V _reconvert(V::VPOLY{N,VN}, static::Val{true}, dim) where {N,VN<:SVector{N}} = V +_reconvert(V::VPOLY{N,VN}, static::Val{true}, dim::Val) where {N,VN<:SVector{N}} = V +_reconvert(V::VPOLY{N,VN}, static::Val{true}, dim::Missing) where {N,VN<:SVector{N}} = V function _reconvert(V::VPOLY{N,VN}, static::Val{true}, dim::Val{n}) where {N,VN<:AbstractVector{N},n} @@ -105,7 +109,7 @@ function _reconvert(V::VPOLY{N,VN}, static::Val{true}, dim::Missing) where {N,VN end Base.convert(::Type{HPolytope{N,VT}}, P::HPolytope{N,VT}) where {N,VT} = P -function Base.convert(::Type{HPolytope{N,VT}}, P) where {N,VT} +function Base.convert(::Type{HPolytope{N,VT}}, P::LazySet) where {N,VT} return HPolytope([HalfSpace(VT(c.a), c.b) for c in constraints_list(P)]) end diff --git a/src/ReachSets/AbstractLazyReachSet.jl b/src/ReachSets/AbstractLazyReachSet.jl index 71044bc3b..17f22c0c5 100644 --- a/src/ReachSets/AbstractLazyReachSet.jl +++ b/src/ReachSets/AbstractLazyReachSet.jl @@ -169,10 +169,8 @@ project(R::AbstractLazyReachSet; vars) = project(R, Tuple(vars)) # projection of an array of reach-sets _project_vec(R, vars) = map(Ri -> project(Ri, Tuple(vars)), R) -project(R::Vector{<:AbstractLazyReachSet}, vars::VecOrTupleOrInt) = _project_vec(R, vars) -project(R::Vector{<:AbstractLazyReachSet}; vars) = _project_vec(R, vars) -project(R::SubArray{<:AbstractLazyReachSet}, vars) = _project_vec(R, vars) -project(R::SubArray{<:AbstractLazyReachSet}; vars) = _project_vec(R, vars) +project(R::AbstractVector{<:AbstractLazyReachSet}, vars::VecOrTupleOrInt) = _project_vec(R, vars) +project(R::AbstractVector{<:AbstractLazyReachSet}; vars::VecOrTupleOrInt) = _project_vec(R, vars) # ------------------------------- # Lazy projection of a reach-set diff --git a/src/ReachSets/AbstractReachSet.jl b/src/ReachSets/AbstractReachSet.jl index f413aec7c..54eca1ea3 100644 --- a/src/ReachSets/AbstractReachSet.jl +++ b/src/ReachSets/AbstractReachSet.jl @@ -240,22 +240,22 @@ end # internal implementation function _is_intersection_empty(R::AbstractReachSet, Y::AbstractReachSet, - method::FallbackDisjointness) + ::FallbackDisjointness) return isdisjoint(set(R), set(Y)) end @commutative function _is_intersection_empty(R::AbstractReachSet, Y::LazySet, - method::FallbackDisjointness) + ::FallbackDisjointness) return isdisjoint(set(R), Y) end @commutative function _is_intersection_empty(R::AbstractReachSet, Y::LazySet, - method::ZonotopeEnclosure) + ::ZonotopeEnclosure) Z = overapproximate(R, Zonotope) return isdisjoint(set(Z), Y) end -@commutative function _is_intersection_empty(R::AbstractReachSet, Y::LazySet, method::BoxEnclosure) +@commutative function _is_intersection_empty(R::AbstractReachSet, Y::LazySet, ::BoxEnclosure) H = overapproximate(R, Hyperrectangle) return isdisjoint(set(H), Y) end @@ -266,18 +266,18 @@ function _is_intersection_empty(P::HPolyhedron, Z::Zonotope, ::BoxEnclosure) end # in this method we assume that the intersection is non-empty -@commutative function _is_intersection_empty(R::AbstractReachSet, Y::LazySet, method::Dummy) +@commutative function _is_intersection_empty(::AbstractReachSet, ::LazySet, ::Dummy) return false end @commutative function _is_intersection_empty(R::AbstractReachSet, Y::UnionSet{N,<:Interval{N},<:Interval{N}}, - method::FallbackDisjointness) where {N} + ::FallbackDisjointness) where {N} return isdisjoint(set(R), Y) end @commutative function _is_intersection_empty(R::AbstractReachSet, Y::UnionSetArray{N,<:Interval{N}}, - method::FallbackDisjointness) where {N} + ::FallbackDisjointness) where {N} return isdisjoint(set(R), Y) end diff --git a/src/ReachSets/TaylorModelReachSet.jl b/src/ReachSets/TaylorModelReachSet.jl index 0652bdc73..f5c54f8d4 100644 --- a/src/ReachSets/TaylorModelReachSet.jl +++ b/src/ReachSets/TaylorModelReachSet.jl @@ -125,53 +125,32 @@ end # Disjointness checks # ====================== -function _is_intersection_empty(R::TaylorModelReachSet, Y::LazySet, method::FallbackDisjointness) +function _is_intersection_empty(R::TaylorModelReachSet, Y::LazySet, ::FallbackDisjointness) return isdisjoint(set(overapproximate(R, Zonotope)), Y) end -# TODO when UnionSet, UnionSetArray <: LazySet -function _is_intersection_empty(R::TaylorModelReachSet, Y::Union{UnionSet,UnionSetArray}, - method::FallbackDisjointness) - return isdisjoint(set(overapproximate(R, Zonotope)), Y) -end -function _is_intersection_empty(R::TaylorModelReachSet, Y::Union{UnionSet,UnionSetArray}, - method::ZonotopeEnclosure) - return isdisjoint(set(overapproximate(R, Zonotope)), Y) -end -function _is_intersection_empty(R::TaylorModelReachSet, Y::Union{UnionSet,UnionSetArray}, - method::BoxEnclosure) - return isdisjoint(set(overapproximate(R, Hyperrectangle)), Y) -end - function _is_intersection_empty(R1::TaylorModelReachSet, R2::TaylorModelReachSet, - method::FallbackDisjointness) + ::FallbackDisjointness) return isdisjoint(set(overapproximate(R1, Zonotope)), set(overapproximate(R2, Zonotope))) end function _is_intersection_empty(R1::TaylorModelReachSet, R2::TaylorModelReachSet, - method::ZonotopeEnclosure) + ::ZonotopeEnclosure) return isdisjoint(set(overapproximate(R1, Zonotope)), set(overapproximate(R2, Zonotope))) end -@commutative function _is_intersection_empty(R::TaylorModelReachSet, - Y::Union{LazySet,UnionSet,UnionSetArray}, - method::ZonotopeEnclosure) +@commutative function _is_intersection_empty(R::TaylorModelReachSet, Y::LazySet, + ::ZonotopeEnclosure) Z = overapproximate(R, Zonotope) return isdisjoint(set(Z), Y) end -@commutative function _is_intersection_empty(R::TaylorModelReachSet, X::Universe, - method::AbstractDisjointnessMethod) - return false -end - -@commutative function _is_intersection_empty(R::TaylorModelReachSet, X::Universe, - method::ZonotopeEnclosure) - return false -end - -@commutative function _is_intersection_empty(R::TaylorModelReachSet, X::Universe, - method::BoxEnclosure) - return false +for T in (:AbstractDisjointnessMethod, :FallbackDisjointness, :ZonotopeEnclosure, :BoxEnclosure, :Dummy) + @eval begin + @commutative function _is_intersection_empty(::TaylorModelReachSet, ::Universe, + method::$T) + return false + end + end end # ====================== From 5ae831886e42c32853997a33c51501db76cb1370 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 10 Mar 2024 17:48:02 +0100 Subject: [PATCH 2/2] remove methods that are not needed anymore --- src/ReachSets/AbstractReachSet.jl | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/ReachSets/AbstractReachSet.jl b/src/ReachSets/AbstractReachSet.jl index 54eca1ea3..7664a8506 100644 --- a/src/ReachSets/AbstractReachSet.jl +++ b/src/ReachSets/AbstractReachSet.jl @@ -270,17 +270,6 @@ end return false end -@commutative function _is_intersection_empty(R::AbstractReachSet, - Y::UnionSet{N,<:Interval{N},<:Interval{N}}, - ::FallbackDisjointness) where {N} - return isdisjoint(set(R), Y) -end - -@commutative function _is_intersection_empty(R::AbstractReachSet, Y::UnionSetArray{N,<:Interval{N}}, - ::FallbackDisjointness) where {N} - return isdisjoint(set(R), Y) -end - # ------------------------------ # Concrete intersection methods # ------------------------------