mcmtroffaes / pycddlib

A Python wrapper for Komei Fukuda's cddlib.
http://packages.python.org/pycddlib/
GNU General Public License v2.0
61 stars 9 forks source link

get_generators() returning strange matrix in H-representation #60

Closed DanSJohnson closed 1 year ago

DanSJohnson commented 1 year ago

Hi everyone,

I'm encountering strange behaviour with pycddlib, I run the following code where I define a matrix in H-rep format:

import cdd

test_mat=[[0              ,  0,  0,  1],
          [5.587155425E-01,  0, -1,  0],
          [5.587155425E-01,  0,  1,  0],
          [5.587155425E-01, -1,  0,  0],
          [5.587155425E-01,  1,  0,  0]]

poly=cdd.Polyhedron(cdd.Matrix(test_mat))
print(poly.get_generators())
print(poly.get_inequalities())

And the result is:

H-representation
begin
 5 4 real
  1.789819548E+00  1  1  0
  1.789819548E+00  1 -1  0
  1.789819548E+00 -1 -1  0
  1.789819548E+00 -1  1  0
  0  0  0  1
end
H-representation
begin
 5 4 real
  1.789819548E+00  1  1  0
  1.789819548E+00  1 -1  0
  1.789819548E+00 -1 -1  0
  1.789819548E+00 -1  1  0
  0  0  0  1
end

Concerningly, poly.get_generators() is returning something in H-representation, and the H-representation returned (by both get_generators() and get_inequalities()) seems to be very different from the H-representation I first passed in. I don't understand why this is, am I doing something wrong?

I am using pycddlib version 2.1.6 installed via pip, my python version is 3.6.9 and my OS is Ubuntu 18.04.05 LTS.

I would be very grateful for any assistance!

mcmtroffaes commented 1 year ago

The matrix is not specified in H-rep format, in which case cddlib's behaviour is undefined. For your code, a quick fix is:

poly.rep_type = cdd.RepType.INEQUALITY

right after you create poly.

With this fix:

>>> print(poly.get_generators())
V-representation
begin
 5 4 real
  1  5.587155425E-01  5.587155425E-01  0
  1  5.587155425E-01 -5.587155425E-01  0
  1 -5.587155425E-01 -5.587155425E-01  0
  1 -5.587155425E-01  5.587155425E-01  0
  0  0  0  1
end
>>> print(poly.get_inequalities())
H-representation
begin
 5 4 real
  0  0  0  1
  5.587155425E-01  0 -1  0
  5.587155425E-01  0  1  0
  5.587155425E-01 -1  0  0
  5.587155425E-01  1  0  0
end
DanSJohnson commented 1 year ago

Thank you so much!