Supply Chain Optimization
Supply chains are complex networks connecting suppliers, factories, warehouses, and customers. Optimizing this network can reduce costs by 10-30% while improving service levels.
Why Supply Chain Optimization?
Supply chain costs account for 50-70% of most companies total expenses. Even small percentage improvements translate to millions in savings:
| Improvement | Impact for $100M company | |:-----------:|:------------------------:| | 5% logistics cost reduction | $3-5M savings | | 10% inventory reduction | $5-10M freed capital | | 2% service level improvement | $2-5M revenue increase | | 15% procurement optimization | $7-15M cost reduction |
What Is Supply Chain Optimization?
Supply chain optimization answers questions like:
- Which suppliers should we buy from?
- How much inventory should each warehouse hold?
- Which warehouse should serve each customer?
- How much should each factory produce?
- What transportation routes minimize costs?
How to Model a Supply Chain with ILP
Problem Setup
A company has 2 factories, 3 warehouses, and 5 customer regions. Each factory has production capacity, each warehouse has storage capacity, and each customer has demand.
import pulp
# Sets
factories = ["Factory_A", "Factory_B"]
warehouses = ["Warehouse_1", "Warehouse_2", "Warehouse_3"]
customers = ["North", "South", "East", "West", "Central"]
# Factory capacity (units per month)
factory_capacity = {"Factory_A": 10000, "Factory_B": 8000}
# Warehouse capacity (units)
warehouse_capacity = {"Warehouse_1": 5000, "Warehouse_2": 4000, "Warehouse_3": 6000}
# Customer demand (units per month)
customer_demand = {"North": 3000, "South": 2500, "East": 4000, "West": 2000, "Central": 3500}
# Production cost per unit at each factory
prod_cost = {"Factory_A": 50, "Factory_B": 55}
# Transportation cost: factory -> warehouse
fw_cost = {
("Factory_A", "Warehouse_1"): 5,
("Factory_A", "Warehouse_2"): 7,
("Factory_A", "Warehouse_3"): 6,
("Factory_B", "Warehouse_1"): 8,
("Factory_B", "Warehouse_2"): 4,
("Factory_B", "Warehouse_3"): 9,
}
# Transportation cost: warehouse -> customer
wc_cost = {
("Warehouse_1", "North"): 3,
("Warehouse_1", "South"): 4,
("Warehouse_1", "East"): 6,
("Warehouse_1", "West"): 8,
("Warehouse_1", "Central"): 5,
("Warehouse_2", "North"): 7,
("Warehouse_2", "South"): 3,
("Warehouse_2", "East"): 5,
("Warehouse_2", "West"): 4,
("Warehouse_2", "Central"): 6,
("Warehouse_3", "North"): 5,
("Warehouse_3", "South"): 6,
("Warehouse_3", "East"): 3,
("Warehouse_3", "West"): 7,
("Warehouse_3", "Central"): 4,
}
# Create problem
prob = pulp.LpProblem("Supply_Chain_Optimization", pulp.LpMinimize)
# Decision variables
# fw: flow from factory to warehouse
fw = {}
for f in factories:
for w in warehouses:
fw[(f, w)] = pulp.LpVariable(f"fw_{f}_{w}", lowBound=0)
# wc: flow from warehouse to customer
wc = {}
for w in warehouses:
for c in customers:
wc[(w, c)] = pulp.LpVariable(f"wc_{w}_{c}", lowBound=0)
# Objective: minimize production + transportation costs
prob += pulp.lpSum(prod_cost[f] * pulp.lpSum(fw[(f, w)] for w in warehouses) for f in factories) + \\
pulp.lpSum(fw_cost[(f, w)] * fw[(f, w)] for f in factories for w in warehouses) + \\
pulp.lpSum(wc_cost[(w, c)] * wc[(w, c)] for w in warehouses for c in customers), "Total_Cost"
# Constraint 1: Factory capacity
for f in factories:
prob += pulp.lpSum(fw[(f, w)] for w in warehouses) <= factory_capacity[f], f"Capacity_{f}"
# Constraint 2: Warehouse flow balance
for w in warehouses:
prob += pulp.lpSum(fw[(f, w)] for f in factories) == pulp.lpSum(wc[(w, c)] for c in customers), f"Balance_{w}"
# Constraint 3: Warehouse capacity
for w in warehouses:
prob += pulp.lpSum(wc[(w, c)] for c in customers) <= warehouse_capacity[w], f"Capacity_{w}"
# Constraint 4: Customer demand
for c in customers:
prob += pulp.lpSum(wc[(w, c)] for w in warehouses) >= customer_demand[c], f"Demand_{c}"
# Solve
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Total Cost: ${pulp.value(prob.objective):,.0f}")
print()
print("Factory -> Warehouse shipments:")
for f in factories:
for w in warehouses:
val = pulp.value(fw[(f, w)])
if val and val > 0:
print(f" {f} -> {w}: {val:,.0f} units")
print()
print("Warehouse -> Customer shipments:")
for w in warehouses:
for c in customers:
val = pulp.value(wc[(w, c)])
if val and val > 0:
print(f" {w} -> {c}: {val:,.0f} units")
Extending the Model
Multi-Period Planning
Add time dimension for monthly planning over 12 months:
# Add time index to all variables
months = range(1, 13)
fw = {(f, w, m): pulp.LpVariable(f"fw_{f}_{w}_{m}", lowBound=0)
for f in factories for w in warehouses for m in months}
Inventory Holding
# Inventory at warehouse at end of each month
inventory = {}
for w in warehouses:
for m in months:
inventory[(w, m)] = pulp.LpVariable(f"inv_{w}_{m}", lowBound=0)
if m == 1:
prob += inventory[(w, m)] == (sum(fw[(f, w, m)] for f in factories)
- sum(wc[(w, c, m)] for c in customers))
else:
prob += inventory[(w, m)] == (inventory[(w, m-1)]
+ sum(fw[(f, w, m)] for f in factories)
- sum(wc[(w, c, m)] for c in customers))
Supplier Selection
# Binary variable: use supplier or not
supplier_selected = {}
for s in suppliers:
supplier_selected[s] = pulp.LpVariable(f"select_{s}", cat="Binary")
prob += supply[(s, m)] <= max_capacity[s] * supplier_selected[s]
Real-World Applications
| Industry | Network Size | Typical Savings | |----------|:------------:|:---------------:| | Retail | 10-50 DCs, 1000+ stores | 5-15% logistics cost | | Manufacturing | 5-20 plants, 50+ suppliers | 10-20% procurement cost | | Pharmaceutical | 3-10 plants, temperature-controlled | 15-25% waste reduction | | Food beverage | 10-30 DCs, short shelf life | 20-30% spoilage reduction |
The Vibe Coding Approach
"I have a supply chain with 2 factories, 3 warehouses, and 5 customer regions. Minimize total cost including production and transportation. Each factory has capacity limits, warehouses have storage limits, and customer demand must be met."
The AI will generate the complete multi-echelon supply chain optimization model.
Summary
Supply chain optimization is one of the highest-value applications of ILP. A well-optimized supply chain reduces costs, improves service levels, and frees capital.
Key takeaways:
- Multi-echelon supply chains include suppliers, factories, warehouses, customers
- Flow balance constraints ensure consistency across echelons
- Capacity constraints model real-world limits
- Multi-period models capture time-dependent decisions
- Inventory holding costs balance supply and demand over time
- Supplier selection uses binary variables
- Typical savings: 10-30% of total supply chain costs
What's Next: Optimization API
The next chapter shows how to deploy optimization models as a web service, enabling applications and users to submit problems and receive solutions programmatically.