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 traces the exchange curve of the utility storeroom of Chapter 4: nine items, from the $3,800 pad-mount transformer to a $2.10 roll of warning tape, each with an ordering cost set by the hours its orders take at $55 an hour. Every policy on the curve orders each item in its economic quantity at some price \(\theta\) on the money tied up in stock. Move \(\theta\) and watch the storeroom trade cycle stock against ordering work.
At a price \(\theta\) the quantities are \(Q_j = \sqrt{2k_j\lambda_j/(\theta c_j)}\), and with \(S = \sum_j \sqrt{k_j c_j \lambda_j}\) the two aggregates are
so every point on the curve has the same product. The storeroom’s own carrying charge, \(\gamma = 0.25\), is the point it operates at. 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 theta = Inputs.range([0.02,2], {step:0.005,value:0.25,label:"Price on investment, θ (a year)"})resetButton([viewof theta])
{const dollars = x =>"$"+Math.round(x).toLocaleString("en-US");const rows = storeroom.map(it => {const Q =Math.sqrt(2* it.k* it.lambda/ (theta * it.c));return [it.label, Q.toFixed(1),dollars(it.c* Q /2),dollars(it.k* it.lambda/ Q), (it.lambda/ Q).toFixed(1)]; });const I = curve.investmentAt(theta), OC = curve.orderingAt(theta);returnhtml`<table class="table table-sm" style="max-width: 46rem; font-size: 0.9rem"> <thead><tr><th>Item</th><th>Q</th><th>Cycle stock</th><th>Ordering a year</th><th>Orders a year</th></tr></thead> <tbody>${rows.map(r =>html`<tr>${r.map(x =>html`<td>${x}</td>`)}</tr>`)}</tbody> </table> <p>At θ = ${theta.toFixed(3)} the storeroom holds <strong>${dollars(I)}</strong> of cycle stock and spends <strong>${dollars(OC)}</strong> a year on ordering, ${Math.round(OC / kappa)} hours of order handling at $${kappa} an hour. It holds ${(I / OC).toFixed(2)} dollars of stock for every dollar a year of ordering, which is 1/θ. The product is ${(I * OC).toExponential(4)}, the same at every θ.</p>`;}
The plot is the curve itself, investment against ordering cost. The gray square is the storeroom’s own carrying charge, \(\theta = 0.25\); the red dot is your price. Notice the shape: near either end a small gain on one axis costs a great deal on the other.
Plot.plot({style: plotStyle,height:300,marginLeft:80,marginBottom:45,x: {label:"Ordering cost a year ($)",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Average cycle stock ($)",grid:true},marks: [ Plot.line(d3.range(0,201).map(j => {const t =0.02*Math.pow(100, j /200);return {oc: curve.orderingAt(t),inv: curve.investmentAt(t)};}), {x:"oc",y:"inv",stroke: theme.primary,strokeWidth:1.5}), Plot.dot([{oc: curve.orderingAt(0.25),inv: curve.investmentAt(0.25)}], {x:"oc",y:"inv",r:6,symbol:"square",fill: theme.muted}), Plot.dot([{oc: curve.orderingAt(theta),inv: curve.investmentAt(theta)}], {x:"oc",y:"inv",r:6,fill: theme.accent}) ],ariaLabel:"The exchange curve of the storeroom",ariaDescription:`At θ = ${theta.toFixed(3)} the storeroom holds $${Math.round(curve.investmentAt(theta))} and spends $${Math.round(curve.orderingAt(theta))} a year on ordering.`})
Things to Try
Start at \(\theta = 0.25\), the storeroom’s carrying charge: $27,939 of cycle stock against $6,985 a year of ordering, or 127 hours of a storekeeper’s time. That is four dollars of stock for every dollar of ordering, \(1/0.25\).
Halve the carrying charge to 0.125. The stock rises to $39,512 and the ordering falls to $4,939, 90 hours. The product of the two has not moved.
Set \(\theta = 1\). Stock and ordering are equal, at $13,970 each.
Read the transformer’s row at any \(\theta\). It alone accounts for 6,134 of the 19,756 in the sum \(S\), which is why the nine items behave in aggregate like 5.68 identical ones, the chapter’s variety index.