LpVariable の辞書関数

Pythonで学ぶサプライチェーン分析

Aaren Stubberfield

Supply Chain Analytics Mgr.

単純から複雑へ

複雑なベーカリーの例

# 意思決定変数の定義
A = LpVariable('A', lowBound=0, cat='Integer')
B = LpVariable('B', lowBound=0, cat='Integer')
C = LpVariable('C', lowBound=0, cat='Integer')
D = LpVariable('D', lowBound=0, cat='Integer')
E = LpVariable('E', lowBound=0, cat='Integer')
F = LpVariable('F', lowBound=0, cat='Integer')
# 目的関数の定義
var_dict = {"A":A, "B":B, "C":C, "D":D, "E":E, "F":F}

# 目的関数の定義
model += lpSum([profit_by_cake[type] * var_dict[type] for type in cake_types])
Pythonで学ぶサプライチェーン分析

LpVariable.dicts() を使う

LpVariable(name, indexs, lowBound=None, upBound=None, cat='Continuous')
  • name = 作成される各 LP 変数名の接頭辞
  • indexs = 変数辞書のキー(文字列)のリスト
  • lowBound = 下限
  • upBound = 上限
  • cat = 変数の型
    • Integer
    • Binary
    • Continuous (既定)
Pythonで学ぶサプライチェーン分析

リスト内包表記での LpVariable.dicts()

  • LpVariable.dicts() は Python のリスト内包表記とよく併用

輸送最適化

# 意思決定変数の定義
customers = ['East','South','Midwest','West']
warehouse = ['New York','Atlanta']
transport = LpVariable.dicts("route", [(w,c) for w in warehouse for c in customers],
                              lowBound=0, cat='Integer')

# 目的の定義 model += lpSum([cost[(w,c)]*transport[(w,c)] for w in warehouse for c in customers])
Pythonで学ぶサプライチェーン分析

まとめ

  • 複雑な問題で多くの LP 変数を作成
  • LpVariable.dicts()
  • リスト内包表記と併用
Pythonで学ぶサプライチェーン分析

さあ、やってみましょう

Pythonで学ぶサプライチェーン分析

Preparing Video For Download...