{
 "format": "stockflow-1",
 "name": "Why stock levels swing when demand rises",
 "notes": "Customers buy 20% more from week 5 and keep doing so. The shop orders a little more, the wholesaler more still, and the factory swings hardest: first far too much, then far too little. Nobody does anything wrong: each stage forecasts its incoming orders, refills its own stock, and waits three weeks for deliveries. Try: the scenario \"Count the orders already on the way\" (Pipeline_Weight = 1), slower stock correction, or faster deliveries. What this model leaves out: limited production capacity, stock-outs that lose sales, information shared along the chain, and costs. Time unit: weeks.",
 "sim": {
  "start": 0,
  "stop": 52,
  "dt": 0.125,
  "unit": "weeks"
 },
 "elements": [
  {
   "type": "stock",
   "name": "Shop_Inventory",
   "eq": "400",
   "nonneg": false,
   "units": "items",
   "doc": "Goods in stock at the shop. Negative = orders it could not fill yet (backlog).",
   "id": "e1",
   "x": 560,
   "y": 80
  },
  {
   "type": "stock",
   "name": "Shop_Pipeline",
   "eq": "100*Delay_Weeks",
   "nonneg": true,
   "units": "items",
   "doc": "Goods the shop has ordered that are still on their way.",
   "id": "e2",
   "x": 300,
   "y": 80
  },
  {
   "type": "stock",
   "name": "Wholesaler_Inventory",
   "eq": "400",
   "nonneg": false,
   "units": "items",
   "doc": "Goods in stock at the wholesaler. Negative = orders it could not fill yet (backlog).",
   "id": "e3",
   "x": 560,
   "y": 300
  },
  {
   "type": "stock",
   "name": "Wholesaler_Pipeline",
   "eq": "100*Delay_Weeks",
   "nonneg": true,
   "units": "items",
   "doc": "Goods the wholesaler has ordered that are still on their way.",
   "id": "e4",
   "x": 300,
   "y": 300
  },
  {
   "type": "stock",
   "name": "Factory_Inventory",
   "eq": "400",
   "nonneg": false,
   "units": "items",
   "doc": "Goods in stock at the factory. Negative = orders it could not fill yet (backlog).",
   "id": "e5",
   "x": 560,
   "y": 520
  },
  {
   "type": "stock",
   "name": "Factory_Pipeline",
   "eq": "100*Delay_Weeks",
   "nonneg": true,
   "units": "items",
   "doc": "Goods the factory has ordered that are still on their way.",
   "id": "e6",
   "x": 300,
   "y": 520
  },
  {
   "type": "flow",
   "name": "Shop_Receipts",
   "eq": "Shop_Pipeline/Delay_Weeks",
   "from": "e2",
   "to": "e1",
   "biflow": false,
   "units": "items/week",
   "doc": "Deliveries arriving at the shop.",
   "id": "e7"
  },
  {
   "type": "flow",
   "name": "Shop_Shipments",
   "eq": "Customer_Demand",
   "from": "e1",
   "to": null,
   "biflow": false,
   "units": "items/week",
   "doc": "What the shop sends on each week: the orders it receives.",
   "id": "e8",
   "tx": 760,
   "ty": 80
  },
  {
   "type": "flow",
   "name": "Shop_Ordering",
   "eq": "Shop_Orders",
   "from": null,
   "to": "e2",
   "biflow": false,
   "units": "items/week",
   "doc": "The shop's orders entering its supply line.",
   "id": "e9",
   "fx": 110,
   "fy": 80
  },
  {
   "type": "flow",
   "name": "Wholesaler_Receipts",
   "eq": "Wholesaler_Pipeline/Delay_Weeks",
   "from": "e4",
   "to": "e3",
   "biflow": false,
   "units": "items/week",
   "doc": "Deliveries arriving at the wholesaler.",
   "id": "e10"
  },
  {
   "type": "flow",
   "name": "Wholesaler_Shipments",
   "eq": "Shop_Orders",
   "from": "e3",
   "to": null,
   "biflow": false,
   "units": "items/week",
   "doc": "What the wholesaler sends on each week: the orders it receives.",
   "id": "e11",
   "tx": 760,
   "ty": 300
  },
  {
   "type": "flow",
   "name": "Wholesaler_Ordering",
   "eq": "Wholesaler_Orders",
   "from": null,
   "to": "e4",
   "biflow": false,
   "units": "items/week",
   "doc": "The wholesaler's orders entering its supply line.",
   "id": "e12",
   "fx": 110,
   "fy": 300
  },
  {
   "type": "flow",
   "name": "Factory_Receipts",
   "eq": "Factory_Pipeline/Delay_Weeks",
   "from": "e6",
   "to": "e5",
   "biflow": false,
   "units": "items/week",
   "doc": "Deliveries arriving at the factory.",
   "id": "e13"
  },
  {
   "type": "flow",
   "name": "Factory_Shipments",
   "eq": "Wholesaler_Orders",
   "from": "e5",
   "to": null,
   "biflow": false,
   "units": "items/week",
   "doc": "What the factory sends on each week: the orders it receives.",
   "id": "e14",
   "tx": 760,
   "ty": 520
  },
  {
   "type": "flow",
   "name": "Factory_Ordering",
   "eq": "Factory_Orders",
   "from": null,
   "to": "e6",
   "biflow": false,
   "units": "items/week",
   "doc": "The factory's orders entering its supply line.",
   "id": "e15",
   "fx": 110,
   "fy": 520
  },
  {
   "type": "aux",
   "name": "Customer_Demand",
   "eq": "100 + STEP(Demand_Rise, 5)",
   "units": "items/week",
   "doc": "What customers buy each week: 100 items, and from week 5 more by Demand_Rise.",
   "id": "e16",
   "x": 860,
   "y": 60
  },
  {
   "type": "aux",
   "name": "Demand_Rise",
   "eq": "20",
   "units": "items/week",
   "slider": {
    "min": 0,
    "max": 50,
    "step": 5,
    "kind": "decision"
   },
   "doc": "How much more customers buy each week from week 5 on.",
   "id": "e17",
   "x": 1000,
   "y": 60
  },
  {
   "type": "aux",
   "name": "Delay_Weeks",
   "eq": "3",
   "slider": {
    "min": 0.5,
    "max": 12,
    "step": 0.1,
    "kind": "decision"
   },
   "units": "weeks",
   "doc": "How long it takes, on average, until ordered goods arrive.",
   "id": "e18",
   "x": 860,
   "y": 200
  },
  {
   "type": "aux",
   "name": "Smooth_Weeks",
   "eq": "4",
   "slider": {
    "min": 0.5,
    "max": 12,
    "step": 0.1,
    "kind": "decision"
   },
   "units": "weeks",
   "doc": "How quickly each stage updates its forecast of incoming orders.",
   "id": "e19",
   "x": 1000,
   "y": 200
  },
  {
   "type": "aux",
   "name": "Adjust_Weeks",
   "eq": "2",
   "slider": {
    "min": 0.5,
    "max": 12,
    "step": 0.1,
    "kind": "decision"
   },
   "units": "weeks",
   "doc": "How quickly each stage tries to bring its stock back to the target. Small = aggressive.",
   "id": "e20",
   "x": 860,
   "y": 300
  },
  {
   "type": "aux",
   "name": "Pipeline_Weight",
   "eq": "0",
   "slider": {
    "min": 0,
    "max": 1,
    "step": 0.1,
    "kind": "decision"
   },
   "units": "",
   "doc": "Does a stage count the goods it has already ordered but not yet received? 0 = no (common in practice), 1 = fully.",
   "id": "e21",
   "x": 930,
   "y": 400
  },
  {
   "type": "aux",
   "name": "Target_Stock",
   "eq": "400",
   "units": "items",
   "doc": "The stock each stage wants to keep.",
   "id": "e22",
   "x": 1000,
   "y": 300
  },
  {
   "type": "aux",
   "name": "Shop_Expected",
   "eq": "SMTH1(Customer_Demand, Smooth_Weeks, 100)",
   "units": "items/week",
   "doc": "The shop's forecast of incoming orders: a smoothed average.",
   "id": "e23",
   "x": 460,
   "y": 190
  },
  {
   "type": "aux",
   "name": "Shop_Orders",
   "eq": "MAX(0, Shop_Expected + (Target_Stock - Shop_Inventory)/Adjust_Weeks + Pipeline_Weight*(Shop_Expected*Delay_Weeks - Shop_Pipeline)/Adjust_Weeks)",
   "units": "items/week",
   "doc": "What the shop orders each week: the forecast, plus a correction towards its target stock, plus (if Pipeline_Weight > 0) a correction for goods already on their way.",
   "id": "e24",
   "x": 300,
   "y": 190
  },
  {
   "type": "aux",
   "name": "Wholesaler_Expected",
   "eq": "SMTH1(Shop_Orders, Smooth_Weeks, 100)",
   "units": "items/week",
   "doc": "The wholesaler's forecast of incoming orders: a smoothed average.",
   "id": "e25",
   "x": 460,
   "y": 410
  },
  {
   "type": "aux",
   "name": "Wholesaler_Orders",
   "eq": "MAX(0, Wholesaler_Expected + (Target_Stock - Wholesaler_Inventory)/Adjust_Weeks + Pipeline_Weight*(Wholesaler_Expected*Delay_Weeks - Wholesaler_Pipeline)/Adjust_Weeks)",
   "units": "items/week",
   "doc": "What the wholesaler orders each week: the forecast, plus a correction towards its target stock, plus (if Pipeline_Weight > 0) a correction for goods already on their way.",
   "id": "e26",
   "x": 300,
   "y": 410
  },
  {
   "type": "aux",
   "name": "Factory_Expected",
   "eq": "SMTH1(Wholesaler_Orders, Smooth_Weeks, 100)",
   "units": "items/week",
   "doc": "The factory's forecast of incoming orders: a smoothed average.",
   "id": "e27",
   "x": 460,
   "y": 630
  },
  {
   "type": "aux",
   "name": "Factory_Orders",
   "eq": "MAX(0, Factory_Expected + (Target_Stock - Factory_Inventory)/Adjust_Weeks + Pipeline_Weight*(Factory_Expected*Delay_Weeks - Factory_Pipeline)/Adjust_Weeks)",
   "units": "items/week",
   "doc": "What the factory orders each week: the forecast, plus a correction towards its target stock, plus (if Pipeline_Weight > 0) a correction for goods already on their way.",
   "id": "e28",
   "x": 300,
   "y": 630
  }
 ],
 "plots": [
  "e16",
  "e24",
  "e26",
  "e28",
  "e5"
 ],
 "scenarios": [
  {
   "id": "s1",
   "name": "Count the orders already on the way",
   "note": "",
   "values": {
    "Pipeline_Weight": 1
   }
  },
  {
   "id": "s2",
   "name": "Correct stock more slowly",
   "note": "",
   "values": {
    "Adjust_Weeks": 6
   }
  },
  {
   "id": "s3",
   "name": "Faster deliveries",
   "note": "",
   "values": {
    "Delay_Weeks": 1
   }
  }
 ]
}