Skip to content

Commit

Permalink
Merge pull request #2479 from JuliaReach/schillic/isdisjoint
Browse files Browse the repository at this point in the history
Fix bug in isdisjoint of two zonotopic sets
  • Loading branch information
schillic authored Jan 3, 2021
2 parents 58c9f05 + 55a5bc8 commit 405580d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
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

0 comments on commit 405580d

Please sign in to comment.