Supply Chain Analytics in Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
Maximum Weight 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))
Maximum Weight 20,000 lbs
Product | Ship or Not |
---|---|
A | No |
B | No |
C | No |
D | Yes |
E | Yes |
F | Yes |
Result
Either product E is selected or product D is selected, but not both.
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))
Maximum Weight 20,000 lbs
Product | Ship or Not |
---|---|
A | No |
B | No |
C | Yes |
D | Yes |
E | No |
F | Yes |
Result
If product D is selected then product B must also be selected.
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))
Maximum Weight 20,000 lbs
Product | Ship or Not |
---|---|
A | No |
B | Yes |
C | No |
D | Yes |
E | No |
F | Yes |
Result
Logical Constraint | Constraint |
---|---|
If item _i_ is selected, then item _j_ is also selected. | x$_{i}$ - x$_{j}$ ≤ 0 |
Either item _i_ is selected or item _j_ is selected, but not both. | x$_{i}$ + x$_{j}$ = 1 |
If item _i_ is selected, then item _j_ is not selected. | x$_{i}$ - x$_{j}$ ≤ 1 |
If item _i_ is not selected, then item _j_ is not selected. | -x$_{i}$ + x$_{j}$ ≤ 0 |
At most one of items _i_, _j_, and _k_ are selected. | x$_{i}$ + x$_{j}$ + x$_{k}$ ≤ 1 |
Supply Chain Analytics in Python