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

Fix bug in isdisjoint of two zonotopic sets #2479

Merged
merged 2 commits into from
Jan 3, 2021
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
4 changes: 2 additions & 2 deletions src/ConcreteOperations/isdisjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ witness.

### Algorithm

``Z1 ∩ Z2 ∅`` iff ``c_1 - c_2 Z(0, (g_1, g_2))`` where ``c_i`` and ``g_i``
``Z1 ∩ Z2 = ∅`` iff ``c_1 - c_2 Z(0, (g_1, g_2))`` where ``c_i`` and ``g_i``
are the center and generators of zonotope `Zi` and ``Z(c, g)`` represents the
zonotope with center ``c`` and generators ``g``.
"""
Expand All @@ -492,7 +492,7 @@ function is_intersection_empty(Z1::AbstractZonotope, Z2::AbstractZonotope,
@assert n == dim(Z2) "zonotopes need to have the same dimensions"
N = promote_type(eltype(Z1), eltype(Z2))
Z = Zonotope(zeros(N, n), hcat(genmat(Z1), genmat(Z2)))
result = (center(Z1) - center(Z2)) Z
result = (center(Z1) - center(Z2)) Z
if result
return witness ? (true, N[]) : true
elseif witness
Expand Down
13 changes: 6 additions & 7 deletions test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,22 @@ for N in [Float64]

gens = N[1 1; -1 1]
Z1 = Zonotope(N[1, 1], gens)
Z2 = Zonotope(N[-1, 1], Matrix{N}(I, 2, 2))
Z3 = minkowski_sum(Z1, Z2)
Z2 = Zonotope(N[-2, -1], Matrix{N}(I, 2, 2))

# intersection with a hyperplane
# isdisjoint with a hyperplane
H1 = Hyperplane(N[1, 1], N(3))
intersection_empty, point = is_intersection_empty(Z1, H1, true)
@test point ∈ Z1 && point ∈ H1
@test !intersection_empty && point ∈ Z1 && point ∈ H1
# zonotope without generators (#2204)
Z3 = Zonotope(N[0, 0], Matrix{N}(undef, 2, 0))
@test isdisjoint(Z3, H1)

# isdisjoint
# isdisjoint with another zonotope
result, w = isdisjoint(Z1, Z2, true)
@test isdisjoint(Z1, Z2) && result && w == N[]
Z3 = Zonotope(N[2, 1], Matrix{N}(I, 2, 2))
@test_throws ErrorException isdisjoint(Z2, Z3, true)
@test !isdisjoint(Z2, Z3)
@test_throws ErrorException isdisjoint(Z1, Z3, true)
@test !isdisjoint(Z1, Z3)

# issubset
Z = Zonotope(N[0, 0], N[1 1; -1 1])
Expand Down