Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specifying tolerance for GLPK solver in PuLP Python

I am running PuLP Programming Library in Python 2.7.8, Windows 32 bit. I'm using GLPK as my solver for a mixed integer linear programming problem. The solver converges to approx. 1% of the optimal quickly, however time to compute the exact optimal solution is high. Is there a way to specify percent tolerance for GLPK solver using PuLP? I searched https://pythonhosted.org/PuLP/solvers.html but it doesn't give any answer for GLPK solver.

like image 634
Akhil Avatar asked Mar 19 '23 01:03

Akhil


1 Answers

If you run "glpsol" on the command line with "--help" you see the "--mipgap tol", where tol is the tolerance.

So, in PuLP, have you tried this:

 model.solve(GLPK(options=['--mipgap', '0.01']))

(from this discussion a while ago) (and notice how you can use this same method to pass in more arguments that you please).

Furthermore, I went into the source code ("solvers.py") and took a look at how GLPK expects its "options" arguments, and indeed it expects the arguments as above (look at line 345 or so in the file reproduced below):

 proc = ["glpsol", "--cpxlp", tmpLp, "-o", tmpSol]
 if not self.mip: proc.append('--nomip')
 proc.extend(self.options)

So you see that "proc" (the command which is run using Python's "subprocess" later) is "extended" with what you specify via "options" (incidentally stored in the variable self.options). So, it looks like the approach above (using '--mipgap' etc. in a list) is (still) correct.

Finally, I have not tried that myself, but I hope this helps.

like image 143
jesperk.eth Avatar answered Mar 23 '23 12:03

jesperk.eth