Udeshi Salgado
Data Lab for Social Good,
Cardiff University, UK
2025-05-22
RecapContinuous Time Markov ChainsThe memoryless property of the exponential distribution:
\[
\Pr(T > t + u \mid T > u) = \Pr(T > t) \quad \text{for all } t, u > 0
\]

Interpretation: Time already spent in the current state does not influence the probability of future transitions.
This is consistent with the Markov property: The future depends only on the current state, not the past.
A stochastic process is a collection of random variables \(\{X(t)\}\) indexed by time \(t\).
The parameter space defines the set of time points:
The state space \(S\) is the set of all possible values \(X(t)\) can take:
\(X(t)\) represents the state of the system at time \(t\).
A continuous-time Markov chain (CTMC) is a stochastic process:
\[ \{X(t) \mid t \geq 0\} \]
where:
The process satisfies the Markov property:
\[ \Pr(A \mid X(t),\, 0 \leq t \leq T) = \Pr(A \mid X(T)) \]
where:
Imagine a small neighborhood pharmacy with space for maximum of two customers at a time. As the shop owner, you’re analyzing foot traffic to optimize customer experience without overcrowding or turning people away.
0, 1, and 2.Let \(T_i\) be the time until the next transition from state \(i \in \{0, 1, 2\}\)
\(T_0 \sim \text{Exp}(1)\) (arrival triggers transition)
\(T_2 \sim \text{Exp}(0.5)\) (departure triggers transition)
\(T_1 = \min(A, D)\), where:
Suppose \(T_1\), \(T_2\) are independent and \[ T_1 \sim \text{Exp}(\lambda_1),\quad T_2 \sim \text{Exp}(\lambda_2) \]
Then:
\[
\min(T_1, T_2) \sim \text{Exp}(\lambda_1 + \lambda_2)
\]
Application to our example:
The generator matrix (Q) summarizes the transition rates between states in a CTMC.
Steady-state probabilities represent the long-run behavior of the system.
They tell us:
To find them, we solve: \[ \boldsymbol{\pi} \mathbf{Q} = \mathbf{0}, \quad \text{with} \quad \sum \pi_i = 1 \]
Where: \(Q\) is the generator matrix of the CTMC, \(\boldsymbol{\pi}\) is a row vector of steady-state probabilities.
From:
\[ \begin{aligned} &-\pi_0 + 0.25\pi_1 = 0 \\ &\pi_0 - 1.25\pi_1 + 0.5\pi_2 = 0 \\ &\pi_1 - 0.5\pi_2 = 0 \\ &\pi_0 + \pi_1 + \pi_2 = 1 \end{aligned} \]
Thus: \[ \pi_0 = \frac{1}{13},\quad \pi_1 = \frac{4}{13},\quad \pi_2 = \frac{8}{13} \]
We calculate:
\[ 0 \cdot \frac{1}{13} + 1 \cdot \frac{4}{13} + 2 \cdot \frac{8}{13} = \frac{20}{13} \approx 1.54 \]
This is the expected number of customers in the shop in the long run.
A queueing system (e.g., customer service desk, call center, clinic) can often be modeled as a continuous-time Markov chain, under assumptions like:
Lab Activity: Part 1 – CTMC (Vaccine Observation Room)In this section, you’ll model an observation room where recently vaccinated patients are monitored for adverse events. The room has limited capacity (e.g., 2 beds).
We will use a Continuous-Time Markov Chain (CTMC) to:
Make sure you load the required R packages: Matrix, expm
Queueing Theory
Welcome to Queueing Theory!
We’ll explore how to model and analyze systems where “waiting” happens — like hospitals, call centers, and shops.
A system with:
Queueing systems are described using: A/B/S/d/e
Example: M/M/2/5/FIFO
→ Exponential arrivals, exponential service, 2 servers,
→ Max 5 customers in system, served in order of arrival
Definition:
A Poisson process with rate \(\lambda\) models random arrivals over time, where:
Traffic intensity: How busy the system is? \[
\rho = \frac{\lambda}{\mu}
\]
💡 Think of \(\rho\) as the load on the server.
If arrivals outpace service, the system can’t cope.
Generator matrix (Q):
\[ \mathbf{Q} = \begin{pmatrix} -\lambda & \lambda & 0 & 0 & \cdots \\ \mu & -(\lambda + \mu) & \lambda & 0 & \cdots \\ 0 & \mu & -(\lambda + \mu) & \lambda & \cdots \\ \vdots & \vdots & \ddots & \ddots & \ddots \end{pmatrix} \]
Assume the system reaches steady state (\(\rho < 1\)), with probabilities \(\{p_n,\ n \geq 0\}\).
These come from solving the balance equations of the CTMC:
State 0 balance:
\[ \lambda p_0 = \mu p_1 \]
For \(n \geq 1\):
\[ (\lambda + \mu)p_n = \lambda p_{n-1} + \mu p_{n+1} \]
Solving recursively gives:
\[ p_n = \rho^n p_0 \quad \text{where} \quad \rho = \frac{\lambda}{\mu} \]
Then apply the normalization condition:
\[ \sum_{n=0}^\infty p_n = 1 \quad \Rightarrow \quad p_0 = 1 - \rho \]
So we get:
Probability the system is empty:
\[p_0 = 1 - \rho\]
Probability the server is busy:
\[1 - p_0 = \rho\]
Probability of \(n\) customers in the system:
\[p_n = \rho^n (1 - \rho)\]
🧠 These describe the stationary distribution of the M/M/1 queue.
Expected number of customers in the system:
\[ L = \sum_{n=0}^{\infty} n p_n = \sum_{n=0}^{\infty} n \rho^n (1 - \rho) = \rho \sum_{n=1}^{\infty} n \rho^{n-1} (1 - \rho) = \frac{\rho}{1 - \rho} \]
💡 Use this to inform decisions on service rates (\(\mu\)) to keep queues manageable.
Four key summary performance measures:
A fundamental relationship linking arrival rate, waiting time, and number in the system.
\[ L = \lambda W \qquad \text{($\lambda$ = arrival rate, $W$ = mean time in system)} \]
Also:
\[ L = L_q + \frac{\lambda}{\mu} \qquad \text{(total in system = queue + in service)} \]
\[ W = W_q + \frac{1}{\mu} \qquad \text{($W_q$ = time in queue, $\frac{1}{\mu}$ = service time)} \]
\[ L_q = \lambda W_q \qquad \text{($\lambda$ = arrival rate, $W_q$ = mean time in queue)} \]
Using \(\rho = \frac{\lambda}{\mu}\) and Little’s Law:
Mean number in the system: \[ L = \frac{\rho}{1 - \rho} \]
Mean number in queue: \[ L_q = \frac{\rho^2}{1 - \rho} \]
Mean time in the system: \[ W = \frac{1}{\mu(1 - \rho)} \]
Mean waiting time in queue: \[ W_q = \frac{\rho}{\mu(1 - \rho)} \]
| Feature | M/M/1 | M/M/s | M/M/s/b |
|---|---|---|---|
| Servers | 1 | \(s\) | \(s\) |
| System Capacity | Infinite | Infinite | \(b\) (finite) |
| Arrival Rate (\(\lambda\)) | Poisson | Poisson | Poisson |
| Service Time | Exponential | Exponential | Exponential |
| Queue Capacity | Infinite | Infinite | \(b - s\) |
| Blocking? | No | No | Yes (if system full) |
| Common Use | Basic single-server queue | Multi-server (e.g., call center) | Limited capacity (e.g., hospital beds) |
You’ll see 3 real-world situations.
For each one, pick the most suitable queueing model:
You’ll have 30 seconds to discuss or decide for each!
An emergency care unit in a district hospital has five treatment beds. Once all beds are occupied, incoming patients must be transferred to a different facility, as there is no space for waiting or holding.
Which queueing model applies?
M/M/s/b Queueing Model
- Multiple beds = multiple servers
- No waiting space = limited capacity
- Incoming patients are blocked if full
A mobile vaccination clinic is staffed by a single nurse. Patients from a rural community arrive randomly and are vaccinated one at a time. If the nurse is busy, others wait in line without any restrictions on queue length.
Which model applies?
M/M/1 Queueing Model
A city hospital’s diagnostic laboratory operates with four technicians. Incoming test samples are processed as soon as a technician is free. If all are busy, samples wait in a queue with no limit.
Which model applies?
M/M/s Queueing Model
Lab Activity: Part 2 – Queueing Theory (Check-In Desk)In this section, you’ll model the check-in desk where patients arrive and wait to be registered by a nurse.
We will use an M/M/1 queue to:
You’ll be guided with real-world tasks followed by code. Let’s begin!

© 2025 Udeshi Salgado – DL4SG, Cardiff University