0-8

Model Building in Mathematical Programming: 12.19 Distribution 1

Optimization NightH. Paul Williams, Model Building in Mathematical Programming, 5th Edition, Wiley, 2013. の輪読会をしているので、そのメモです。

宿題

12.19 Distribution 1

5章でLPとネットワークの関係について学んだので、その典型的な応用である配送問題。

問題文の解釈に困るところがあったけど、まぁ典型的な問題だった。制約をちょっと緩めた時の目的関数の値の変化が、ちゃんと shadow price と呼ばれる量 (pulp だと、制約式の pi 属性) と対応していることを確かめたりした。

あと、わりとどうでもいい気もするけど、pd.DataFrame.applymap を使って制約を一挙に追加する術を身につけた。pulpの変数を値に持つDataFrameを作ってやって、下記のような感じで制約を追加していく。

df.applymap(lambda x: problem.addConstraint(x == 0))

また、applymapの戻り値はDataFrameなので、これを使って結果を表示するととてもわかりやすい。

f:id:ohtaman:20200701175753p:plain

僕の答案は以下のリンクの通り(輪読会のあとでやった)

colab.research.google.com