Operations 4 min read

Simulating a Single-Server Queue: Daily Service Count and Wait Times

This article models a single-mechanic repair shop as a single-server queue with exponentially distributed arrivals and uniformly distributed service times, then uses Python to simulate one workday and 1,000 workdays, reporting average daily serviced customers and average customer waiting time.

Model Perspective
Model Perspective
Model Perspective
Simulating a Single-Server Queue: Daily Service Count and Wait Times

1 Queue Problem

1.1 Problem

A repair shop has only one mechanic. Customer arrival intervals follow an exponential distribution with a given mean, and service times follow a uniform distribution (minutes). When many customers arrive, some must queue on a first‑come‑first‑served basis with unlimited queue length; serviced customers leave the shop. Assume a workday lasts 480 minutes. (1) Simulate the number of services completed in a workday and the average customer waiting time. (2) Simulate 1,000 workdays and compute the average daily number of services and the average daily waiting time.

1.2 Modeling

Let the inter‑arrival time of the i‑th customer be \(t_i\), the arrival time \(c_i\), the departure time \(g_i\), and the waiting time \(w_i\). These values can be derived recursively from the inter‑arrival times and service times.

1.3 Solution

Simulation of a single workday yields unstable results; over 1,000 simulated workdays the average daily number of services is about 44 and the average waiting time is approximately 25.66 minutes.

<code>from numpy.random import exponential, uniform, seed
from numpy import mean, array, zeros
seed(4)  # ensure reproducibility

def oneday():
    W = [0]  # waiting time of the first customer
    t0 = exponential(10)
    c0 = t0
    g0 = c0 + uniform(4, 15)
    g = g0
    while g < 480:
        t = exponential(10)  # next inter‑arrival time
        c = c0 + t            # next arrival time
        w = max(0, g - c)    # next waiting time
        g = max(g, c) + uniform(4, 15)  # next departure time
        c0 = c                # store current arrival time
        W.append(w)          # store waiting time
    return len(W), mean(W)

W1 = oneday()
print("服务人数和平均等待时间分别为:", W1)

d = 1000  # number of simulated days
T = zeros(d)
N = zeros(d)
for i in range(d):
    N[i], T[i] = oneday()
print("平均服务人数为:", round(N.mean()))
print("平均等待时间为:", T.mean())
</code>

Result:

服务人数和平均等待时间分别为:(39, 27.715473775462396)
平均服务人数为:44
平均等待时间为:25.66246800140869
simulationpythonoperations researchmonte carloqueueing theory
Model Perspective
Written by

Model Perspective

Insights, knowledge, and enjoyment from a mathematical modeling researcher and educator. Hosted by Haihua Wang, a modeling instructor and author of "Clever Use of Chat for Mathematical Modeling", "Modeling: The Mathematics of Thinking", "Mathematical Modeling Practice: A Hands‑On Guide to Competitions", and co‑author of "Mathematical Modeling: Teaching Design and Cases".

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.