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

Fix ambiguities #811

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions src/Algorithms/BFFPSV18/reach_homog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 10 additions & 15 deletions src/Algorithms/BFFPSV18/reach_inhomog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/Flowpipes/setops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ 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)
return Ω0 = Hyperrectangle(Vector(Ω0.center), Matrix(Ω0.radius); check_bounds=false)
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
Expand All @@ -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
Expand All @@ -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}
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/ReachSets/AbstractLazyReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 5 additions & 16 deletions src/ReachSets/AbstractReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -266,21 +266,10 @@ 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}
return isdisjoint(set(R), Y)
end

@commutative function _is_intersection_empty(R::AbstractReachSet, Y::UnionSetArray{N,<:Interval{N}},
method::FallbackDisjointness) where {N}
return isdisjoint(set(R), Y)
end

# ------------------------------
# Concrete intersection methods
# ------------------------------
Expand Down
45 changes: 12 additions & 33 deletions src/ReachSets/TaylorModelReachSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ======================
Expand Down
Loading