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.

Keep the daily ledger in order
  1. Start of day

    receive due orders

  2. Serve demand
    served=min⁡(stock,D)\text{served}=\min(\text{stock},D)
  3. Update, then order
    stock←stock−served\text{stock}\gets\text{stock}-\text{served}
Reference illustration. The source advances the pipeline, serves today’s demand, records lost sales, then places orders with a two-day lead time. Changing the order of these operations changes the inventory process.

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.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

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?

Back to the Python editor

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?

Choose an answer
Need a hint?
Hint 1

Distinguish on-hand stock from inventory position.

Hint 2

Follow an order through the pipeline before placing another.

Your notes