Dynamic lot sizing, solved exactly.
Demand that changes every period breaks the EOQ assumption of a steady draw. This lab solves the resulting lot-sizing problem to optimality with the Wagner-Whitin recurrence, then puts the answer next to what lot-for-lot and the Silver-Meal heuristic would have ordered.
What each policy costs
Cost breakdown
Orders and inventory over the horizon
Bar height is end-of-period inventory. The figure above a bar is the quantity ordered in that period. The table below carries the same numbers.
| Period | Demand | Opening | Order | End inventory | Setup cost | Holding cost | Period cost |
|---|
The recurrence, on your numbers
F(j) is the cheapest way to cover periods 1 through j and finish with nothing on hand. The winning start i is the period whose order covers the run ending at j.
| j | F(j) | Winning start i | Read as |
|---|
How the exact solution works
Why EOQ will not do
The economic order quantity assumes demand arrives at a constant rate, so one order size repeats forever. When demand is known but different every period — a production schedule, a promotional calendar, a project bill of materials — that assumption is gone, and the question changes shape. It is no longer how much, it is which periods get an order at all. That is a combinatorial question, and it has an exact answer.
The structure the answer has
Setup cost is a fixed charge and holding cost is linear, so the total cost is concave in the order quantities. Under those costs an optimal plan never places an order while stock is still on hand: if it did, you could shift that order later, pay the same setup and carry less. This is the zero-inventory-ordering property, and it collapses the search. Every order covers a whole, contiguous run of future demands, so a plan is nothing more than a way of cutting the horizon into consecutive blocks.
Cost of the block running from period i to period j, with its order placed in period i:
The bracket is an indicator: it is 1 when the block carries any demand and 0 when it does not. That matters only for a block of pure zeros — there is nothing to order, so no setup is paid. Everything after the plus sign is holding: demand for period t sits in stock for t − i full periods before it is used.
The recurrence
F(j) is the cheapest plan for the first j periods that ends with nothing in stock. To build it, guess which period starts the last block; everything before it is a smaller problem already solved. F(T) is the optimum, and reading the winning i backwards from T recovers the orders. The work is proportional to the square of the horizon, so a year of monthly buckets solves instantly.
When two plans cost the same, this tool takes the one that orders later. Both are optimal to the model; the later one is the one a planner would rather defend.
A worked example you can check by hand
Five periods of demand — 20, 50, 10, 50, 30 — with K = 100 per order and h = 1 per unit per period. This is the case the tool loads by default.
First the block costs. Covering periods 1 to 3 with one order means 20 units used immediately, 50 held one period, and 10 held two: c(1,3) = 100 + (0·20 + 1·50 + 2·10) = 170. The rest come out the same way:
Now roll the recurrence forward:
The optimum is 300. Backtracking: the last block starts at period 4, so it covers 4–5; what remains is the first three periods, whose winning start is 1, so that block covers 1–3. Two orders — 80 units in period 1 and 80 units in period 4. Two setups cost 200, and the inventory carried (60, then 10, then 30 unit-periods) costs 100.
The benchmarks: lot-for-lot orders every period, pays five setups and holds nothing — 500, two thirds above the optimum. Silver-Meal starting from period 1 sees average costs per period covered of 100, 75, 56.67, then 80; it stops when the average turns up and closes the block at period 3. Restarting at period 4 it sees 100 then 65 and runs to the horizon. Same blocks, same 300 — on this instance the heuristic is exactly right, but another demand pattern can make it miss the optimum.
What the two benchmarks do
- Lot-for-lot orders exactly this period's demand, every period that has any. It never carries stock, so its cost is one setup per non-empty period. It is the right policy when setups are cheap or holding is expensive, and it is the honest baseline for how much the batching decision is actually worth.
- Silver-Meal is the least-period-cost heuristic. Starting a block, it keeps adding periods while the average cost per period covered falls, and closes the block the first time that average would rise. It is greedy and myopic: it cannot see past the first upturn, so a low-demand period followed by a large one can stop it early.
The Load a lumpy case button above is one of the misses, and it is worth clicking. Twelve periods, K = 450, h = 2.50, with two empty periods and two spikes. The exact answer is $3,575 in five orders. Silver-Meal closes its first block one period early — the running average turns up at period 4, just before the period-5 spike would have pulled it back down — and finishes at $3,825, seven percent dearer. Lot-for-lot pays $4,500. The heuristic is not wrong so much as short-sighted, and on a demand pattern with quiet stretches that is exactly the shape that costs money.
Two rules the textbook statement of Silver-Meal leaves open are fixed here explicitly: a zero-demand period at the start of a block is skipped rather than charged a setup, and a tie closes the block rather than extending it.
Assumptions, stated plainly
- Demand is known. Every period's requirement is a fixed number, not a forecast with error around it. This is a deterministic model; nothing here sizes a buffer against uncertainty.
- One fixed setup cost. K is the same in every period and does not depend on order size. No quantity discounts, no supplier minimums, no cost of the units themselves — purchase cost is omitted because with no shortages and a fixed horizon the total units bought are the same under every policy, so it cannot change the ranking.
- Holding is charged on end-of-period inventory at a constant h per unit per period. Orders arrive at the start of the period they are placed in, so an order in period t can serve dt without being held at all.
- No shortages. Demand must be met in the period it occurs. No backorders, no lost sales, no expediting.
- No capacity limit. Any quantity can be ordered or produced in any period. A real line with a weekly ceiling needs the capacitated version of this problem, which is a genuinely harder one.
- Zero starting inventory, and the horizon closes at zero. Nothing is carried in, and nothing is left over. A rolling schedule with opening stock or a planned closing balance is a different instance.
- Demand must be non-negative, and both costs must be non-negative. Returns and negative carrying charges break the concavity the whole argument rests on.
The horizon-end assumption is the one that bites in practice. Solving a twelve-period window exactly and then re-solving next month is a rolling horizon, and the optimal plan for the window is not the optimal plan for the business. The usual defence is to solve a horizon longer than you intend to commit to and only act on the first few periods.
Sources
- Wagner, H. M. and Whitin, T. M. “Dynamic Version of the Economic Lot Size Model.” Management Science 5(1), 89–96 (1958). The dynamic lot-sizing model behind this lab. pubsonline.informs.org/doi/10.1287/mnsc.5.1.89
- MIT OpenCourseWare, Logistics and Supply Chain Management — lecture notes on dynamic economic lot sizing, including the zero-inventory-ordering property and shortest-path formulation. ocw.mit.edu