我希望你做得很好。
我目前正在自学 Python,但在使用 Pulp 时遇到了障碍。我正在努力解决模型。
解决此问题将不胜感激。
设想:
您正在为厨房烤箱制造商提供咨询,帮助他们规划下个月的物流。有两个仓库位置(纽约和亚特兰大)和四个区域客户位置(东部、南部、中西部、西部)。下个月东部的预期需求为 1,800,南部为 1,200,中西部为 1,100,西部为 1000。将每个仓库位置运送到区域客户的成本如下表所示. 您的目标是以最低的价格满足区域需求。
客户 纽约 亚特兰大 东 $211 $232 南 $232 $212 中西部 $240 $230 西 $300 $280
已经为您创建了两个 Python 字典 cost 和 var_dict,其中包含模型的成本和决策变量。
{('New York', 'East'): 211, ('New York', 'South'): 232, ('New York', 'Midwest'): 240, ('New York', 'West'): 300, ('Atlanta', 'East'): 232, ('Atlanta', 'South'): 212, ('Atlanta', 'Midwest'): 230, ('Atlanta', 'West'): 280}```
```print(var_dict)
{('New York', 'East'): ne, ('New York', 'South'): ns, ('New York', 'Midwest'): nm, ('New York', 'West'): nw, ('Atlanta', 'East'): atle, ('Atlanta', 'South'): atls, ('Atlanta', 'Midwest'): atlm, ('Atlanta', 'West'): atlw}```
My code that I ran thus far:
```from pulp import *
# Initialize Model
model = LpProblem("Minimize Transportation Costs", LpMinimize)
# Build the lists and the demand dictionary
warehouse = ['New York', 'Atlanta']
customers = ['East', 'South', 'Midwest', 'West']
regional_demand = [1800, 1200, 1100, 1000]
demand = dict(zip(customers, regional_demand))
# Define Objective
model += lpSum([costs[(w, c)] * var_dict[(w, c)]
for c in customers for w in warehouse])
# For each customer, sum warehouse shipments and set equal to customer demand
for c in customers:
model += lpSum([var_dict[(w, c)] for w in warehouse]) == demand[c]
model.solve()
print("Fulfill regional demand at {} price".format(costs[var_dict]))```