Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 36 Ā· Projects and Practice

Project: A Bank Queue Simulator

Build a simulator for a bank with several tellers, compare it with the exact Erlang C formula, and use it to decide how many tellers you need.

In this project you build a tool that a manager could use: how many tellers does a bank branch need so customers do not wait too long? You will combine the Poisson arrival process, exponential service times, the M/M/1 queue and the birth-death machinery from earlier lessons.

The model: M/M/c

Customers arrive as a Poisson process with rate λ per minute. There are c identical tellers, each serving one customer at a time with Exponential(μ) service times. Customers wait in a single first-come, first-served line. This is the M/M/c queue.

Let a = λ/μ (offered load, measured in "busy tellers") and ρ = a/c (utilization per teller). A stable system needs ρ < 1.

The number in the system is a birth-death process with λₙ = Ī» and μₙ = min(n, c) μ. From detailed balance, the chance that an arriving customer has to wait (all tellers busy) is the Erlang C formula:

Text
C(c, a) = [ a^c / c! · 1/(1 - ρ) ] / [ Σ_{k=0}^{c-1} a^k / k!  +  a^c / c! · 1/(1 - ρ) ]

and the mean wait in the queue is

Text
Wq = C(c, a) / (c μ - λ)

(PASTA: Poisson arrivals see time averages, so the probability that an arrival finds all servers busy equals the stationary probability of that event.)

Step 1: the exact formulas

Python Erlang C calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You need at least five tellers, because four would give ρ = 1. With more tellers the waiting probability falls sharply.

Step 2: simulate it

Event-driven simulation can be short. Keep a list of the times when each teller becomes free. When a customer arrives, they take the teller who becomes free first. Their start time is the later of the arrival time and that free time. This works for first-come first-served service and any service distribution.

Python Multi-server queue simulation

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The simulated mean waits and waiting probabilities agree with the Erlang C numbers. The last column, the share of customers who wait more than two minutes, is a "service level" that managers like, and the simulation gives it for free. The simulator also works for non-exponential service times, where no simple formula exists.

Step 3: use it for a decision

Suppose the branch has a rule: at least 90% of customers must wait less than 1 minute. How many tellers are needed at Ī» = 2 per minute, mean service time 2 minutes? Wrap the simulator in a loop and search for the smallest c that meets the target.

Python Staffing decision

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The answer is a table of service level against staffing, not a single magic number. In real use you would also add random-seed repeats and look at the spread.

Extensions to try

  • Replace exponential service by a constant time (an M/D/c queue) and see how waits drop. Less variability means shorter queues at the same load.
  • Add a time-varying arrival rate using the thinning algorithm to model a lunchtime rush.
  • Let customers leave if their wait exceeds a patience time (abandonment).
  • Estimate teller utilization, the fraction of time each teller is busy.

The model is a simplification: real customers do not arrive exactly as a Poisson process and service times are rarely exactly exponential. Treat the output as a planning guide and compare with measured data when you have it.

Check your understanding

Quick check Ā· 4 questions

of 4 answered You scored / 4 Ā· perfect!

  1. 1. In an M/M/c queue with λ = 6 per hour and μ = 2 per hour per teller, what is the smallest c that makes the system stable?

    Offered load is a = Ī»/μ = 3, and stability requires c > a, so c ≄ 4.
  2. 2. What does the Erlang C formula give?

    C(c, a) is the probability that all c servers are busy when a customer arrives.
  3. 3. In the simulation, what determines when a customer starts service?

    The customer cannot start before arriving or before a teller is free.
  4. 4. Why should the first few thousand simulated customers be discarded?

    Starting empty makes initial waiting times unrepresentative of steady state.

Summary

  • M/M/c is a birth-death chain; the Erlang C formula gives the waiting probability and Wq = C/(cμ āˆ’ Ī»).
  • A heap of teller free-times simulates the queue exactly in a few lines.
  • Compare simulation with formulas to validate the code, then use the simulation for questions without formulas (service levels, other service laws).
  • Stability needs Ī» < cμ.

Next: Project: Stock Price Paths