Patient flow & resource simulation
Explore how resource capacity affects queues, throughput and waiting in a service pathway.
Concepts and reasoning
Simulating events rather than fixed time steps
A discrete-event simulation advances from one event to the next: a patient arrives, begins service, finishes a consultation, or joins another queue. Between events the relevant system state does not change. This differs from a fixed-cycle model that updates everyone at regular intervals.
Resources have limited capacity, such as consultation rooms or staffed treatment stations. Patients request a resource, wait if none is available, receive service, and release it. Routing determines the next station or discharge. The queue discipline determines who is served next; first-in, first-out is one possibility, not a universal feature of patient care.
Average demand below nominal capacity does not imply no waiting. Arrivals can bunch together and service times can vary. As utilization approaches one, small fluctuations can create long queues. Increasing capacity at a non-bottleneck station may have little effect on the overall pathway.
A model of the service system
An arrival rate describes expected arrivals per time unit. A service rate is expected completions per server per time unit under the specified model. Both must use compatible units. A service rate of four per hour corresponds to a mean service time of 15 minutes.
Exponential interarrival times produce a Poisson arrival process; exponential service times have SD equal to their mean. These are useful starting assumptions, but appointments, shifts, priorities, and scheduled procedures can behave very differently. The SimPy shared-resource tutorial demonstrates the event-and-resource logic with a small worked queue.
Mathematical foundations
Utilization and a simple analytical benchmark
For arrival rate λ, c identical servers, and service rate μ per server, nominal utilization is
A simple infinite-capacity stationary queue requires λ < cμ for stability. A network also needs feasible routing and adequate capacity at each relevant station; checking one average utilization is not sufficient.
For an M/M/1 queue—Poisson arrivals, exponential service, one server, and the standard steady-state assumptions—
where W is average time in the system and Wq is average waiting before service. Expected service time is 1/μ, so W = Wq + 1/μ.
Little's law connects long-run average number in a stable system, throughput, and time:
The population, boundary, and time definitions must match. Using arrivals from one station and waiting time from another does not produce a meaningful check.
Across R independent simulation replications with output means Zr, the SE of the estimated mean is the SD of the replication outputs divided by √R. Correlated patient outcomes within one congested run should not simply be treated as independent replications.
Worked example
Worked example: a small utilization increase, a large delay
Consider one service station with μ = 6 patients per hour, so average service time is 10 minutes.
| Arrival rate per hour | Utilization | Mean wait Wq | Mean total time W |
|---|---|---|---|
| 3.0 | 0.500 | 10 min | 20 min |
| 4.0 | 0.667 | 20 min | 30 min |
| 5.0 | 0.833 | 50 min | 60 min |
| 5.5 | 0.917 | 110 min | 120 min |
At λ = 4, W = 1/(6 − 4) = 0.5 hours. Wq = 4/[6(6 − 4)] = 1/3 hour. Little's law gives L = 4 × 0.5 = 2 patients in the system on average, including the patient in service.
Increasing arrivals from 4 to 5 per hour raises utilization from 0.667 to 0.833 but more than doubles waiting time, from 20 to 50 minutes. Capacity planning based only on the mean workload can miss this nonlinear effect.
A simulation built with these exact assumptions should approach these benchmarks as run length and independent replication increase, after handling initialization. A discrepancy can reveal a unit error, an incorrect queue rule, insufficient run length, or a different output definition.
Suppose 25 independent runs give mean waiting time 20 minutes and an SD of run means of 5 minutes. The estimated SE is 5/√25 = 1 minute. This describes Monte Carlo precision of the estimated model mean, not the much wider variation in individual patient waits.
Interpreting the results
Waiting depends on variability as well as average capacity
Queue waiting is time before service; time in system also includes service and movement through subsequent stations. Utilization is the fraction of available server time spent busy. High utilization can coexist with rapidly growing waits because random arrivals and service durations create temporary overload even when average capacity exceeds average demand.
Average queue length is a time-based measure, while average waiting time is a patient-based measure. Their populations and observation windows must be compatible before applying relationships such as Little's law. A peak queue summarizes extremes and is not interchangeable with average occupancy.
A capacity comparison estimates the effect of the modeled change under common assumptions about demand and service. Expanding one resource can expose another bottleneck. A reduction in simulated wait is not evidence that staffing, routing, or service-time assumptions will hold in practice.
Assumptions and limitations
Describe the operational system explicitly
A queue model needs arrival timing, service distributions, number of parallel servers, routing, priority rules, and an initial condition. Exponential interarrival and service times are convenient but may poorly describe appointment schedules, batching, or long-tailed tasks. Means alone do not identify the variability that drives waits.
First-in-first-out assumes patients are served in arrival order at each station without triage priority. A fixed route assumes every patient visits the same ordered services. Real systems may branch, return to earlier stations, abandon queues, or operate with shifts and downtime.
Starting empty produces a transient period. A warm-up can reduce its effect when estimating ongoing operation, but is not appropriate for every terminating service day. The observation horizon and whether patients are followed after arrivals stop must match the operational question.
Diagnostics and sensitivity analysis
Validate the mechanism before comparing capacity
Reconcile demand, service durations, server counts, and routing with observed operations. Check a simple low-load scenario where waits should be small, then increase demand to inspect the expected bottleneck. An implausible response often exposes a unit or capacity error.
Use independent replications and inspect Monte Carlo uncertainty. Sharing arrival and service streams across capacity scenarios can improve precision of their difference; separate scenario intervals do not capture that pairing. SimPy's resource tutorial illustrates how requests wait for limited capacity.
Vary demand, service variability assumptions, warm-up, and horizon. Distinguish numerical stability from realism. Validate against observed waits, throughput, and utilization where possible, and report whether summaries concern arrivals, completed patients, or time within a fixed window.
References and other material
Read the methodological references and supporting tutorials below. The examples in this lesson are original teaching calculations, not findings from these sources.
- SimPy tutorial: shared resources — A small queueing example showing requests for limited resources.