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

Removing constraints of empty polyhedron results in non-empty set #146

Open
mforets opened this issue Jan 20, 2019 · 4 comments
Open

Removing constraints of empty polyhedron results in non-empty set #146

mforets opened this issue Jan 20, 2019 · 4 comments
Labels

Comments

@mforets
Copy link
Member

mforets commented Jan 20, 2019

The following example shows what i think is a bug in removehredundancy!:

# p is a rectangle
julia> p = polyhedron(hrep([HalfSpace([1.0, 0.0], 0.308261),
                            HalfSpace([-1.0, 0.0], -0.2),
                            HalfSpace([0.0, 1.0], 0.1),
                            HalfSpace([0.0, -1.0], 0.106045)]), CDDLib.Library());

# q is an unbounded unidimensional set  (a "ray" from the origin towards `x->+oo`, `y->-oo` and slope `-0.714286`)
julia> q = polyhedron(hrep([HalfSpace([-1.0, 0.0], 0.0),
                            HalfSpace([-0.714286, -1.0], 0.0),
                            HalfSpace([0.714286, 1.0], 0.0)]), CDDLib.Library());

julia> P = Polyhedra.intersect(p, q)
Polyhedron CDDLib.Polyhedron{Float64}:
7-element iterator of HalfSpace{Float64,Array{Float64,1}}:
 HalfSpace([1.0, 0.0], 0.308261)
 HalfSpace([-1.0, 0.0], -0.2)
 HalfSpace([0.0, 1.0], 0.1)
 HalfSpace([0.0, -1.0], 0.106045)
 HalfSpace([-1.0, 0.0], 0.0)
 HalfSpace([-0.714286, -1.0], 0.0)
 HalfSpace([0.714286, 1.0], 0.0)

julia> Polyhedra.removehredundancy!(P)

# the polyhedron P is unbounded in the y coordinate: 0.2 <= x <= 0.308261, y <= 0.1
# but it shouldn't: y should be bounded as well since `x` is bounded 
julia> P
Polyhedron CDDLib.Polyhedron{Float64}:
3-element iterator of HyperPlane{Float64,Array{Float64,1}}:
 HyperPlane([1.0, 0.0], 0.308261)
 HyperPlane([-1.0, 0.0], -0.2)
 HyperPlane([0.0, 1.0], 0.1)

(reported here @schillic)


(EDITED)

I had a quick look at a workaround using a Polyhedra.Ray:

julia> v = polyhedron(vrep([Polyhedra.Ray([-0.714286, 1.0])]), CDDLib.Library())
Polyhedron CDDLib.Polyhedron{Float64}:
1-element iterator of Array{Float64,1}:
 [0.0, 0.0],
1-element iterator of Ray{Float64,Array{Float64,1}}:
 Ray([-0.714286, 1.0])

julia> P = Polyhedra.intersect(p, v)
Polyhedron CDDLib.Polyhedron{Float64}:
1-element iterator of HyperPlane{Float64,Array{Float64,1}}:
 HyperPlane([-1.4, -1.0], 0.0),
5-element iterator of Polyhedra.HalfSpace{Float64,Array{Float64,1}}:
 HalfSpace([1.0, 0.0], 0.308261)
 HalfSpace([-1.0, 0.0], -0.2)
 HalfSpace([0.0, 1.0], 0.1)
 HalfSpace([0.0, -1.0], 0.106045)
 HalfSpace([1.0, -0.0], 0.0)

julia> Polyhedra.removehredundancy!(P)

julia> P 
Polyhedron CDDLib.Polyhedron{Float64}:
3-element iterator of HyperPlane{Float64,Array{Float64,1}}:
 HyperPlane([-1.4, -1.0], 0.0)
 HyperPlane([1.0, 0.0], 0.308261)
 HyperPlane([-1.0, 0.0], -0.2)

i just plotted this in geogebra; the intersection is actually empty :)

screen shot 2019-01-20 at 18 14 57

indeed:

julia> Polyhedra.isempty(Polyhedra.intersect(p, q))
true

and

julia> Polyhedra.isempty(Polyhedra.intersect(p, v))
true

given this, i take back my assumption that removehredundancy! is buggy.

@mforets mforets closed this as completed Jan 20, 2019
@schillic
Copy link
Contributor

Is it not even worse if the removal of redundant constraints from an empty set results in a non-empty set?

@mforets mforets changed the title Removing redundancy results in unbounded intersection Removing constraints of empty polyhedron results in non-empty set Jan 21, 2019
@mforets
Copy link
Member Author

mforets commented Jan 21, 2019

@schillic true, i've reopened this issue with a different title to suggest that some action should be taken, either make it clear in removehredundancy! docs that the input polyhedron should not be empty, or revise the algorithm.

@mforets mforets reopened this Jan 21, 2019
@blegat blegat added the bug label Jan 21, 2019
@blegat
Copy link
Member

blegat commented Jan 21, 2019

Isn't the bug in CDD ?

@schillic
Copy link
Contributor

schillic commented Jan 21, 2019

Isn't the bug in CDD ?

The problem also occurs with the "default library". (EDIT: simplified the numbers)

for backend in [CDDLib.Library(), default_library(2, Float64)]
    p = polyhedron(hrep([HalfSpace([1.0, 0.0], 0.3),
                         HalfSpace([-1.0, 0.0], -0.2),
                         HalfSpace([0.0, 1.0], 0.1),
                         HalfSpace([0.0, -1.0], 0.1)]), backend)
    q = polyhedron(hrep([HalfSpace([-1.0, 0.0], 0.0),
                         HalfSpace([-0.7, -1.0], 0.0),
                         HalfSpace([0.7, 1.0], 0.0)]), backend)
    P = Polyhedra.intersect(p, q)
    Polyhedra.removehredundancy!(P)
    println(P)
end
HyperPlane([1.0, 0.0], 0.3)
  HyperPlane([-1.0, 0.0], -0.2)
  HyperPlane([0.0, 1.0], 0.1)

HyperPlane([0.7, 1.0], 0.0) : 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants