In the print dialog, choose "Save as PDF" as the destination.
Modeling and Simulation - Lesson 2
Follow the computer representation of a FIFO queue one event at a time, from t = 0 until the sixth delay ends.
Q(t) and B(t)t = 8.6 and produce each snapshotd(n), q(n) and u(n) in the report generator and say what they meanPart 1
A short recap of lecture 2
A(i) is the inter-arrival time between customer i-1 and customer i0.4 + 1.2 = 1.6S(i) is the service time of customer i; for customer 1 we write A1 and S1, and so onEach arrival time is the previous arrival time plus A(i)
| Customer | A(i) | Arrival time | S(i) |
|---|---|---|---|
| 1 | 0.4 | 0.4 | 2.0 |
| 2 | 1.2 | 1.6 | 0.7 |
| 3 | 0.5 | 2.1 | 0.2 |
| 4 | 1.7 | 3.8 | 1.1 |
| 5 | 0.2 | 4.0 | 3.7 |
| Customer | A(i) | Arrival time | S(i) |
|---|---|---|---|
| 6 | 1.6 | 5.6 | 0.6 |
| 7 | 0.2 | 5.8 | |
| 8 | 1.4 | 7.2 | |
| 9 | 1.9 | 9.1 |
The rule that picks which waiting customer is served next when the server becomes free.
i waits in the queue: the time service starts minus the arrival time.D(i) = 0D2 = 2.4 - 1.6 = 0.8t (not counting the one in service).1 if the server is busy at time t, 0 if it is idle.q(n) and u(n)n = 6n?t = 8.6: customer 5 departs and customer 6 starts serviceT(6) = 8.6, and both time averages divide by itPart 2
From lecture 1
0The data side of the model
The code side of the model
Start
Initialization routine
clock set to 0, state, counters, event list
Timing routine
next event type i, advance clock
Event routine i
state, counters, future events
Simulation over?
no: back to timing
Report generator
estimates, write report
Part 3
State, event list, counters, and the update rules
| Variable | Holds | At t = 0 |
|---|---|---|
| Server status | 1 busy, 0 idle | 0 |
| Number in queue | customers waiting, not in service | 0 |
| Times of arrival | arrival time of each waiting customer, in queue order | empty |
| Time of last event | clock value of the previous event | 0 |
| Item | Holds | At t = 0 |
|---|---|---|
| Clock | current simulated time | 0 |
| Next arrival A | time of the next arrival | A1 = 0.4 |
| Next departure D | time of the next departure | ∞ |
| Counter | Accumulates | At t = 0 |
|---|---|---|
| Number delayed | delays observed so far | 0 |
| Total delay | sum of those delays | 0 |
| Area under Q(t) | queue length times the time since the last event | 0 |
| Area under B(t) | server status times the time since the last event | 0 |
t is the new clock, τ the time of the last eventQ(τ) and B(τ) are the values before this event changes themτ to tA = t + A(i+1), where t is the clock and i the arriving customer0, add 1 to number delayed, set server status to 1, schedule D = t + S of this customerThe two branches, side by side; t is the clock
| Step | Queue empty | Queue not empty |
|---|---|---|
| 1 | Update both areas | Update both areas |
| 2 | Set server status to 0 | Delay: the clock minus the first time in the array |
| 3 | D = ∞ | Add it to total delay, add 1 to number delayed |
| 4 | Set the time of last event to the clock | Schedule D = t + S of the new customer |
| 5 | Subtract 1 from number in queue, shift the array up |
Part 4
13 events, t = 0 to t = 8.6. Each slide shows only the values the event changes; the clock and the time of last event always move to the event time. The full snapshots are on the lesson page. Predict before each reveal.
Event 1 of 13
Event list: A = 0.4, D = ∞. The smaller is A, so the clock and the time of last event move to 0.4.
| Item | Before | After | How |
|---|---|---|---|
| Server status | 0 | 1 | customer 1 starts service at once |
| Next arrival A | 0.4 | 1.6 | 0.4 + 1.2 (A2) |
| Next departure D | ∞ | 2.4 | 0.4 + 2.0 (S1) |
| Number delayed (total delay) | 0 (0) | 1 (0) | delay 0, still counted |
Events 2 and 3 of 13
Both are arrivals to a busy server: each time, A is smaller than D = 2.4.
| Item | After t = 1.6 | After t = 2.1 |
|---|---|---|
| Queue (times of arrival) | 1 (1.6) | 2 (1.6, 2.1) |
| Next arrival A | 2.1 | 3.8 |
| Area under Q(t) | 0 | 0.5 |
| Area under B(t) | 1.2 | 1.7 |
Event 4 of 13
Event list: A = 3.8, D = 2.4. The smaller is D, so the clock and the time of last event move to 2.4.
| Item | Before | After | How |
|---|---|---|---|
| Queue (times of arrival) | 2 (1.6, 2.1) | 1 (2.1) | customer 2 enters service, the array moves up |
| Next departure D | 2.4 | 3.1 | 2.4 + 0.7 (S2) |
| Number delayed (total delay) | 1 (0) | 2 (0.8) | delay 2.4 - 1.6 = 0.8, read before the shift |
Event 4 of 13
| Item | Before | After | How |
|---|---|---|---|
| Area under Q(t) | 0.5 | 1.1 | 0.5 + 2 × (2.4 - 2.1) |
| Area under B(t) | 1.7 | 2.0 | 1.7 + 1 × (2.4 - 2.1) |
Event 5 of 13
Event list: A = 3.8, D = 3.1. The smaller is D, so the clock and the time of last event move to 3.1.
| Item | Before | After | How |
|---|---|---|---|
| Queue (times of arrival) | 1 (2.1) | 0 (empty) | customer 3 enters service, the array moves up |
| Next departure D | 3.1 | 3.3 | 3.1 + 0.2 (S3) |
| Number delayed (total delay) | 2 (0.8) | 3 (1.8) | delay 3.1 - 2.1 = 1.0, read before the shift |
| Area under Q(t) | 1.1 | 1.8 | 1.1 + 1 × (3.1 - 2.4) |
| Area under B(t) | 2.0 | 2.7 | 2.0 + 1 × (3.1 - 2.4) |
Event 6 of 13
Event list: A = 3.8, D = 3.3. The smaller is D, so the clock and the time of last event move to 3.3.
| Item | Before | After | How |
|---|---|---|---|
| Server status | 1 | 0 | queue empty: the server goes idle |
| Next departure D | 3.3 | ∞ | no one in service |
| Area under B(t) | 2.7 | 2.9 | 2.7 + 1 × (3.3 - 3.1) |
Event 7 of 13
Event list: A = 3.8, D = ∞. The smaller is A, so the clock and the time of last event move to 3.8.
| Item | Before | After | How |
|---|---|---|---|
| Server status | 0 | 1 | customer 4 starts service at once |
| Next arrival A | 3.8 | 4.0 | 3.8 + 0.2 (A5) |
| Next departure D | ∞ | 4.9 | 3.8 + 1.1 (S4) |
| Number delayed (total delay) | 3 (1.8) | 4 (1.8) | delay 0, still counted |
Event 8 of 13
Event list: A = 4.0, D = 4.9. The smaller is A, so the clock and the time of last event move to 4.0.
| Item | Before | After | How |
|---|---|---|---|
| Queue (times of arrival) | 0 (empty) | 1 (4.0) | customer 5 joins, time 4.0 in location 1 |
| Next arrival A | 4.0 | 5.6 | 4.0 + 1.6 (A6) |
| Area under B(t) | 2.9 | 3.1 | 2.9 + 1 × (4.0 - 3.8) |
Event 9 of 13
Event list: A = 5.6, D = 4.9. The smaller is D, so the clock and the time of last event move to 4.9.
| Item | Before | After | How |
|---|---|---|---|
| Queue (times of arrival) | 1 (4.0) | 0 (empty) | customer 5 enters service, the array moves up |
| Next departure D | 4.9 | 8.6 | 4.9 + 3.7 (S5) |
| Number delayed (total delay) | 4 (1.8) | 5 (2.7) | delay 4.9 - 4.0 = 0.9, read before the shift |
| Area under Q(t) | 1.8 | 2.7 | 1.8 + 1 × (4.9 - 4.0) |
| Area under B(t) | 3.1 | 4.0 | 3.1 + 1 × (4.9 - 4.0) |
Events 10 to 12 of 13
Customer 5 is in service until D = 8.6, so three arrivals come first and the queue grows to 3.
| Item | After t = 5.6 | After t = 5.8 | After t = 7.2 |
|---|---|---|---|
| Queue (times of arrival) | 1 (5.6) | 2 (5.6, 5.8) | 3 (5.6, 5.8, 7.2) |
| Next arrival A | 5.8 | 7.2 | 9.1 |
| Area under Q(t) | 2.7 | 2.9 | 5.7 |
| Area under B(t) | 4.7 | 4.9 | 6.3 |
Event 13 of 13
Event list: A = 9.1, D = 8.6. The smaller is D, so the clock and the time of last event move to 8.6.
| Item | Before | After | How |
|---|---|---|---|
| Queue (times of arrival) | 3 (5.6, 5.8, 7.2) | 2 (5.8, 7.2) | customer 6 enters service, the array moves up |
| Next departure D | 8.6 | 9.2 | 8.6 + 0.6 (S6) |
| Number delayed (total delay) | 5 (2.7) | 6 (5.7) | delay 8.6 - 5.6 = 3.0, read before the shift |
Event 13 of 13
| Item | Before | After | How |
|---|---|---|---|
| Area under Q(t) | 5.7 | 9.9 | 5.7 + 3 × (8.6 - 7.2) |
| Area under B(t) | 6.3 | 7.7 | 6.3 + 1 × (8.6 - 7.2) |
4 customers waited; the other two did not.
| Customer | Arrival | Service starts | Delay |
|---|---|---|---|
| 2 | 1.6 | 2.4 | 0.8 |
| 3 | 2.1 | 3.1 | 1.0 |
| 5 | 4.0 | 4.9 | 0.9 |
| 6 | 5.6 | 8.6 | 3.0 |
Part 5
Q(t), B(t) and the report generator
Group the intervals by how many were waiting
| Q(t) | Intervals | Total length | Area |
|---|---|---|---|
| 1 | 1.6 to 2.1, 2.4 to 3.1, 4.0 to 4.9, 5.6 to 5.8 | 2.3 | 2.3 |
| 2 | 2.1 to 2.4, 5.8 to 7.2 | 1.7 | 3.4 |
| 3 | 7.2 to 8.6 | 1.4 | 4.2 |
Idle
0 to 0.4
Busy
0.4 to 3.3
Idle
3.3 to 3.8
Busy
3.8 to 8.6
Called by the main program once number delayed = 6
| 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 |
Event at t = 2.1: customer 3 arrives and Q goes from 1 to 2
| Item | Wrong | Right |
|---|---|---|
| Area under Q(t) | 0 + 2 × (2.1 - 1.6) = 1.0 | 0 + 1 × (2.1 - 1.6) = 0.5 |
| Uses | the queue length after the arrival | the queue length that held during the interval |
t = 3.3 customer 3 departs and the queue is empty0 and D = ∞, so the next event is the arrival at 3.8D keeps a stale time, the timing routine can pick a departure for a customer who does not existB(t) from 3.3 to 3.8Event at t = 2.4: the array before the event is 1.6, 2.1
| Item | Wrong | Right |
|---|---|---|
| Order | shift first, the array becomes 2.1 | delay first, then shift to 2.1 |
| Delay | 2.4 - 2.1 = 0.3: customer 3's arrival, not customer 2's | 2.4 - 1.6 = 0.8 for customer 2 |
5.6)9.2)6, at t = 8.6, so T(6) = 8.6Part 6
Two runs to trace, about 30 minutes
Practice, about 10 minutes
| i | A(i) | S(i) |
|---|---|---|
| 1 | 0.5 | 1.2 |
| 2 | 0.3 | 0.6 |
| 3 | 1.8 | 0.7 |
| 4 | 0.4 | 1.1 |
| 5 | 0.6 |
Practice, about 20 minutes
| i | A(i) | S(i) |
|---|---|---|
| 1 | 1.0 | 1.4 |
| 2 | 0.5 | 0.8 |
| 3 | 0.6 | 0.5 |
| 4 | 2.5 | 1.2 |
| 5 | 0.3 | 1.3 |
A and D; set the clock t to itQ(τ) × (t - τ) and B(τ) × (t - τ) to the two areas, where τ is the time of the last eventA, then join the queue or start serviceD = ∞; otherwise delay first, then shiftnAnswers
| Customer | Arrival | Service starts | Delay |
|---|---|---|---|
| 1 | 0.5 | 0.5 | 0 |
| 2 | 0.8 | 1.7 | 0.9 |
| 3 | 2.6 | 2.6 | 0 |
| 4 | 3.0 | 3.3 | 0.3 |
Answers
| Measure | Working | Value |
|---|---|---|
| Area under Q(t) | 0.9 + 0.3 | 1.2 |
| Area under B(t) | 1.8 + 0.7 | 2.5 |
d(4) | 1.2 / 4 | 0.30 |
q(4) | 1.2 / 3.3 | 0.36 |
u(4) | 2.5 / 3.3 | 0.76 |
Answers
| Customer | Arrival | Service starts | Delay |
|---|---|---|---|
| 1 | 1.0 | 1.0 | 0 |
| 2 | 1.5 | 2.4 | 0.9 |
| 3 | 2.1 | 3.2 | 1.1 |
| 4 | 4.6 | 4.6 | 0 |
| 5 | 4.9 | 5.8 | 0.9 |
Answers
| Measure | Working | Value |
|---|---|---|
| Area under Q(t) | 0.6 + 0.6 + 0.8 + 0.4 + 1.0 | 3.4 |
| Area under B(t) | 2.7 + 1.2 | 3.9 |
d(5) | 2.9 / 5 | 0.58 |
q(5) | 3.4 / 5.8 | 0.59 |
u(5) | 3.9 / 5.8 | 0.67 |
t jumps from event to event: t = min(A, D)D = ∞n, and T(n) is that clock valuen, the two areas by T(n)Mahmoud Abas|Single-Server Queue: Event-by-Event Simulation