Supply Chain Analytics in Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
Maximaal gewicht 20.000 lb
| Product | Gewicht (lb) | Winst ($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))
Maximaal gewicht 20.000 lb
| Product | Verzenden of niet |
|---|---|
| A | Nee |
| B | Nee |
| C | Nee |
| D | Ja |
| E | Ja |
| F | Ja |
Resultaat
Of product E wordt gekozen of product D, maar niet allebei.
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))
Maximaal gewicht 20.000 lb
| Product | Verzenden of niet |
|---|---|
| A | Nee |
| B | Nee |
| C | Ja |
| D | Ja |
| E | Nee |
| F | Ja |
Resultaat
Als product D is gekozen, moet product B ook worden gekozen.
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))
Maximaal gewicht 20.000 lb
| Product | Verzenden of niet |
|---|---|
| A | Nee |
| B | Ja |
| C | Nee |
| D | Ja |
| E | Nee |
| F | Ja |
Resultaat
| Logische restrictie | Restrictie |
|---|---|
| Als item _i_ is gekozen, wordt item _j_ ook gekozen. | x$_{i}$ - x$_{j}$ ≤ 0 |
| Of item _i_ of item _j_ wordt gekozen, maar niet allebei. | x$_{i}$ + x$_{j}$ = 1 |
| Als item _i_ is gekozen, wordt item _j_ niet gekozen. | x$_{i}$ - x$_{j}$ ≤ 1 |
| Als item _i_ niet is gekozen, wordt item _j_ niet gekozen. | -x$_{i}$ + x$_{j}$ ≤ 0 |
| Uiterlijk één van items _i_, _j_ en _k_ wordt gekozen. | x$_{i}$ + x$_{j}$ + x$_{k}$ ≤ 1 |
Supply Chain Analytics in Python