Common constraint mistakes

Supply Chain Analytics in Python

Aaren Stubberfield

Supply Chain Analytics Mgr.

Dependent demand constraint

Context

  • Production Plan
  • Planning for 2 products (A, and B)
  • Planning for production over 3 months (Jan - Mar)
  • Product A is used as an input for production of product B

Constraint Problem

  • For each unit of B, we must also have at least 3 units of A
Supply Chain Analytics in Python

Dependent demand constraint

For each unit of B, we must also have at least 3 units of A

  • 3B ≤ A
  • 3(2) ≤ A
  • 6 ≤ A

Common Mistake:

  • B ≤ 3A
  • 3B = A
Supply Chain Analytics in Python

Code example

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]

Supply Chain Analytics in Python

Code example continued

for t in time:
    model += 3*X[('B',t)] <= X[('A',t)]
Supply Chain Analytics in Python

Extended constraint

For each unit of B, we must also have at least 3 units of A and account for direct to customer sells of A.

  • 3B + Demand$_{\text{A}}$ ≤ A
Supply Chain Analytics in Python

Combination constraint

Context

  • Warehouse distribution plan
  • 2 warehouses (WH1, and WH2)
  • We ship 2 products (A, and B) from each warehouse
  • Warehouse WH1 is small and can either ship 12 A products per a week or 15 B products per a week

Constraint Problem

  • What combinations of A, or B can be shipped in 4 weeks?
Supply Chain Analytics in Python
  • 1 week only: (1/12)A + (1/15)B ≤ 1

Correct Form

  • (1/12)A + (1/15)B ? ≤
  • (1/12)(32) + (1/15)(20) ≤ 4
  • (32/12) + (20/15) ≤ 4
  • 4 ≤ 4

Common Mistakes

  • 12A + 15B ≤ 4
  • (1/12)A + (1/15)B = 4
Supply Chain Analytics in Python
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")
Supply Chain Analytics in Python

Code example continued

# 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]
Supply Chain Analytics in Python

Code example continued

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
Supply Chain Analytics in Python

Extend constraint

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?

  • (1/12)A + (1/15)B + (1/5)C ≤ 4
Supply Chain Analytics in Python

Summary

  • Common Mistakes
    • Dependent constraint
    • Combination selection constraint
  • How to extend constraints
  • Check constraint by plugging in a value
Supply Chain Analytics in Python

Let's practice

Supply Chain Analytics in Python

Preparing Video For Download...