Supply Chain Analytics in Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
Context
Constraint Problem
For each unit of B, we must also have at least 3 units of A
Common Mistake:
from pulp import *
demand = {'A':[0,0,0],'B':[8,7,6]}
costs = {'A':[20,17,18],'B':[15,16,15]}
# Initialize Model
model = LpProblem("Aggregate Production Planning",
LpMinimize)
# Define Variables
time = [0, 1, 2]
prod = ['A', 'B']
X = LpVariable.dicts(
"prod", [(p, t) for p in prod for t in time],
lowBound=0, cat="Integer")
# Define Objective
model += lpSum([costs[p][t] * X[(p, t)]
for p in prod for t in time])
# Define Constraint So Production is >= Demand
for p in prod:
for t in time:
model += X[(p, t)] >= demand[p][t]
for t in time:
model += 3*X[('B',t)] <= X[('A',t)]
For each unit of B, we must also have at least 3 units of A and account for direct to customer sells of A.
Context
Constraint Problem
Correct Form
Common Mistakes
from pulp import *
import pandas as pd
demand = pd.read_csv("Warehouse_Constraint_Demand.csv", index_col=['Product'])
costs = pd.read_csv("Warehouse_Constraint_Cost.csv", index_col=['WH','Product'])
# Initialize Model
model = LpProblem("Distribution Planning", LpMinimize)
# Define Variables
wh = ['W1','W2']
prod = ['A', 'B']
cust = ['C1', 'C2', 'C3', 'C4']
X = LpVariable.dicts("ship", [(w, p, c) for c in cust for p in prod for w in wh],
lowBound=0, cat="Integer")
# Define Objective
model += lpSum([X[(w, p, c)]*costs.loc[(w, p), c]
for c in cust for p in prod for w in wh])
# Define Constraint So Demand Equals Total Shipments
for c in cust:
for p in prod:
model += lpSum([X[(w, p, c)] for w in wh]) == demand.loc[p, c]
Constraint
model += ((1/12) * lpSum([X['W1', 'A', c] for c in cust])
+ (1/15) * lpSum([X['W1', 'B', c] for c in cust])) <= 4
Warehouse WH1 is small and either ship 12 A products per a week, 15 B products per a week, or 5 C products per a week. What combinations of A, B, or C can be shipped in 4 weeks?
Supply Chain Analytics in Python