Simulate systems over timeLesson 40 of 76 · 9 min
Keep an inventory ledger
Simulate demand, receipts and lost sales in a consistent time order.
A dynamic inventory model needs a ledger: on-hand stock, outstanding orders, receipts, demand and unmet demand. The timing convention is part of the policy. Here receipts arrive at the start of a day, demand is served next, and a reorder decision is made at the end.
Inventory position includes on-hand stock plus outstanding orders. Reordering from on-hand stock alone can place duplicate orders while an earlier delivery is already on its way. A two-slot pipeline represents an order arriving two days after its end-of-day placement.
Unmet sales are lost in this example. A backorder instead keeps unmet demand to deliver later. Lead time is the delay from ordering to receipt; here it is fixed at two days. Independent Poisson demand and a full starting shelf are teaching assumptions. A short run can look better than sustained operation.
- Start of day
receive due orders
- Serve demand
- Update, then order
Should outstanding orders count when deciding whether another order is needed?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Mean lost sales over 30 days: 0.313 P(any lost sale): 0.133 Mean final stock: 14.432
Read the first result
The pipeline and demand are updated in a declared order. Changing that order changes the operational model.
Try an edit
Replace trials, days, lead = 2000, 30, 2 with trials, days, lead = 2000, 30, 4. Select Run Python again. Compare Mean lost sales over 30 days, P(any lost sale) and Mean final stock. What changes when orders take longer to arrive but the reorder rule stays fixed?
Scope. The model omits backorders, variable lead times, order capacity and seasonality.
Try a fresh case
You ignore outstanding orders when reordering. Which problem can arise?
Need a hint?
Hint 1
Distinguish on-hand stock from inventory position.
Hint 2
Follow an order through the pipeline before placing another.