物流規劃問題 2
你再次為一家廚房烤箱製造商提供顧問服務,協助規劃物流。這次你要擬定未來 6 個月(1–6 月)的計畫。仍有兩個倉庫據點(New York 與 Atlanta),以及四個區域客戶地點(East、South、Midwest、West)。各倉庫運送到各區域客戶的運費如下表所示。你的目標是決定每個倉庫在各月份對各客戶的出貨量,使總成本最低。
| Customer | New York | Atlanta |
|---|---|---|
| East | $211 | $232 |
| South | $232 | $212 |
| Midwest | $240 | $230 |
| West | $300 | $280 |
系統已為你建立一個名為 costs 的 Python 字典,包含模型的成本,另外也提供三個清單 months、warehouse、customers。costs 已經為你印出,你也可以在主控台中查看這些清單。此外,模型也已替你初始化完成。
本練習屬於課程
Python 的供應鏈分析
練習說明
- 先用列表推導式遍歷
months、warehouse、customers清單,建立鍵值組合的清單,並用該清單搭配LpVariable.dicts()來定義模型中的決策變數。 - 定義目標函式:將 6 個月份中,來自各倉庫運往各客戶的所有運輸成本加總。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define decision variables
key = [(m, w, ____) for m in months for w in warehouse for c in customers]
var_dict = LpVariable.dicts('num_of_shipments',
key,
lowBound=____, cat=____)
# Use the LpVariable dictionary variable to define objective
model += lpSum([costs[(w, c)] * ____[(____, ____, ____)]
for m in months for w in warehouse for c in customers])