Python में सप्लाई चेन एनालिटिक्स
Aaren Stubberfield
Supply Chain Analytics Mgr.
अधिकतम वज़न 20,000 lbs
| Product | Weight (lbs) | Profitability ($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 lbs
| Product | Ship or Not |
|---|---|
| A | No |
| B | No |
| C | No |
| D | Yes |
| E | Yes |
| F | Yes |
परिणाम
या तो प्रोडक्ट 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 lbs
| Product | Ship or Not |
|---|---|
| A | No |
| B | No |
| C | Yes |
| D | Yes |
| E | No |
| F | Yes |
परिणाम
अगर प्रोडक्ट 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 lbs
| Product | Ship or Not |
|---|---|
| A | No |
| B | Yes |
| C | No |
| D | Yes |
| E | No |
| F | Yes |
परिणाम
| Logical Constraint | Constraint |
|---|---|
| अगर आइटम _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 |
Python में सप्लाई चेन एनालिटिक्स