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 works the demand history of Chapter 1 with the history in your hands. A location opens a window with some units on hand, demands arrive at the times you give for the quantities you give, and unfilled demand is backordered. Change the history and watch three service measures that average over different things move apart or together:
the ready rate, the fraction of the window with stock on hand, averages over time;
the unit fill rate, the share of units filled from stock on arrival, averages over units;
the transaction fill rate, the share of transactions filled completely on arrival, averages over transactions.
It also reports the average backorders and the customer wait, which by Little’s law are two views of one quantity, \(\bar{B} = \lambda \overline{W}\). You may add receipts; a receipt fills waiting units first come, first served, and a receipt at the same instant as a demand is put away first. The page runs in your browser and records nothing. The cycle service level is not shown, because it needs a replenishment policy to define a cycle.
The History
viewof I0 = Inputs.number({value:10,label:"Units on hand at the start, I₀"})viewof T = Inputs.number({value:5,label:"Length of the window, T"})viewof demandText = Inputs.textarea({value:"1, 3\n2, 4\n3, 5\n4, 2\n5, 1",rows:6,label:"Demands: time, units"})viewof receiptText = Inputs.textarea({value:"",rows:2,label:"Receipts: time, units"})resetButton([viewof I0, viewof T, viewof demandText, viewof receiptText])
import {trace} from"./explorers/lib/servicetrace.js"result = {const problems = [];const parse = (text, what) => text.split("\n").map(s => s.trim()).filter(Boolean).map((s, n) => {const v = s.split(/[,\s]+/).map(Number);if (v.length!==2|| v.some(x =>!Number.isFinite(x))) problems.push(`${what} line ${n +1} needs two numbers: a time and a number of units.`);return v; });const demands =parse(demandText,"Demand").map(([t, D]) => ({t, D}));const receipts =parse(receiptText,"Receipt").map(([t, Q]) => ({t, Q}));if (demands.length>200) problems.push(`There are ${demands.length} demands; this page takes at most 200.`);if (problems.length) return {ok:false, problems};try {return {ok:true,r:trace({I0, T, demands, receipts})}; } catch (e) {return {ok:false,problems: [e.message.charAt(0).toUpperCase() + e.message.slice(1) +"."]}; }}
{if (!result.ok) {returnhtml`<div class="callout callout-style-simple callout-warning"><div class="callout-body"> <p><strong>The page cannot trace this history.</strong></p> <ul>${result.problems.map(p =>html`<li>${p}</li>`)}</ul></div></div>`; }const {r} = result;const pct = x => (100* x).toFixed(1) +"%";const n = x => (Math.abs(x -Math.round(x)) <1e-9?String(Math.round(x)) : x.toFixed(4));returnhtml`<div style="overflow-x: auto; max-width: 100%"> <table class="table table-sm" style="font-size: 0.9rem; white-space: nowrap"> <thead><tr><th>Time</th><th>Event</th><th>On hand before</th><th>Filled now</th><th>Backordered</th><th>On hand after</th><th>Owed after</th><th>Yᵢ</th></tr></thead> <tbody>${r.rows.map(e => e.kind==="demand"?html`<tr><td>${n(e.t)}</td><td>demand of ${e.D}</td><td>${e.before}</td><td>${e.filled}</td><td>${e.short}</td><td>${e.onHand}</td><td>${e.B}</td><td>${e.Y}</td></tr>`:html`<tr style="color: ${theme.muted}"><td>${n(e.t)}</td><td>receipt of ${e.n}</td><td></td><td colspan="2">${e.shipped} to waiting units</td><td>${e.onHand}</td><td>${e.B}</td><td></td></tr>`)} <tr style="font-weight: 600"><td>Total</td><td>${r.units} units</td><td></td><td>${r.filledNow}</td><td>${r.backordered}</td><td></td><td></td><td>${r.complete}</td></tr></tbody> </table></div> <table class="table table-sm" style="max-width: 36rem"> <thead><tr><th>Measure</th><th>Averages over</th><th>Value</th></tr></thead> <tbody> <tr><td>Ready rate</td><td>time</td><td>${pct(r.readyRate)}</td></tr> <tr><td>Unit fill rate, ${r.filledNow}/${r.units}</td><td>units</td><td>${pct(r.unitFillRate)}</td></tr> <tr><td>Transaction fill rate, ${r.complete}/${r.transactions}</td><td>transactions</td><td>${pct(r.transactionFillRate)}</td></tr> <tr><td>Average on hand, Ī</td><td>time</td><td>${r.averageOnHand.toFixed(4)}</td></tr> <tr><td>Average backorders, B̄</td><td>time</td><td>${r.averageBackorders.toFixed(4)}</td></tr> <tr><td>Average wait per unit, W̄</td><td>units</td><td>${r.meanWait.toFixed(4)}</td></tr> <tr><td>Average wait of the units that waited</td><td>units that waited</td><td>${r.conditionalWait.toFixed(4)}</td></tr> </tbody> </table> <p>The demand rate is λ = ${r.units}/${n(r.T)} = ${n(r.lambda)} units per unit time, and B̄/λ = ${r.littleWait.toFixed(4)}, the same as the average wait read unit by unit: Little's law${r.stillWaiting>0?`, with the ${r.stillWaiting} units still owed at the end counted only up to T`:""}.</p>`;}
The plot is the history drawn over the window: on hand as the solid line and units owed as the dashed one. The ready rate is the fraction of the window in which the solid line is above zero; the average backorders are the area under the dashed line divided by \(T\).
result.ok? (() => {const {r} = result;const pts = [...r.steps, {t: r.T,I: r.steps[r.steps.length-1].I,B: r.steps[r.steps.length-1].B}];const series = pts.flatMap(p => [{t: p.t,units: p.I,what:"On hand"}, {t: p.t,units: p.B,what:"Owed"}]);return Plot.plot({style: plotStyle,height:240,marginLeft:50,marginBottom:45,x: {label:"Time",labelAnchor:"center",labelOffset:38,domain: [0, r.T],grid:true},y: {label:"Units",grid:true},color: {domain: ["On hand","Owed"],range: [theme.primary, theme.accent],legend:true},marks: [ Plot.ruleY([0], {stroke: theme.muted}), Plot.line(series, {x:"t",y:"units",stroke:"what",curve:"step-after",strokeWidth:1.75,strokeDasharray: d => d.what==="Owed"?"5,3":null,z:"what"}) ],ariaLabel:"On hand and units owed over the window",ariaDescription:`The ready rate is ${(100* r.readyRate).toFixed(1)}%.` });})() :html``
Things to Try
The starting history is the chapter’s: 10 units on hand and five demands over five time units. The ready rate is 60.0%, the unit fill rate 66.7% and the transaction fill rate 40.0%. Average backorders are 1.2 units and the average wait is 0.4 time units, and \(1.2 = 3 \times 0.4\).
Start with 12 units instead of 10. The ready rate does not move, because the shelf still empties at \(t = 3\), but the unit fill rate rises to 80.0% and the transaction fill rate to 60.0%.
Return to 10 units and break the demand at \(t = 3\) into five demands of one unit, at \(t = 3, 3.2, 3.4, 3.6\) and \(3.8\). The same 15 units are demanded and the same 10 filled, so the unit fill rate stays at 66.7%; the transaction fill rate rises to 55.6%, because five of the nine transactions are now filled completely, and the ready rate to 68.0%.
Add a receipt of 10 units at \(t = 3.5\). It fills the two units owed and restocks the shelf: the ready rate is 90.0%, the unit fill rate 86.7%, and average backorders fall to 0.2.
Check What You Found
Check what you found
1. Starting the chapter’s history with 12 units instead of 10 raises the unit fill rate from 66.7% to 80.0% and the transaction fill rate from 40.0% to 60.0%, but leaves the ready rate at 60.0%. Why does the ready rate not move?