我試圖用Python紙漿下列公式AttributeError是什麼:'LpElement'對象沒有屬性'cat',爲什麼會產生這個錯誤?
我寫了下面的Python代碼
prob = LpProblem('Resource', LpMaximize)
# x variables
xs = [LpVariable("x{0}{1}{2}".format(i + 1, j + 1, k + 1), cat = "Binary")
for i in range(0, 3)
for j in range(0, 5)
for k in range(0, 2)
]
print("\nX Variable\n")
for i in range(0, len(xs)):
print(xs[i])
# y variables
ys = [LpVariable("y{0}{1}".format(i + 1, j + 1), cat = "Binary")
for i in range(0, 3)
for j in range(0, 5)
]
print("\nY Variable\n")
for i in range(0, len(ys)):
print(ys[i])
for j in range(0, 5):
for k in range(0, 2):
for i in range(0, 3):
con = "x{0}{1}{2} <= y{3}{4}".format(i + 1, j + 1, k + 1, i + 1, j + 1)
prob += LpAffineExpression(LpElement(con))
print(con)
status = prob.solve()
這給跟隨漿誤差模型:
Traceback (most recent call last): File "C:\Python34\Cloud 3.py", line 446, in resource(request, pmachine, l, q) File "C:\Python34\Cloud 3.py", line 136, in resource status = prob.solve() File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\pulp.py", line 1643, in solve status = solver.actualSolve(self, **kwargs) File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\solvers.py", line 1303, in actualSolve return self.solve_CBC(lp, **kwargs) File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\solvers.py", line 1325, in solve_CBC tmpMps, rename = 1) File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\pulp.py", line 1431, in writeMPS if mip and v.cat == LpInteger: AttributeError: 'LpElement' object has no attribute 'cat'
AttributeError: 'LpElement' object has no attribute 'cat'
是什麼以及爲什麼產生這個錯誤?