JuliaPolyhedra / Polyhedra.jl

Polyhedral Computation Interface
Other
172 stars 27 forks source link

It eliminated the incorrect variable, didn't it? #338

Closed WuSiren closed 5 months ago

WuSiren commented 5 months ago
using JuMP, Polyhedra, CDDLib
m = Model()
@variable(m, d[1:2])
@variable(m, 0 <= g[1:2] <= 1)
@constraint(m, d[1] == 1 + 100g[1])
@constraint(m, d[2] == 2 + 100g[2])
all_variables(m) # To check the dimension names.
p = polyhedron(m, CDDLib.Library(:exact))
P = eliminate(p, [3:4;])
[1, 2] in P, [0, 0] in P

The result is (false, true), which indicates the projection polyhedron is with respect to the eliminated variable g[1:2] but not the expected d[1:2].

Is this a bug, or I didn't use it correctly?

Looking forward to response. Thanks!

schillic commented 5 months ago

Let me add some more information.

This is the variable order:

julia> all_variables(m)
4-element Vector{VariableRef}:
 d[1]
 d[2]
 g[1]
 g[2]

The result P is

Polyhedron CDDLib.Polyhedron{Rational{BigInt}}:
4-element iterator of HalfSpace{Rational{BigInt}, Vector{Rational{BigInt}}}:
 HalfSpace(Rational{BigInt}[-1, 0], 0//1)
 HalfSpace(Rational{BigInt}[0, -1], 0//1)
 HalfSpace(Rational{BigInt}[1, 0], 1//1)
 HalfSpace(Rational{BigInt}[0, 1], 1//1)

which is $0 \le x_1 \le 1 \land 0 \le x_2 \le 1$.

And for completeness, here is the other projection:

julia> P = eliminate(p, [1:2;])
Polyhedron CDDLib.Polyhedron{Rational{BigInt}}:
4-element iterator of HalfSpace{Rational{BigInt}, Vector{Rational{BigInt}}}:
 HalfSpace(Rational{BigInt}[-1, 0], -1//1)
 HalfSpace(Rational{BigInt}[0, -1], -2//1)
 HalfSpace(Rational{BigInt}[1, 0], 101//1)
 HalfSpace(Rational{BigInt}[0, 1], 102//1)

which is $1 \le x_1 \le 101 \land 2 \le x_2 \le 102$.

WuSiren commented 5 months ago

Yes, thanks. But it behaves oppositely to the example here, doesn't it?

WuSiren commented 5 months ago

Pardon me, is there any change? I retested the above example, why didn't I see any changes?

schillic commented 5 months ago

@WuSiren there is not yet a new release of this package. For now you can use the development version via the dev command:

pkg> dev Polyhedra
WuSiren commented 5 months ago

Oh, I see. Many thanks! 🤝