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 = 作為 LP 變數字典鍵的字串清單
  • lowBound = 下界
  • upBound = 上界
  • cat = 變數型別
    • Integer
    • Binary
    • Continuous (default)
Python 的供應鏈分析

結合 list comprehension 的 LpVariable.dicts()

  • LpVariable.dicts() 常與 Python 的 list comprehension 一起使用

運輸最佳化

# 定義決策變數
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()
  • 搭配 list comprehension 使用
Python 的供應鏈分析

換你來試試看

Python 的供應鏈分析

Preparing Video For Download...