Single-Server Queue: Event-by-Event Simulation
This section follows a computer simulation of a single-server FIFO queue one event at a time. Starting from an empty system at t = 0, we apply the arrival and departure event routines, take a snapshot of the computer representation after each of the 13 events, and stop at t = 8.6 when the sixth customer finishes waiting. The report generator then turns the statistical counters into the three measures of performance.
Objectives
- Recall the queueing ideas the simulation needs: arrivals, service, FIFO, delay in queue,
Q(t)andB(t). - Describe how a discrete-event simulation program is organized around the next-event time advance.
- Name every state variable, the event list and the four statistical counters.
- Apply the exact update rules of the arrival and departure event routines.
- Trace all 13 events of the exercise to
t = 8.6and produce each snapshot. - Compute
d(n),q(n)andu(n)and explain what each one says about the system.
1. Queueing ideas we need
Key elements
- Customer: anything that arrives at a facility and requires service (people, machines, trucks, email).
- Server: any resource that provides the service. At any moment it is either busy or idle.
- Calling population: the potential customers. Here it is treated as infinite, so the arrival rate does not depend on how many customers are already in the system.
- System capacity: unlimited in this exercise.
A customer who is waiting is in the queue. A customer who is being served is in the system but not in the queue.
Arrivals and service
A_i is the inter-arrival time between customer i-1 and customer i, so the arrival time of a customer is the running sum of the inter-arrival times. S_i is the service time of customer i. Both are independent, identically distributed (IID) random variables, most often exponential, which gives Poisson arrivals. In this exercise they are given:
| Customer | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| A_i | 0.4 | 1.2 | 0.5 | 1.7 | 0.2 | 1.6 | 0.2 | 1.4 | 1.9 |
| Arrival time | 0.4 | 1.6 | 2.1 | 3.8 | 4.0 | 5.6 | 5.8 | 7.2 | 9.1 |
| S_i | 2.0 | 0.7 | 0.2 | 1.1 | 3.7 | 0.6 |
Queue discipline
The queue discipline decides which waiting customer is served next when the server becomes free: FIFO (first in, first out), LIFO (last in, first out), SIRO (service in random order), SPT (shortest processing time first) or PR (by priority). This lesson uses FIFO, so customers start service in arrival order: customer k uses service time S_k, and the first location of the times-of-arrival array always belongs to the next customer to be served.
Delay in queue
The delay D_i of customer i is the time he waits in the queue: the time his service starts minus his arrival time. If the server is idle when he arrives, service starts at once and D_i = 0; that zero delay still counts as an observed delay. In general, departure time = arrival time + delay + service time.
Q(t) and B(t)
Q(t)is the number of customers in the queue at timet(the customer in service is not counted).B(t)is the busy function:1if the server is busy at timet,0if it is idle.
Both functions change only at events, so between two events they are flat. The area under each one is a sum of rectangles, value times interval length.
The three measures of performance
d(n) = (D_1 + D_2 + ... + D_n) / n average delay in queue
q(n) = (area under Q(t) from 0 to T(n)) / T(n) time-average number in queue
u(n) = (area under B(t) from 0 to T(n)) / T(n) server utilization| Measure | Meaning |
|---|---|
d(n) | Average time a customer waits in the queue |
q(n) | Average number of customers waiting, weighted by time |
u(n) | Fraction of the run during which the server is busy |
Customers want d(n) and q(n) small; the organization wants u(n) high. A good design balances the two.
The stopping rule
The run stops when n delays in queue have been observed, here n = 6. The check is made after every event. In the exercise this happens at t = 8.6, when customer 5 departs and customer 6 starts service, so T(6) = 8.6. Note that the run does not stop when customer 6 arrives (at 5.6): it stops when he finishes waiting.
2. How the program is organized
Next-event time advance
- Set the simulation clock to 0.
- Read the times of future events from the event list.
- Advance the clock to the most imminent event, the smallest time in the list.
- Execute that event: update the system state and the statistical counters, and possibly the event list.
- Repeat until the stopping rule is satisfied.
The clock jumps from one event to the next, and periods of inactivity are skipped. The alternative, fixed-increment time advance, moves the clock in equal steps and treats every event in a step as happening at its end, which is less accurate.
Components of a discrete-event simulation model
| Component | Role |
|---|---|
| System state | Variables that describe the system at a particular time |
| Simulation clock | Current value of simulated time |
| Event list | Time of the next event of each type (here: next arrival, next departure) |
| Statistical counters | Variables that accumulate information about performance |
| Initialization routine | Sets up the model at time 0 |
| Timing routine | Finds the next event from the event list and advances the clock to it |
| Event routine | Updates the system state when an event of its type occurs (one per type) |
| Library routine | Generates random variates from the chosen distributions |
| Report generator | Computes the measures of performance from the counters at the end |
| Main program | Calls the timing routine, then the right event routine, checks for termination, and calls the report generator |
Flow of the main program
Start
-> Initialization routine: clock = 0, initialize state, counters, event list
-> repeat:
Timing routine: next event type i, advance the clock
Event routine i: update state, update counters, schedule future events
(library routine supplies random variates)
Simulation over? no -> repeat yes -> Report generator
-> Report generator: compute estimates, write report
StopIn this exercise the A and S values are given, so the library routine simply hands over the next value from the list.
3. The computer representation
State, clock, event list and counters
| Part | Variable | Meaning | At t = 0 |
|---|---|---|---|
| System state | Server status | 1 busy, 0 idle | 0 |
| System state | Number in queue | customers waiting, not the one in service | 0 |
| System state | Times of arrival | arrival time of each waiting customer, in queue order | empty |
| System state | Time of last event | clock value of the previous event | 0 |
| Clock | Clock | current simulated time | 0 |
| Event list | A | time of the next arrival | 0.4 |
| Event list | D | time of the next departure, ∞ when the server is idle | ∞ |
| Counters | Number delayed | delays observed so far | 0 |
| Counters | Total delay | sum of those delays | 0 |
| Counters | Area under Q(t) | running area under the queue-length curve | 0 |
| Counters | Area under B(t) | running area under the busy function | 0 |
The times-of-arrival array exists because, when a waiting customer finally starts service, the program needs his arrival time to compute his delay.
Rule 1: update the areas first, with the previous state
lag = clock - time_of_last_event
area_Q = area_Q + (number in queue BEFORE the event) x lag
area_B = area_B + (server status BEFORE the event) x lag
time_of_last_event = clockBetween the last event and now, the queue length and server status held their old values, so that rectangle is what the counter adds.
Rule 2: the arrival event routine
- Update both areas with the previous state.
- Schedule the next arrival:
A = clock + A_next. - If the server is busy: add 1 to the number in queue and store the clock in the next free location of the times-of-arrival array.
- If the server is idle: the delay is 0; add 1 to number delayed (total delay is unchanged); set server status to 1; schedule this customer's departure
D = clock + S. - Set time of last event = clock.
Rule 3: the departure event routine
- Queue empty: update both areas, set server status to 0 and
D = ∞, set time of last event = clock. - Queue not empty: update both areas; compute the delay of the customer entering service as clock minus the first time in the array; add it to total delay and add 1 to number delayed; schedule
D = clock + Sfor the new customer; subtract 1 from the number in queue and move every time in the array up one place; set time of last event = clock.
The delay must be computed before the array is shifted: the entering customer's arrival time sits in the first location only until the shift.
4. Event-by-event walkthrough
The run below has 13 events. For each one: the timing routine's choice, the updates in order, and the snapshot after the event. The first four events are the ones shown on the exercise slides; the rest complete the exercise.
t = 0: initialization
Clock = 0, server idle, queue empty, all counters 0. The first event is always an arrival, so A = A1 = 0.4 and D = ∞.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | empty | 0 | 0.4 | ∞ | 0 | 0 | 0 | 0 |
Event 1, t = 0.4: arrival of customer 1
- Timing routine: event list holds
A = 0.4andD = ∞, the smaller is A = 0.4. - Areas first, with the previous state:
Q: 0 + 0 x (0.4 - 0) = 0andB: 0 + 0 x (0.4 - 0) = 0. - Schedule the next arrival:
A = 0.4 + 1.2 = 1.6(usesA2). - Server idle: customer 1 starts service at once, delay
0, number delayed = 1. - Server status = 1, schedule the departure:
D = 0.4 + 2.0 = 2.4(usesS1).
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 0.4 | 1 | 0 | empty | 0.4 | 1.6 | 2.4 | 1 | 0 | 0 | 0 |
Event 2, t = 1.6: arrival of customer 2
- Timing routine: event list holds
A = 1.6andD = 2.4, the smaller is A = 1.6. - Areas first, with the previous state:
Q: 0 + 0 x (1.6 - 0.4) = 0andB: 0 + 1 x (1.6 - 0.4) = 1.2. - Schedule the next arrival:
A = 1.6 + 0.5 = 2.1(usesA3). - Server busy: customer 2 joins the queue,
Q = 1, time1.6stored in location 1.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 1.6 | 1 | 1 | 1.6 | 1.6 | 2.1 | 2.4 | 1 | 0 | 0 | 1.2 |
Event 3, t = 2.1: arrival of customer 3
- Timing routine: event list holds
A = 2.1andD = 2.4, the smaller is A = 2.1. - Areas first, with the previous state:
Q: 0 + 1 x (2.1 - 1.6) = 0.5andB: 1.2 + 1 x (2.1 - 1.6) = 1.7. - Schedule the next arrival:
A = 2.1 + 1.7 = 3.8(usesA4). - Server busy: customer 3 joins the queue,
Q = 2, time2.1stored in location 2.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 2.1 | 1 | 2 | 1.6, 2.1 | 2.1 | 3.8 | 2.4 | 1 | 0 | 0.5 | 1.7 |
Event 4, t = 2.4: departure of customer 1
- Timing routine: event list holds
A = 3.8andD = 2.4, the smaller is D = 2.4. - Areas first, with the previous state:
Q: 0.5 + 2 x (2.4 - 2.1) = 1.1andB: 1.7 + 1 x (2.4 - 2.1) = 2.0. - Customer 2 leaves the queue: delay
2.4 - 1.6 = 0.8, read before the shift. - Total delay
0 + 0.8 = 0.8, number delayed = 2. - Schedule the departure:
D = 2.4 + 0.7 = 3.1(usesS2). - Q = 1, array moves up one place: 2.1.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 2.4 | 1 | 1 | 2.1 | 2.4 | 3.8 | 3.1 | 2 | 0.8 | 1.1 | 2.0 |
Event 5, t = 3.1: departure of customer 2
- Timing routine: event list holds
A = 3.8andD = 3.1, the smaller is D = 3.1. - Areas first, with the previous state:
Q: 1.1 + 1 x (3.1 - 2.4) = 1.8andB: 2.0 + 1 x (3.1 - 2.4) = 2.7. - Customer 3 leaves the queue: delay
3.1 - 2.1 = 1.0, read before the shift. - Total delay
0.8 + 1.0 = 1.8, number delayed = 3. - Schedule the departure:
D = 3.1 + 0.2 = 3.3(usesS3). - Q = 0, array moves up one place: empty.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 3.1 | 1 | 0 | empty | 3.1 | 3.8 | 3.3 | 3 | 1.8 | 1.8 | 2.7 |
Event 6, t = 3.3: departure of customer 3
- Timing routine: event list holds
A = 3.8andD = 3.3, the smaller is D = 3.3. - Areas first, with the previous state:
Q: 1.8 + 0 x (3.3 - 3.1) = 1.8andB: 2.7 + 1 x (3.3 - 3.1) = 2.9. - Queue empty: server status = 0 and
D = ∞.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 3.3 | 0 | 0 | empty | 3.3 | 3.8 | ∞ | 3 | 1.8 | 1.8 | 2.9 |
Event 7, t = 3.8: arrival of customer 4
- Timing routine: event list holds
A = 3.8andD = ∞, the smaller is A = 3.8. - Areas first, with the previous state:
Q: 1.8 + 0 x (3.8 - 3.3) = 1.8andB: 2.9 + 0 x (3.8 - 3.3) = 2.9. - Schedule the next arrival:
A = 3.8 + 0.2 = 4.0(usesA5). - Server idle: customer 4 starts service at once, delay
0, number delayed = 4. - Server status = 1, schedule the departure:
D = 3.8 + 1.1 = 4.9(usesS4).
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 3.8 | 1 | 0 | empty | 3.8 | 4.0 | 4.9 | 4 | 1.8 | 1.8 | 2.9 |
Event 8, t = 4.0: arrival of customer 5
- Timing routine: event list holds
A = 4.0andD = 4.9, the smaller is A = 4.0. - Areas first, with the previous state:
Q: 1.8 + 0 x (4.0 - 3.8) = 1.8andB: 2.9 + 1 x (4.0 - 3.8) = 3.1. - Schedule the next arrival:
A = 4.0 + 1.6 = 5.6(usesA6). - Server busy: customer 5 joins the queue,
Q = 1, time4.0stored in location 1.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 4.0 | 1 | 1 | 4.0 | 4.0 | 5.6 | 4.9 | 4 | 1.8 | 1.8 | 3.1 |
Event 9, t = 4.9: departure of customer 4
- Timing routine: event list holds
A = 5.6andD = 4.9, the smaller is D = 4.9. - Areas first, with the previous state:
Q: 1.8 + 1 x (4.9 - 4.0) = 2.7andB: 3.1 + 1 x (4.9 - 4.0) = 4.0. - Customer 5 leaves the queue: delay
4.9 - 4.0 = 0.9, read before the shift. - Total delay
1.8 + 0.9 = 2.7, number delayed = 5. - Schedule the departure:
D = 4.9 + 3.7 = 8.6(usesS5). - Q = 0, array moves up one place: empty.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 4.9 | 1 | 0 | empty | 4.9 | 5.6 | 8.6 | 5 | 2.7 | 2.7 | 4.0 |
Event 10, t = 5.6: arrival of customer 6
- Timing routine: event list holds
A = 5.6andD = 8.6, the smaller is A = 5.6. - Areas first, with the previous state:
Q: 2.7 + 0 x (5.6 - 4.9) = 2.7andB: 4.0 + 1 x (5.6 - 4.9) = 4.7. - Schedule the next arrival:
A = 5.6 + 0.2 = 5.8(usesA7). - Server busy: customer 6 joins the queue,
Q = 1, time5.6stored in location 1.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 1 | 1 | 5.6 | 5.6 | 5.8 | 8.6 | 5 | 2.7 | 2.7 | 4.7 |
Event 11, t = 5.8: arrival of customer 7
- Timing routine: event list holds
A = 5.8andD = 8.6, the smaller is A = 5.8. - Areas first, with the previous state:
Q: 2.7 + 1 x (5.8 - 5.6) = 2.9andB: 4.7 + 1 x (5.8 - 5.6) = 4.9. - Schedule the next arrival:
A = 5.8 + 1.4 = 7.2(usesA8). - Server busy: customer 7 joins the queue,
Q = 2, time5.8stored in location 2.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 5.8 | 1 | 2 | 5.6, 5.8 | 5.8 | 7.2 | 8.6 | 5 | 2.7 | 2.9 | 4.9 |
Event 12, t = 7.2: arrival of customer 8
- Timing routine: event list holds
A = 7.2andD = 8.6, the smaller is A = 7.2. - Areas first, with the previous state:
Q: 2.9 + 2 x (7.2 - 5.8) = 5.7andB: 4.9 + 1 x (7.2 - 5.8) = 6.3. - Schedule the next arrival:
A = 7.2 + 1.9 = 9.1(usesA9). - Server busy: customer 8 joins the queue,
Q = 3, time7.2stored in location 3.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 7.2 | 1 | 3 | 5.6, 5.8, 7.2 | 7.2 | 9.1 | 8.6 | 5 | 2.7 | 5.7 | 6.3 |
Event 13, t = 8.6: departure of customer 5
- Timing routine: event list holds
A = 9.1andD = 8.6, the smaller is D = 8.6. - Areas first, with the previous state:
Q: 5.7 + 3 x (8.6 - 7.2) = 9.9andB: 6.3 + 1 x (8.6 - 7.2) = 7.7. - Customer 6 leaves the queue: delay
8.6 - 5.6 = 3.0, read before the shift. - Total delay
2.7 + 3.0 = 5.7, number delayed = 6. - Schedule the departure:
D = 8.6 + 0.6 = 9.2(usesS6). - Q = 2, array moves up one place: 5.8, 7.2.
- Number delayed = 6 = n: stopping rule met, the report generator runs.
| Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|
| 8.6 | 1 | 2 | 5.8, 7.2 | 8.6 | 9.1 | 9.2 | 6 | 5.7 | 9.9 | 7.7 |
The whole run in one table
| Event | Type | Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | init | 0 | 0 | 0 | empty | 0 | 0.4 | ∞ | 0 | 0 | 0 | 0 |
| 1 | arrival 1 | 0.4 | 1 | 0 | empty | 0.4 | 1.6 | 2.4 | 1 | 0 | 0 | 0 |
| 2 | arrival 2 | 1.6 | 1 | 1 | 1.6 | 1.6 | 2.1 | 2.4 | 1 | 0 | 0 | 1.2 |
| 3 | arrival 3 | 2.1 | 1 | 2 | 1.6, 2.1 | 2.1 | 3.8 | 2.4 | 1 | 0 | 0.5 | 1.7 |
| 4 | departure 1 | 2.4 | 1 | 1 | 2.1 | 2.4 | 3.8 | 3.1 | 2 | 0.8 | 1.1 | 2.0 |
| 5 | departure 2 | 3.1 | 1 | 0 | empty | 3.1 | 3.8 | 3.3 | 3 | 1.8 | 1.8 | 2.7 |
| 6 | departure 3 | 3.3 | 0 | 0 | empty | 3.3 | 3.8 | ∞ | 3 | 1.8 | 1.8 | 2.9 |
| 7 | arrival 4 | 3.8 | 1 | 0 | empty | 3.8 | 4.0 | 4.9 | 4 | 1.8 | 1.8 | 2.9 |
| 8 | arrival 5 | 4.0 | 1 | 1 | 4.0 | 4.0 | 5.6 | 4.9 | 4 | 1.8 | 1.8 | 3.1 |
| 9 | departure 4 | 4.9 | 1 | 0 | empty | 4.9 | 5.6 | 8.6 | 5 | 2.7 | 2.7 | 4.0 |
| 10 | arrival 6 | 5.6 | 1 | 1 | 5.6 | 5.6 | 5.8 | 8.6 | 5 | 2.7 | 2.7 | 4.7 |
| 11 | arrival 7 | 5.8 | 1 | 2 | 5.6, 5.8 | 5.8 | 7.2 | 8.6 | 5 | 2.7 | 2.9 | 4.9 |
| 12 | arrival 8 | 7.2 | 1 | 3 | 5.6, 5.8, 7.2 | 7.2 | 9.1 | 8.6 | 5 | 2.7 | 5.7 | 6.3 |
| 13 | departure 5 | 8.6 | 1 | 2 | 5.8, 7.2 | 8.6 | 9.1 | 9.2 | 6 | 5.7 | 9.9 | 7.7 |
The six delays
| Customer | Arrival | Service starts | Delay |
|---|---|---|---|
| 1 | 0.4 | 0.4 | 0 |
| 2 | 1.6 | 2.4 | 0.8 |
| 3 | 2.1 | 3.1 | 1.0 |
| 4 | 3.8 | 3.8 | 0 |
| 5 | 4.0 | 4.9 | 0.9 |
| 6 | 5.6 | 8.6 | 3.0 |
Total delay = 0 + 0.8 + 1.0 + 0 + 0.9 + 3.0 = 5.7. Customers 1 and 4 found the server idle, so their delay is 0, but each still counts in number delayed.
5. Q(t), B(t) and the areas
Q(t)
| Interval | Q(t) | Length | Q x length |
|---|---|---|---|
| 0 to 1.6 | 0 | 1.6 | 0 |
| 1.6 to 2.1 | 1 | 0.5 | 0.5 |
| 2.1 to 2.4 | 2 | 0.3 | 0.6 |
| 2.4 to 3.1 | 1 | 0.7 | 0.7 |
| 3.1 to 4.0 | 0 | 0.9 | 0 |
| 4.0 to 4.9 | 1 | 0.9 | 0.9 |
| 4.9 to 5.6 | 0 | 0.7 | 0 |
| 5.6 to 5.8 | 1 | 0.2 | 0.2 |
| 5.8 to 7.2 | 2 | 1.4 | 2.8 |
| 7.2 to 8.6 | 3 | 1.4 | 4.2 |
Grouping the intervals by queue length:
area under Q(t) = 1 x [(2.1 - 1.6) + (3.1 - 2.4) + (4.9 - 4.0) + (5.8 - 5.6)] + 2 x [(2.4 - 2.1) + (7.2 - 5.8)] + 3 x [(8.6 - 7.2)]
= 1 x 2.3 + 2 x 1.7 + 3 x 1.4
= 2.3 + 3.4 + 4.2 = 9.9This is exactly the value the area-under-Q counter reached at t = 8.6: the event routines build the same sum one rectangle at a time.
B(t)
| Interval | B(t) | Length |
|---|---|---|
| 0 to 0.4 | 0 | 0.4 |
| 0.4 to 3.3 | 1 | 2.9 |
| 3.3 to 3.8 | 0 | 0.5 |
| 3.8 to 8.6 | 1 | 4.8 |
area under B(t) = 1 x [(3.3 - 0.4) + (8.6 - 3.8)] = 2.9 + 4.8 = 7.76. The report generator
Once number delayed reaches 6, the main program calls the report generator:
d(6) = 5.7 / 6 = 0.95
q(6) = 9.9 / 8.6 = 1.15
u(6) = 7.7 / 8.6 = 0.90 (89.5 percent)| Measure | Value | What it says |
|---|---|---|
d(6) | 0.95 | On average a customer waited 0.95 minutes in the queue |
q(6) | 1.15 | Averaged over time, 1.15 customers were waiting in the queue |
u(6) | 0.90 | The server was busy 89.5 percent of the time |
The exercise slide writes the utilization as 0.9; to two decimals it is 0.90.
7. Common mistakes
- Updating the areas with the new state. At
t = 2.1the queue goes from 1 to 2. The correct update is0 + 1 x (2.1 - 1.6) = 0.5; using the new value gives0 + 2 x (2.1 - 1.6) = 1.0, which is wrong. - Forgetting
D = ∞when the server goes idle. Att = 3.3the queue is empty, so the server becomes idle andD = ∞; the next event is then the arrival at3.8. A staleDwould make the timing routine pick a departure for a customer who does not exist. Server status must drop to 0 as well, so nothing is added to the area underB(t)from 3.3 to 3.8. - Shifting the array before computing the delay. At
t = 2.4the array holds1.6, 2.1. Customer 2's delay is2.4 - 1.6 = 0.8. Shifting first would give2.4 - 2.1 = 0.3, which is customer 3's arrival time, not customer 2's. - The stopping rule. The run stops when number delayed = 6, at
t = 8.6, soT(6) = 8.6. It does not stop when customer 6 arrives (5.6) or when he departs (9.2).
Quick self-check: zero delays count in number delayed, the counters never decrease, and after every event the time of last event equals the clock.
8. Practice
Trace each run event by event, starting from the t = 0 snapshot, until number delayed reaches n. Give the snapshot after every event, then compute d(n), q(n) and u(n). Answers are at the end of this page.
Run 1: n = 4
| i | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| A_i | 0.5 | 0.3 | 1.8 | 0.4 | 0.6 |
| S_i | 1.2 | 0.6 | 0.7 | 1.1 |
Run 2: n = 5
| i | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| A_i | 1.0 | 0.5 | 0.6 | 2.5 | 0.3 | 0.4 | 1.1 |
| S_i | 1.4 | 0.8 | 0.5 | 1.2 | 1.3 |
Checklist for every event:
- Pick the smaller of
AandDand set the clock to it. - Add the previous queue length times the lag, and the previous server status times the lag, to the two areas.
- Arrival: schedule the next arrival, then join the queue or start service.
- Departure: an empty queue gives
D = ∞; otherwise compute the delay first, then shift. - Set time of last event = clock and compare number delayed with
n.
Key takeaways
- The clock jumps from event to event:
clock = min(A, D). - Every event updates the areas first, with the previous state.
- An idle server always means
D = ∞. - A departure reads the delay before shifting the times-of-arrival array.
- The run ends when number delayed = n, and
T(n)is that clock value. - The report generator divides total delay by
n, and each area byT(n).
Answers
Run 1
Event 1, t = 0.5: arrival of customer 1. Areas first, with the previous state: Q: 0 + 0 x (0.5 - 0) = 0 and B: 0 + 0 x (0.5 - 0) = 0. Schedule the next arrival: A = 0.5 + 0.3 = 0.8 (uses A2). Server idle: customer 1 starts service at once, delay 0, number delayed = 1. Server status = 1, schedule the departure: D = 0.5 + 1.2 = 1.7 (uses S1).
Event 2, t = 0.8: arrival of customer 2. Areas first, with the previous state: Q: 0 + 0 x (0.8 - 0.5) = 0 and B: 0 + 1 x (0.8 - 0.5) = 0.3. Schedule the next arrival: A = 0.8 + 1.8 = 2.6 (uses A3). Server busy: customer 2 joins the queue, Q = 1, time 0.8 stored in location 1.
Event 3, t = 1.7: departure of customer 1. Areas first, with the previous state: Q: 0 + 1 x (1.7 - 0.8) = 0.9 and B: 0.3 + 1 x (1.7 - 0.8) = 1.2. Customer 2 leaves the queue: delay 1.7 - 0.8 = 0.9, read before the shift. Total delay 0 + 0.9 = 0.9, number delayed = 2. Schedule the departure: D = 1.7 + 0.6 = 2.3 (uses S2). Q = 0, array moves up one place: empty.
Event 4, t = 2.3: departure of customer 2. Areas first, with the previous state: Q: 0.9 + 0 x (2.3 - 1.7) = 0.9 and B: 1.2 + 1 x (2.3 - 1.7) = 1.8. Queue empty: server status = 0 and D = ∞.
Event 5, t = 2.6: arrival of customer 3. Areas first, with the previous state: Q: 0.9 + 0 x (2.6 - 2.3) = 0.9 and B: 1.8 + 0 x (2.6 - 2.3) = 1.8. Schedule the next arrival: A = 2.6 + 0.4 = 3.0 (uses A4). Server idle: customer 3 starts service at once, delay 0, number delayed = 3. Server status = 1, schedule the departure: D = 2.6 + 0.7 = 3.3 (uses S3).
Event 6, t = 3.0: arrival of customer 4. Areas first, with the previous state: Q: 0.9 + 0 x (3.0 - 2.6) = 0.9 and B: 1.8 + 1 x (3.0 - 2.6) = 2.2. Schedule the next arrival: A = 3.0 + 0.6 = 3.6 (uses A5). Server busy: customer 4 joins the queue, Q = 1, time 3.0 stored in location 1.
Event 7, t = 3.3: departure of customer 3. Areas first, with the previous state: Q: 0.9 + 1 x (3.3 - 3.0) = 1.2 and B: 2.2 + 1 x (3.3 - 3.0) = 2.5. Customer 4 leaves the queue: delay 3.3 - 3.0 = 0.3, read before the shift. Total delay 0.9 + 0.3 = 1.2, number delayed = 4. Schedule the departure: D = 3.3 + 1.1 = 4.4 (uses S4). Q = 0, array moves up one place: empty. Number delayed = 4 = n: stopping rule met, the report generator runs.
| Event | Type | Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | init | 0 | 0 | 0 | empty | 0 | 0.5 | ∞ | 0 | 0 | 0 | 0 |
| 1 | arrival 1 | 0.5 | 1 | 0 | empty | 0.5 | 0.8 | 1.7 | 1 | 0 | 0 | 0 |
| 2 | arrival 2 | 0.8 | 1 | 1 | 0.8 | 0.8 | 2.6 | 1.7 | 1 | 0 | 0 | 0.3 |
| 3 | departure 1 | 1.7 | 1 | 0 | empty | 1.7 | 2.6 | 2.3 | 2 | 0.9 | 0.9 | 1.2 |
| 4 | departure 2 | 2.3 | 0 | 0 | empty | 2.3 | 2.6 | ∞ | 2 | 0.9 | 0.9 | 1.8 |
| 5 | arrival 3 | 2.6 | 1 | 0 | empty | 2.6 | 3.0 | 3.3 | 3 | 0.9 | 0.9 | 1.8 |
| 6 | arrival 4 | 3.0 | 1 | 1 | 3.0 | 3.0 | 3.6 | 3.3 | 3 | 0.9 | 0.9 | 2.2 |
| 7 | departure 3 | 3.3 | 1 | 0 | empty | 3.3 | 3.6 | 4.4 | 4 | 1.2 | 1.2 | 2.5 |
T(4) = 3.3
d(4) = 1.2 / 4 = 0.30
q(4) = 1.2 / 3.3 = 0.36
u(4) = 2.5 / 3.3 = 0.76 (75.8 percent)Run 2
Event 1, t = 1.0: arrival of customer 1. Areas first, with the previous state: Q: 0 + 0 x (1.0 - 0) = 0 and B: 0 + 0 x (1.0 - 0) = 0. Schedule the next arrival: A = 1.0 + 0.5 = 1.5 (uses A2). Server idle: customer 1 starts service at once, delay 0, number delayed = 1. Server status = 1, schedule the departure: D = 1.0 + 1.4 = 2.4 (uses S1).
Event 2, t = 1.5: arrival of customer 2. Areas first, with the previous state: Q: 0 + 0 x (1.5 - 1.0) = 0 and B: 0 + 1 x (1.5 - 1.0) = 0.5. Schedule the next arrival: A = 1.5 + 0.6 = 2.1 (uses A3). Server busy: customer 2 joins the queue, Q = 1, time 1.5 stored in location 1.
Event 3, t = 2.1: arrival of customer 3. Areas first, with the previous state: Q: 0 + 1 x (2.1 - 1.5) = 0.6 and B: 0.5 + 1 x (2.1 - 1.5) = 1.1. Schedule the next arrival: A = 2.1 + 2.5 = 4.6 (uses A4). Server busy: customer 3 joins the queue, Q = 2, time 2.1 stored in location 2.
Event 4, t = 2.4: departure of customer 1. Areas first, with the previous state: Q: 0.6 + 2 x (2.4 - 2.1) = 1.2 and B: 1.1 + 1 x (2.4 - 2.1) = 1.4. Customer 2 leaves the queue: delay 2.4 - 1.5 = 0.9, read before the shift. Total delay 0 + 0.9 = 0.9, number delayed = 2. Schedule the departure: D = 2.4 + 0.8 = 3.2 (uses S2). Q = 1, array moves up one place: 2.1.
Event 5, t = 3.2: departure of customer 2. Areas first, with the previous state: Q: 1.2 + 1 x (3.2 - 2.4) = 2.0 and B: 1.4 + 1 x (3.2 - 2.4) = 2.2. Customer 3 leaves the queue: delay 3.2 - 2.1 = 1.1, read before the shift. Total delay 0.9 + 1.1 = 2.0, number delayed = 3. Schedule the departure: D = 3.2 + 0.5 = 3.7 (uses S3). Q = 0, array moves up one place: empty.
Event 6, t = 3.7: departure of customer 3. Areas first, with the previous state: Q: 2.0 + 0 x (3.7 - 3.2) = 2.0 and B: 2.2 + 1 x (3.7 - 3.2) = 2.7. Queue empty: server status = 0 and D = ∞.
Event 7, t = 4.6: arrival of customer 4. Areas first, with the previous state: Q: 2.0 + 0 x (4.6 - 3.7) = 2.0 and B: 2.7 + 0 x (4.6 - 3.7) = 2.7. Schedule the next arrival: A = 4.6 + 0.3 = 4.9 (uses A5). Server idle: customer 4 starts service at once, delay 0, number delayed = 4. Server status = 1, schedule the departure: D = 4.6 + 1.2 = 5.8 (uses S4).
Event 8, t = 4.9: arrival of customer 5. Areas first, with the previous state: Q: 2.0 + 0 x (4.9 - 4.6) = 2.0 and B: 2.7 + 1 x (4.9 - 4.6) = 3.0. Schedule the next arrival: A = 4.9 + 0.4 = 5.3 (uses A6). Server busy: customer 5 joins the queue, Q = 1, time 4.9 stored in location 1.
Event 9, t = 5.3: arrival of customer 6. Areas first, with the previous state: Q: 2.0 + 1 x (5.3 - 4.9) = 2.4 and B: 3.0 + 1 x (5.3 - 4.9) = 3.4. Schedule the next arrival: A = 5.3 + 1.1 = 6.4 (uses A7). Server busy: customer 6 joins the queue, Q = 2, time 5.3 stored in location 2.
Event 10, t = 5.8: departure of customer 4. Areas first, with the previous state: Q: 2.4 + 2 x (5.8 - 5.3) = 3.4 and B: 3.4 + 1 x (5.8 - 5.3) = 3.9. Customer 5 leaves the queue: delay 5.8 - 4.9 = 0.9, read before the shift. Total delay 2.0 + 0.9 = 2.9, number delayed = 5. Schedule the departure: D = 5.8 + 1.3 = 7.1 (uses S5). Q = 1, array moves up one place: 5.3. Number delayed = 5 = n: stopping rule met, the report generator runs.
| Event | Type | Clock | Server status | Number in queue | Times of arrival | Time of last event | A | D | Number delayed | Total delay | Area under Q(t) | Area under B(t) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | init | 0 | 0 | 0 | empty | 0 | 1.0 | ∞ | 0 | 0 | 0 | 0 |
| 1 | arrival 1 | 1.0 | 1 | 0 | empty | 1.0 | 1.5 | 2.4 | 1 | 0 | 0 | 0 |
| 2 | arrival 2 | 1.5 | 1 | 1 | 1.5 | 1.5 | 2.1 | 2.4 | 1 | 0 | 0 | 0.5 |
| 3 | arrival 3 | 2.1 | 1 | 2 | 1.5, 2.1 | 2.1 | 4.6 | 2.4 | 1 | 0 | 0.6 | 1.1 |
| 4 | departure 1 | 2.4 | 1 | 1 | 2.1 | 2.4 | 4.6 | 3.2 | 2 | 0.9 | 1.2 | 1.4 |
| 5 | departure 2 | 3.2 | 1 | 0 | empty | 3.2 | 4.6 | 3.7 | 3 | 2.0 | 2.0 | 2.2 |
| 6 | departure 3 | 3.7 | 0 | 0 | empty | 3.7 | 4.6 | ∞ | 3 | 2.0 | 2.0 | 2.7 |
| 7 | arrival 4 | 4.6 | 1 | 0 | empty | 4.6 | 4.9 | 5.8 | 4 | 2.0 | 2.0 | 2.7 |
| 8 | arrival 5 | 4.9 | 1 | 1 | 4.9 | 4.9 | 5.3 | 5.8 | 4 | 2.0 | 2.0 | 3.0 |
| 9 | arrival 6 | 5.3 | 1 | 2 | 4.9, 5.3 | 5.3 | 6.4 | 5.8 | 4 | 2.0 | 2.4 | 3.4 |
| 10 | departure 4 | 5.8 | 1 | 1 | 5.3 | 5.8 | 6.4 | 7.1 | 5 | 2.9 | 3.4 | 3.9 |
T(5) = 5.8
d(5) = 2.9 / 5 = 0.58
q(5) = 3.4 / 5.8 = 0.59
u(5) = 3.9 / 5.8 = 0.67 (67.2 percent)