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 two constrained examples of Chapter 4 with the multiplier in your hands. The distributor’s three items share either a $10,000 limit on average investment or a receiving dock that can take 50 replenishments a year. Move the multiplier \(\theta\) and watch each item’s quantity respond and the resource the plan uses rise or fall toward the limit; move the limit and see what it costs.
Recall that the multiplier is a price on the shared resource. Under an investment limit it surcharges holding, and under a replenishment limit it surcharges ordering:
The constrained answer is the plan at the multiplier \(\theta^{*}\) that uses the whole of the limit and no more. 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 items of your own, use the general explorer.
The Limit
viewof which = Inputs.select(newMap([["Investment limit","investment"], ["Replenishment limit","replenishment"]]), {value:"investment",label:"The shared limit"})viewof theta = Inputs.range([0, which ==="investment"?0.5:150], {step: which ==="investment"?0.00001:0.0001,value:0,label:"Multiplier, θ"})viewof A = Inputs.range(which ==="investment"? [4000,14000] : [25,100], {step: which ==="investment"?100:1,value: which ==="investment"?10000:50,label: which ==="investment"?"Investment limit, A ($)":"Replenishments a year, A"})useOptimum = {const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">Use θ*</button>`; button.onclick= () => { viewof theta.value= solved.theta; viewof theta.dispatchEvent(newEvent("input", {bubbles:true})); };returnhtml`<div style="margin: 0.5rem 0">${button}</div>`;}resetButton([viewof theta, viewof A])
import {solve, planAt} from"./explorers/lib/multiitem.js"items = [[12000,20,50], [25000,10, which ==="investment"?50:20], [8000,15, which ==="investment"?50:80]].map(([lambda, c, k], j) => ({label:`Item ${j +1}`, lambda, c, k}))i =0.30here =planAt(items, i, which, theta)solved =solve(items, i, which, A)free = solved.freeunit = which ==="investment"?"dollars of investment":"replenishments a year"
{const dollars = x =>"$"+ x.toLocaleString("en-US", {minimumFractionDigits:2,maximumFractionDigits:2});const used = x => which ==="investment"?dollars(x) : x.toFixed(2);const gap = here.used- A;const shownGap =Math.abs(gap) < (which ==="investment"?0.005:0.00005) ?0: gap;returnhtml`<table class="table table-sm" style="max-width: 46rem"> <thead><tr><th>Item</th><th>Free Q</th><th>Q at θ = ${theta}</th><th>Ordering</th><th>Holding</th></tr></thead> <tbody>${here.rows.map((r, j) =>html`<tr><td>${r.label}</td><td>${free.rows[j].Q.toFixed(2)}</td><td>${r.Q.toFixed(2)}</td> <td>${dollars(r.ordering)}</td><td>${dollars(r.holding)}</td></tr>`)} <tr style="font-weight: 600"><td>Total</td><td></td><td></td><td>${dollars(here.ordering)}</td><td>${dollars(here.holding)}</td></tr></tbody> </table> <p>At θ = ${theta} the plan uses ${used(here.used)} against a limit of ${used(A)}, so R(θ) = ${which ==="investment"?dollars(shownGap) : shownGap.toFixed(4)}:${Math.abs(gap) < (which ==="investment"?0.5:0.005) ?"the limit is met exactly.": gap >0?"over the limit, so θ must rise.":"under the limit, so θ could fall and save money."} Its relevant cost is ${dollars(here.relevant)}.</p> <p>${solved.binds?`The limit binds. Its multiplier is θ* = ${solved.theta.toFixed(5)}, where the plan costs ${dollars(solved.relevant)}, which is ${dollars(solved.relevant- free.relevant)} a year more than the free plan's ${dollars(free.relevant)}.`:`The limit does not bind: the free plan uses ${used(free.used)}, within the limit, so θ* = 0 and the limit costs nothing.`}</p>`;}
The first plot is the resource function: what the plan uses at each multiplier, against the limit as a dashed line. It falls as \(\theta\) rises and crosses the limit once, at \(\theta^{*}\). The red dot is your multiplier.
Plot.plot({style: plotStyle,height:240,marginLeft:70,marginBottom:45,x: {label:"Multiplier, θ",labelAnchor:"center",labelOffset:38,grid:true},y: {label: which ==="investment"?"Average investment ($)":"Replenishments a year",grid:true,domain: [0,1.1* free.used]},marks: [ Plot.ruleY([A], {stroke: theme.muted,strokeDasharray:"5,3"}), Plot.line(d3.range(0,201).map(j => {const t = (which ==="investment"?0.5:150) * j /200;return {t,u:planAt(items, i, which, t).used};}), {x:"t",y:"u",stroke: theme.primary,strokeWidth:1.5}), Plot.dot([{t: theta,u: here.used}], {x:"t",y:"u",r:6,fill: theme.accent}) ],ariaLabel:"Resource used against the multiplier",ariaDescription:`The plan uses the limit exactly at θ* = ${solved.theta.toFixed(4)}.`})
The second plot is what the limit costs, the constrained cost less the free cost, against the limit itself. Notice how fast it rises as the limit tightens, and that it is zero once the limit no longer binds. The red dot is your limit.
Plot.plot({style: plotStyle,height:240,marginLeft:70,marginBottom:45,x: {label: which ==="investment"?"Investment limit, A ($)":"Replenishments a year, A",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Cost of the limit ($ a year)",grid:true},marks: [ Plot.line(d3.range(0,81).map(j => {const a = which ==="investment"?4000+10000* j /80:25+75* j /80, p =solve(items, i, which, a);return {a,cost: p.relevant- p.free.relevant}; }), {x:"a",y:"cost",stroke: theme.primary,strokeWidth:1.5}), Plot.dot([{a: A,cost: solved.relevant- free.relevant}], {x:"a",y:"cost",r:6,fill: theme.accent}) ],ariaLabel:"The cost of the limit against the limit",ariaDescription:`At the chosen limit the cost is $${(solved.relevant- free.relevant).toFixed(2)} a year.`})
Things to Try
Under the investment limit, slide \(\theta\) to 0.15, the first midpoint of the chapter’s bisection. The plan uses $9,960.25, under the $10,000 limit, so \(\theta\) is too high.
Press Use θ*. The multiplier is 0.14643, the quantities are 366.61, 748.33 and 345.64, and the plan costs $7,464.30, $145.04 a year more than the free plan. The holding cost is exactly $3,000: the limit fixed the investment, and so the holding cost with it.
Tighten the limit to $8,000. The multiplier rises to 0.39755 and the limit now costs $661.11 a year. Loosen it to $12,000 and it costs $0.99; at $12,198.77 and above it costs nothing, because the free plan already fits.
Switch to the replenishment limit. At 50 a year, \(\theta^{*} = 64.3293\): each order is charged $64.33 more than its own ordering cost, and the plan costs $7,621.27, $805.93 more than the free plan’s $6,815.33.
Check What You Found
Check what you found
1. Under the $10,000 investment limit the multiplier is \(\theta^{*} = 0.14643\). What does that number tell the person who controls the budget?
2. Under the investment limit each item’s quantity falls from its free value by the same factor: \(366.61/447.21\), \(748.33/912.87\) and \(345.64/421.64\) all equal 0.81975. Why?