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 runs METRIC and VARI-METRIC side by side on the utility’s transformers of Chapter 10. Four storerooms alike each see \(\lambda_j = 45\) failures a year, rebuild \(\phi_j = 0.3\) of them locally in \(T_j = 30\) days, and wait \(O_j = 10\) days for a unit shipped from the depot. The depot repairs what it receives in \(T_0\) days. Move the depot’s stock and watch the delay it imposes reach every storeroom at once; move a storeroom’s stock and watch the two models part company.
Recall the chain. The depot sees \(\lambda_0 = \sum_j (1-\phi_j)\lambda_j\), its pipeline is Poisson with mean \(\mu_0 = \lambda_0 T_0\), its backorders give the delay by Little’s Law, and the delay enters each storeroom’s pipeline:
METRIC takes the storeroom’s pipeline to be Poisson at that mean. VARI-METRIC adds its variance, with \(f_j = (1-\phi_j)\lambda_j/\lambda_0\) the storeroom’s share of the depot’s requests,
and fits a negative binomial to the two moments. 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. For a system of your own, use the general explorer.
The Two Levels
viewof S0 = Inputs.range([0,30], {step:1,value:16,label:"Depot stock, S₀"})viewof Sj = Inputs.range([0,10], {step:1,value:4,label:"Stock at each storeroom, Sⱼ"})viewof T0days = Inputs.range([30,90], {step:5,value:60,label:"Depot repair time, T₀ (days)"})resetButton([viewof S0, viewof Sj, viewof T0days])
{const d = metricRun.depot, m = metricRun.stores[0], v = variRun.stores[0];const n = (x, k =4) => x.toFixed(k);const rows = [ ["Depot demand rate, λ₀ (a year)",n(d.lambda0,1),n(d.lambda0,1)], ["Depot pipeline, μ₀",n(d.mu0),n(d.mu0)], ["Depot backorders, B̄₀",n(d.B0),n(d.B0)], ["Variance of depot backorders","not used",n(d.varB0)], ["Delay, W̄ (days)",n(365* d.W,2),n(365* d.W,2)], ["Storeroom pipeline mean, μⱼ",n(m.mean),n(v.mean)], ["Storeroom pipeline variance, σⱼ²",n(m.mean),n(v.variance)], ["Family", m.dist.family, v.dist.family], ["Backorders at one storeroom, B̄ⱼ",n(m.B),n(v.B)], ["On hand at one storeroom, Īⱼ",n(m.I),n(v.I)], ["Ready rate at a storeroom",n(m.readyRate),n(v.readyRate)], ["Backorders at all four storerooms",n(metricRun.storeroomBackorders),n(variRun.storeroomBackorders)] ];const ratio = variRun.storeroomBackorders/ metricRun.storeroomBackorders;returnhtml`<table class="table table-sm" style="max-width: 40rem"> <thead><tr><th>Quantity</th><th>METRIC</th><th>VARI-METRIC</th></tr></thead> <tbody>${rows.map(r =>html`<tr><td>${r[0]}</td><td>${r[1]}</td><td>${r[2]}</td></tr>`)}</tbody> </table> <p>VARI-METRIC reports ${Math.abs(ratio -1) <5e-5?"the same backorders as METRIC":`${(100* (ratio -1)).toFixed(1)}% more backorders than METRIC`} on this plan of${S0 +4* Sj} transformers. The means agree in every row, because every mean either model computes is exact; only the variance differs. The check: Īⱼ − B̄ⱼ = ${n(v.I- v.B)} and Sⱼ − μⱼ = ${n(Sj - v.mean)}.</p>`;}
The first plot is the delay against the depot’s stock, at the repair time you chose. Each unit added at the depot shortens it by less than the unit before. The red dot is your depot.
Plot.plot({style: plotStyle,height:230,marginLeft:60,marginBottom:45,x: {label:"Depot stock, S₀",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Delay, W̄ (days)",grid:true},marks: [ Plot.line(d3.range(0,31).map(s => ({s,w:365*evaluate({...system.depot,S0: s}, system.rooms, {metric:true}).depot.W})), {x:"s",y:"w",stroke: theme.primary,strokeWidth:1.5}), Plot.dot([{s: S0,w:365* metricRun.depot.W}], {x:"s",y:"w",r:6,fill: theme.accent}) ],ariaLabel:"The delay against the depot's stock",ariaDescription:`At S₀ = ${S0} the delay is ${(365* metricRun.depot.W).toFixed(2)} days.`})
The second plot is the distribution of the units in one storeroom’s pipeline under each model. Notice that they share a mean and that the negative binomial is wider at both ends; the dashed line is the storeroom’s stock, and everything to its right is a backorder.
{const m = metricRun.stores[0].dist, v = variRun.stores[0].dist;const top =Math.max(Sj +3,Math.ceil(variRun.stores[0].mean+4*Math.sqrt(variRun.stores[0].variance)));const rows = d3.range(0, top +1).flatMap(x => [{x,model:"METRIC",g: m.g(x)}, {x,model:"VARI-METRIC",g: v.g? v.g(x) :0}]);return Plot.plot({style: plotStyle,height:230,marginLeft:60,marginBottom:45,x: {label:"Units in resupply at one storeroom",labelAnchor:"center",labelOffset:38},y: {label:"Probability",grid:true},color: {domain: ["METRIC","VARI-METRIC"],range: [theme.primary, theme.accent],legend:true},marks: [ Plot.barY(rows, {x:"x",y:"g",fill:"model",fillOpacity:0.7,dx:0,insetLeft:1,insetRight:1,mixBlendMode: theme.dark?"screen":"multiply"}), Plot.ruleX([Sj], {stroke: theme.fg,strokeDasharray:"5,3"}) ],ariaLabel:"The storeroom pipeline under METRIC and VARI-METRIC",ariaDescription:`The probability of no units in resupply is ${m.g(0).toFixed(4)} under METRIC and ${v.g? v.g(0).toFixed(4) :"not defined"} under VARI-METRIC.` });}
The third plot holds the depot where you set it and varies the storerooms’ stock. The dots mark your storerooms’ stock. The gap between the two lines is what METRIC conceals, and notice that it widens as the storerooms hold more: backorders are a tail quantity, and the tail is where the two distributions differ.
{const rows = d3.range(0,11).flatMap(s => {const sys =utility({T0days, S0,S: s});return [{s,model:"METRIC",b:evaluate(sys.depot, sys.rooms, {metric:true}).storeroomBackorders}, {s,model:"VARI-METRIC",b:evaluate(sys.depot, sys.rooms).storeroomBackorders}]; });return Plot.plot({style: plotStyle,height:230,marginLeft:60,marginBottom:45,x: {label:"Stock at each storeroom, Sⱼ",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Backorders, all storerooms",grid:true,type:"log"},color: {domain: ["METRIC","VARI-METRIC"],range: [theme.primary, theme.accent],legend:true},marks: [ Plot.line(rows, {x:"s",y:"b",stroke:"model",strokeWidth:1.5}), Plot.dot(rows.filter(d => d.s=== Sj), {x:"s",y:"b",fill:"model",r:5}) ],ariaLabel:"Storeroom backorders against storeroom stock under both models",ariaDescription:`At Sⱼ = ${Sj}, METRIC reports ${metricRun.storeroomBackorders.toFixed(4)} and VARI-METRIC ${variRun.storeroomBackorders.toFixed(4)}.` });}
Things to Try
Start at the utility’s plan, \(S_0 = 16\) and \(S_j = 4\). The depot owes 5.0201 units, a request waits 14.54 days, and each storeroom has 3.2276 units in resupply. METRIC reports 0.4055 backorders a storeroom and VARI-METRIC 0.4815, 18.8% more, from a variance of 3.9527 against the Poisson’s 3.2276.
Step the depot from 16 to 22. The delay falls to 3.64 days and the storeroom pipeline to 2.2863 units, at all four storerooms at once, and METRIC’s backorders fall to 0.1238 a storeroom.
Set the depot’s stock to 0. Every request waits the full 60 days of repair, and the two models report the same 13.0342 backorders in all: with no stock at the depot its backorders are its pipeline, whose variance equals its mean.
Return the depot to 16 and raise the storerooms to 8. METRIC reports 0.0345 backorders in all and VARI-METRIC 0.0878, two and a half times as many. A planner sizing the storerooms with METRIC would believe the plan does better than it does.
Return the storerooms to 4 and shorten the depot’s repair to 45 days. VARI-METRIC reports 0.6091 backorders in all. At 60 days the depot needs 22 units, not 16, to do as well (0.6005): that is the repair contract of the chapter’s worksheet example.
Check What You Found
Check what you found
1. On the utility’s plan, \(S_0 = 16\) and \(S_j = 4\), both models give each storeroom a pipeline mean of 3.2276 units, yet VARI-METRIC reports 0.4815 backorders a storeroom where METRIC reports 0.4055. Where does the difference come from?