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

Floating point representation for value 0 and 1 #64

Closed JacksonZyy closed 1 year ago

JacksonZyy commented 1 year ago

Hi,

I am using your newest version of pycddlib, thank you for the detailed documentation! I have some problems with value representation.

inequs = finalPoly.get_inequalities()
print(inequs)

I use the code above to check H representation, and the printout is as follows:

begin
 6 3 real
  5.920433079E+01  0 -1
  1.199483299E+02  1  1
  7.008025541E+01  1  0
  8.403677732E+01  1 -1
  0 -1  1
  8.841803167E+01 -1 -1
end

However, when I try to access H representation line by line as the code shown below,

for j in range(length):
    row = inequs.__getitem__(j)
    print(row)

The printout is as follows, where the pervious coefficient 0 is a very small value but not 0; and coefficient 1/-1 is a value extremely close but not exactly the same:

(59.20433078483063, 1.3194420136845506e-15, -1.0)
(119.94832982507154, 1.0, 0.9999999999999983)
(70.08025540756066, 1.0, 2.2265483112176617e-16)
(84.0367773107571, 1.0, -1.0000000000000009)
(-2.6156447839923854e-14, -1.0, 1.0000000000000007)
(88.41803166348132, -1.0, -0.9999999999999964)

Could you please kindly assist me in obtaining value 0/-1/1 instead of those floating point representations that introduces error? Thank you so much!

mcmtroffaes commented 1 year ago

Use the "fraction" number representation; there are some examples here: https://pycddlib.readthedocs.io/en/latest/polyhedron.html

I hope this helps!

JacksonZyy commented 1 year ago

Yes, 'fraction' works, thank you!!