果汁生産における影価格
ある企業が、2台の機械 \(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 トンまでしか受け取りません。これらは上限(upper bounds)です。
pulp はすでにインポート済みで、model と、グレープフルーツジュースとオレンジジュースを表す変数 g と o も定義されています。
この演習はコースの一部です
Pythonで学ぶOptimization入門
演習の手順
- 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.")