Skip to content

Commit

Permalink
generalize isdisjoint(::CPA, ::HPolyhedron) to AbstractPolyhedron
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 4, 2019
1 parent 2270cc9 commit 9125c90
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/src/lib/binary_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ is_intersection_empty(::Universe{N}, ::LazySet{N}, ::Bool=false) where {N<:Real}
is_intersection_empty(::Complement{N}, ::LazySet{N}, ::Bool=false) where {N<:Real}
is_intersection_empty(::Zonotope{N}, ::Zonotope{N}, ::Bool=false) where {N<:Real}
is_intersection_empty(::Interval{N}, ::Interval{N}, ::Bool=false) where {N<:Real}
is_intersection_empty(X::CartesianProductArray{N}, Y::HPolyhedron{N}) where {N<:Real}
is_intersection_empty(X::CartesianProductArray{N}, Y::AbstractPolyhedron{N}) where {N<:Real}
is_intersection_empty(X::CartesianProductArray{N}, Y::CartesianProductArray{N}) where {N}
```

Expand Down
50 changes: 32 additions & 18 deletions src/is_intersection_empty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,37 +1368,50 @@ function is_intersection_empty(X::LazySet{N},
end

"""
is_intersection_empty(X::CartesianProductArray{N, S},
P::HPolyhedron{N}) where {N<:Real, S<:LazySet{N}}
is_intersection_empty(cpa::CartesianProductArray{N},
P::AbstractPolyhedron{N}) where {N<:Real}
Check whether a Cartesian product array intersects with a H-polyhedron.
Check whether a Cartesian product array intersects with a polyhedron.
### Input
- `X` -- Cartesian product array of convex sets
- `P` -- H-polyhedron
- `cpa` -- Cartesian product array of convex sets
- `P` -- polyhedron
### Output
`true` iff ``X ∩ Y = ∅ ``.
`true` iff ``\\text{cpa} ∩ Y = ∅ ``.
"""
function is_intersection_empty(X::CartesianProductArray{N},
P::HPolyhedron{N}) where {N<:Real}
cpa_low_dim, vars, block_structure = get_constrained_lowdimset(X, P)

function is_intersection_empty(cpa::CartesianProductArray{N},
P::AbstractPolyhedron{N}) where {N<:Real}
cpa_low_dim, vars, _block_structure = get_constrained_lowdimset(cpa, P)
return isdisjoint(cpa_low_dim, project(P, vars))
end

# symmetric method
function is_intersection_empty(P::HPolyhedron{N},
X::CartesianProductArray{N, S}) where {N<:Real, S<:LazySet{N}}
is_intersection_empty(X, P)
function is_intersection_empty(P::AbstractPolyhedron{N},
cpa::CartesianProductArray{N}) where {N<:Real}
return is_intersection_empty(cpa, P)
end

# disambiguation
function is_intersection_empty(cpa::CartesianProductArray{N},
hs::HalfSpace{N}) where {N<:Real}
return invoke(is_intersection_empty,
Tuple{CartesianProductArray{N}, AbstractPolyhedron{N}},
cpa, hs)
end
function is_intersection_empty(hs::HalfSpace{N},
cpa::CartesianProductArray{N}) where {N<:Real}
return is_intersection_empty(cpa, hs)
end

"""
is_intersection_empty(X::CartesianProductArray{N}, Y::CartesianProductArray{N}) where {N}
is_intersection_empty(X::CartesianProductArray{N},
Y::CartesianProductArray{N}) where {N}
Check whether two Cartesian products of a finite number of convex sets do not intersect.
Check whether two Cartesian products of a finite number of convex sets do not
intersect.
### Input
Expand All @@ -1409,14 +1422,15 @@ Check whether two Cartesian products of a finite number of convex sets do not in
`true` iff ``X ∩ Y = ∅ ``.
"""
function is_intersection_empty(X::CartesianProductArray{N}, Y::CartesianProductArray{N}) where {N}
@assert same_block_structure(array(X), array(Y)) "block structure has to be the same"
function is_intersection_empty(X::CartesianProductArray{N},
Y::CartesianProductArray{N}) where {N}
@assert same_block_structure(array(X), array(Y)) "block structure has to " *
"be the same"

for i in 1:length(X.array)
if isdisjoint(X.array[i], Y.array[i])
return true
end
end

return false
end
19 changes: 11 additions & 8 deletions test/unit_CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,15 @@ for N in [Float64, Float32]
h2 = Hyperrectangle(low=N[5, 5], high=N[6, 8])
cpa1 = CartesianProductArray([i1, i2, h1])
cpa2 = CartesianProductArray([i1, i2, h2])
G = HPolyhedron([HalfSpace(N[1, 0, 0, 0], N(1))])
G_empty = HPolyhedron([HalfSpace(N[1, 0, 0, 0], N(-1))])
cpa1_box = overapproximate(cpa1)
cpa2_box = overapproximate(cpa2)

@test is_intersection_empty(cpa1, cpa2) == is_intersection_empty(cpa1_box, cpa2_box) == false
@test is_intersection_empty(cpa1, G_empty) == is_intersection_empty(cpa1_box, G_empty) == true
@test is_intersection_empty(cpa1, G) == is_intersection_empty(Approximations.overapproximate(cpa1), G) == false
G = HalfSpace(N[1, 0, 0, 0], N(1))
G_empty = HalfSpace(N[1, 0, 0, 0], N(-1))
cpa1_box = overapproximate(cpa1)
cpa2_box = overapproximate(cpa2)

@test !is_intersection_empty(cpa1, cpa2) &&
!is_intersection_empty(cpa1_box, cpa2_box)
@test is_intersection_empty(cpa1, G_empty) &&
is_intersection_empty(cpa1_box, G_empty)
@test !is_intersection_empty(cpa1, G) &&
!is_intersection_empty(Approximations.overapproximate(cpa1), G)
end
8 changes: 4 additions & 4 deletions test/unit_overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ for N in [Float64, Float32]
o_cpa1 = overapproximate(cpa1)
cpa2 = CartesianProductArray([i1, i2, h2])
o_cpa2 = overapproximate(cpa2)
G = HPolyhedron([HalfSpace(N[1, 0, 0, 0], N(1))])
G_3 = HPolyhedron([HalfSpace(N[0, 0, 1, 0], N(1))])
G_3_neg = HPolyhedron([HalfSpace(N[0, 0, -1, 0], N(0))])
G = HalfSpace(N[1, 0, 0, 0], N(1))
G_3 = HalfSpace(N[0, 0, 1, 0], N(1))
G_3_neg = HalfSpace(N[0, 0, -1, 0], N(0))

d_int_g = Intersection(cpa1, G)
d_int_g_3 = Intersection(cpa1, G_3)
Expand Down Expand Up @@ -206,7 +206,7 @@ for N in [Float64]
i2 = Interval(N[2, 3])
h1 = Hyperrectangle(low=N[3, 4], high=N[5, 7])
cpa = CartesianProductArray([i1, i2, h1])
G_comb = HPolyhedron([HalfSpace(N[1, 1, 0, 0], N(2.5))])
G_comb = HalfSpace(N[1, 1, 0, 0], N(2.5))
int_g_comb = Intersection(cpa, G_comb)
o_d_int_g_comb = overapproximate(int_g_comb, CartesianProductArray, Hyperrectangle)
o_bd_int_g_comb = overapproximate(int_g_comb, BoxDirections)
Expand Down

0 comments on commit 9125c90

Please sign in to comment.