Companion film
Monte Carlo in a cell
Model revenue and cost as distributions, widen uncertainty, and watch the launch decision change with the odds.
21 secGrid 0.61.0
Open film page →Canonical Grid model
Simulated-time coverage: STOCK integration, PREV smoothing, DELAY lead times, clock reads, a seeded demand fan, and a trajectory handle.
What this model gives you
25 min to study · Source reviewed 2026-08-24
Continue with guided practiceExpected checkpoint
At the opening simulation coordinate before advancing model time.
Clock defaults and STOCK initial values keep the model readable outside a simulation run.
PREV smooths demand, DELAY carries shipment history, and STOCK integrates on-hand and on-order state.
A finite trajectory turns the stateful model into an inspectable experiment without copying it into another tool.
MODEL "Model-Time Warehouse Simulation"
DESCRIPTION "Simulated-time coverage: STOCK integration, PREV smoothing, DELAY lead times, clock reads, a seeded demand fan, and a trajectory handle."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "portable", "simulation", "model-time", "inventory"
# Static parameters. A simulation run advances a hypothetical clock (here
# t0=0, dt=1, steps=52, timeUnit=week) as one replayable ledger event whose
# internal steps never write ordinary bindings, so these inputs stay intact.
A1 = 480
A2 = 60
A3 = 4
A4 = 0.3
A5 IS currency = 2.40
# Clock reads. Outside a simulation resolve SIM_TIME and SIM_STEP return
# #N/A, so DEFAULT keeps the point-estimate resolve clean.
B1 = SIM_TIME() DEFAULT 0
B2 = SIM_STEP() DEFAULT 0
B3 = B2 > 0 THEN "in-run" ELSE "opening"
# Weekly demand follows a 13-week seasonal swing driven by model time, and
# PREV supplies the one-step memory for exponential smoothing.
C1 = A2 * (1 + 0.25 * SIN(2 * PI() * B1 / 13))
C2 = PREV(C3, A2)
C3 = A4 * C1 + (1 - A4) * C2
# Replenishment: order up to lead-time-plus-safety cover. DELAY keeps the
# fixed shipping history (lag_steps must be a positive integer literal), so
# today's arrival is the order placed four simulated weeks back.
D1 = C3 * (A3 + 2)
D2 = MAX(D1 - E1 - E2, 0)
D3 = DELAY(D2, 4, 0)
# Integrated state. STOCK adds dt * net_flow every simulated step; outside a
# run each stock reports its initial value, which keeps this file portable.
E1 = STOCK(A1, D3 - C1)
E2 = STOCK(0, D2 - D3)
E3 = STOCK(0, C1)
# Service and economics readouts.
F1 = E1 < C3 * A3 THEN "reorder-risk" ELSE "covered"
F2 IS currency = E1 * A5
F3 = ROUND(C3, 1)
# Reproducible demand-shock fan. Fixed seeds make the Monte Carlo sweep
# replayable, and each experiment row records its own runId in model history.
G1 = [NORM.INV(RAND_SEEDED(seed), 1.0, 0.08) FOR seed IN 301..316]
G2 = ROUND(AVERAGE(G1), 3)
G3 = COUNTIF(G1, ">1.1") / 16
G4 = ROUND(D1 * MAX(G1), 0)
# Trajectory seam. In workbook semantics SIM_TRAJECTORY returns the resident
# value; under RENDER it pages a finite read-only frame (column t plus the
# tracked output) on an independent presentation clock.
H1 = SIM_TRAJECTORY(E1, {t0: 0, dt: 1, steps: 52, timeUnit: "week"})
H2 = `on_hand={E1} on_order={E2} smoothed_demand={F3} status={F1}`
END MODEL