问题描述
对于Django网站,我使用了Thomas Finley的glpk Python库( http://tfinley .net/software/pyglpk/glpk.html#LPX )来求解整数线性程序.我遵循了他的教程(请参见 http://tfinley.net/software/pyglpk/中的简单示例" Discussion.html 或位于文章底部)来构建我的实例,但是在更新了系统(并假设是python-glpk)之后,我现在得到此错误:
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.
推荐答案
在最近的glpk版本中,已弃用的"LPX api"(以'lpx'开头的函数和常量)已被删除. python绑定也需要更新.
The deprecated "LPX api" (functions and constants starting with 'lpx') was removed in a recent version of glpk. The python bindings need to be updated too.
这篇关于Python中的线性编程:“模块"对象没有属性"LPX"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!