Supply Chain Analytics ด้วย Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
น้ำหนักสูงสุด 20,000 ปอนด์
| สินค้า | น้ำหนัก (ปอนด์) | กำไร ($US) |
|---|---|---|
| A | 12,800 | 77,878 |
| B | 10,900 | 82,713 |
| C | 11,400 | 82,728 |
| D | 2,100 | 68,423 |
| E | 11,300 | 84,119 |
| F | 2,300 | 77,765 |
prod = ['A', 'B', 'C', 'D', 'E', 'F'] weight = {'A':12800, 'B':10900, 'C':11400, 'D':2100, 'E':11300, 'F':2300} prof = {'A':77878, 'B':82713, 'C':82728, 'D':68423, 'E':84119, 'F':77765}# Initialize Class model = LpProblem("Loading Truck Problem", LpMaximize) # Define Decision Variables x = LpVariable.dicts('ship_', prod, cat='Binary')# Define Objective model += lpSum([prof[i]*x[i] for i in prod]) # Define Constraint model += lpSum([weight[i]*x[i] for i in prod]) <= 20000# Solve Model model.solve() for i in prod: print("{} status {}".format(i, x[i].varValue))
น้ำหนักสูงสุด 20,000 ปอนด์
| สินค้า | ส่งหรือไม่ |
|---|---|
| A | ไม่ |
| B | ไม่ |
| C | ไม่ |
| D | ใช่ |
| E | ใช่ |
| F | ใช่ |
ผลลัพธ์
เลือกสินค้า E หรือสินค้า D ได้เพียงอย่างเดียวเท่านั้น
model += x['E'] + x['D'] <= 1
prod = ['A', 'B', 'C', 'D', 'E', 'F']
weight = {'A':12800, 'B':10900, 'C':11400,
'D':2100, 'E':11300, 'F':2300}
prof = {'A':77878, 'B':82713, 'C':82728,
'D':68423, 'E':84119, 'F':77765}
# Initialize Class
model = LpProblem("Loading Truck Problem",
LpMaximize)
# Define Decision Variables
x = LpVariable.dicts('ship_', prod,
cat='Binary')
# Define Objective
model += lpSum([prof[i]*x[i] for i in prod])
# Define Constraint
model +=
lpSum([weight[i]*x[i] for i in prod]) <= 20000
model += x['E'] + x['D'] <= 1
# Solve Model
model.solve()
for i in prod:
print("{} status {}".format(i, x[i].varValue))
น้ำหนักสูงสุด 20,000 ปอนด์
| สินค้า | ส่งหรือไม่ |
|---|---|
| A | ไม่ |
| B | ไม่ |
| C | ใช่ |
| D | ใช่ |
| E | ไม่ |
| F | ใช่ |
ผลลัพธ์
ถ้าเลือกสินค้า D ต้องเลือกสินค้า B ด้วย
model += x['D'] <= x['B']prod = ['A', 'B', 'C', 'D', 'E', 'F'] weight = {'A':12800, 'B':10900, 'C':11400, 'D':2100, 'E':11300, 'F':2300} prof = {'A':77878, 'B':82713, 'C':82728, 'D':68423, 'E':84119, 'F':77765} # Initialize Class model = LpProblem("Loading Truck Problem", LpMaximize) # Define Decision Variables x = LpVariable.dicts('ship_', prod, cat='Binary')
# Define Objective
model += lpSum([prof[i]*x[i] for i in prod])
# Define Constraint
model +=
lpSum([weight[i]*x[i] for i in prod]) <= 20000
model += x['D'] <= x['B']
# Solve Model
model.solve()
for i in prod:
print("{} status {}".format(i, x[i].varValue))
น้ำหนักสูงสุด 20,000 ปอนด์
| สินค้า | ส่งหรือไม่ |
|---|---|
| A | ไม่ |
| B | ใช่ |
| C | ไม่ |
| D | ใช่ |
| E | ไม่ |
| F | ใช่ |
ผลลัพธ์
| ข้อจำกัดเชิงตรรกะ | ข้อจำกัด |
|---|---|
| ถ้าเลือกรายการ _i_ แล้วต้องเลือกรายการ _j_ ด้วย | x$_{i}$ - x$_{j}$ ≤ 0 |
| เลือกรายการ _i_ หรือรายการ _j_ ได้เพียงอย่างเดียว | x$_{i}$ + x$_{j}$ = 1 |
| ถ้าเลือกรายการ _i_ แล้วต้องไม่เลือกรายการ _j_ | x$_{i}$ - x$_{j}$ ≤ 1 |
| ถ้าไม่เลือกรายการ _i_ แล้วต้องไม่เลือกรายการ _j_ | -x$_{i}$ + x$_{j}$ ≤ 0 |
| เลือกได้อย่างมากหนึ่งรายการจาก _i_, _j_ และ _k_ | x$_{i}$ + x$_{j}$ + x$_{k}$ ≤ 1 |
Supply Chain Analytics ด้วย Python