Designing the pack
How many pack types, which size mix, which goes to which store? Units in the wrong size, a full scan of the seventy candidates, the warehouse limit, the curve of the number of pack types, and how the size profiles relate to the sales-mix clusters.
Size and Pack · 4 / 6
The last article gave every store a size curve. In this article we use those curves to design the packA sealed pack of sizes mixed in a fixed ratio. At Lumoda seven units, 1-2-2-1-1 in size order; six for one-size accessories. Cheap to pick, but it does not fit size needs exactly. (the prepack, or ratio pack). There are three decisions: how many pack types to build, how many units of each size go into each type, and which type goes to which store. And there is a limit: how much stock of each size the warehouse holds.
The code again comes from the working code under cases/size-and-pack/, the
numbers from the case’s report. In the code a pack type’s size content is
called a pattern, and the number of pack types K. A pack pattern is five
numbers such as 1-2-2-1-1: the units, in size order.
Three decisions and a limit
The quantity of stock does not change in this series. Every store gets as many packs of every option as it got in Lumoda’s first allocation; only the inside of the pack changes. We will open that up in the fifth article as “the same stock”. For the design it means this: how many packs each store gets is known from the start, and that number is the store’s weight in the design. If the pack of a store that gets many packs is wrong, the error is large too.
The pack is seven units. We counted in the first article: there are 330 ways to split seven units across five sizes. We require the three middle sizes to be in every pack with at least one unit. If a pack carries none of those three, it reaches the store as a broken set; the customer cannot find one of the middle sizes on the rail. With that condition 70 candidates are left:
# size_and_pack/pack_design.py
def candidates(units: int = constants.PACK_UNITS) -> np.ndarray:
B = constants.SIZE_COUNT
core = np.zeros(B, dtype=np.int64)
core[[b - 1 for b in constants.CORE_SIZES]] = 1
rest = units - int(core.sum())
if rest < 0:
raise ValueError(f"the core sizes do not fit into a pack of {units} units")
rows = []
for bars in combinations(range(rest + B - 1), B - 1): # stars and bars
edges = (-1,) + bars + (rest + B - 1,)
rows.append(tuple(edges[i + 1] - edges[i] - 1 for i in range(B)))
return np.array(sorted(rows), dtype=np.int64) + core
One unit is placed in each of the three middle sizes first; the remaining four units are spread across the five sizes in every possible way. For a twelve-unit pack the same function produces 715 candidates.
Units in the wrong size
How well does a pack fit a store? In the first article Pars put it in units: how many of the pack’s units sit in the wrong size against the store’s curve?
# size_and_pack/pack_design.py
def mismatch(pack, curve_row, weight: float = 1.0) -> float:
"""Expected shortfall in units: weight × Σ_b max(0, a × curve_b − pack_b), a = the pack's
units (module note)."""
p = np.asarray(pack, dtype="float64")
e = np.asarray(curve_row, dtype="float64")
return float(weight * np.round(np.maximum(0.0, p.sum() * e - p).sum(), 12))
The store’s curve says how much of the seven units it wants in each size. A store with a large profile wants more than two of the seven units in the fourth size, and Lumoda’s pack carries one; the difference is the units missing from that size. Adding up the shortfall across all sizes gives the pack’s expected shortfall in units. Shortfall and excess balance each other: every unit missing from one size sits in excess in another. So the same number is the number of units in the wrong size.
“Is that different from the L1 distance in the first article?” says Ali.
“It ranks the same way,” says Pars. “The shortfall in units is the pack’s units times half the L1 distance. Both tell you which of two packs is better. But units add up: multiply by the store’s number of packs, add across all the stores, and I’ve got the stock sitting in the wrong size in the chain’s initial allocation.”
We chose the measure before seeing the results and did not change it. The code’s note gives one more reason: log-based measures are undefined for a pack that puts no units in the first or the fifth size.
All seventy candidates
A design with K types means choosing K of the 70 candidates. Once the types are chosen the assignment is easy: each store takes, of those types, the one that leaves the smallest shortfall against its own curve. The hard part is choosing the types. With a seven-unit pack it is possible to try every option one by one:
# size_and_pack/pack_design.py
def _sets(C: np.ndarray, K: int):
"""Every K-set of candidates in lexicographic order, chunk by chunk: (sets [c, K],
unconstrained total [c])."""
CT = C.T
it = combinations(range(C.shape[1]), K)
while True:
block = np.fromiter(chain.from_iterable(islice(it, _CHUNK)), dtype=np.int64)
if block.size == 0:
return
block = block.reshape(-1, K)
yield block, CT[block].min(axis=1).sum(axis=1)
def _full(C: np.ndarray, K: int) -> np.ndarray:
"""A full scan of every K-set of candidates (lexicographic order); the best set [K]."""
best, chosen = np.inf, None
for block, total in _sets(C, K):
low = total.min()
if chosen is None or not _le_tol(best, low):
i = int(np.flatnonzero(total <= low + _TIE * max(1.0, abs(low)))[0])
best, chosen = float(total[i]), block[i]
return chosen
C is a table: for every store, every candidate’s shortfall in units,
multiplied by the store’s number of packs. A set of candidates is worth the
sum, over the stores, of each store’s best candidate in that set. _sets
produces every K-set in turn, _full keeps the one with the smallest total.
On a tie the first set in lexicographic order stays; the same input always
gives the same design.
How many sets are scanned? The code’s note says:
size_and_pack/pack_design.py (module note)
… For a 7-unit pack at K = 4 that is C(70, 4) = 916,895 sets: a full search, `is_optimal = True`.
When the number of sets exceeds `FULL_SEARCH_LIMIT` (e.g. K = 3 for a 12-unit pack) the search
alternates …, `is_optimal = False`.
# size_and_pack/pack_design.py
FULL_SEARCH_LIMIT = 2_000_000 # the most candidate sets a full search scans
A twelve-unit pack has 715 candidates, and the number of three-type sets is far beyond this limit. There the code switches to an alternating search: choose the types, assign every store to its best type, replace each type with the candidate that best fits its own stores, and carry on until nothing changes. It resembles the k-means of Store Grouping. This search cannot prove on its own that it has found the best. But there is a lower bound: the store-specific design, in which every store takes its own best pack out of the 715 candidates. No design with K types can beat it. If the alternating search reaches that bound, it has found the best. With a twelve-unit pack it reaches it at three types.
The code counts one more thing: the types actually used. If you ask for four types and find that three are enough, the design comes back with three types. Why that matters will show in the results shortly.
The warehouse
However good the packs, they cannot send stock that is not in the warehouse. This is the design’s last condition:
size_and_pack/pack_design.py (module note)
Σ_m w_m × p_{a(m), b} ≤ dc_share_b × a × Σ_m w_m
that is, `dc_share_b` = units of size b in the DC / total units shipped in the initial allocation
(a × Σ w); its total may exceed 1 (stock left in the DC).
# size_and_pack/pack_design.py (design)
dc_feasible = dc_excess = None
if dc_share is not None:
cap = dc_share * units * w.sum()
if _excess(w, A, choice, cap).any():
method = "mip"
choice, optimal = _constrained(C, w, A, cap, set_k, seed)
dc_excess = _excess(w, A, choice, cap)
dc_feasible = not dc_excess.any()
In every size the units going to the stores may not exceed the units in the warehouse (the DC, in the code). The search first finds the best unconstrained design. If that design fits the warehouse the job is done, because the limit can only make a design worse. If it does not, the search switches to a mixed integer model: first it minimises the units over the warehouse, then, with that excess, the units in the wrong size.
How do we know the stock in the warehouse? At decision time we have the size quantities of the initial order. Part of the stock fails quality control on delivery and is written off; but most deliveries arrive after the decision day. So the design is built from the order quantities known at decision time; the warehouse net of faulty stock is used only to check afterwards. In this data the two definitions give the same designs.
In the first size the warehouse is right at the limit. Against the units the seven-unit pack ships, the first size’s warehouse share is 0.1454 by the order and 0.1429 once faulty stock is written off; that is, one in seven. Every one of Lumoda’s packs carries one unit of the first size, and the warehouse holds exactly that much stock of that size. All the seven-unit designs also put one unit of the first size in every pack; they fill the warehouse exactly, without going over.
In this data the warehouse limit binds in no design; the best unconstrained design fits the warehouse anyway. Still, there is an example that shows what the limit looks like. Had we wanted to make Lumoda’s pack twelve units, we would have had to put two units in the first size: two in twelve, 0.1667. Against the units the twelve-unit arms ship, the warehouse gives 0.1428; again about one in seven. That pack cannot be built. We will come back to what this means in the fifth article.
We apply the limit to the total of all the options, not option by option. The cost: the warehouse may fall short in a single option. Before the simulation an option-by-option check is made; in no design does even one of the 193 options go over.
How many pack types
Now the real question. The report prints the best design for each K and the shortfall in units per pack:
| Pack | Types | Patterns | Shortfall per pack (units) |
|---|---|---|---|
| 7 units | Lumoda | 1-2-2-1-1 | 0.9487 |
| 7 units | 1 | 1-1-2-2-1 | 0.8533 |
| 7 units | 2 | 1-1-2-2-1 + 1-2-2-1-1 | 0.5835 |
| 7 units | 3 | 1-1-2-2-1 + 1-2-2-1-1 | 0.5835 |
| 7 units | 4 | 1-1-2-2-1 + 1-2-2-1-1 | 0.5835 |
| 7 units | store-specific | 1-1-2-2-1 + 1-2-2-1-1 | 0.5835 |
| 12 units | 1 | 1-3-4-3-1 | 1.3146 |
| 12 units | 2 | 1-2-4-3-2 + 2-3-4-2-1 | 0.6826 |
| 12 units | 3 | 1-2-3-4-2 + 1-3-4-3-1 + 2-3-4-2-1 | 0.5484 |
| 12 units | 4 | 1-2-3-4-2 + 1-3-4-3-1 + 2-3-4-2-1 | 0.5484 |
| 12 units | store-specific | 1-2-3-4-2 + 1-3-4-3-1 + 2-3-4-2-1 | 0.5484 |
Apart from Lumoda’s row, every design is provably the best.
With the seven-unit pack the gain stops at the second type. Three types, four types, even every store’s own best pack: all of them give the same two patterns.
“What if I asked for four types?” says Pelin.
“You’d still get two,” says Pars. “I picked each of the 69 stores its own best pack. Only two different packs came out.”
The reason is the coarseness of seven units. The medium profile’s curve and the large profile’s are clearly apart, but brought down to seven units both have the same best pack: 1-1-2-2-1. The difference between them is less than one unit and does not fit into the pack. The two-type design splits the stores like this:
| Profile \ pack | 1-1-2-2-1 | 1-2-2-1-1 |
|---|---|---|
| Large | 28 | 0 |
| Medium | 22 | 0 |
| Small | 0 | 19 |
60.2% of the packs are 1-1-2-2-1, 39.8% 1-2-2-1-1.
“The stores leaning towards small sizes get our pack,” says Pelin. “The pack we’ve used for years.”
“It isn’t a bad pack,” says Pars. “It just goes to every store.”
With the twelve-unit pack the shares get finer and each profile gets its own pack: 1-2-3-4-2 for the large profile, 1-3-4-3-1 for the medium, 2-3-4-2-1 for the small. The store-specific design also stays with these three patterns; a fourth type adds nothing. If a single type is asked for, the medium profile’s pack goes to the whole chain.
The table’s last column cannot be compared directly between the two pack sizes: in a twelve-unit pack there are more units to sit in the wrong size, too. To compare, you need to look at the size shares the pack carries. The table below is the distance from the size share of the stock going to the stores to two curves: the mean L1, weighted by the number of packs the store gets. The first column uses the answer key, the second the curve estimated in the last article.
| Pack | To true demand | To the estimated curve |
|---|---|---|
| Lumoda 1-2-2-1-1 | 0.2544 | 0.2711 |
| One type, 7 units | 0.2372 | 0.2438 |
| Two types, 7 units | 0.1634 | 0.1667 |
| One type, 12 units | 0.2210 | 0.2191 |
| Two types, 12 units | 0.1217 | 0.1138 |
| Three types, 12 units | 0.1085 | 0.0914 |
Two things stand out. First, on this design measure the number of pack types does more work than the size of the pack: two seven-unit types are much closer than a single twelve-unit type. Second, even the best design is 0.1085 from true demand. A pack carries an average; it never sits exactly on a store’s own curve.
Let me give a warning now. The figures here are a design measure, not the rail itself, and the simulation turns the first observation upside down. A single twelve-unit type beats two seven-unit types on all three measures of the first four weeks, and on the season’s gross profit as well. In the first four weeks the size-loss share is 48.46% against 56.48%, availability 97.09% against 96.64%; gross profit TRY 541,634,844 against TRY 540,277,650. With the twelve-unit pack, three pack types clearly gain on the design measure against a single type, but they do not reduce the size loss of the first four weeks; they raise it slightly. In the fifth article we will state each gain by its own measure.
Nor did we put the cost of a pack type into the design. The supplier has a separate filling instruction for each type, the warehouse a separate location for each type; these vary from chain to chain, and shown with a made-up number they would mislead. The table leaves the curve to the reader: is what the second type brings more than your cost?
How accurate is the assignment
The design assigns the stores by the estimated curve. How much would the assignment change if the answer key were known? We kept the two-type design’s patterns and reassigned every store by its true demand.
Only one store changes place: Izmir 2. We saw it in the last article; having no curve, it took the large profile and was assigned 1-1-2-2-1. By its true demand it should have got 1-2-2-1-1. Against true demand the units in the wrong size fall from 66,440.6 to 64,833.8, −2.4%. Izmir 2 gets 2.1% of the packs. All 68 stores whose curve can be read are already in the right pack. So we did not run an arm assigned by the answer key separately in the simulation; the difference is a single store.
Size and sales mix
We split the stores into three groups by size profile. In the Store Grouping series we split the same stores into five clusters by sales mix. Do the two groupings resemble each other?
“If they do, our job’s easy,” says Veli. “Pelin builds the plan by cluster; we’ll build the pack by cluster too.”
| Size profile \ sales cluster | 0 | 1 | 2 | 3 | 4 | Total |
|---|---|---|---|---|---|---|
| Large | 11 | 5 | 3 | 7 | 2 | 28 |
| Medium | 11 | 2 | 4 | 2 | 3 | 22 |
| Small | 11 | 1 | 0 | 5 | 2 | 19 |
They do not. The largest sales cluster, cluster 0, has 11 stores from each of the three profiles. The ARI of the two groupings is −0.014. We count an ARI whose absolute value is below 0.05 as independent; we set that line for the narrative. What a store sells and which size its customers wear are, at Lumoda, two separate questions.
In the fourth article of the Store Grouping series, when we added the size curve and seasonality to the sales mix, the clusters moved away from the answer key. In that article we said these two blocks split on something other than the customer profile. This table shows that the size curve is independent of the sales mix; most likely one of the things pulling the clusters apart was the size axis itself.
“So two separate labels,” says Pars. “A store’s plan comes from its sales cluster, its pack from its size profile. Put one in place of the other and you spoil both.”
What is hard in your data
The first is the cost of a pack type. How many types will the supplier agree to, and what does each type cost the warehouse to handle? In this article we priced neither. In your chain those two numbers decide where on the curve to stop.
The second is size sets. At Lumoda a store takes the same pattern in every size set, because in the data’s design a store’s shift does not depend on the category. That is also why the number of pack types is the number of patterns shared across all the sets. In reality a store’s jeans curve and its T-shirt curve may differ. Then the number of types multiplies by the number of sets, and each set’s design is built with fewer stores.
The third is the warehouse. In this data the limit did not bind, and we applied it to the total. In a chain whose buy changes option by option, the warehouse may not carry the size the pack wants in some options; the design should then be built per option.
The fourth is having no answer key to measure against. Here we could test the accuracy of the assignment with the key, and saw that only the new store was wrong. You will have the distance to the estimated curve; and that is only as good as the curve.
In the next article we send these packs into the world of Initial Allocation: the same stock, the same stores, only different packs. What changes on the rail?