# Computing polyhedron from MIP

I want to run the following code (I'm using SAGE v6.10 release version 2015-12-18):

P = MixedIntegerLinearProgram()
x = P.new_variable()
A = random_matrix(RR, 3, 2);
P.polyhedron()


However, it outputs the error message:

AttributeError: type object 'float' has no attribute 'fraction_field'

I noticed that if instead of using real variables I use only integer variables, then it works fine. For instance:

P = MixedIntegerLinearProgram()
x = P.new_variable()
A = random_matrix(ZZ, 3, 2);
P.polyhedron()


outputs:

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex and 2 rays

What do you suggest to overcome this problem?

Thanks

edit retag close merge delete

About 2 years ago (not sure which version of Sage that was), the polyhedron worked. But, it appears to be an issue now.

1

It is fixed in 8.0

sage: P = MixedIntegerLinearProgram()
sage: x = P.new_variable()
sage: A = random_matrix(ZZ, 3, 2);
sage: P.polyhedron()
A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 3 vertices


Sort by » oldest newest most voted

A workaround ould be the following. Thanks to linearity, you can:

• approximate all the real numbers by closest rational, for example QQ(1.2) results in 6/5
• find a common denominator of each entry (using the gcd function an the denominator method for rational numbers)
• make an integer program out of this
• construct the polyhedron as wanted
• rescale the polyhedron : if P is a polyhedron and q is an integer, the fraction P/q is well defined in Sage and will result into a rescaled polyhedron.

EDIT: note that with recent versions of Sage the polyhedron method works again for floating-point linear programs:

sage: P = MixedIntegerLinearProgram()
....: x = P.new_variable()
....: A = random_matrix(RR, 3, 2);
....: P.polyhedron()
....:
A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 2 vertices and 2 rays

more