Skip to content

Commit

Permalink
Merge pull request #3335 from JuliaReach/schillic/1229
Browse files Browse the repository at this point in the history
#1229 - Generic overapproximate by falling back to convert
  • Loading branch information
schillic authored Jun 20, 2023
2 parents 494db08 + 8c04862 commit 06fccad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
22 changes: 21 additions & 1 deletion src/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ function overapproximate(X::S, ::Type{S}, args...; kwargs...) where {S<:LazySet}
return X
end

"""
overapproximate(S::LazySet, T::Type{<:LazySet}, [args]...; [kwargs]...)
Default overapproximation method that falls back to `convert`.
### Input
- `X` -- set
- `Type{S}` -- target set type
- `args` -- further arguments
- `kwargs` -- further keyword arguments
### Output
The result of `convert`, or a `MethodError` if no such method exists.
"""
function overapproximate(X::T1, T2::Type{<:LazySet}, args...; kwargs...) where {T1<:LazySet}
return convert(T2, X, args...; kwargs...)
end

"""
overapproximate(S::LazySet)
Expand Down Expand Up @@ -130,9 +150,9 @@ for ST in LazySets.subtypes(LazySet, true)
end
@eval overapproximate(∅::EmptySet, ::Type{<:$ST}) =
end
overapproximate(∅::EmptySet, ::Type{<:LazySet}, args...; kwargs...) =
overapproximate(∅::EmptySet, ::Real) =
overapproximate(∅::EmptySet, ::Type{<:HPolygon}, ::Real=Inf; kwargs...) =
overapproximate(∅::EmptySet, ::Type{<:EmptySet}, args...; kwargs...) =
function overapproximate(∅::EmptySet, ::Type{<:Zonotope},
::Union{AbstractDirections,Type{<:AbstractDirections}};
kwargs...)
Expand Down
20 changes: 0 additions & 20 deletions src/Approximations/overapproximate_zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,6 @@ function _overapproximate_convex_hull_zonotope_GGP09(X::ConvexHull{N}) where {N}
return Zonotope(c, G)
end

"""
overapproximate(lm::LinearMap{N, <:AbstractZonotope},
::Type{<:Zonotope}) where {N}
Overapproximate a lazy linear map of a zonotopic set with a zonotope.
### Input
- `lm` -- lazy linear map of a zonotopic set
- `Zonotope` -- target set type
### Output
The tight zonotope corresponding to `lm`.
"""
function overapproximate(lm::LinearMap{N,<:AbstractZonotope},
::Type{<:Zonotope}) where {N}
return convert(Zonotope, lm)
end

# Given center, (dependent) generator matrix and exponent matrix of a (simple)
# sparse polynomial zonotope, compute thew new center and generator matrix of
# its zonotope overapproximation.
Expand Down
4 changes: 4 additions & 0 deletions test/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ for N in [Float64, Rational{Int}, Float32]
oa = overapproximate(b, Ball1, Hyperrectangle)
@test oa isa Ball1

# default fallback to `convert`
B = BallInf(c, N(1))
overapproximate(B, Zonotope) == Zonotope(c, N[1 0; 0 1])

# HPolygon approximation with box directions
p = overapproximate(b, HPolygon)
for d in [N[1, 0], N[-1, 0]]
Expand Down

0 comments on commit 06fccad

Please sign in to comment.