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

#1638 - Efficient way to obtain precise Interval bounds in 1D #1976

Merged
merged 2 commits into from
Feb 20, 2020
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
72 changes: 67 additions & 5 deletions src/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ end
"""
overapproximate(S::LazySet{N}, ::Type{<:Interval}) where {N<:Real}

Return the overapproximation of a real unidimensional set with an interval.
Return the overapproximation of a unidimensional set with an interval.

### Input

Expand All @@ -601,12 +601,74 @@ An interval.

### Algorithm

The method relies on the exact conversion to `Interval`. Two support
function evaluations are needed in general.
We use two support-function evaluations.
"""
function overapproximate(S::LazySet{N}, ::Type{<:Interval}) where {N<:Real}
@assert dim(S) == 1 "cannot overapproximate a $(dim(S))-dimensional set with an `Interval`"
return convert(Interval, S)
@assert dim(S) == 1 "cannot overapproximate a $(dim(S))-dimensional set " *
"with an `Interval`"
return Interval(-ρ(N[-1], S), ρ(N[1], S))
end

"""
overapproximate(cap::Intersection{N}, ::Type{<:Interval}) where {N<:Real}

Return the overapproximation of a unidimensional intersection with an interval.

### Input

- `cap` -- one-dimensional lazy intersection
- `Interval` -- type for dispatch

### Output

An interval.

### Algorithm

The algorithm recursively overapproximates the two intersected sets with
intervals and then intersects these.
"""
function overapproximate(cap::Intersection{N}, ::Type{<:Interval}) where {N<:Real}
@assert dim(cap) == 1 "cannot overapproximate a $(dim(cap))-dimensional " *
"intersection with an `Interval`"
X = overapproximate(cap.X, Interval)
Y = overapproximate(cap.Y, Interval)
return intersection(X, Y)
end

"""
overapproximate(cap::IntersectionArray{N}, ::Type{<:Interval}) where {N<:Real}

Return the overapproximation of a unidimensional intersection with an interval.

### Input

- `cap` -- one-dimensional lazy intersection
- `Interval` -- type for dispatch

### Output

An interval.

### Algorithm

The algorithm recursively overapproximates the two intersected sets with
intervals and then intersects these.
"""
function overapproximate(cap::IntersectionArray{N},
::Type{<:Interval}) where {N<:Real}
@assert dim(cap) == 1 "cannot overapproximate a $(dim(cap))-dimensional " *
"intersection with an `Interval`"
a = array(cap)
X = overapproximate(a[1], Interval)
@inbounds for i in 2:length(a)
Y = a[i]
X = intersection(X, Y)
if isempty(X)
return X
end
end
return X
end

function overapproximate_cap_helper(X::LazySet{N}, # convex set
Expand Down
6 changes: 3 additions & 3 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ Interval{Float64,IntervalArithmetic.Interval{Float64}}([0, 1])
```
"""
function convert(::Type{Interval}, H::AbstractHyperrectangle)
@assert dim(H) == 1 "can only convert a one-dimensional $(typeof(H)) to `Interval`"
return Interval([low(H); high(H)])
@assert dim(H) == 1 "cannot convert a $(dim(H))-dimensional $(typeof(H)) to `Interval`"
return Interval(low(H)[1], high(H)[1])
end

"""
Expand All @@ -510,7 +510,7 @@ Converts a convex set to an interval.
An interval.
"""
function convert(::Type{Interval}, S::LazySet{N}) where {N<:Real}
@assert dim(S) == 1 "can only convert a one-dimensional $(typeof(S)) to `Interval`"
@assert dim(S) == 1 "cannot convert a $(dim(H))-dimensional $(typeof(S)) to `Interval`"
return Interval(-ρ(N[-1], S), ρ(N[1], S))
end

Expand Down
10 changes: 8 additions & 2 deletions test/unit_overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ for N in [Float64, Rational{Int}, Float32]

# Interval approximation
b = Ball1(N[0], N(1))
p = overapproximate(b, LazySets.Interval)
p1 = overapproximate(b, LazySets.Interval)
cap = Intersection(b, BallInf(N[1], N(1)))
p2 = overapproximate(cap, LazySets.Interval)
caparray = IntersectionArray([b, BallInf(N[1], N(1)), BallInf(N[1//2], N(1//4))])
p3 = overapproximate(caparray, LazySets.Interval)
for d in [N[1], N[-1]]
@test σ(d, p)[1] ≈ σ(d, b)[1]
for (o, p) in [(b, cap, caparray), (p1, p2, p3)]
@test σ(d, o)[1] ≈ d[1]
end
end

# approximation with an axis-aligned hyperrectangle
Expand Down