Supply Chain Analytics ด้วย Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
PuLP คือ framework สำหรับสร้างโมเดล Linear Programming (LP) และ Integer Programming (IP) ใน Python
ดูแลโดย COIN-OR Foundation (Computational Infrastructure for Operations Research)
PuLP เชื่อมต่อกับ Solver ต่าง ๆ
CPLEXCOINGurobi| เค้ก A | เค้ก B | |
|---|---|---|
| เตาอบ | 0.5 วัน | 1 วัน |
| เบเกอร์ | 1 วัน | 2.5 วัน |
| พนักงานแพ็ค | 1 วัน | 2 วัน |
.
| เค้ก A | เค้ก B | |
|---|---|---|
| กำไร | $20.00 | $40.00 |
LpProblem(name='NoName', sense=LpMinimize)
name = ชื่อของปัญหาที่ใช้ในไฟล์ .lp ที่ส่งออก เช่น "My LP Problem"sense = กำหนดว่าจะ Maximize หรือ Minimize ฟังก์ชันวัตถุประสงค์LpMinimize (ค่าเริ่มต้น)LpMaximizefrom pulp import *
# Initialize Class
model = LpProblem("Maximize Bakery Profits", LpMaximize)
LpVariable(name, lowBound=None, upBound=None, cat='Continuous', e=None)
name = ชื่อตัวแปรที่ใช้ในไฟล์ .lp ที่ส่งออกlowBound = ขอบเขตล่างupBound = ขอบเขตบนcat = ประเภทของตัวแปรe = ใช้สำหรับการสร้างโมเดลแบบ column-based# Define Decision Variables
A = LpVariable('A', lowBound=0, cat='Integer')
B = LpVariable('B', lowBound=0, cat='Integer')
# Define Objective Function
model += 20 * A + 40 * B
# Define Constraints
model += 0.5 * A + 1 * B <= 30
model += 1 * A + 2.5 * B <= 60
model += 1 * A + 2 * B <= 22
# Solve Model
model.solve()
print("Produce {} Cake A".format(A.varValue))
print("Produce {} Cake B".format(B.varValue))
from pulp import *
# Initialize Class
model = LpProblem("Maximize Bakery Profits",
LpMaximize)
# Define Decision Variables
A = LpVariable('A', lowBound=0,
cat='Integer')
B = LpVariable('B', lowBound=0,
cat='Integer')
# Define Objective Function
model += 20 * A + 40 * B
# Define Constraints
model += 0.5 * A + 1 * B <= 30
model += 1 * A + 2.5 * B <= 60
model += 1 * A + 2 * B <= 22
# Solve Model
model.solve()
print("Produce {} Cake A".format(A.varValue))
print("Produce {} Cake B".format(B.varValue))
ทบทวน 5 ขั้นตอนของกระบวนการสร้างโมเดลด้วย PuLP
ฝึกตัวอย่างการจัดสรรทรัพยากรเสร็จสมบูรณ์
Supply Chain Analytics ด้วย Python