Skip to content

Commit ff1d759

Browse files
committed
fix box_approximation of Intersection with unbounded component
1 parent 4057c84 commit ff1d759

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Approximations/box_approximation.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function load_staticarrays_directions()
2727
end # quote / load_staticarrays_directions
2828

2929
"""
30-
box_approximation(S::LazySet{N}) where {N}
30+
box_approximation(S::LazySet)
3131
3232
Overapproximate a set by a tight hyperrectangle.
3333
@@ -48,7 +48,11 @@ An alias for this function is `interval_hull`.
4848
The center and radius of the hyperrectangle are obtained by averaging the low
4949
and high coordinates of `S` computed with the `extrema` function.
5050
"""
51-
function box_approximation(S::LazySet{N}) where {N}
51+
function box_approximation(S::LazySet)
52+
return _box_approximation_extrema(S)
53+
end
54+
55+
function _box_approximation_extrema(S::LazySet{N}) where {N}
5256
n = dim(S)
5357
c = Vector{N}(undef, n)
5458
r = Vector{N}(undef, n)
@@ -73,6 +77,19 @@ function box_approximation(S::LazySet{N}) where {N}
7377
return Hyperrectangle(c, r)
7478
end
7579

80+
function box_approximation(cap::Intersection{N,T1,T2}) where {N,T1,T2}
81+
if ispolyhedral(cap.X) && ispolyhedral(cap.Y)
82+
if isboundedtype(T1) && isboundedtype(T2)
83+
S = convert(HPolytope, cap)
84+
else
85+
S = convert(HPolyhedron, cap)
86+
end
87+
else
88+
S = cap
89+
end
90+
return _box_approximation_extrema(S)
91+
end
92+
7693
"""
7794
interval_hull
7895

test/Approximations/box_approximation.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ for N in [Float64, Rational{Int}, Float32]
4141
# alias constructors
4242
@test interval_hull(b) == (b) == box_approximation(b)
4343

44+
# box_approximation of lazy intersection
45+
# both arguments are bounded
46+
X = Ball1(zeros(N, 2), N(1))
47+
Y = Ball1(N[1//2, 0], N(1))
48+
Z = box_approximation(X Y)
49+
@test isequivalent(Z, Hyperrectangle(N[1//4, 0], N[3//4, 3//4]))
50+
# one argument is unbounded
51+
X = Hyperrectangle(N[0], N[1]) × Universe{N}(1)
52+
Y = Hyperrectangle(N[0, 0], N[1, 1])
53+
Z = box_approximation(X Y)
54+
@test isequivalent(Z, Y)
55+
4456
# ===================================================================
4557
# Testing box_approximation_symmetric (= symmetric interval hull)
4658
# ===================================================================

0 commit comments

Comments
 (0)