Supply Chain Analytics in Python
Aaren Stubberfield
Supply Chain Analytics Mgr.
Context
Constraint-vraag
Voor elke eenheid B hebben we minimaal 3 eenheden A nodig
Veelgemaakte fout:
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)]
Voor elke eenheid B hebben we ook minimaal 3 eenheden A nodig en rekening houden met directe verkoop van A aan klanten.
Context
Constraint-vraag
Juiste vorm
Veelgemaakte fouten
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
Magazijn WH1 is klein en kan óf 12 A per week, 15 B per week, of 5 C per week verzenden. Welke combinaties van A, B of C kunnen in 4 weken worden verzonden?
Supply Chain Analytics in Python