Next: October 8
Up: November 6
Previous: Event-driven simulation
A single-chair barbershop. From when it opens in the morning until it
closes, customers arrive at random times. If the barber is not busy,
he serves a customer immediately, otherwise they must wait in a queue
(FIFO order). The time needed to serve each customer is also random.
The entities are:
- Server (idle or busy)
- customer (arrival and service times)
The events:
- customer arrives
- customer departs
The arrival and departure events encapsulate everything we care to
know about a customer, so we don't need to track customers
explicitly.
System state:
- Simulation time (starts at 0)
- event list (starts empty)
- server status (initially idle)
- customer queue (initial value empty)
The first two elements are properly part of the simulation program,
rather than the system we're modelling. The last two are part of the
barbershop simulation. There is always a single event list, since it
represents the flow of time and all events end up there. There may be
multiple event lists, depending on the system we're modelling.
Initialization:
- Schedule the first customer
Arrival event:
- If the server is idle, start service immediately (change server
status to busy and schedule an end of service event). Otherwise the
customer waits in queue (in some models they may ``balk'' and decide
they don't have time to wait).
- Schedule the next customer arrival at random, given the desired
distribution (more about this later).
Departure event:
- Change server status to idle
- If the customer queue is not empty, start service on the first
customer in the queue (change the server status back to busy and
schedule an end of service event).
Statistics
- Average delay: keep track of how long each customer waits (even
if the waiting time is zero). At the end of the simulation, compute
the average waiting time per customer (assuming >= 1 customer).
- Average server utilization: the fraction of the total time that
the server was busy. Add up all the time the server was busy,
divided by the total simulation time.
- Average number of customers in the queue: this could be a
weighted sum: 0*(fraction of time the queue is empty) + 1*(fraction
of time the queue has 1 person) + 2*(fraction of time the queue has
2 people) + ...
- To compute all of these statistics, we need to keep track of the
following additional quantities during the simulation (the total
simulation time is already stored in the system state): the total
number of customers for the duration of the simulation, the total
time spent waiting for all customers, the total amount of time that
the server was busy, and the weighted sum of the number of customers
waiting in the queue.
- At the end of the simulation, the server finishes working the
the current request (if any), ignores anyone in the waiting list,
except to record the size of the waiting list. No further
statistics about the length of delay are collected, since this is
unknowable (everybody goes home).
Next: October 8
Up: November 6
Previous: Event-driven simulation
Danny Heap
2002-12-16