Inventory 5: Choosing a Policy
Requires Pro (SharedState)
Problem statement
Lesson 5.3 built a system, two stores and a warehouse, and measured how it behaves with one set of policy numbers. Those numbers were never chosen. The stores reorder at 32 and ask for 12; the warehouse reorders at 60 and orders 72. Somebody has to pick them, and the question is not “which policy looks best in a run” but “which policy is cheapest, and how sure are we?”
The decision. Three numbers need choosing: the store reorder point R, the store order quantity Q and the warehouse reorder point RW. R and Q are the same at both stores. The warehouse’s lot stays 72 and its supplier takes 4 days, as in lesson 5.3. The warehouse shares out a shortage pro rata, the rule lesson 5.3 found serves the system better. Demand is as in lesson 5.3: NegativeBinomial(r = 8, p = 0.5) at each store, independent of each other at first.
The cost model. A policy needs a price list before it can be compared. These five numbers are invented, chosen so that the trade-off is real (a policy that holds more stock loses fewer sales; a small Q sends many requests), and the lesson is about the method, not these figures:
| Cost | Amount | Charged |
|---|---|---|
| Holding at a store | 0.10 per unit per day | on every unit on a store’s shelf at the end of the day |
| Holding at the warehouse | 0.04 per unit per day | on every unit on the warehouse’s shelf at the end of the day |
| A store request | 2 | each day a store sends the warehouse a request |
| A supplier order | 15 | each day the warehouse orders from the supplier |
| A lost unit | 4 | each unit of demand a store cannot serve |
The warehouse has no penalty of its own for being short: a short shipment costs money only through the sales the store then loses. Ordering and holding are priced at both levels. The warehouse’s lot is fixed, so the supplier-order cost is almost the same for every policy (79 to 81 orders a year), and it adds a near-constant to every total.
The candidates. A grid of 45 policies to screen, R in 24, 28, 32, 36, 40, Q in 12, 20, 28 and RW in 48, 60, 72, then a finer grid of 25 around the winner.
What “fair” has to mean. A comparison of policies from simulation runs can mislead in four ways: the runs start from a state the system never returns to; the run is too short, or its error bars are wrong because the days are not independent; each policy sees different random demand, so part of every difference is luck; and the winner of 45 contenders is picked from the same data that ranks them. The lesson deals with each in turn.
The questions:
- Where does the cost come from in the model, and how can it be checked?
- How many days of each run are start-up, and how long must a run be?
- What do the same random demand for every policy buy, and how can it be verified?
- Which policy is the cheapest, which others cannot be told apart from it, and how many runs would it take to separate the top two?
- How does the answer move if a lost sale costs half or twice as much, or if the two stores’ demands are correlated?
- Lesson 5.3 found less risk pooling than the textbook rule predicts. Can that be explained?
The model
The model is samples/pro/inventory-policy.xml, lesson 5.3’s shared-warehouse model with the policy numbers made declared values and one more column. The nodes of lesson 5.3 are unchanged (the two imports of inventory-store-lib.xml, the customers, the warehouse), so only the changed parts are shown. Four declared values, and the warehouse’s cells as one of them, because the cells string travels as one declared value (lesson 5.2):
<definitions>
<declare name="corr" value="1, 0; 0, 1"/>
<declare name="RS" value="32"/>
<declare name="QS" value="12"/>
<declare name="hub" value="whs=72, w1=0, w2=0, w3=0, alloc=1, rw=60, qw=72, shipA=0, shipB=0,
stockA=40, lostA=0, seenA=0, reqA=0, stockB=40, lostB=0, seenB=0, reqB=0"/>
</definitions>
RS and QS go to both imports as before. The warehouse reorder point rw, its lot qw and the allocation switch alloc (1 is pro rata) are now inside hub, and <SharedState name="Hub" cells="$hub"/> uses it. The last node of lesson 5.3, an Arrange named Day that picked twelve columns, is now named Row, and a Calculate named Day follows it, passes the twelve columns through and adds the cost of the day as the thirteenth:
<Calculate name="Day" dimension="13"
expression="y[0] = x[0]; y[1] = x[1]; y[2] = x[2]; y[3] = x[3]; y[4] = x[4]; y[5] = x[5];
y[6] = x[6]; y[7] = x[7]; y[8] = x[8]; y[9] = x[9]; y[10] = x[10]; y[11] = x[11];
y[12] = 0.10 * (x[0] + x[4]) + 0.04 * x[8] + 2 * ((x[3] > 0) + (x[7] > 0))
+ 15 * (x[11] > 0) + 4 * (x[1] + x[5])">
<input name="Row"/>
</Calculate>
Column by column, the cost is 0.10 times the two stores’ end-of-day stock (columns 0 and 4), plus 0.04 times the warehouse’s (column 8), plus 2 for each store whose request is above zero (columns 3 and 7), plus 15 if the supplier order is above zero (column 11), plus 4 times the units lost (columns 1 and 5). The comparisons > 0 give 1 or 0. The prices sit in the expression because a Calculate cannot read a declared value, so changing a price means editing one number; the pass-through is needed because a node can feed only one other node. The file has 31 nodes of its own, and the shipped CSV, inventory-policy.csv, is recorded from its seed, 1005.
grind --count 365 inventory-policy.xml
The first ten days of seed 1005. The columns are the first twelve of lesson 5.3’s model (units lost are 0 in all ten rows and are left out of the table), then the cost:
| Day | Demand A | Stock A | Request A | Demand B | Stock B | Request B | Warehouse | Shipped A | Shipped B | Supplier order | Cost |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 40 | 0 | 0 | 40 | 0 | 72 | 0 | 0 | 0 | 10.88 |
| 2 | 0 | 40 | 0 | 0 | 40 | 0 | 72 | 0 | 0 | 0 | 10.88 |
| 3 | 7 | 33 | 0 | 5 | 35 | 0 | 72 | 0 | 0 | 0 | 9.68 |
| 4 | 3 | 30 | 0 | 8 | 27 | 0 | 72 | 0 | 0 | 0 | 8.58 |
| 5 | 6 | 24 | 12 | 13 | 14 | 12 | 72 | 0 | 0 | 0 | 10.68 |
| 6 | 2 | 22 | 0 | 10 | 4 | 12 | 48 | 12 | 12 | 0 | 6.52 |
| 7 | 8 | 26 | 0 | 11 | 5 | 12 | 36 | 0 | 12 | 72 | 21.54 |
| 8 | 7 | 19 | 12 | 11 | 6 | 12 | 24 | 0 | 12 | 0 | 7.46 |
| 9 | 2 | 17 | 12 | 3 | 15 | 12 | 0 | 12 | 12 | 0 | 7.20 |
| 10 | 4 | 25 | 0 | 4 | 23 | 0 | 48 | 12 | 12 | 0 | 6.72 |
Two rows show where a day’s cost comes from. Day 6 costs 6.52: 0.10 x (22 + 4) = 2.60 for the stores’ shelves, 0.04 x 48 = 1.92 for the warehouse’s, and 2.00 for the one request (store B’s); no supplier order, no lost units. Day 7 costs 21.54: 3.10 + 1.44 + 2.00 for the same three items, and 15.00 for the supplier order of 72 the warehouse placed that day. A day’s cost is lumpy, 6 to 22 for these rows, and the lumps are what the rest of the lesson has to average.
The seed-1005 year (365 rows) costs 4,233.30 in all, 11.598 a day, with 119 of 5,717 units lost (a fill rate of 97.92%). That is one draw, and it is not the policy’s long-run cost: the same policy’s long-run cost is about 11.35 a day (measured below), and the standard deviation of a year’s mean is about 0.30 (0.0579 x sqrt(10,000 / 365), from the replications below).
Two checks on the model itself. The cost column against the cost recomputed in Python from the other twelve columns, over 100,000 rows at seed 7: the largest difference is 0. And the first twelve columns against lesson 5.3’s model with alloc=1 at the same seed, 20,000 rows: 0 rows differ. So the new model is lesson 5.3’s, plus a column that adds up what it says.
The simulation runs for the comparison are Grind runs of this model with the numbers in RS, QS and hub changed in a throwaway copy, and the cost is rebuilt by the script from the twelve columns (so the price of a lost unit can be changed afterwards without running anything again). The two agree exactly, as just shown.
Throw away the start
Every run starts the same way: 40 units on each store’s shelf and 72 on the warehouse’s, and the first two days have no demand (the pipeline of lesson 5.3 is filling). The system never returns to that state, and a policy that needs more stock than it starts with pays for it later, or one that needs less is overstocked at first. The usual remedy is a warm-up: run longer and drop the first days. How many? Measure it, with the method of lesson 3.2: run many copies, average the cost of each day across copies, and look at where the average stops moving.
Three policies chosen to differ the most: a lean one, the baseline of lesson 5.3 and a generous one, each run 500 times for 1,500 days (seeds 1 to 500). The long-run level is the mean of days 801 to 1,500: 13.87, 11.35 and 12.40 for (24, 12, 48), (32, 12, 60) and (40, 28, 72). The standard deviation of one day across runs is 13.25, 8.30 and 7.05, so a 20-day window of 500 runs has a standard error of 0.13, 0.083 and 0.070. Against those, the first window (days 1 to 20) is off by -1.25, -0.08 and +0.71; the second (days 21 to 40) by -0.11, -0.08 and +0.08; and from day 41 on every window is within about two standard errors (2.2 at most) of the long-run level. After day 200 the largest window is 0.30 off for the lean policy (2.2 standard errors), 0.11 for the baseline (1.3) and 0.05 for the generous one (0.7).
The start-up is real and short: about 40 days. The 40 days are also small money. Had nothing been dropped, the start-up would add at most 0.0013 a day to the mean of a run of 10,000 days (the total excess cost over days 1 to 800 is -12.9, -5.9 and +12.0 for the three policies, which is at most 0.0013 a day over 10,000; the noise in each total is 9 to 17, so read them as bounds), and the top two policies below differ by 0.033. So the warm-up here is cheap insurance: every run below drops its first 200 days, five times the visible start-up. Its price is 2% of a 10,000-day run.
How long a run, and what correlation does to the error bar
Daily costs are not independent: today’s stock is yesterday’s stock less today’s sales, and the warehouse orders on a cycle. Lesson 3.3 showed what that does to a standard error, and lesson 1.5 gave the rule for independent draws: the rows needed for a half-width h at 95% are about 1.96 squared times the variance of one row over h squared. Both have to be adapted. Two measurements on the baseline policy (32, 12, 60): one run of 300,000 days after the 200 dropped (seed 99), and 300 independent replications of 10,000 days (seeds 1 to 300).
| Lag (days) | 1 | 2 | 3 | 5 | 10 | 20 |
|---|---|---|---|---|---|---|
| Autocorrelation of the daily cost | -0.137 | -0.216 | -0.150 | +0.141 | +0.005 | -0.052 |
| Autocorrelation of the stores’ total stock | +0.583 | +0.340 | +0.118 | +0.093 | +0.032 | +0.003 |
The stock is the textbook case of correlated output. The cost is correlated too, but with a sign pattern that comes from the supplier order of 15 every four or five days: an expensive day is followed by cheap ones (negative at lags 1 to 3) and the next order comes at about lag 5. The effect on the error bar is the opposite of lesson 3.3’s. The mean daily cost is 11.351, with a standard deviation of one day of 8.33. If the days were independent, the standard deviation of the mean of 10,000 days would be 8.33 over 100, or 0.0833. The 300 replications give 0.0579 (their mean cost is 11.350), 0.70 of the naive value: the naive error bar is 44% too wide. The asymptotic variance (the number of days times the variance of their mean, lesson 3.3) is 33.6, against the variance of one day, 69.4, an integrated autocorrelation time of 0.48 days. Batch means from the one long run agree with the replications: batches of 100 days (3,000 of them) give a standard error for a 10,000-day mean of 0.0579, batches of 1,000 days (300 of them) 0.0584; batches of 10 days give 0.0594, and 30 batches of 10,000 days (too few to be sharp) 0.0526.
Three things follow. The direction of the error is not something to assume; measure it, with replications or batch means, as here. The rule of lesson 1.5 holds if the variance of a row is replaced by the asymptotic variance: the days needed for a half-width h are 1.96 squared times that variance over h squared. For one policy’s cost to within 0.02, 3.84 x 33.6 / 0.0004 is about 323,000 days. And the choice between one long run and many replications is not about the error bar (both agree) but about convenience: replications can run in parallel, cost 200 warm-up days each, and give one independent, same-seed pair per seed, which is what the comparison needs. The runs below are replications of 10,000 days (about 27 years each).
The same demand for every policy
Lesson 4.3 showed how two models can be given the same random numbers: each node that draws gets a stream from the seed and its own name, so models with the same seed and the same node names draw the same values. Here the draws belong to the Copula named Draws (it draws the correlated pair; the two NegativeBinomial nodes only turn it into counts), and none of the policy numbers is in any path that reaches it. So running the 45 policies with the same seed should give every policy the same demand.
It can be checked, and it should be. For each of seeds 1 to 30, the script keeps a checksum of the two demand columns of the run, all 10,200 rows, and compares it across the 45 policies: identical in 30 of 30 seeds, and the 30 seeds give 30 different demand streams. What breaks it is a rename: with the Copula renamed to Draws2 in a throwaway copy (seed 5, 10,000 rows), store A’s demand equals the original’s in 694 rows (6.9%) and store B’s in 758 (7.6%), which is chance (two independent NegativeBinomial(8, 0.5) draws are equal with probability 0.0744). Renaming the NegativeBinomial node DrawA changes nothing (all 10,000 rows equal), because it is the Copula that draws. Which node draws is the model’s business, and it is why the check is on the output.
What does the same demand buy? Take the best policy and each of the other 44 of the screening below, and for each seed take the difference of their costs. With the same seeds the standard deviation of that difference is smaller than with different seeds; the different-seeds version needs no new runs, it pairs a policy’s replication for seed s with the other’s for seed s+1 (a different seed, so independent).
For the top two policies of the finer grid, over 80 seeds, the standard deviation of the cost difference is 0.078 with common random numbers and 0.116 with independent seeds: a variance ratio of 2.2, so the same precision needs about 2.2 times fewer runs. Over all 24 challengers of that grid the variance ratio has a median of 2.3 (quartiles 2.0 and 2.5, range 1.6 to 3.0), and over the 44 challengers of the screening grid a median of 2.5 (quartiles 1.8 and 3.0, range 0.9 to 5.4). The costs of two policies on the same seed have a correlation of 0.4 to 0.65 for the pairs shown, and 0.55 for the top two.
That is a modest gain next to lesson 4.3’s 15 to 1,600 times, and the reason is worth knowing. In lesson 4.3 the two versions were the same draws passed through two curves, so the noise was shared almost entirely. Here the same demand drives two systems whose stocks, orders and shortages respond to it differently, so only part of the noise is shared. Common random numbers never hurt (the variance ratio is above 1 for 42 of the 44 screening challengers and 0.91 and 0.93 for the other two, which is within the noise of a ratio from 30 seeds), but how much they help depends on how much of a model’s randomness the two versions pass through the same way.
Screening 45 policies
Each of the 45 policies is run on the same 30 seeds (1 to 30) of 10,000 days after a 200-day warm-up: 1,350 runs. The cost of a policy is the mean of its 30 replications; each of the other 44 is compared with the cheapest by the paired difference over the 30 seeds. A word on the interval: with 44 comparisons, one 95% interval per comparison would leave about two of them excluding zero by luck, so the intervals below are widened to hold for all 44 at once (Bonferroni: the t quantile for 29 degrees of freedom at 1 - 0.025/44, which is 3.611 instead of the single comparison’s 2.045). A policy “cannot be told apart from the best” if its widened interval includes 0.
The cheapest is (R, Q, RW) = (32, 20, 60) at 11.037 a day. The next ones:
| Policy (R, Q, RW) | Cost per day (se) | Minus the best (paired se) | Interval for all 44 differences | Told apart? |
|---|---|---|---|---|
| (32, 20, 60) | 11.037 (0.015) | best | ||
| (32, 20, 72) | 11.155 (0.007) | +0.118 (0.012) | +0.074 to +0.163 | yes |
| (32, 28, 60) | 11.190 (0.013) | +0.154 (0.015) | +0.099 to +0.208 | yes |
| (36, 20, 60) | 11.203 (0.012) | +0.166 (0.013) | +0.120 to +0.213 | yes |
| (28, 20, 60) | 11.215 (0.017) | +0.179 (0.012) | +0.135 to +0.222 | yes |
| (32, 12, 60) | 11.355 (0.009) | +0.318 (0.012) | +0.274 to +0.362 | yes (lesson 5.3’s policy) |
Every other policy of the 45 is separated from the best by more than the noise at 30 seeds (the smallest lower limit is +0.074), so there is no tie at this resolution. Lesson 5.3’s policy, (32, 12, 60), costs 0.318 a day more, 2.8% of its cost. The two policies serve differently, and the cheaper is the one with the lower fill rate:
| Policy | Fill rate | Stock at stores + at warehouse | Requests a year | Supplier orders a year |
|---|---|---|---|---|
| (32, 20, 60) | 97.79% | 34.4 + 29.8 | 317 | 79.2 |
| (32, 12, 60) | 98.28% | 27.9 + 37.6 | 490 | 79.6 |
| (32, 20, 72) | 98.95% | 37.1 + 46.8 | 293 | 80.2 |
Where the difference comes from, in cost per day by part (the same 30 seeds):
| Policy | Store holding | Warehouse holding | Requests | Supplier orders | Lost units | Total |
|---|---|---|---|---|---|---|
| (32, 20, 60) | 3.440 | 1.191 | 1.737 | 3.257 | 1.411 | 11.037 |
| (32, 12, 60) | 2.794 | 1.505 | 2.683 | 3.273 | 1.101 | 11.355 |
| (32, 20, 72) | 3.709 | 1.873 | 1.604 | 3.295 | 0.674 | 11.155 |
Against lesson 5.3’s policy the winner saves 0.946 a day on requests (317 a year instead of 490), 0.314 on the warehouse’s shelf and 0.016 on supplier orders, and pays 0.646 more for the stores’ shelves and 0.310 more in lost sales: a net 0.320 (0.318 from the paired runs, the parts being rounded). The supplier-order line barely moves, as expected from the fixed lot. At these prices the sales lost to a lower fill rate cost less than the stock it would take to prevent them: the third policy, with the highest fill rate of the three (98.95%), spends 0.95 more on shelves than the 0.74 it saves in lost units.
Zooming in, on fresh seeds
The winner of 45 was picked from the same 30 seeds that ranked it, which flatters it a little (the best of many noisy estimates is on average too good). The cure is to rerun the leaders on seeds the choice has not seen. The second stage reruns a finer grid around the winner, R in 28, 30, 32, 34, 36 and Q in 16, 18, 20, 22, 24 (RW stays at 60), 25 policies on 80 fresh seeds (1001 to 1080), 2,000 runs. The stage-1 winner costs 11.0366 on the fresh seeds, against 11.037 in the screening: no flattery to speak of here, though one case proves nothing about the next.
Close to the best the surface is not a smooth bowl. At R = 32 the cost above the best goes +0.092, +0.143, 0, +0.082, +0.365 for Q = 16, 18, 20, 22, 24; Q = 18 is dearer than both 16 and 20, and Q = 24 is dearer than any other Q in that column. The cause, which the test below supports, is the interplay of the warehouse’s reorder point with the size of what is shipped out of it. The warehouse’s position falls in steps of the stores’ Q, so a reorder point only matters through the values the position can take. With Q = 24 the position is a multiple of 24 (it starts at 72 and falls by 24 or rises by 72), until a shortage breaks the pattern, so a warehouse reorder point of 60 acts like 48, and with Q = 18 like 54. A direct test: (32, 24, 48) and (32, 24, 60) have identical cost in 10 of 10 seeds (11.3969 both), and so do (32, 18, 54), (32, 18, 60) and (32, 18, 66) (11.1747 each), while (32, 24, 72) and (32, 18, 72) are different policies (11.5629 and 11.4226). These are the same policy under different labels, and with common random numbers they give exactly the same cost, to every decimal; with independent seeds they would look different by the noise. The grid’s jagged edge in Q is partly this: a “60” is not the same warehouse reorder point at every Q.
The ranking of the finer grid, with the same kind of widened interval (24 differences at once, a t quantile of 3.183 against 1.990 for one alone):
| Policy (R, Q, RW) | Cost per day (se) | Minus the best (paired se) | Interval for all 24 differences |
|---|---|---|---|
| (32, 20, 60) | 11.0366 (0.0091) | best | |
| (30, 20, 60) | 11.0696 (0.0093) | +0.0330 (0.0088) | +0.005 to +0.061 |
| (34, 16, 60) | 11.1006 (0.0056) | +0.0640 (0.0081) | +0.038 to +0.090 |
| (32, 22, 60) | 11.1186 (0.0089) | +0.0820 (0.0088) | +0.054 to +0.110 |
| (34, 20, 60) | 11.1265 (0.0082) | +0.0899 (0.0090) | +0.061 to +0.119 |
| (32, 16, 60) | 11.1286 (0.0075) | +0.0920 (0.0072) | +0.069 to +0.115 |
The recommendation. (R, Q, RW) = (32, 20, 60), at 11.037 a day (standard error 0.009, from 80 runs of 10,000 days). The runner-up is (30, 20, 60), 0.033 a day dearer: the 95% interval for that difference alone is +0.016 to +0.051, and for all 24 at once +0.005 to +0.061, which still excludes zero, narrowly. Every other policy of the 25 is separated from the best.
How firmly is the winner chosen? Per replication, the runner-up is dearer than the best in 55 of 80 replications with common seeds, so a single 10,000-day run would have picked the wrong one of the two about 31% of the time. The number of replications decides this. Using the first n of the 80 fresh seeds:
| Replications n | 5 | 10 | 20 | 40 | 80 |
|---|---|---|---|---|---|
| Policies (of the other 24) not separated from the best | 13 | 4 | 3 | 0 | 0 |
| Best at n replications | (32, 20, 60) | (32, 20, 60) | (32, 20, 60) | (32, 20, 60) | (32, 20, 60) |
How many runs does it take to separate the top two? With the standard deviation of their paired difference, 0.0784 for a 10,000-day replication, and the gap 0.0330, the rule of lesson 1.5 with the asymptotic variance says n = (1.96 x 0.0784 / 0.0330)^2, which is 22 replications (217,000 days) for the interval to clear zero about half the time, and (2.80 x 0.0784 / 0.0330)^2 = 44 replications (442,000 days) for 80% of the time. With independent seeds the numbers would be 48 and 97, the variance ratio of 2.2 again. As a check, resampling the 80 pairs: with n = 10, 20, 40, 80, 160 replications the 95% interval for the difference excludes zero in 27%, 45%, 73%, 96% and 100% of draws with common random numbers, and in 13%, 24%, 38%, 70% and 95% with independent seeds. These are single-comparison intervals, and the widened interval used above needs more. The 80 replications used are enough here; 40 would have cleared zero in about three draws in four, and independent seeds would have needed 160 to be as sure as common random numbers are at 80.
What if the assumptions are wrong?
A recommendation rests on the five prices and on the demand model. Two assumptions are worth moving: the price of a lost sale (half and double: 2 and 8) and the correlation between the two stores’ demands (0, and 0.6 in the Gaussian copula, as in lesson 5.3). The cost is linear in the lost units, so the script rebuilds the table for the other prices from the same runs. The correlation needs new runs: the 45 policies again at correlation 0.6 on the same 30 seeds. These are screening-grid answers, 30 seeds each, not refined ones.
| Lost-sale cost | Correlation 0: best, runner-up | Correlation 0.6: best, runner-up | Policy (32, 20, 60) costs more by (corr 0 / corr 0.6) |
|---|---|---|---|
| 2 (half) | (28, 20, 60) at 10.094; (28, 28, 48) +0.163 | (28, 20, 60) at 10.158; (24, 20, 60) +0.190 | +0.237 (2.3%) / +0.271 (2.7%) |
| 4 (as above) | (32, 20, 60) at 11.037; (32, 20, 72) +0.118 | (32, 20, 72) at 11.208; (32, 20, 60) +0.141 | 0 / +0.141 (1.3%) |
| 8 (double) | (36, 20, 72) at 11.791; (32, 20, 72) +0.038 | (36, 20, 72) at 11.853; (32, 20, 72) +0.069 | +0.657 (5.6%) / +1.338 (11.3%) |
Three readings. The order quantity is robust: Q = 20 is in the best policy of all six cells. The reorder point is not: it follows the price of a lost sale, 28 for 2, 32 for 4 and 36 for 8, and at the high price the warehouse’s reorder point moves to 72. And the price of a lost sale is the assumption that matters most. Using the recommended (32, 20, 60) when a lost sale really costs 8 gives up 0.66 a day (5.6%), and 1.34 (11.3%) if the demands are also correlated; if it costs 2 the loss is 0.24 (2.3%). The correlation alone matters less: at correlation 0.6 the best policy at the lesson’s prices is (32, 20, 72), the same stores and a bigger warehouse reorder point, and (32, 20, 60) costs 0.141 more (se 0.020). At correlation 0.6 that policy’s fill rate falls from 97.79% to 97.12% and its cost rises from 11.037 to 11.349, a bad day at one store being more often a bad day at the other. The runner-up gaps are small at the double price (+0.038 with a standard error of 0.012, not separated from the best by the widened interval), so the pair (36, 20, 72) and (32, 20, 72) is a tie at 30 seeds there.
So the recommendation is conditional: (32, 20, 60) if a lost unit costs about 4, and the price is worth pinning down before the policy is, because it moves the answer more than the demand correlation does.
Back to the weak pooling of lesson 5.3
Lesson 5.3 measured that one shared warehouse saves less stock than two half-sized ones at the same service than the textbook square-root rule predicts, and said it had not isolated the cause. The pieces of this lesson make a cheap isolation possible. The rule says that for independent demands the safety stock of one warehouse serving two stores is 1/sqrt(2) = 0.71 of the two separate safety stocks, for the same service. Here the stores have their own stock and the warehouse has lots, so there are four things that could weaken it: the rule that shares out a shortage (fixed order or pro rata), the lot at the warehouse, the lots at the stores, and the point of operation (a warehouse that is rarely short has little safety stock to pool).
Three rule sets, each with the shared warehouse under the fixed order (store A first) and pro rata, and the two half-sized warehouses of lesson 5.3, nine to eleven warehouse reorder points each, 16 runs of 25,000 days per point (seeds 3000 to 3015), independent demands. “Lots at the stores and at the warehouse” is lesson 5.3 as it was. “No lot at the warehouse” replaces the warehouse’s reorder rule by order-up-to (it orders the amount that brings its position back to its target, a unit at a time). “No lots anywhere” does the same at the stores too (order-up-to 44).
| Rules | Warehouse stock for 97% of units requested shipped: shared / halves (ratio) | Total stock for 97% system fill: shared (A first), shared (pro rata), halves | Saving, A first | Saving, pro rata |
|---|---|---|---|---|
| Lots at the stores and at the warehouse | 36.9 / 48.5 (0.76) | 59.3, 56.8, 61.9 | 2.7 (sd 0.2) | 5.1 (sd 0.2) |
| No lot at the warehouse | 15.6 / 24.9 (0.63) | 35.9, 31.0, 39.2 | 3.3 (sd 0.1) | 8.2 (sd 0.1) |
| No lots anywhere | 15.7 / 23.8 (0.66) | 36.9, 29.2, 32.0 | -4.9 (sd 0.1) | 2.8 (sd 0.1) |
The bootstrap standard deviations come from resampling the 16 runs and do not include the interpolation between grid points. The first row’s A-first saving, 2.7 units, is lesson 5.3’s number (the same grid, 16 runs instead of 20).
What this says, in the order of the table’s columns. At the warehouse itself, pooling does what the square-root rule says: with no lot the shared warehouse needs 0.63 to 0.66 of the two halves’ stock for the same share of requested units shipped, a little better than 0.71; with the lot of 72 the ratio is 0.76, because the cycle stock of the lot is much the same in both systems. So the weak pooling is not at the warehouse.
At the system level, in the first row, two things take the saving away, and they interact. Pro rata alone raises the saving from 2.7 to 5.1 units (of about 60): serving store A first starves store B, and the system’s lost sales go up. Dropping the warehouse’s lot alone raises it only from 2.7 to 3.3. Both together give 8.2 units (of 31), 5.5 more than lesson 5.3 had and more than the two gains of 2.4 and 0.6 added up. And without the lot, with pro rata, the system’s saving (8.2) is close to what the warehouse itself saves at equal warehouse service (24.9 - 15.6 = 9.3 units): the system behaves as the textbook says, its saving being the warehouse’s safety stock saving. With the lot the system’s saving, 5.1, is less than half of the warehouse’s, 11.6 (48.5 - 36.9). Two things plausibly account for that and have not been separated: the lot’s cycle stock is the same in both systems and dilutes the saving, and at 97% system fill the shared warehouse ships only 92% of the units requested (92% to 93% in this row), not 97%, so the system is run with a warehouse that is short on purpose and a warehouse with a small safety stock has little to pool.
The third row is not a clean test of lots at the stores. Order-up-to 44 at the stores makes them need so little from the warehouse that the 97% point falls where the warehouse ships only about two thirds of the units requested (67% for pro rata, 69% for the halves), far from the regime of the textbook rule, and with the fixed order the shared warehouse is then worse than the halves (-4.9). It is better read as a change of regime than as a measurement of the lots at the stores; with pro rata it is still positive (2.8).
So lesson 5.3’s weak pooling is mostly explained: the fixed order of service and the warehouse’s lot together hid 5.5 of the 8.2 units. What remains is how the rest of the 5.1 units, against the warehouse’s own 11.6, splits between the lot’s cycle stock and the warehouse being run short. What this does not isolate is the effect of the lots at the stores by themselves, and all of it is for one set of stores’ numbers (R = 32, Q = 12, or order-up-to 44) and independent demands. For this lesson the consequence is small: its model uses pro rata, and the policy comparison does not depend on pooling at all.
Check: do the numbers match the math?
What can be exact here, and what cannot.
The cost accounting is exact. The cost column equals the cost recomputed in Python from the other columns in 100,000 of 100,000 rows (the largest difference is 0), and the hand-added cost of days 6 and 7 above agrees to the cent. The first twelve columns are lesson 5.3’s, row for row (0 of 20,000 rows differ).
The cost of the stores matches lesson 5.3’s chain. With a warehouse that is never short (start it with 10,000,000 units and no supplier orders, in a throwaway copy), each store reduces to the Markov chain of lesson 5.3: a fill rate of 98.62125%, an average stock of 14.3664 and 239.978 requests a year per store. The cost of the two stores (holding, requests and lost units, not the warehouse’s own) is then exactly 0.10 x 2 x 14.3664 + 2 x 2 x 239.978 / 365 + 4 x 2 x 8 x (1 - 0.9862125) = 6.3856 a day. Over 32 runs of 100,000 days (seeds 5000 to 5031): 6.3881 (se 0.0029, z 0.87). Its parts: the stores’ average stock 28.744 against 28.733 (z 1.56), requests a year 479.89 against 479.96 (z -1.09), lost units a day 0.2210 against 0.2206 (z 0.57).
The same demand is exact, and identical policies are identical. The demand columns are the same in 30 of 30 seeds across the 45 policies, checked on every row by checksum. The policy pairs that should coincide do, to the last decimal.
The error bars are checked against each other. The standard error of a 10,000-day mean, 0.0579 from 300 replications, is 0.0579 and 0.0584 from batch means over the one long run (batches of 100 and of 1,000 days). The warm-up is measured on 500 runs per policy.
What is not exact. There is no closed form for the shared warehouse when it runs short, so the policy costs rest on simulation and on the error bars above. The ranking’s confidence is as good as the assumption of the t intervals (replication means of 10,000 days are close to normal here); the Bonferroni widening is conservative; the stage-two comparison has 25 policies and 80 seeds, and nothing here says a policy outside the two grids is not cheaper. The sensitivity table and the pooling investigation are one-grid, 30-seed and 16-run answers.
What the model leaves out
A request is never remembered: a short shipment does not become a backorder, and a customer who finds an empty shelf is lost for good, so the cost of a lost sale (4) stands for the margin and the goodwill together. Lead times are fixed (3 days to a store, 4 days to the warehouse) with no delay that varies; a real supplier’s lead time has its own randomness, which would need its own safety stock. Demand is a fixed distribution known exactly: there is no forecast, no trend, no seasonality, and the policy numbers are chosen for a demand the policy-maker is certain about. The price reaction of lesson 5.4 is switched off: the stores’ demand does not respond to a shortage. The costs are invented, there are no fixed costs of running a warehouse, no costs of capital, and no difference between the stores. The comparison uses the same policy at both stores, and a search over different numbers for each would find a cheaper pair if the stores differed. Every statement about the best policy is a statement about this model and these prices.
What this gives you: a fair way to choose among policies by simulation. The cost of a day goes into the model as a column (a Calculate with comparisons) and is checked against a recomputation and, in a limit, against an exact Markov chain (6.3881 against 6.3856, z 0.87). A warm-up is measured, not guessed (about 40 days of start-up, 200 dropped). The error bar of a mean of correlated output is measured by replications and batch means (here the naive one was 44% too wide, because the cost’s autocorrelation is negative; the stock’s is positive). Common random numbers need the same seed and the same node names, are verified by a checksum of the demand columns (30 of 30 seeds), and here cut the variance of a policy difference by a factor of 2.2 to 2.5, a modest gain next to lesson 4.3’s because the policies change how the system responds, not just a scale. A 45-policy screen on 30 seeds, then a finer grid on 80 fresh seeds, picks (R, Q, RW) = (32, 20, 60) at 11.037 a day, 0.033 below the runner-up, with the widened interval on that gap +0.005 to +0.061, and 22 to 44 replications of 10,000 days needed to separate the two. The recommendation moves with the lost-sale cost (R = 28, 32, 36 for 2, 4, 8) more than with demand correlation, and keeps Q = 20 in all six cases. Lesson 5.3’s weak pooling is mostly the fixed order of service and the warehouse’s lot together (5.5 of the 8.2 units). The companion page lets you set the price of a lost sale and the correlation, and shows the cost of every policy, the cheapest, and which others cannot be told apart from it.
This lesson finishes the track, and the five modules fit together as one way of working. Module 1, Monte Carlo basics, taught the loop: draw many trials from distributions, count, and put a standard error on every answer. Module 2, paths and time, turned draws into paths (a runway of cash month by month) and asked what the whole path does, not one number. Module 3, state, added a memory (a queue, a recursion, a Markov chain), and with it the warm-up and the correlated output that this lesson used again. Module 4, what-if analysis, made models into parts with declared parameters, compared two versions fairly with common random numbers, injected changes and replayed history. Module 5, systems, let the parts share state and loop back on each other, and ended by choosing among policies with the uncertainty on the table. Every lesson has the same ending, a check of the model against something exact or against an independent calculation, because a simulation that cannot be checked is an opinion.
The capstone idea is to do the whole thing once on a process of your own. Pick a process you know (a queue, a pipeline, a stock, a project), choose distributions for what is random and say where each came from. Build the model, as small as will run. Verify it by hand where there is an exact answer, in a limit if not in general. Validate it against real data, which is a different question: does the output look like what the process produced? Then compare two scenarios fairly, with a warm-up, the same random numbers, enough runs for a stated precision and an interval on the difference, and write down what the model leaves out.
The lessons in this track are a checklist, and each one builds on those before it. The capstone is finding out which parts of that checklist your own process needs.