果汁生產的陰影價格
一家公司使用兩台機器 \(M_1\) 和 \(M_2\) 將葡萄柚汁($g$)與柳橙汁($o$)灌裝入瓶。目標是在以下限制式下最大化利潤:
M1:\(6g + 5.5o \leq 40\) 以及 M2:\(3g + 2.5o \leq 20\)
這些限制式反映機器的生產力與可用時數。例如,M1 每週可用 40 小時,灌裝 1 噸葡萄柚汁需要 6 小時,灌裝 1 噸柳橙汁需要 5.5 小時。
另外還有供應量限制:公司每週最多只收到 6 噸葡萄柚,以及 12 噸柳橙。這些是上界。
pulp 已為你匯入,model 也已定義,並設定了變數 g 與 o 代表葡萄柚汁與柳橙汁。
本練習屬於課程
Python 最佳化入門
練習說明
- 完成 for 迴圈,加入檢查陰影價格是否為正的判斷。
- 輸入在放寬限制式時,衡量目標函式邊際增幅的變數。
- 輸入衡量限制式鬆緊程度的變數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
print(LpStatus[model.status])
print(f'The optimal amount of {g.name} embottled is: {g.varValue:.2f} tons')
print(f'The optimal amount of {o.name} embottled is: {o.varValue:.2f} tons')
for name, c in model.constraints.items():
# Check if shadow value is positive
if c.____ > 0:
# Enter the variable that measures marginal increase in objective when constraint is relaxed
print(f"Increasing the capacity of {name} by one unit would increase profit by {c.____} units.")
else:
# Enter the variable that measures how tight the constraint is
print(f"{name} has {c.____} units of unused capacity.")