Chapter 6, Material and Distribution Requirements Planning
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 page computes the six rows of one item’s record, as Chapter 6 defines them, for requirements you enter: it nets them against the opening stock and the scheduled receipts, lets a lot sizing rule decide the planned receipts, carries the balance, and offsets the receipts by the lead time. It starts from the deck assembly’s record; Reset returns to it. 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 requirements. Gross requirements known for every period of the horizon, one number per period, separated by commas or spaces. Zeros are allowed. At most 60 periods. Scheduled receipts are entered the same way, from period 1; a blank means none, and a shorter list means none after it.
The item. An opening stock \(I_0\), a safety stock \(\mathit{SS}\), and a lead time \(L\) of whole periods, 0 or more. A receipt the lead time would release before period 1 is reported as past due and released nowhere.
The rule. Lot-for-lot, any rule of Chapter 5, or a fixed order quantity. A rule of Chapter 5 is applied to the net requirements before lot sizing, from the first period that has one.
The costs. A fixed cost \(k\) per order and a holding cost \(h\) per unit on hand at the end of a period, both the same in every period.
NoteFor anything else, use the software
Several items in a bill of material, explored level by level, are on the deck structure’s page. Structures of your own, allocations, and costs that change by period are in the code the chapter teaches, in the chapter’s Using the Software section, and the chapter’s workbook computes the same record cell by cell.
Your Record
viewof grossText = Inputs.textarea({value:"0, 0, 0, 0, 0, 40, 60, 120, 300, 420, 260, 120, 40, 0, 80, 180, 220",rows:4,label:"Gross requirements, one per period"})viewof srText = Inputs.textarea({value:"",rows:2,label:"Scheduled receipts, from period 1"})viewof onHand = Inputs.number({value:0,label:"Opening stock, I₀"})viewof SS = Inputs.number({value:0,label:"Safety stock, SS"})viewof L = Inputs.number({value:1,label:"Lead time, L (periods)"})viewof rule = Inputs.select(["Lot-for-lot","Periodic order quantity","Wagner-Whitin","Silver-Meal","Least unit cost","Part-period balancing","Adjusted economic order quantity","Fixed order quantity"], {value:"Lot-for-lot",label:"Lot sizing rule"})viewof quantity = Inputs.number({value:500,label:"Fixed order quantity (that rule only)"})viewof k = Inputs.number({value:500,label:"Ordering cost, k ($ an order)"})viewof h = Inputs.number({value:3.6,label:"Holding cost, h ($ a unit a period)"})viewof unnetted = Inputs.toggle({label:"Leave out the netting",value:false})resetButton([viewof grossText, viewof srText, viewof onHand, viewof SS, viewof L, viewof rule, viewof quantity, viewof k, viewof h, viewof unnetted])
import {record} from"./explorers/lib/mrp.js"result = {const parse = s => s.split(/[\s,;]+/).filter(Boolean).map(Number);const gross =parse(grossText), SR =parse(srText);const problems = [];if (!gross.length) problems.push("Enter at least one gross requirement.");if (gross.some(x =>!Number.isFinite(x) || x <0)) problems.push("Every gross requirement must be a number, 0 or more.");if (gross.length>60) problems.push(`The record has ${gross.length} periods; this page takes at most 60.`);if (SR.some(x =>!Number.isFinite(x) || x <0)) problems.push("Every scheduled receipt must be a number, 0 or more.");if (SR.length> gross.length) problems.push("There are more scheduled receipts than periods.");if (!(onHand >=0)) problems.push("The opening stock must be 0 or more.");if (!(SS >=0)) problems.push("The safety stock must be 0 or more.");if (!(Number.isInteger(L) && L >=0)) problems.push("The lead time must be a whole number of periods, 0 or more.");if (rule ==="Fixed order quantity"&&!(quantity >0)) problems.push("The fixed order quantity must be positive.");if (!(k >=0)) problems.push("The ordering cost cannot be negative.");if (!(h >0)) problems.push("The holding cost must be positive.");if (problems.length) return {ok:false, problems};const item = {id:"X",label:"Your item", L, rule, quantity, onHand, SS, SR, k,c: h,i:1};const r =record(item, gross);// Without netting nothing is planned: the balance runs with every planned receipt zero.let on = onHand;const bare = gross.map((g, t) => (on = on + (SR[t] ??0) - g));return {ok:true, r, bare};}
{if (!result.ok) {returnhtml`<div class="callout callout-style-simple callout-warning"><div class="callout-body"> <p><strong>The page cannot compute this record.</strong></p> <ul>${result.problems.map(p =>html`<li>${p}</li>`)}</ul></div></div>`; }const {r, bare} = result;const n = x => (Math.abs(x -Math.round(x)) <1e-9?Math.round(x) : x).toLocaleString("en-US", {maximumFractionDigits:2});const dollars = x =>"$"+ x.toLocaleString("en-US", {minimumFractionDigits:2,maximumFractionDigits:2});const rows = unnetted? [["Gross requirements, GR", r.GR], ["Scheduled receipts, SR", r.SR], ["Projected on hand, I", bare]]: [["Gross requirements, GR", r.GR], ["Scheduled receipts, SR", r.SR], ["Projected on hand, I", r.I], ["Net requirements, NR", r.NR], ["Planned order receipts, POR", r.POR], ["Planned order releases, Rel", r.Rel], ["NR before lot sizing", r.before]];const shade = j => (j === rows.length-1&&!unnetted ?`color: ${theme.muted}`:"");const verdict = unnetted?`With nothing netted, nothing is planned, and the balance ends at ${n(bare[bare.length-1])}. Every negative entry is a shortage the plan has not dealt with.`:`The record places ${r.orders} order${r.orders===1?"":"s"}: ${dollars(r.setup)} of setup and ${dollars(r.carrying)} of carrying, ${dollars(r.relevant)} in all.`;returnhtml`<p>${verdict}</p>${!unnetted && r.pastDue>0?html`<p style="color: ${theme.accent}"><strong>${n(r.pastDue)} units are past due:</strong> the lead time puts their release before period 1, so no plan inside this horizon can place them.</p>`:""} <div style="overflow-x: auto; max-width: 100%"> <table class="table table-sm" style="font-size: 0.85rem; white-space: nowrap"> <thead><tr><th>Period</th>${r.GR.map((_, t) =>html`<th style="text-align: right">${t +1}</th>`)}</tr></thead> <tbody>${rows.map(([name, xs], j) =>html`<tr style="${shade(j)}"><td>${name}</td>${xs.map(x =>html`<td style="text-align: right">${n(x)}</td>`)}</tr>`)}</tbody> </table></div>${unnetted ?"":html`<p>The last row, in gray, is what would have to arrive if nothing were carried beyond the opening stock and the scheduled receipts: the stream the rule was given. The net requirement row above it is the printed reading, after the rule's receipts are in the balance.</p>`}`;}
The plot is the projected on hand at the end of each period, as blue bars, with the gross requirements as red dots. Under lot-for-lot with nothing on hand the bars are flat at the safety stock; a rule that batches builds them up and draws them down.
result.ok? (() => {const {r, bare} = result;const I = unnetted ? bare : r.I;return Plot.plot({style: plotStyle,height:240,marginLeft:60,marginBottom:45,x: {label:"Period",labelAnchor:"center",labelOffset:38,tickFormat: d => (d %Math.max(1,Math.ceil(r.GR.length/20)) ===0? d :"")},y: {label:"Units",grid:true},marks: [ Plot.ruleY([0], {stroke: theme.muted}), Plot.barY(I.map((x, t) => ({t: t +1, x})), {x:"t",y:"x",fill: theme.primary,fillOpacity:0.7}), Plot.dot(r.GR.map((x, t) => ({t: t +1, x})), {x:"t",y:"x",r:4,fill: theme.accent}) ],ariaLabel:"Projected on hand and gross requirements by period",ariaDescription:`The balance at the end of the horizon is ${I[I.length-1]}.` });})() :html``
Things to Try
The starting record is the deck assembly’s: five empty months, then the twelve-month schedule, lot-for-lot with a lead time of one month. It places 11 orders for $5,500, the balance never leaves zero, and the releases are the schedule pulled back one month.
Turn on Leave out the netting. The balance falls to \(-1,840\), the whole year’s requirement: correct arithmetic and a useless plan.
Set the opening stock to 60. In period 6 the net requirement is zero and 20 units carry into period 7, whose net requirement falls to 40. The record places 10 orders, and the 60 units carried for five months and the 20 carried for one cost $1,152.
Set the opening stock back to 0 and the safety stock to 20. The record asks for the 20 in period 1, which the lead time makes past due, and then holds 20 in every period, at $1,224 of carrying.
Choose the fixed order quantity of 500. Compare the last two rows: in periods 7 and 8 the rule was given 60 and 120, but the printed net requirements are zero, because the 500 received in period 6 covers them. That is the chapter’s two readings of the net requirement.
Choose Wagner-Whitin. The record places 9 orders for $4,860, the deck assembly’s figure in the chapter’s comparison of rules.
Set the lead time to 6. The receipt due in period 6 would be released in period 0, so 40 units are past due: five empty months are not enough lead-in for a lead time of six.
Check What You Found
Check what you found
1. An item is planned lot-for-lot with a safety stock of 20, nothing on hand, nothing on order, and a lead time of one month. Its first gross requirement falls in month 6. In which month does the record first ask for the 20 units?