ฟังก์ชัน LpVariable dictionary

Supply Chain Analytics ด้วย Python

Aaren Stubberfield

Supply Chain Analytics Mgr.

จากปัญหาง่ายสู่ปัญหาซับซ้อน

ตัวอย่างร้านเบเกอรีที่ซับซ้อน

# Define Decision Variables
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')
# Define Objective Function
var_dict = {"A":A, "B":B, "C":C, "D":D, "E":E, "F":F}

# Define Objective Function
model += lpSum([profit_by_cake[type] * var_dict[type] for type in cake_types])
Supply Chain Analytics ด้วย Python

การใช้ LpVariable.dicts()

LpVariable(name, indexs, lowBound=None, upBound=None, cat='Continuous')
  • name = คำนำหน้าชื่อของตัวแปร LP แต่ละตัวที่สร้างขึ้น
  • indexs = รายการสตริงที่เป็น key ของ dictionary ของตัวแปร LP
  • lowBound = ขอบเขตล่าง
  • upBound = ขอบเขตบน
  • cat = ประเภทของตัวแปร
    • Integer
    • Binary
    • Continuous (ค่าเริ่มต้น)
Supply Chain Analytics ด้วย Python

LpVariable.dicts() กับ list comprehension

  • LpVariable.dicts() มักใช้ร่วมกับ list comprehension ของ Python

การเพิ่มประสิทธิภาพการขนส่ง

# Define Decision Variables
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')

# Define Objective model += lpSum([cost[(w,c)]*transport[(w,c)] for w in warehouse for c in customers])
Supply Chain Analytics ด้วย Python

สรุป

  • การสร้างตัวแปร LP จำนวนมากสำหรับปัญหาที่ซับซ้อน
  • LpVariable.dicts()
  • ใช้ร่วมกับ list comprehension
Supply Chain Analytics ด้วย Python

มาฝึกกันเถอะ!

Supply Chain Analytics ด้วย Python

Preparing Video For Download...