我正在努力解决基于我们每周库存交付的最低每周制造人员水平。
import numpy as np
import pulp as p
inventory_delivery = np.array([200, 500, 0, 900, 0]) # deliveries over 5 weeks
productivity = 1 # using 1 to keep it simple for now. This varies week by week.
prob = p.LpProblem('Decision', p.LpMinimize)
a = list()
for x in inventory_delivery:
a.append(p.LpVariable(f'a{len(a)}', 0, None))
# objective
output = sum(a * productivity for a in a) # number of workers * weekly productivity
prob += output
# constraints
prob += output == sum(inventory_delivery) # Need total output by the end to equal total deliveries
#### How do I add a constraint that says my weekly output cannot exceed the inventory I have on hand in a given week?
#### (i.e., Cumulative Inventory - Cumulative Output >= 0 every week)
status = prob.solve()
print(p.LpStatus[status])
print("Objective value:", p.value(prob.objective))
print ('\nThe values of the variables : \n')
for v in prob.variables():
print(v.name, "=", v.varValue)
现在,它通过在a0中前置人员来解决,当我希望它基于我的库存分布在所有5周的时候。
当前产量:
Optimal
Objective value: 1600.0
The values of the variables :
a0 = 1600.0
a1 = 0.0
a2 = 0.0
a3 = 0.0
a4 = 0.0
**编辑:**忘记提到a
的人员编制只能保持不变或逐周增加,绝不能减少。因此,我正在努力解决这5周内员工总数最低的问题。
1条答案
按热度按时间kokeuurv1#
稍微读一下字里行间,我认为下面就是你正在寻找的东西。以下几个关键概念将对您有所帮助:
staff_level
的类别更改为整数,这会使模型变慢一些,但在这个小模型中没有什么明显的东西。numpy
。它只会使事情变得更加复杂,并且不会在这些类型的模型中增加任何加速。代码:
(部分)输出: