Back to trackLesson 23 of 25

Inventory 3: Two Stores, One Warehouse

Requires Pro (SharedState, Import and declare)

Problem statement

Lesson 5.2 made the store a set of named parts around a shared cell. This lesson uses that to do what a single Recur could not: two stores that draw their stock from one warehouse, which in turn buys from an outside supplier. When the warehouse has enough, both stores get what they ask for. When it does not, someone has to decide who gets what, and the stores’ separate demands now compete for the same units.

The system, with every choice made once:

  • The stores are the same store, written once. The store of lesson 5.2 goes into a library file with declared parameters, and the model imports it twice, as A and B, exactly as Module 4 imported a latency model. Each import has its own cells and its own shelf.
  • One row is one day. Each store’s demand is NegativeBinomial with r = 8 and p = 0.5 (mean 8, variance 16), as in lessons 5.1 and 5.2. The two demands are tied together by a Gaussian Copula with a correlation that the model declares: independent in the first runs, correlated later.
  • A store asks, the warehouse ships. A store no longer orders from a supplier. When its position (shelf plus what is arriving plus what it has already asked for) is at or below its reorder point R = 32, it sends the warehouse a request for Q = 12 units. The warehouse ships what it has, and the shipment is on the store’s shelf two days after the request is written.
  • The warehouse is a store too. It holds a shelf, and it buys from an outside supplier in lots of 72 when its own position is at or below 60. The supplier takes 4 days. The warehouse starts with 72 units.
  • What is not shipped is lost. If the warehouse has 5 units and a store asks for 12, the store gets 5 and the other 7 are gone: the store does not remember the request, and the warehouse does not owe it. This keeps every quantity an exact count, and it is the same lost-sales choice as at the shelf.
  • A fixed rule decides who is served first. When both stores ask on the same day for more than the warehouse has, the first rule serves store A in full before store B. The second rule shares what there is in proportion to the requests. The model has a switch for it.

Two things differ from the store of lesson 5.2, and both are consequences of what was learned there. The store’s lead time is now 3 days, not 2: the loop through cells puts one day between the policy and the request, one between the request and the warehouse’s decision, and one between the shipment and the shelf. It needs a bigger reorder point to cover that, hence R = 32 (3 days of mean demand is 24) and Q = 12. The quantities are small on purpose: the warehouse’s numbers move in lots of 12, and a smaller lot makes the comparison later in the lesson less lumpy. The second difference is that the stores’ customers live outside the library, for a reason explained below.

The measures. For each store, a stockout day is a day on which some demand is not met, and the fill rate is 1 minus the lost units over the units demanded, as in lesson 5.1. The system’s fill rate is the same ratio over both stores. At the warehouse, a short request is a request that is not shipped in full (the count is over both stores); units short is the units not shipped. Average stock is the mean end-of-day stock, at the stores and at the warehouse, and orders a year counts store requests and supplier orders separately, scaled to 365 days.

The questions:

  • How does a library store become two stores, and what does the parent model have to supply?
  • When the warehouse is short, does the order of service matter, and what in the model does and does not depend on node order?
  • Does one warehouse for two stores need less stock than two warehouses of half the size, and what does correlated demand do to that?

The model

The store library, samples/pro/inventory-store-lib.xml, is the store of lesson 5.2 with a request in place of an order. It declares three values, the policy numbers R and Q and the starting cells, and it travels the way lesson 5.2 found it has to: R and Q as Constant columns appended to the policy’s input, the cells string as one declared value.

<dataset columns="stock, lost, demand, request">
  <root node="Day"/>
  <definitions>
    <declare name="cells" value="stock=40, rcv=0, req=0, dem=0, lost=0, seen=0"/>
    <declare name="R" value="32"/>
    <declare name="Q" value="12"/>
  </definitions>
  <nodes>
    <SharedState name="Store" cells="$cells"/>
    <StateRead name="ShelfForPolicy" collaborate.state="Store" cells="stock, rcv, req"/>
    <Constant name="Rcol" value="$R" type="double"/>
    <Constant name="Qcol" value="$Q" type="double"/>
    <Append name="PolicyIn">
      <input name="ShelfForPolicy"/>
      <input name="Rcol"/>
      <input name="Qcol"/>
    </Append>
    <Calculate name="Policy" dimension="1" expression="y[0] = if(x[0] + x[1] + x[2] &lt;= x[3], x[4], 0)">
      <input name="PolicyIn"/>
    </Calculate>
    <StateWrite name="PlaceRequest" collaborate.state="Store" cells="req" mode="set">
      <input name="Policy"/>
    </StateWrite>
    <StateRead name="ShelfForSales" collaborate.state="Store" cells="stock, rcv, dem"/>
    <Calculate name="Sales" dimension="3"
               expression="y[0] = max(0, x[0] + x[1] - x[2]); y[1] = max(0, x[2] - x[0] - x[1]); y[2] = x[2]">
      <input name="ShelfForSales"/>
    </Calculate>
    <StateWrite name="Close" collaborate.state="Store" cells="stock, lost, seen" mode="set">
      <input name="Sales"/>
    </StateWrite>
    <Constant name="Zero" value="0" type="double"/>
    <StateWrite name="ClearReceipts" collaborate.state="Store" cells="rcv" mode="set">
      <input name="Zero"/>
    </StateWrite>
    <Append name="Pair">
      <input name="Close"/>
      <input name="PlaceRequest"/>
      <input name="ClearReceipts"/>
    </Append>
    <Arrange name="Day" columns="0,1,2,3">
      <input name="Pair"/>
    </Arrange>
  </nodes>
</dataset>

What differs from lesson 5.2:

NodeWhat it is
StoreThe cells: stock (end of the day), rcv (units arriving at the start of the next day), req (the request sent to the warehouse), dem (the day’s demand) and the doors lost and seen.
PolicyIf stock + rcv + req <= R, request Q. The three terms are the shelf, the shipment arriving now and the request the warehouse is filling, so the store does not ask twice for the same units.
PlaceRequestWrites the request into req (set). The warehouse reads it the next day.
Sales and CloseThe day’s sales from the shelf and the arriving shipment, with demand read from the cell dem. A store in the library has customers but does not own them: dem has no writer inside the library, and whoever imports the library writes it.
ClearReceiptsSets rcv to 0 every row. The warehouse adds its shipment into rcv in the same row. A cell takes its set value first and then adds the row’s add amounts, so the shelf sees the shipment on the next day and the cell is empty again after that. Without this node rcv would grow without bound.
DayThe row: stock at the end of the day, units lost, demand seen and the request sent (the fifth column, the zero written to rcv, is dropped with Arrange).

Run on its own, this library has no customers and no supplier, so every row is the same: the shelf stays at 40 and nothing is requested. It is a part, and its recorded output (inventory-store-lib.csv) only shows that it runs.

The system is samples/pro/inventory-warehouse.xml, 30 nodes, seed 601:

<dataset columns="aStock, aLost, aDemand, aRequest, bStock, bLost, bDemand, bRequest, warehouseStock, shipA, shipB, supplierOrder" seed="601">
  <root node="Day"/>
  <definitions>
    <declare name="corr" value="1, 0; 0, 1"/>
    <declare name="RS" value="32"/>
    <declare name="QS" value="12"/>
  </definitions>
  <nodes>
    <!-- customers: a correlated pair of daily demands, passed to the stores through the Desk -->
    <SharedState name="Desk" cells="dA=0, dB=0"/>
    <NegativeBinomial name="DrawA" r="8" p="0.5"/>
    <NegativeBinomial name="DrawB" r="8" p="0.5"/>
    <Copula name="Draws" correlation="$corr">
      <input name="DrawA"/>
      <input name="DrawB"/>
    </Copula>
    <StateWrite name="PostDraws" collaborate.state="Desk" cells="dA, dB" mode="set">
      <input name="Draws"/>
    </StateWrite>
    <StateRead name="DeskA" collaborate.state="Desk" cells="dA"/>
    <StateWrite name="ToDemandA" collaborate.state="A.Store" cells="dem" mode="set">
      <input name="DeskA"/>
    </StateWrite>
    <StateRead name="DeskB" collaborate.state="Desk" cells="dB"/>
    <StateWrite name="ToDemandB" collaborate.state="B.Store" cells="dem" mode="set">
      <input name="DeskB"/>
    </StateWrite>

    <!-- the two stores -->
    <Import name="A" file="inventory-store-lib.xml" R="$RS" Q="$QS"/>
    <Import name="B" file="inventory-store-lib.xml" R="$RS" Q="$QS"/>

    <!-- the warehouse: cells, the stores' numbers copied in, the allocation, the shelf, and the supplier -->
    <SharedState name="Hub"
                 cells="whs=72, w1=0, w2=0, w3=0, alloc=0, rw=60, qw=72, shipA=0, shipB=0, stockA=40, lostA=0, seenA=0, reqA=0, stockB=40, lostB=0, seenB=0, reqB=0"/>
    <StateWrite name="LedgerA" collaborate.state="Hub" cells="stockA, lostA, seenA, reqA" mode="set">
      <input name="A"/>
    </StateWrite>
    <StateWrite name="LedgerB" collaborate.state="Hub" cells="stockB, lostB, seenB, reqB" mode="set">
      <input name="B"/>
    </StateWrite>

    <StateRead name="ReadForA" collaborate.state="Hub" cells="whs, w3, alloc, reqA, reqB"/>
    <Calculate name="ShipA" dimension="1"
               expression="y[0] = if(x[2] == 1, if(x[3] + x[4] &lt;= x[0] + x[1], x[3], floor((x[0] + x[1]) * x[3] / (x[3] + x[4]))), min(x[3], x[0] + x[1]))">
      <input name="ReadForA"/>
    </Calculate>
    <StateWrite name="ToStoreA" collaborate.state="A.Store" cells="rcv" mode="add">
      <input name="ShipA"/>
    </StateWrite>
    <StateRead name="ReadForB" collaborate.state="Hub" cells="whs, w3, alloc, reqA, reqB"/>
    <Calculate name="ShipB" dimension="1"
               expression="y[0] = if(x[2] == 1, if(x[3] + x[4] &lt;= x[0] + x[1], x[4], floor((x[0] + x[1]) * x[4] / (x[3] + x[4]))), min(x[4], x[0] + x[1] - min(x[3], x[0] + x[1])))">
      <input name="ReadForB"/>
    </Calculate>
    <StateWrite name="ToStoreB" collaborate.state="B.Store" cells="rcv" mode="add">
      <input name="ShipB"/>
    </StateWrite>

    <StateRead name="ReadShelf" collaborate.state="Hub" cells="whs, w3"/>
    <Append name="Shelf">
      <input name="ReadShelf"/>
      <input name="ToStoreA"/>
      <input name="ToStoreB"/>
    </Append>
    <Calculate name="NewShelf" dimension="3" expression="y[0] = x[0] + x[1] - x[2] - x[3]; y[1] = x[2]; y[2] = x[3]">
      <input name="Shelf"/>
    </Calculate>
    <StateWrite name="CloseShelf" collaborate.state="Hub" cells="whs, shipA, shipB" mode="set">
      <input name="NewShelf"/>
    </StateWrite>

    <StateRead name="ReadForSupplier" collaborate.state="Hub" cells="whs, w1, w2, w3, rw, qw"/>
    <Calculate name="Supplier" dimension="3" expression="y[0] = if(x[0] + x[1] + x[2] + x[3] &lt;= x[4], x[5], 0); y[1] = x[1]; y[2] = x[2]">
      <input name="ReadForSupplier"/>
    </Calculate>
    <StateWrite name="PlaceSupplierOrder" collaborate.state="Hub" cells="w1, w2, w3" mode="set">
      <input name="Supplier"/>
    </StateWrite>
    <Arrange name="SupplierOrder" columns="0">
      <input name="PlaceSupplierOrder"/>
    </Arrange>

    <Append name="Everything">
      <input name="LedgerA"/>
      <input name="LedgerB"/>
      <input name="CloseShelf"/>
      <input name="SupplierOrder"/>
      <input name="PostDraws"/>
      <input name="ToDemandA"/>
      <input name="ToDemandB"/>
    </Append>
    <Arrange name="Day" columns="0,1,2,3,4,5,6,7,8,9,10,11">
      <input name="Everything"/>
    </Arrange>
  </nodes>
</dataset>

The parts, in the order they appear:

NodesWhat they do
Desk, DrawA, DrawB, Draws, PostDraws, DeskA, DeskB, ToDemandA, ToDemandBThe customers. Copula ties two NegativeBinomial(8, 0.5) draws together with the correlation declared as corr (the default 1, 0; 0, 1 is independent). One node feeds only one other, so the pair cannot go to the two stores directly. PostDraws writes it to the Desk store, and two readers pass one column each into the stores’ dem cells. Two cells are in the way, so the pair drawn on day n is the demand of day n + 2, and the first two days have no demand. The demand each store sees is still NegativeBinomial(8, 0.5) day after day.
A, BThe two imports. R="$RS" Q="$QS" hands the parent’s own declared values on to each import, an outer declared value passed on to an import. A parent node reaches into an import by its prefixed name: A.Store is store A’s cell store.
HubThe warehouse’s cells. whs is its shelf; w1, w2, w3 the supplier’s order on its way (three cells make the 4-day lead time); alloc is the allocation switch; rw and qw the supplier rule’s numbers (no node writes them: a cell nothing writes is a constant); shipA, shipB the day’s shipments; and the doors stockA, lostA, seenA, reqA and the same for B.
LedgerA, LedgerBCopy each store’s four output columns into the hub. The only one the warehouse needs is the request, but a StateWrite needs one cell per column, so the store’s day goes through the same door. The request written on day n is read on day n + 1.
ReadForA, ShipA, ToStoreA (and B)Read the shelf, the supplier’s arrival, the switch and both requests; compute how much goes to store A; add it into A.Store’s rcv cell. This is where the library’s set writer and the parent’s add writer meet.
ReadShelf, Shelf, NewShelf, CloseShelfThe warehouse’s shelf: the new whs is the old one plus the arrival minus both shipments.
ReadForSupplier, Supplier, PlaceSupplierOrder, SupplierOrderThe supplier rule: order qw when whs + w1 + w2 + w3 <= rw, and move the pipeline along one day.
Everything, DayThe row.

The two ship nodes are the allocation rule. With alloc = 0 store A gets min(request A, available) and store B gets min(request B, what is left). With alloc = 1, if the requests fit both are filled; if not, each gets floor(available x its request / total requests) and a leftover unit stays on the shelf. Each is one Calculate with if, min and floor, and with comparisons that give 1 or 0:

y[0] = if(x[2] == 1, if(x[3] + x[4] <= x[0] + x[1], x[3], floor((x[0] + x[1]) * x[3] / (x[3] + x[4]))), min(x[3], x[0] + x[1]))

Here x[0] + x[1] is the warehouse’s shelf plus the arriving supplier order, x[2] is the switch and x[3], x[4] are the two requests.

grind --count 365 inventory-warehouse.xml

The first ten days with the model’s seed, 601 (the columns are the shipped inventory-warehouse.csv):

DayDemand AStock ARequest ADemand BStock BRequest BWarehouse stockShipped AShipped BSupplier order
10400040072000
20400040072000
36340238072000
49250632072000
5916123291272000
61421282104812120
7150 (1 lost)1242903612072
8391272212241200
9101107150012120
104191213141272000

A request makes a three-day trip, and the table shows one. Store A’s position falls to 25 on day 4 and the request for 12 is written on day 5 (the policy read the end of day 4). The warehouse reads it on day 6 and ships: its shelf drops from 72 to 48, and the shipment lands in store A’s rcv cell. Store A’s day 7 reads rcv and sells from 2 + 12 = 14 against a demand of 15: it ends with 0 and loses 1 unit. The shipment is on the shelf for day 7, not day 6, which is why the store’s lead time, from the end of the day the policy looked at, is 3 days.

The supplier works the same way, a day longer. On day 7 the warehouse reads an end-of-day-6 position of 48 (at or below 60), writes an order of 72 into w1, and the order moves through w2 and w3. On day 10 the shelf reads w3, so day 10 starts with the 72 units and the end-of-day stock is 72. On day 9 the warehouse shipped its last 24 units (12 to each store) and ended the day at 0. Nobody had asked for more that day, so nothing went unfilled, and the supplier’s 72 arrived the next morning.

The picture follows the three shelves for 90 days of the seed-601 year.

End-of-day stock of the warehouse (a black step line that falls with the shipments and jumps by 72 when a supplier order arrives) and of store A (solid rust line) and store B (dashed blue line), for 90 days of the seed 601 year; one green triangle marks day 94, the day a request was not filled in full

Read the year of seed 601: the stores lost 27 of 2,874 units demanded at A and 22 of 2,797 at B (fill rates 99.06% and 99.21%), had 7 and 5 stockout days, and the warehouse had 1 short request in the year, on day 94, when both stores asked for 12 on day 93 and the warehouse had 12 left: A got its 12, B got none, and B lost the cover it would have had. The year is one draw. Over 200 one-year runs (seeds 1 to 200) the stores’ fill rate averages 98.17% with a standard deviation of 0.51 percentage points between years (from 96.6% to 99.5%), and the number of short requests a year averages 10.3 with a standard deviation of 4.1 (from 1 to 22). Seed 601 is a good year.

The long-run numbers come from 32 runs of 200,000 days (seeds 2000 to 2031, the first 1,000 days of each dropped), with the standard error of each mean from the 32 runs:

MeasureStore AStore BBoth stores or the warehouse
Fill rate98.46%97.84%98.15%
Stockout days a year11.40 (se 0.03)14.87 (se 0.04)13.13 per store
Average stock27.94 at the stores, 37.82 at the warehouse, 65.75 in all
Requests a year488.5 (about 244 each)
Short requests a year, units short10.85 (se 0.03), 130.2 units (se 0.4)
Supplier orders a year79.61 (se 0.01)

Store B does worse than store A, by 0.62 percentage points of fill rate and 3.5 stockout days, for no reason in the stores: they are the same store with the same demand. The cause is the order in which the warehouse serves them, which is the next section. The warehouse’s shortage costs the stores some service: a store whose warehouse is never short has a fill rate of 98.62% (exact, derived in the check below), so the shared warehouse at this policy costs the stores 0.47 percentage points of fill rate.

When the warehouse is short

The same reorder point of 60 gives the warehouse few short days, so the allocation rule hardly shows. To see it, tighten the warehouse to a reorder point of 48 (the declared value in the Hub cells, edited in a throwaway copy) and run the three rules, each for 32 runs of 80,000 days with independent demands (seeds 6000 to 6031). The third rule is the first with the two stores’ roles swapped (store B served first), written by swapping the two ship formulas.

Grouped bars of the fill rate of store A and store B under three rules at warehouse reorder point 48: A first gives 96.70 and 94.25 percent, pro rata 96.02 and 96.02, B first 94.22 and 96.68

RuleFill rate AFill rate BSystemStockout days A / BShort requests a yearUnits short a year
A first96.70% (se 0.01)94.25% (se 0.02)95.47%21.4 / 34.066.3795
Pro rata96.02% (se 0.02)96.02% (se 0.01)96.02%25.5 / 25.487.0803
B first94.22% (se 0.02)96.68% (se 0.01)95.45%34.1 / 21.566.5798

Three things stand out. A fixed order gives the first store the service and the second the shortage: the gap is 2.4 to 2.5 percentage points in either direction, and swapping the roles mirrors it (within 0.03 points). Pro rata shares the shortage evenly, as it should. And pro rata has a better system fill rate than either fixed order, by 0.55 points, at the same stock (50.3 against 50.6 units) and almost the same units short (803 against 795 a year): it has more short requests (87 against 66), but each shorts a store by less. A store with a few units on its shelf survives a small shortfall, and that is lost when one store takes the whole shortage. With the reorder point at 60 the gap shrinks (A 98.47%, B 97.83% against 98.29% and 98.28% for pro rata, system 98.15% against 98.29%) and at 72 or more the warehouse is never short and the rules agree.

What depends on the order of the nodes, and what does not

Lesson 5.2 found that where a node sits does not change a result, and the same holds here in the larger model. Two checks on 100,000 rows (seed 7). Swapping the two stores under the root Append (LedgerB first, LedgerA second) gives the same numbers with the store blocks swapped: the first row with demand is 10, 0, 7, 12, 17, 0, 10, 0, ... in the original and 17, 0, 10, 0, 10, 0, 7, 12, ... after the swap, and with the two four-column blocks put back all 100,000 rows are identical. Listing all 30 nodes of the file in reverse order also gives 0 differing rows.

The rule is different, and it is not an effect of the engine. Serving B first instead of A first is a different policy, by the table above: with the same seed, 87,280 of the 100,000 rows differ, the first one on row 30. The distinction is the useful one for this module: the engine promises that where a node sits changes nothing; what a node computes is the model, and a rule such as “A first” is part of the model whatever order the nodes are written in.

One warehouse or two

Two stores with a shared warehouse is one design. The alternative is a warehouse for each store, each half the size: the second sample, samples/pro/inventory-warehouse-split.xml, is the same stores, the same customers (the same seed gives the same demands row for row), and the same supplier lead time, with two warehouses, HubA and HubB, of half the numbers: a reorder point of 30 instead of 60, an order quantity of 36 instead of 72, 36 units to start instead of 72. A unit on A’s warehouse shelf cannot go to B. The total quantity ordered is the same; the lots are half the size, so each warehouse orders twice as often.

This comparison is where risk pooling is supposed to show. When the demands at the two stores are independent, one store’s quiet day offsets the other’s busy one, so a single warehouse needs less safety stock than two. The sum of two independent demands has a standard deviation of 1.41 times one, not 2 times. It is also the place to be careful: the model moves stock in lots of 12 (the request) and 72 (the supplier’s order), so the warehouse’s position takes values in steps, and a reorder point only changes anything when it crosses a step. Of the nine reorder points 0, 12, …, 96 swept below, the split system, whose halves have 0, 6, …, 48, has only five distinct policies.

Each system was run for the nine reorder points at four correlations (0, 0.3, 0.6, 0.9 in the copula), 20 runs of 40,000 days for each setting, with the same seeds for every setting (so differences between settings are paired). The picture plots fill rate against total average stock, stores plus warehouse, so the two systems are compared on stock and not on a reorder point whose meaning differs.

Fill rate against total average stock for the shared warehouse with independent demands (rust), with correlation 0.6 (gold) and for two half-sized warehouses (blue dashed), zoomed to 90 to 99 percent; the curves lie close together, the shared warehouse a little to the left of the two-warehouse curve

The curves are close. Read at the same stock, the shared warehouse serves a little better: to reach a fill rate of 97% the shared warehouse with independent demands needs about 59.4 units of stock in all, the shared warehouse with correlation 0.6 about 60.5, and the two half-sized warehouses about 62.1 (the standard deviation of each, from 400 bootstrap resamples of the 20 runs, is about 0.1 to 0.2 units). The saving is 2.7 units for independent demands, 1.8 for correlation 0.6, out of about 60. At 95% it is 2.6 and 2.0, at 98% 11.7 and 7.3. These are linear interpolations between grid points, and the larger numbers are interpolations across a wide gap in the split curve (its points near 98% are 29 units of stock apart), so treat them as the size of the effect, a few units to about a dozen, and not as three measured quantities. A reorder-point sweep this coarse cannot resolve more.

What the table below shows clearly is the warehouse itself. At the shared reorder point of 60 and its split equivalent, 30 for each half (independent demands, 20 runs of 40,000 days, the split numbers are exact from the check below):

SystemFill rateTotal average stockShort requests a yearSupplier orders a year
Shared warehouse, reorder point 6098.13%65.711.179.6
Two half-sized warehouses, 30 each96.64%56.546.9156.8

The shared warehouse short-changes a request 4 times less often, and orders half as often. It also holds 9 units more stock and serves 1.5 points better, so this row cannot be read as “the same stock”. The curve above is the fair view of the fill rate, and the honest summary of it is that pooling gives a modest saving in stock here, a few percent of the total, and a large saving in supplier orders and in short requests. A textbook square-root rule would predict a larger saving of safety stock than the measured one. The lots (a store asks for 12, the supplier ships 72, and the policy looks at the position once a day) take away part of the textbook case, which assumes smooth demand on the warehouse. This lesson does not isolate the cause, and the numbers are what the model gives.

Correlated demand

Pooling works because the two stores’ demands offset each other, and correlation takes that away. The split system cannot lose anything to correlation, since each half sees one store: its fill rate is flat in the correlation (at 24 per half: 96.61%, 96.60%, 96.60%, 96.60% for correlations 0, 0.3, 0.6, 0.9, with standard errors of about 0.02) and the exact Markov chain below does not depend on it. The shared warehouse sees the sum of the two demands, and the sum gets more variable. At the shared reorder point of 60 (the table is the same 20 runs of 40,000 days per column):

Demand correlation (Gaussian copula)00.30.60.9
Output correlation of the two demand columns, exact00.2920.5890.892
Output correlation measured0.0000.2920.5900.893
Fill rate, shared warehouse98.13%97.95%97.73%97.48%
Short requests a year11.115.120.026.2
Stockout days a year, per store13.314.315.516.9
Average total stock65.765.164.463.4

The copula’s correlation is that of the underlying normal variables, not of the demands: a Gaussian correlation of 0.6 gives 0.589 between two negative binomial columns, exact from the integral derived in the check below. A correlation of 0.6 makes the warehouse short 1.8 times as often (20.0 short requests a year against 11.1) and takes 0.40 points off the fill rate; at 0.9 it is 2.4 times as often. At a reorder point of 60 the shared warehouse is still better than the two halves (96.6%) at every correlation tried, though not by the margin it had. The interpolated stock saving at 97% falls from 2.7 units to 1.8 at 0.6 (and at 98% from 11.7 to 7.3). Pooling is worth most when the stores’ demands are unrelated, and worth less when a rainy day empties both shelves at once.

Check: do the numbers match the math?

What can be exact here, and what cannot.

A store with a never-short warehouse is the store of lesson 5.2. Start the warehouse with 10,000,000 units and no supplier orders (the Hub cells whs=10000000, rw=-1, in a throwaway copy). Every request is then shipped in full, and each store reduces to the Markov chain of the lesson 5.2 copy: the state (stock, shipment arriving, request waiting) with the policy stock + arriving + waiting <= 32, and 132 states. Its stationary answer is a fill rate of 98.621%, 10.459 stockout days a year, an average stock of 14.366 and 239.98 requests a year. Over 32 runs of 200,000 days (seeds 5000 to 5031) store A’s fill rate is 98.618% (se 0.004, z -0.92) and its stockout days 10.49 (se 0.03, z 1.29); store B’s are 98.620% (z -0.51) and 10.45 (z -0.45); the average stock of the two stores is 14.369 (z 0.94) and the requests a year 239.97 (z -0.25). There are no short requests and no supplier orders, as there should not be.

The split system is two copies of one chain. Each half is one store, one warehouse and one supplier, and sees one demand with the negative binomial distribution whatever the correlation is, so its measures are those of a single Markov chain whose state is (stock, shipment arriving, request waiting, warehouse stock, three supplier-order cells): from 630 to 1,230 reachable states for the nine reorder points. The standard library computes all nine stationary distributions in under a minute. The split model’s 20 runs of 40,000 days are compared with these chains in the script: 127 distinct comparisons of a measured value with its exact one (fill rate, stockout days, short requests, units short, stock at the store and at the warehouse, supplier orders, requests). The largest |z| is 2.69 and none is beyond 3, but 19 are beyond 2 where about 6 would be expected from chance. The comparisons are not independent (store A’s half is the same run at all four correlations, and the eight measures of a run are related), the standard errors come from only 20 runs, and the signs are mixed (55 positive, 72 negative), so this reads as sampling noise with optimistic standard errors; no pattern was found by measure or by reorder point that points to a fault, and the sharper comparison with 32 long runs in the never-short limit above is within 1.3 standard errors everywhere. The exact values for the reorder point 30 per half are a fill rate of 96.635%, 21.85 stockout days a year per store, 23.45 short requests a year per warehouse and 78.38 supplier orders a year per warehouse; the average stock is 12.63 at the store and 15.61 at the warehouse.

The accounting identities hold exactly. In the seed-601 year, store A starts with 40, receives 2,820 units in rows 1 to 364 and sells 2,847, which leaves 13: the stock at the end of day 365 is 13. Store B: 40 + 2,748 - 2,775 = 13, and it is 13. The warehouse: 72 + 5,544 units arrived (the orders of rows 1 to 362, each arriving 3 rows after it was placed) - 5,592 shipped = 24, and the shelf ends at 24. The requests of rows 1 to 364 add to 5,604 units and the shipments of rows 2 to 365 to 5,592: the 12 units not shipped are the one short request on day 94.

An independent implementation reproduces every cell. The script re-implements the rules (the stores, the warehouse, the supplier and the allocation) in a few dozen lines of plain Python, takes only the demand columns from a Grind run and replays the system. For the fixed rule, the pro rata rule, the B-first rule and a pro rata run at reorder point 36, each of 100,000 rows (1,200,000 cells), no cell differs; for the split model (1,400,000 cells) none differs. This is the check of the model against its description.

The demands are what they should be. The marginal demand of each store has mean 7.997 and 8.001 over 4 million days (exact 8). The correlation of the two columns, from the exact integral of the bivariate normal over the cells of the negative binomial’s distribution function, is 0.29183, 0.58932 and 0.89248 for Gaussian correlations of 0.3, 0.6 and 0.9. Measured over 20 runs of 100,000 days: 0.29174 (z -0.10), 0.58919 (z -0.19) and 0.89252 (z 0.23).

What is not exact. The shared warehouse when it is short has no exact answer here. Its state is both stores’ states and the warehouse’s, with a joint demand distribution (the copula) over a 75 by 75 grid of outcomes, which is far more than the single-store chains. It could be done, but not in a lesson’s script. The numbers of the shared warehouse with a short warehouse rest on the checks above (the limits it reduces to, the identities and the replay), on the size of the standard errors, and on the one-year runs agreeing with the long runs (fill rate 98.17% over 200 years against 98.15% over the long runs; the years include the start-up). The stock saving of pooling rests on a coarse grid and linear interpolation, said above.

What the model leaves out

A request is never remembered: a short shipment does not become a backorder, and the warehouse never ships ahead. Orders and shipments arrive whole and on time, the supplier’s lead time is fixed at 4 days, and nothing is ever damaged or late. The two stores have the same policy and the same demand, and a real chain would tune them separately. There are no costs, no transport cost and no shipping time that depends on volume. Demand is independent from one day to the next, and the correlation is between the stores on the same day only. The warehouse looks at its position once a day and decides from yesterday’s state, like every loop through a cell. Lesson 5.5 puts costs on all of it.

What this gives you: one store written once as a library and imported twice (declare for the policy numbers, Import with forwarded overrides, StateWrite with mode="add" adding a shipment into an imported store’s cell next to the library’s own set writer); a warehouse that is a set of cells, with an allocation rule written as one Calculate with if, min, floor and comparisons; and a demand desk that ties the two stores together with a Copula. The measured effects: the order of service moves 2.4 points of fill rate between two identical stores when the warehouse is short, and pro rata shares it and serves the system 0.55 points better; one warehouse needs a few percent less stock than two half-sized ones for the same service, orders half as often and is short a quarter as often at the same reorder point, and correlated demand takes much of that away (a correlation of 0.6 makes it short 1.8 times as often). The numbers that can be exact are: the never-short limit matches the chain of the store to within 1.3 standard errors; the split system matches its chains; the accounting identities hold to the unit; and an independent implementation reproduces the model cell for cell. The companion page lets you pick the system, the correlation and the warehouse reorder point.

The system behaves, and it is open loop in one respect: the stores’ demand does not care what happens at the warehouse. Lesson 5.4 closes a second loop. When the warehouse is short the price goes up, and demand responds to the price through the same shared cells. The question is whether the system settles at a price or swings around it.