对于Django的网站,我用托马斯·芬利的GLPK Python库( http://tfinley.net/software/pyglpk/glpk.html#LPX )来解决整数线性规划。 我顺着他的教程(见“简单的例子” http://tfinley.net/software/pyglpk/discussion.html或在文章底部),以建立我的情况,但我的系统的更新后(和我假设,蟒蛇,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
之前,我试图(通过快速的一个我还没有发现有很多令人信服的东西看)重写我的代码与其他图书馆,有一个简单的解决这个? (例如,在这里使用的功能被重新命名为别的东西吗?)在此先感谢您的帮助。