Explore: Splitting Transformers Between the Levels
Chapter 10, Multi-Echelon Inventory Systems
theme = Generators.observe(notify => {const read = () => {const css =getComputedStyle(document.body);const v = (name, fallback) => (css.getPropertyValue(name).trim() || fallback);return {dark:document.body.classList.contains("quarto-dark"),fg:v("--bs-body-color","#212529"),bg:v("--bs-body-bg","#ffffff"),muted:v("--bs-secondary-color","#6c757d"),grid:v("--bs-border-color","#dee2e6"),primary:v("--bs-link-color","#0d6efd"),accent:v("--bs-danger","#dc3545"),good:v("--bs-success","#198754") }; };// Quarto swaps stylesheets when the theme changes, and the new variables apply only once// the stylesheet has loaded; read them again shortly after, and keep the last reading.let last ="";const emit = () => {const t =read();const key =JSON.stringify(t);if (key !== last) { last = key;notify(t); } };const update = () => { emit();setTimeout(emit,100);setTimeout(emit,400); };update();const observer =newMutationObserver(update); observer.observe(document.body, {attributes:true,attributeFilter: ["class"]});return () => observer.disconnect();})
plotStyle = ({// "inherit" takes the page's text color directly, so axes and labels follow a theme// switch even before the plot redraws.color:"inherit",background:"transparent",fontSize:"13px",overflow:"visible"})
themedButton = (label, counterLabel =null) => {const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`;// The counter shows which run is on screen, so every press visibly does something and a// reader can tell runs apart. It reads 1 at page load and after Reset.const counter = counterLabel?html`<span class="bisc-run-counter" aria-live="polite"></span>`:null;const form =html`<form class="bisc-explorer-control">${button}${counter ||""}</form>`;const show = () => { if (counter) counter.textContent=`${counterLabel}${form.value+1}`; }; form.value=0;show(); button.onclick= () => { form.value+=1; form.dispatchEvent(newEvent("input", {bubbles:true})); };// Reset sets the value back to 0 and dispatches input; refresh the counter either way. form.addEventListener("input", show);return form;}
resetButton = (controls, label ="Reset to the starting values") => {// This runs once per page, because the cell that calls it depends on the controls// themselves (viewof), not on their values; so these are the values at page load.const start = controls.map(c => c.value);const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`; button.onclick= () => { controls.forEach((c, k) => { c.value= start[k]; c.dispatchEvent(newEvent("input", {bubbles:true})); }); };returnhtml`<div style="margin: 0.5rem 0">${button}</div>`;}
// A small seeded generator (mulberry32), so a run can be repeated.makeRandom = (seed) => {let a = seed >>>0;return () => { a = (a +0x6D2B79F5) >>>0;let t = a; t =Math.imul(t ^ (t >>>15), t |1); t ^= t +Math.imul(t ^ (t >>>7), t |61);return ((t ^ (t >>>14)) >>>0) /4294967296; };}
This explorer builds the efficient curve of Chapter 10 for the utility’s transformer: for every total number of transformers bought, the split between the depot and the four storerooms that leaves the fewest crews waiting. Choose a total and see every way of holding it; read the curve and find where it stops being convex.
The split is found as the code finds it. For each depot level, every storeroom starts empty and each further unit goes to the storeroom whose next unit removes the most backorders, \(P\{X_j > S_j\}\); the best depot level for a total is the one with the least backorders at the storerooms. A total whose point lies above the line joining its neighbors on the curve is struck out, and the procedure buys two at once across it. That is convexification. The page runs in your browser and records nothing. Its formulas are a restatement in JavaScript of the book’s code, and they are tested against that code.
The Curve
viewof total = Inputs.range([0,30], {step:1,value:13,label:"Transformers in all"})viewof model = Inputs.select(newMap([["VARI-METRIC",false], ["METRIC",true]]), {value:false,label:"Model"})resetButton([viewof total, viewof model])
{const n = x => x.toFixed(4);const spread = levels => levels.slice(1).join(", ");const allAtDepot = ways.find(w => w.depot=== total);returnhtml`<p>The best way to hold <strong>${total}</strong> transformers puts <strong>${pick.depot}</strong> at the depot and${spread(pick.levels)} at the four storerooms, leaving ${n(pick.backorders)} backorders at the storerooms.${pick.depot< total ?`Holding all ${total} at the depot would leave ${n(allAtDepot.value)}, which is ${n(allAtDepot.value- pick.backorders)} more.`:"Every unit sits at the depot."}${total >0? (pick.kept?"This total is on the convex curve.":`<strong>This total is struck out:</strong> its point lies above the line joining its neighbors, so the procedure never stops here.`) :""}</p> <div style="max-height: 22rem; overflow-y: auto; max-width: 30rem"> <table class="table table-sm"> <thead><tr><th>S₀</th><th>Storerooms</th><th>Backorders</th></tr></thead> <tbody>${ways.map(w =>html`<tr style="${w.depot=== pick.depot?"font-weight: 600":""}"><td>${w.depot}</td><td>${w.levels.join(", ")}</td><td>${n(w.value)}</td></tr>`)}</tbody> </table></div> <p>Each row holds ${total} transformers, with the depot at S₀ and the rest spread by the rule above; the bold row is the best. ${model ?"":"Notice that the backorders fall and then rise as units move forward: past the best split, the depot's delay costs more than the forward units save."}</p>`;}
The first plot is the curve: the least backorders for each total. A blue dot is kept by convexification and a red ring is struck out; the large red ring is your total.
Plot.plot({style: plotStyle,height:260,marginLeft:60,marginBottom:45,x: {label:"Transformers in all",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Backorders at the storerooms",grid:true},marks: [ Plot.line(built.hull.filter(p => p.total<=30), {x:"total",y:"backorders",stroke: theme.primary,strokeWidth:1}), Plot.dot(built.points.slice(0,31).filter(p => p.kept), {x:"total",y:"backorders",r:3,fill: theme.primary}), Plot.dot(built.points.slice(0,31).filter(p =>!p.kept), {x:"total",y:"backorders",r:4,stroke: theme.accent,fill:"none",strokeWidth:1.5}), Plot.dot([pick], {x:"total",y:"backorders",r:7,stroke: theme.accent,strokeWidth:2,fill:"none"}) ],ariaLabel:"The efficient curve of the transformer",ariaDescription:`Struck out: ${built.points.slice(0,31).filter(p =>!p.kept).map(p => p.total).join(", ")}.`})
The table below is the curve for totals 10 to 21, as the chapter prints it. Read the Reduction column for an increase: where the reduction rises, the total above it is struck out.
Start at 13 transformers under VARI-METRIC. The best split is 9 at the depot and one at each storeroom, leaving 15.6433 backorders, against 15.6584 with all thirteen at the depot. Notice that the backorders fall as the first four units move forward and rise at the fifth.
Read the curve from 10 to 21. The reduction rises from 0.9850 at 12 to 0.9870 at 13, and from 0.8559 at 20 to 0.8627 at 21, so totals 12 and 20 are struck out.
Choose 12, then 13. The best depot level falls from 12 to 9 as the total rises by one: adding a unit to the system takes three units out of the depot.
Switch to METRIC. Its best split of 12 is 8 at the depot and one at each storeroom, where VARI-METRIC holds all 12 at the depot, and it strikes out 12, 19 and 26 instead of 12 and
The two models choose different plans, not only different numbers for the same one.
Check What You Found
Check what you found
1. On the transformer’s efficient curve the twelfth unit removes 0.9850 backorders and the thirteenth removes 0.9870, and convexification strikes out the total of 12. What does that mean for a planner buying one unit at a time?