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 plans the mower deck belt’s twelve months of Chapter 5 by every method the chapter compares, and costs each plan. The requirements run from 40 belts in month 1 to 420 in month 5, fall to none in month 9, and climb again to 220 in month 12. Holding a belt for a month costs \(h = \$1.00\), and an order costs \(k = \$300\); move \(k\) and watch the plans change.
Recall that the window cost \(w(t, u)\) is the cost of ordering in month \(t\) for months \(t\) through \(u\): the ordering cost plus a month of holding for every belt for every month it waits. The Wagner-Whitin recursion builds the least cost to cover months 1 through \(t\),
and the three heuristics extend one window at a time until a rule says stop. Every cost on this page is the relevant cost; the purchase cost is the same under every plan. The page runs in your browser and records nothing. Its methods are a restatement in JavaScript of the book’s code, and they are tested against that code. For a schedule of your own, use the general explorer.
The Plans
viewof k = Inputs.range([50,1200], {step:10,value:300,label:"Ordering cost, k ($ an order)"})viewof shown = Inputs.select(["Wagner-Whitin","Silver-Meal","Least unit cost","Part-period balancing","Lot-for-lot","Periodic order quantity","Adjusted economic order quantity"], {value:"Silver-Meal",label:"Plan to draw beside the optimum"})resetButton([viewof k, viewof shown])
The recursion, one month at a time. Each \(V(t)\) is the least cost of covering months 1 through \(t\), and \(s\) is the month whose order covers month \(t\) in that least-cost plan. Reading the \(s\) row back from month 12 gives the optimal order months.
The plot shows the requirements as gray bars and the stock carried out of each month under the optimal plan, the solid blue line, and the plan you chose, the dashed red one. Every belt-month above zero costs $1; notice where the chosen plan carries stock the optimal one does not.
Plot.plot({style: plotStyle,height:280,marginLeft:50,marginBottom:45,x: {label:"Month",labelAnchor:"center",labelOffset:38,domain: d.map((_, i) => i +1)},y: {label:"Belts",grid:true},color: {legend:true,domain: ["Requirement","Optimal: stock carried",`${shown}: stock carried`],range: [theme.grid, theme.primary, theme.accent]},marks: [ Plot.barY(d.map((x, i) => ({t: i +1, x})), {x:"t",y:"x",fill: theme.grid}), Plot.line(optimum.I.map((x, i) => ({t: i +1, x})), {x:"t",y:"x",stroke: theme.primary,strokeWidth:2,marker:"dot"}), Plot.line(picked.I.map((x, i) => ({t: i +1, x})), {x:"t",y:"x",stroke: theme.accent,strokeWidth:2,strokeDasharray:"5,3",marker:"dot"}) ],ariaLabel:"Requirements and the stock carried each month",ariaDescription:`The optimal plan carries ${optimum.carrying} belt-months; ${shown} carries ${picked.carrying}.`})
Things to Try
At \(k = \$300\) the optimum orders in months 1, 4, 5, 6, 10 and 12 for $2,480. Silver-Meal costs $2,660, least unit cost $3,040, and part-period balancing $2,600, the chapter’s comparison.
Draw Silver-Meal. Its order of 840 belts in month 5 covers months 5 through 9 and carries 420, 160 and 40 belts out of months 5, 6 and 7. Each added month had a small requirement, so the cost per month kept falling and the rule never stopped.
Notice that every heuristic orders five times and the optimum six. They lose by ordering too seldom, not too often.
Move \(k\) to $100 and then to $1,000. At both, Silver-Meal lands on the optimum, at $1,000 and $5,380. Its shortfall at $300 belongs to this schedule at that cost, not to the rule.
At \(k = \$100\), lot-for-lot is only 10% above the optimum; at $1,000 it is more than twice it. Ordering every month is reasonable only when an order is cheap.
Check What You Found
Check what you found
1. At \(k = \$300\) the optimal plan for the belt orders six times for $2,480, and Silver-Meal orders five times for $2,660. Where does Silver-Meal lose the $180?
2. Move \(k\) from $300 to $1,000. Silver-Meal now places the same orders as the optimum, at the same cost. What does that show?