| name | lot-sizing-problems |
| description | When the user wants to optimize production or order lot sizes over multiple periods, solve multi-period inventory planning problems, or determine when and how much to order/produce with time-varying demand. Also use when the user mentions "lot sizing," "lot-for-lot," "fixed order quantity," "POQ" (periodic order quantity), "part-period balancing," "Silver-Meal heuristic," "Wagner-Whitin algorithm," "least unit cost," "lot sizing with capacity constraints," or "multi-item lot sizing." For single-period problems, see newsvendor-problem. For time-varying lot sizing, see dynamic-lot-sizing. |
Lot-Sizing Problems
You are an expert in multi-period lot-sizing models and production/inventory planning optimization. Your goal is to help determine optimal order or production quantities across multiple time periods to minimize total costs including setup, holding, and sometimes shortage costs.
Initial Assessment
Before solving lot-sizing problems, understand:
-
Planning Context
- Planning horizon? (weeks, months, quarters)
- Rolling or fixed horizon?
- Demand pattern? (deterministic, forecast, actual orders)
- Lead time considerations?
-
Cost Structure
- Setup/ordering cost per order ($)?
- Holding cost per unit per period ($/unit/period)?
- Production/purchase cost per unit?
- Backorder or shortage costs?
- Cost structure time-varying?
-
Capacity and Constraints
- Production capacity limits per period?
- Storage capacity limits?
- Minimum lot sizes or batch constraints?
- Multiple items sharing capacity?
-
Product Characteristics
- Single item or multiple items?
- Bill of materials structure?
- Product substitutability?
- Shelf life or obsolescence?
-
Operational Requirements
- Can backorders occur?
- Must demand be satisfied immediately?
- Multi-level production (BOM)?
- Supplier constraints (MOQ, lead times)?
Lot-Sizing Problem Fundamentals
Problem Statement
Given:
- Planning horizon: T periods (t = 1, 2, ..., T)
- Demand in each period: D_t (known deterministically)
- Setup cost: S (fixed cost incurred when ordering/producing)
- Holding cost: h per unit per period
- Unit cost: c (often ignored if constant)
Decision:
- When to order/produce?
- How much to order/produce in each period?
Objective:
- Minimize total cost = setup costs + holding costs
Key Lot-Sizing Policies
1. Lot-for-Lot (L4L)
- Order exactly what is needed each period: Q_t = D_t
- Minimizes holding cost (zero inventory)
- Maximizes setup costs
- Use when setup costs are very low
2. Fixed Order Quantity (FOQ)
- Order the same quantity Q every time
- Simple to implement
- May not match demand patterns well
3. Economic Order Quantity (EOQ)
- Use EOQ formula with average demand
- Assumes constant demand rate
4. Period Order Quantity (POQ)
- Order every N periods (N determined by EOQ)
- Combines multiple periods' demand
5. Least Unit Cost (LUC)
- Choose lot size that minimizes cost per unit
- Forward-looking heuristic
6. Least Total Cost (LTC) / Part-Period Balancing
- Balance setup and holding costs
- Choose lot when cumulative holding cost ≈ setup cost
7. Silver-Meal Heuristic
- Minimize average cost per period
- Popular practical heuristic
8. Wagner-Whitin Algorithm
- Dynamic programming approach
- Finds optimal solution for uncapacitated problem
- Polynomial time complexity O(T²)
Python Implementation: Lot-Sizing Models
Basic Lot-Sizing Heuristics
import numpy as np
import pandas as pd
from typing import List, Dict, Tuple
import matplotlib.pyplot as plt
class LotSizingProblem:
"""
Multi-period lot-sizing problem solver
Implements various heuristics and optimal algorithm
"""
def __init__(self, demands: List[float], setup_cost: float,
holding_cost: float, unit_cost: float = 0):
"""
Parameters:
-----------
demands : list
Demand for each period [D1, D2, ..., DT]
setup_cost : float
Fixed cost incurred when placing order/production run
holding_cost : float
Cost per unit held in inventory per period
unit_cost : float
Variable cost per unit (often omitted if constant)
"""
self.demands = np.array(demands)
self.T = len(demands)
self.S = setup_cost
self.h = holding_cost
self.c = unit_cost
def lot_for_lot(self) -> Dict:
"""
Lot-for-Lot (L4L) policy: Order exactly demand each period
Minimizes inventory but incurs setup cost every period
"""
orders = self.demands.copy()
inventory = np.zeros(self.T + 1)
setup_costs = np.zeros(.T)
holding_costs = np.zeros(.T)
t (.T):
inventory[t] += orders[t]
inventory[t] -= .demands[t]
orders[t] > :
setup_costs[t] = .S
holding_costs[t] = inventory[t] * .h
inventory[t + ] = inventory[t]
total_setup = setup_costs.()
total_holding = holding_costs.()
total_cost = total_setup + total_holding
{
: ,
: orders,
: inventory[:-],
: total_setup,
: total_holding,
: total_cost,
: (orders > ).()
}
() -> :
orders = np.zeros(.T)
inventory = np.zeros(.T + )
setup_costs = np.zeros(.T)
holding_costs = np.zeros(.T)
t (.T):
inventory[t] < .demands[t]:
orders[t] = Q
inventory[t] += Q
inventory[t] -= .demands[t]
inventory[t] < :
num_orders = (np.ceil(-inventory[t] / Q))
orders[t] += num_orders * Q
inventory[t] += num_orders * Q
orders[t] > :
setup_costs[t] = .S * (orders[t] / Q)
holding_costs[t] = (, inventory[t]) * .h
inventory[t + ] = inventory[t]
total_setup = setup_costs.()
total_holding = holding_costs.()
total_cost = total_setup + total_holding
{
: ,
: orders,
: inventory[:-],
: total_setup,
: total_holding,
: total_cost,
: (orders > ).()
}
() -> :
orders = np.zeros(.T)
inventory = np.zeros(.T + )
t =
t < .T:
best_periods =
min_avg_cost = ()
k (, .T - t + ):
total_demand = (.demands[t:t+k])
holding_cost = ((j - t) * .demands[t+j] * .h
j (k))
total_cost = .S + holding_cost
avg_cost = total_cost / k
avg_cost < min_avg_cost:
min_avg_cost = avg_cost
best_periods = k
:
order_qty = (.demands[t:t+best_periods])
orders[t] = order_qty
inv = order_qty
j (best_periods):
t + j < .T:
inventory[t + j] = inv
inv -= .demands[t + j]
t += best_periods
setup_costs = np.where(orders > , .S, )
holding_costs = inventory[:-] * .h
{
: ,
: orders,
: inventory[:-],
: setup_costs.(),
: holding_costs.(),
: setup_costs.() + holding_costs.(),
: (orders > ).()
}
() -> :
orders = np.zeros(.T)
inventory = np.zeros(.T + )
t =
t < .T:
min_unit_cost = ()
best_periods =
k (, .T - t + ):
total_demand = (.demands[t:t+k])
holding_cost = ((j - t) * .demands[t+j] * .h
j (k))
total_cost = .S + holding_cost
unit_cost = total_cost / total_demand
unit_cost < min_unit_cost:
min_unit_cost = unit_cost
best_periods = k
:
order_qty = (.demands[t:t+best_periods])
orders[t] = order_qty
inv = order_qty
j (best_periods):
t + j < .T:
inventory[t + j] = inv
inv -= .demands[t + j]
t += best_periods
setup_costs = np.where(orders > , .S, )
holding_costs = inventory[:-] * .h
{
: ,
: orders,
: inventory[:-],
: setup_costs.(),
: holding_costs.(),
: setup_costs.() + holding_costs.(),
: (orders > ).()
}
() -> :
T = .T
F = np.full(T + , np.inf)
F[] =
pred = np.zeros(T + , dtype=)
t (, T + ):
j (t):
holding_cost =
k (j + , t + ):
holding_cost += (k - j - ) * .demands[k - ] * .h
cost = F[j] + .S + holding_cost
cost < F[t]:
F[t] = cost
pred[t] = j
orders = np.zeros(T)
t = T
t > :
j = pred[t]
order_qty = (.demands[j:t])
orders[j] = order_qty
t = j
inventory = np.zeros(T + )
t (T):
inventory[t] += orders[t]
inventory[t] -= .demands[t]
inventory[t + ] = inventory[t]
setup_costs = np.where(orders > , .S, )
holding_costs = inventory[:-] * .h
{
: ,
: orders,
: inventory[:-],
: setup_costs.(),
: holding_costs.(),
: setup_costs.() + holding_costs.(),
: (orders > ).(),
:
}
() -> pd.DataFrame:
methods = [
.lot_for_lot(),
.silver_meal(),
.least_unit_cost(),
.wagner_whitin()
]
avg_demand = .demands.mean()
avg_demand > :
eoq = np.sqrt( * avg_demand * .T * .S / .h)
methods.append(.fixed_order_quantity(eoq))
results = []
method methods:
results.append({
: method[],
: method[],
: method[],
: method[],
: method[],
: method[].mean()
})
df = pd.DataFrame(results)
df = df.sort_values()
df
():
fig, (ax1, ax2, ax3) = plt.subplots(, , figsize=(, ))
periods = np.arange(, .T + )
ax1.bar(periods, .demands, alpha=, label=, color=)
order_periods = periods[solution[] > ]
order_qtys = solution[][solution[] > ]
ax1.bar(order_periods, order_qtys, alpha=, label=, color=)
ax1.set_xlabel(, fontsize=)
ax1.set_ylabel(, fontsize=)
ax1.set_title(,
fontsize=, fontweight=)
ax1.legend()
ax1.grid(, alpha=)
ax2.plot(periods, solution[], marker=, linewidth=,
color=, label=)
ax2.fill_between(periods, , solution[], alpha=, color=)
ax2.axhline(y=solution[].mean(), linestyle=,
color=, label=)
ax2.set_xlabel(, fontsize=)
ax2.set_ylabel(, fontsize=)
ax2.set_title(, fontsize=, fontweight=)
ax2.legend()
ax2.grid(, alpha=)
setup_costs = np.where(solution[] > , .S, )
holding_costs = solution[] * .h
width =
ax3.bar(periods - width/, setup_costs, width, label=,
color=, alpha=)
ax3.bar(periods + width/, holding_costs, width, label=,
color=, alpha=)
ax3.set_xlabel(, fontsize=)
ax3.set_ylabel(, fontsize=)
ax3.set_title(, fontsize=, fontweight=)
ax3.legend()
ax3.grid(, alpha=)
plt.tight_layout()
plt
():
( + * )
()
( * )
demands = [, , , , , , , , , , , ]
problem = LotSizingProblem(
demands=demands,
setup_cost=,
holding_cost=,
unit_cost=
)
()
()
()
()
()
()
()
t, d (demands, ):
()
( + * )
()
( * )
comparison = problem.compare_methods()
( + comparison.to_string(index=))
optimal = problem.wagner_whitin()
( + * )
()
( * )
()
()
()
()
()
()
t (problem.T):
optimal[][t] > :
()
problem.plot_solution(optimal)
plt.savefig(, dpi=, bbox_inches=)
()
problem, optimal
__name__ == :
example_lot_sizing()
Capacitated Lot-Sizing
Single-Item Capacitated Lot-Sizing Problem (CLSP)
from pulp import *
class CapacitatedLotSizing:
"""
Capacitated Lot-Sizing Problem (CLSP)
Production capacity constraints in each period
"""
def __init__(self, demands: List[float], setup_cost: float,
holding_cost: float, production_cost: float,
capacity: List[float]):
"""
Parameters:
-----------
demands : list
Demand for each period
setup_cost : float
Fixed setup cost per period
holding_cost : float
Holding cost per unit per period
production_cost : float
Variable production cost per unit
capacity : list
Production capacity each period
"""
self.demands = np.array(demands)
self.T = len(demands)
self.S = setup_cost
self.h = holding_cost
self.c = production_cost
self.capacity = np.array(capacity)
def solve_mip(self) -> Dict:
"""
Solve using Mixed-Integer Programming
Decision variables:
- x_t: production quantity in period t
- y_t: binary, 1 if production occurs in period t
- I_t: inventory at end of period t
"""
prob = LpProblem("Capacitated_Lot_Sizing", LpMinimize)
x = [LpVariable(f"x_{t}", lowBound=0) for t in (.T)]
y = [LpVariable(, cat=) t (.T)]
I = [LpVariable(, lowBound=) t (.T + )]
prob += (lpSum([.S * y[t] + .c * x[t] + .h * I[t]
t (.T)]))
prob += I[] ==
t (.T):
prob += I[t + ] == I[t] + x[t] - .demands[t]
t (.T):
prob += x[t] <= .capacity[t] * y[t]
prob.solve(PULP_CBC_CMD(msg=))
production = np.array([x[t].varValue t (.T)])
setup_decisions = np.array([y[t].varValue t (.T)])
inventory = np.array([I[t].varValue t (.T + )])
setup_cost = .S * setup_decisions.()
prod_cost = .c * production.()
holding_cost = .h * inventory[:-].()
total_cost = value(prob.objective)
{
: LpStatus[prob.status],
: production,
: inventory[:-],
: setup_decisions,
: total_cost,
: setup_cost,
: prod_cost,
: holding_cost,
: (setup_decisions.())
}
():
( + * )
()
( * )
demands = [, , , , , ]
capacity = [, , , , , ]
problem = CapacitatedLotSizing(
demands=demands,
setup_cost=,
holding_cost=,
production_cost=,
capacity=capacity
)
()
()
()
()
()
()
()
t, d (demands, ):
()
solution = problem.solve_mip()
()
()
( * )
()
()
()
()
()
()
()
t (problem.T):
solution[][t] > :
(
)
problem, solution
__name__ == :
example_capacitated()
Tools & Libraries
Python Libraries
Optimization:
pulp: Linear/mixed-integer programming
pyomo: Optimization modeling
scipy.optimize: General optimization
ortools: Google OR-Tools
Numerical:
numpy, pandas: Data manipulation
Commercial Software
Production Planning:
- SAP APO: Advanced Planning & Optimization with lot-sizing
- Oracle Demantra: Demand and supply planning
- Blue Yonder: Supply chain planning
- Kinaxis RapidResponse: Integrated planning
MRP Systems:
- Most ERP systems have lot-sizing rules (SAP, Oracle, Microsoft Dynamics)
Common Challenges & Solutions
Challenge: Capacity Constraints
Problem:
- Production capacity insufficient in some periods
- Cannot produce when needed
Solutions:
- Use capacitated lot-sizing MIP model
- Consider overtime production (higher cost)
- Build inventory in advance during low-demand periods
- Outsource production for peak periods
Challenge: Setup Time vs. Setup Cost
Problem:
- Setups consume both time (capacity) and cost
- Simple models consider only cost
Solutions:
- Include setup time in capacity constraints
- Use CLSP with setup times
- Sequence-dependent setup times → more complex models
Challenge: Multi-Item Lot-Sizing
Problem:
- Multiple products share same production capacity
- Joint setup costs or time
Solutions:
- Multi-item CLSP formulation
- Proportional Lot-Sizing (PROPLS) heuristic
- Priority-based allocation
- See multi-item examples in code
Challenge: Uncertainty in Demand
Problem:
- Lot-sizing assumes deterministic demand
- Real demand is uncertain
Solutions:
- Use rolling horizon planning (replan each period)
- Add safety stock to demands
- Robust optimization with demand scenarios
- See stochastic-inventory-models and dynamic-lot-sizing
Related Skills
- economic-order-quantity: Single-period lot-sizing
- dynamic-lot-sizing: Time-varying parameters and stochastic demand
- stochastic-inventory-models: Probabilistic inventory models
- master-production-scheduling: Aggregate production planning
- capacity-planning: Long-term capacity decisions
- production-scheduling: Short-term scheduling