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

Empty polyhedra intersection is broken #843

Closed
schillic opened this issue Oct 21, 2018 · 2 comments
Closed

Empty polyhedra intersection is broken #843

schillic opened this issue Oct 21, 2018 · 2 comments
Assignees
Labels
bug 🐛 Something isn't working

Comments

@schillic
Copy link
Member

schillic commented Oct 21, 2018

julia> using LazySets, Polyhedra

julia> H = LazySets.HalfSpace([-1.0], -21.0); # x >= 21

julia> P = HPolytope([LazySets.HalfSpace([1.0], 18.1), # x <= 18.1
                      LazySets.HalfSpace([-1.0], -18.0)]); # x >= 18

In v0.6 this results in:

julia> cap = intersection(H, P)
LazySets.HPolytope{Float64}(LazySets.HalfSpace{Float64}[
 LazySets.HalfSpace{Float64}([1.0], 18.1),
 LazySets.HalfSpace{Float64}([-1.0], -18.0),
 LazySets.HalfSpace{Float64}([-1.0], -18.1),
 LazySets.HalfSpace{Float64}([1.0], 18.0)])

julia> isempty(cap)
true

In v0.7 this results in:

julia> cap = intersection(H, P)
HPolytope{Float64}(LazySets.HalfSpace{Float64}[])

julia> isempty(cap)
false

Problems:

  1. Why does v0.6 not simplify?
    It might be because the simplification with CDDLib is hard to interpret (contains two hyperplanes):
julia> Q = polyhedron(cap, CDDLib.CDDLibrary())
Polyhedron CDDLib.CDDPolyhedron{1,Float64}:
4-element iterator of Polyhedra.HalfSpace{1,Float64,Array{Float64,1}}:
 HalfSpace([1.0], 18.1)
 HalfSpace([-1.0], -18.0)
 HalfSpace([-1.0], -18.1)
 HalfSpace([1.0], 18.0)

julia> removehredundancy!(Q)

julia> Q
Polyhedron CDDLib.CDDPolyhedron{1,Float64}:
2-element iterator of Polyhedra.HyperPlane{1,Float64,Array{Float64,1}}:
 HyperPlane([1.0], 18.1)
 HyperPlane([-1.0], -18.0)
  1. The v0.7 result (polyhedron without constraints) is due to Dimension error for default Polyhedra backend in >= v0.7 #842. By hard-coding a 1 in the code, the result is as follows:
julia> cap = intersection(H, P)
HPolytope{Float64}(LazySets.HalfSpace{Float64}[HalfSpace{Float64}([1.0], 0.0), HalfSpace{Float64}([0.0], 1.0), HalfSpace{Float64}([-1.0], -0.0), HalfSpace{Float64}([-0.0], -1.0)])

This is still a strange result.

  1. Assuming that the v0.7 result (polyhedron without constraints) can occur after fixing Dimension error for default Polyhedra backend in >= v0.7 #842: This polytope is not empty by definition. But it seems that Polyhedra interprets it like that. We should catch this case in the intersection methods and return an EmptySet in this case. Maybe we should check if Polyhedra returns a specific status flag or something to indicate empty intersections.
@mforets
Copy link
Member

mforets commented Nov 16, 2018

in #master and v0.7 one now gets:

julia> using LazySets, Polyhedra

julia> H = LazySets.HalfSpace([-1.0], -21.0); # x >= 21

julia> P = HPolytope([LazySets.HalfSpace([1.0], 18.1), # x <= 18.1
                      LazySets.HalfSpace([-1.0], -18.0)]); # x >= 18

julia> cap = intersection(H, P);

julia> isempty(cap)
true # correct

julia> cap.constraints
4-element Array{LazySets.HalfSpace{Float64},1}:
 LazySets.HalfSpace{Float64}([1.0], 0.0)  
 LazySets.HalfSpace{Float64}([0.0], 1.0)  
 LazySets.HalfSpace{Float64}([-1.0], -0.0)
 LazySets.HalfSpace{Float64}([-0.0], -1.0)

julia> remove_redundant_constraints(cap)
LP is not optimal

this is a case where "LP is not optimal" is indicating that it is empty.

@mforets
Copy link
Member

mforets commented Jan 22, 2019

After PR #1050

julia> using Revise, LazySets
[ Info: Recompiling stale cache file /Users/forets/.julia/compiled/v1.0/LazySets/NjrGc.ji for LazySets [b4f0291d-fe17-52bc-9479-3d1a343d9043]

julia> H = LazySets.HalfSpace([-1.0], -21.0); # x >= 21

julia> P = HPolytope([LazySets.HalfSpace([1.0], 18.1), # x <= 18.1

                             LazySets.HalfSpace([-1.0], -18.0)]); # x >= 18

julia> cap = intersection(H, P)
EmptySet{Float64}()

julia> using Polyhedra

julia> isempty(HP)
true

julia> isdisjoint(H, P)
true

julia> isdisjoint(P, H)
true

julia> using BenchmarkTools

julia> @btime intersection($H, $P)
  18.596 μs (55 allocations: 4.00 KiB)
EmptySet{Float64}()

julia> @btime isdisjoint($H, $P)
  17.676 μs (56 allocations: 3.73 KiB)
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants