Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

More robust isdisjoint witness for Interval #3907

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

Open
schillic wants to merge 1 commit into master
base: master
Choose a base branch
Loading
from schillic/isdisjoint_interval
Open
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
9 changes: 6 additions & 3 deletions src/Sets/Interval/isdisjoint.jl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ function _isdisjoint(I1::Interval, I2::Interval, ::Val{false})
end

function _isdisjoint(I1::Interval, I2::Interval, ::Val{true})
check = _isdisjoint(I1, I2, Val(false))
if check
if _isdisjoint(I1, I2, Val(false))
N = promote_type(eltype(I1), eltype(I2))
return (true, N[])
else
return (false, [max(min(I1), min(I2))])
# mid-point, most robust witness
l = max(min(I1), min(I2))
h = min(max(I1), max(I2))
w = [l + (h - l) / 2]
return (false, w)
end
end
20 changes: 12 additions & 8 deletions test/Sets/Interval.jl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -492,25 +492,29 @@ for N in [Float64, Float32, Rational{Int}]
@test_throws AssertionError isdisjoint(X, X2)
# disjoint
Y = Interval(N(3), N(4))
@test isdisjoint(X, Y) && isdisjoint(Y, X)
for (pair, Z) in ((isdisjoint(X, Y, true), Y), (isdisjoint(Y, X, true), Y))
res, w = pair
for (Z, W) in ((X, Y), (Y, X))
@test isdisjoint(Z, W)
res, w = isdisjoint(Z, W, true)
@test res && w isa Vector{N} && isempty(w)
end
# overlapping
Y = Interval(N(1), N(3))
@test !isdisjoint(X, X) && !isdisjoint(X, Y) && !isdisjoint(Y, X)
for (pair, Z) in ((isdisjoint(X, X, true), X), (isdisjoint(X, Y, true), Y),
(isdisjoint(Y, X, true), Y))
res, w = pair
@test !res && w isa Vector{N} && w ∈ X && w ∈ Z
for (Z, W) in ((X, X), (X, Y), (Y, X))
@test !isdisjoint(Z, W)
res, w = isdisjoint(Z, W, true)
@test !res && w isa Vector{N} && w ∈ Z && w ∈ W
end
# tolerance
if N == Float64
Y = Interval(2.0 + 1e-9, 3.0)
@test !isdisjoint(X, Y)
res, w = isdisjoint(X, Y, true)
# TODO ∈ and isdisjoint should be consistent
@test_broken !res && w isa Vector{N} && w ∈ X && w ∈ Y
LazySets.set_rtol(Float64, 1e-10)
@test isdisjoint(X, Y)
res, w = isdisjoint(X, Y, true)
@test res && w isa Vector{N} && isempty(w)
# restore tolerance
LazySets.set_rtol(Float64, LazySets.default_tolerance(Float64).rtol)
end
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /