For a Django website, I used Thomas Finley's glpk Python library (http://tfinley.net/software/pyglpk/glpk.html#LPX) to solve an integer linear program. I followed his tutorial (see "simple example" in http://tfinley.net/software/pyglpk/discussion.html or at the bottom of the post) to build my instance, but after an update of my system (and, I assume, of python-glpk) I now get this error:
----> 1 lp = glpk.LPX()
AttributeError: 'module' object has no attribute 'LPX'
If you want to reproduce the error, you can use his example which I paste here (the error should happen as soon as the second line):
import glpk # Import the GLPK module
lp = glpk.LPX() # Create empty problem instance
lp.name = 'sample' # Assign symbolic name to problem
lp.obj.maximize = True # Set this as a maximization problem
lp.rows.add(3) # Append three rows to this instance
for r in lp.rows: # Iterate over all rows
r.name = chr(ord('p')+r.index) # Name them p, q, and r
lp.rows[0].bounds = None, 100.0 # Set bound -inf < p <= 100
lp.rows[1].bounds = None, 600.0 # Set bound -inf < q <= 600
lp.rows[2].bounds = None, 300.0 # Set bound -inf < r <= 300
lp.cols.add(3) # Append three columns to this instance
for c in lp.cols: # Iterate over all columns
c.name = 'x%d' % c.index # Name them x0, x1, and x2
c.bounds = 0.0, None # Set bound 0 <= xi < inf
lp.obj[:] = [ 10.0, 6.0, 4.0 ] # Set objective coefficients
lp.matrix = [ 1.0, 1.0, 1.0, # Set nonzero entries of the
10.0, 4.0, 5.0, # constraint matrix. (In this
2.0, 2.0, 6.0 ] # case, all are non-zero.)
lp.simplex() # Solve this LP with the simplex method
Before I attempt rewriting my code with another library (and by looking quickly for one I have not found a lot of convincing stuff), is there a simple fix to this? (e.g, have the functions used here been renamed to something else?) Thanks in advance for your help.
from glpk import glpk?help()function on objects to get more information about these. Try looking for LPX by usinghelp(glpk)andhelpon its attributes.print glpk.LPX()gave me<glpk.LPX 0-by-0 at 0xb728802c>. Is it possible that you have your own program calledglpk.pywhich is the one being imported?print glpk.__file__to check.