对于Django网站,我使用了Thomas Finley的glpk Python库(http://tfinley.net/software/pyglpk/glpk.html#LPX)来解决整数线性程序。我按照他的教程(参见http://tfinley.net/software/pyglpk/discussion.html或帖子底部的“简单示例”)来构建我的实例,但是在我的系统更新之后(我假设是python-glpk)我现在得到了这个错误:
----> 1 lp = glpk.LPX()
AttributeError: 'module' object has no attribute 'LPX'
如果你想重现错误,你可以使用我在这里粘贴的例子(错误应该在第二行发生):
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
在我尝试用另一个库重写我的代码之前(通过快速查找一个我没有找到很多令人信服的东西),有一个简单的解决方法吗? (例如,将此处使用的功能重命名为其他功能吗?) 在此先感谢您的帮助。
答案 0 :(得分:2)
已弃用的&#34; LPX api&#34; (在最近版本的glpk中删除了以&#39; lpx&#39;开头的函数和常量)。 python绑定也需要更新。