So a while back I had asked this question: Is there a Linear Programming Library that natively supports fractions instead of floating point arithmetic?
And basically the overwhelming consensus was that the best libraries for exact linear programming were:
and there were a few others. So I wanted libraries that are nicely compatible with python3 on a mac os.
I started with QSOPT-Exact, which I installed via the two links below
This library has worked well for me in the past but today it seems like it has a segfault (this might be due to Mac OS) which I raised as an issue here: https://github.com/jonls/python-qsoptex/issues/8
Now the next option was GLPK and I was able get GLPK working with python3 by installing
brew install glpk
python3 -m pip install PuLP
But while GLPK can be called via the exact flag it does not output rationals but rather a floating point representation of the exact result. See here:
And heres the code:
from fractions import Fraction prob = pulp.LpProblem("sidsproblem", pulp.LpMaximize) x1 = pulp.LpVariable("x_1",0,1) x2 = pulp.LpVariable("x_2",0,1) prob += x1 + x2 prob += (5*x1 + 4*x2 <= 1) prob += (4*x1 - 11*x2 <= -1) prob += (x1 <= 0.23) prob += (x2 <= Fraction(2,9)) prob.writeLP("sidsproblem2.lp") prob.solve(pulp.GLPK(options=['--exact'])) for v in prob.variables(): print(v.name, "=", v.varValue)
So clearly GLPK is doing exact arithmetic but the interface which talks to python3 hands python3 a float as opposed to a rational. Which defeats the point on my end.
Which now makes me wonder, what high quality WORKING implementations of exact linear programming libraries exist for python3? It seems like the options are few and limited now and I wanted to know what any of you have successfully used in the past year.