-2
我跟着python PLUP的tutorial,但得到了不同的結果。 而不是python PLUP意外的結果
Optimal weekly number of soldiers to produce: 20
Optimal weekly number of trains to produce: 60
我:
Optimal weekly number of soldiers to produce: 0
Optimal weekly number of trains to produce: 0
但休息是相同的......如果你想知道,是什麼;是代碼(幾乎複製和粘貼):
prob = pulp.LpProblem('Giapetto', pulp.LpMinimize)
soldiers = pulp.LpVariable('soldiers', lowBound=0, cat='Integer')
trains = pulp.LpVariable('trains', lowBound=0, cat='Integer')
raw_material_costs = 10 * soldiers + 9 * trains
variable_costs = 14 * soldiers + 10 * trains
revenues = 27 * soldiers + 21 * trains
profit = revenues - (raw_material_costs + variable_costs)
prob += profit
carpentry_hours = soldiers + trains
prob += (carpentry_hours <= 80)
finishing_hours = 2*soldiers + trains
prob += (finishing_hours <= 100)
prob += (soldiers <= 40)
print(prob)
optimization_result = prob.solve()
assert optimization_result == pulp.LpStatusOptimal
for var in (soldiers, trains):
print('Optimal weekly number of {} to produce: {:1.0f}'.format(var.name, var.value()))
有什麼不對嗎?
對我來說,就像你告訴它最大限度地減少利潤,它已經成功地將利潤最小化。 – user2357112