Skip to content

#3844 - Make box_approximation of polyhedral Intersections precise and work #3845

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

Merged
merged 1 commit into from
May 23, 2025
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
21 changes: 19 additions & 2 deletions src/Approximations/box_approximation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function load_staticarrays_directions()
end # quote / load_staticarrays_directions

"""
box_approximation(S::LazySet{N}) where {N}
box_approximation(S::LazySet)

Overapproximate a set by a tight hyperrectangle.

Expand All @@ -48,7 +48,11 @@ An alias for this function is `interval_hull`.
The center and radius of the hyperrectangle are obtained by averaging the low
and high coordinates of `S` computed with the `extrema` function.
"""
function box_approximation(S::LazySet{N}) where {N}
function box_approximation(S::LazySet)
return _box_approximation_extrema(S)
end

function _box_approximation_extrema(S::LazySet{N}) where {N}
n = dim(S)
c = Vector{N}(undef, n)
r = Vector{N}(undef, n)
Expand All @@ -73,6 +77,19 @@ function box_approximation(S::LazySet{N}) where {N}
return Hyperrectangle(c, r)
end

function box_approximation(cap::Intersection{N,T1,T2}) where {N,T1,T2}
if ispolyhedral(cap.X) && ispolyhedral(cap.Y)
if isboundedtype(T1) || isboundedtype(T2)
S = convert(HPolytope, cap)
else
S = convert(HPolyhedron, cap)
end
else
S = cap
end
return _box_approximation_extrema(S)
end

"""
interval_hull

Expand Down
12 changes: 12 additions & 0 deletions test/Approximations/box_approximation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ for N in [Float64, Rational{Int}, Float32]
# alias constructors
@test interval_hull(b) == □(b) == box_approximation(b)

# box_approximation of lazy intersection
# both arguments are bounded
X = Ball1(zeros(N, 2), N(1))
Y = Ball1(N[1//2, 0], N(1))
Z = box_approximation(X ∩ Y)
@test isequivalent(Z, Hyperrectangle(N[1//4, 0], N[3//4, 3//4]))
# one argument is unbounded
X = Hyperrectangle(N[0], N[1]) × Universe{N}(1)
Y = Hyperrectangle(N[0, 0], N[1, 1])
Z = box_approximation(X ∩ Y)
@test isequivalent(Z, Y)

# ===================================================================
# Testing box_approximation_symmetric (= symmetric interval hull)
# ===================================================================
Expand Down
Loading