Week 11 · Discrete-event simulation and validation

Simulate a queue using real event order and assess model error on held-out data.

← Week 10 · Subject contents · Week 12 →

Simulate a queue using real event order and assess model error on held-out data.

Work through the problem

For sorted arrivals aᵢ and service durations sᵢ, the next service starts at bᵢ = max(aᵢ,dᵢ₋₁), departs at dᵢ = bᵢ+sᵢ, and waits bᵢ−aᵢ. Jumping directly between events avoids choosing a numerical time step. At arrivals [0,1,4] with durations [2,2,2], waits are [0,1,0].

Fit a constant service duration using a separate batch. Hold arrival times fixed and compare predicted waits with waits from recorded variable durations. The resulting mean absolute error measures how much the service assumption matters on this batch.

Run the Python lab

import numpy as np
def waiting(arrivals, service):
    end = 0
    waits = []
    for a, s in zip(arrivals, service, strict=True):
        begin = max(a,end)
        waits.append(begin-a)
        end = begin+s
    return np.array(waits)
holdout_arrivals = [0,1,4,4]
observed = waiting(holdout_arrivals,[3,1,2,1])
estimated = waiting(holdout_arrivals,[np.mean([1,2,3])]*4)
print("Observed, predicted:", observed, estimated)
print("MAE:", abs(observed-estimated).mean())
assert waiting([0,1,4],[2,2,2]).tolist()==[0,1,0]

Output from the lab

Observed, predicted: [0 2 0 2] [0. 1. 0. 2.]
MAE: 0.25

Practice

  1. What other metric would reveal that the model misses severe delays?

Check your reasoning

  1. Compare upper quantiles or exceedances of a specific service-level threshold.

← Week 10 · Subject contents · Week 12 →

Further reading · MIT 6.262 · Discrete Stochastic Processes