'太多价值无法解包'-纸浆/蟒蛇皮

时间:2019-06-15 21:53:25

标签: python pulp

我正在尝试使用纸浆库执行混合整数优化程序。我不断收到“要解压的值太多”错误,但我知道我的代码是正确的。

我几次调整值都没有成功。

#Model in Python
from pulp import*

prob = LpProblem('Toys-R-4-U', LpMaximize)

x1 = LpVariable('Units of toy 1', lowBound = 0)
x2 = LpVariable('Units of toy 2', lowBound = 0)
y1 = LpVariable('Toy 1 decision: 1-y, 0-n', lowBound = 0, upBound = 1, cat      = "Integer")
y2 = LpVariable('Toy 2 decision: 1-y, 0-n', lowBound = 0, upBound = 1, cat   = "Integer")
y3 = LpVariable('Factor Decision: 1-1, 0-2', lowBound = 0, upBound = 1, cat = "Integer")
M = 100000

#Objective F(x)
prob += 10*x1 + 15*x2 - 50000*y1 - 80000*y2, "Z"

#Contraints
prob += 0.02*x1 + 0.025*x2 <= 500 + M*y3
prob += 0.025*x1 + 0.04*x2 <= 700 + M*(1-y3)
prob += x1 <= M*y1
prob += x2 <= M*y2
prob += y1 + y2 <= 2
prob += x1, x2 >= 0 
prob += y1, y2, y3 == 0, 1

print(prob)

prob.solve()
print("status: " + LpStatus[prob.status])

for variable in prob.variables():
    print("{}* = {}".format(variable.name, variable.varValue))

print("Z* = ",value(prob.objective))

我应该得到一个“最佳解决方案”,但是我却得到“解开太多值(决策2)”。

0 个答案:

没有答案