The Event-Scheduling/Time-
Advanced Algorithm
Modeling and Simulation-Fall 2023
Discrete System
• One in which all state variables change only at a
discrete set of points in time.
• A bank is an example of discrete systems
• State Variable -> Number of customers change only when a
customer arrives or when the service provided for a customer
is completed.
• Think of modeling state changes occur at discrete
points in time, as producing a sequence of system
snapshots that represent the evolution of the system
through time.
Discrete Event Simulation(Cont.)
• A given snapshot at time(t) includes not only the system
state at time (t) but also a list of all activities currently in
progress and when each such activity will end, the
status of all entities, and current values of cumulative
statistics and counters used to calculate summary
statistics at the end of the simulation.
Event Scheduling/Time Advance algorithm
• The mechanism for advancing simulation and
guaranteeing all events occur in correct order is based
on future event list (FEL).
• FEL contains all event notices that have been
scheduled to occur at a future time.
• Scheduling a future event means that at the instant an
activity begins, its duration is computed and its end
activity is placed on the FEL.
Event Scheduling/Time Advance algorithm
• Clock-> represents time (t)
• System State at time t:
1. LQ → number of customers in waiting line
2. LS → server state(0 for idle or 1 busy)
• Event Notice (Event Type, Event Time) :
(A,t) → Arrival at time t
(D,t) → Departure at time t
(E,t) → Stopping Event(E,t) at time t
Event Scheduling/Time Advance algorithm
• Cumulative Statistics:
S → Total time spent by customers at time t
𝑁𝐷 → Number of customers who departed at time t
F → Number of customers who spend required time.
B → Total server busy time
MQ → Maximum Queue Length
Discrete Event Simulation
• Steps:
1. Compute Departure Time
2. Initialization Step:
• Clock at time 0.
• LQ =0.
• LS=1.
• All statistics = 0.
• Generate the next Arrival Event and the current Departure in
FEL
3. Create simulation table following the Event scheduling
algorithm steps
Example1
• A grocery store with one checkout counter, the system
consists of those customers in waiting line plus the one
(if any) checking out. A stopping time of 60 minutes is
set.
Find number of customers who spend 5 or more
minutes in the system.
IAT - 1 1 6 3 7
ST 4 2 5 4 1 5
STEP1: Compute Departure Time
NO. IAT AT SST ST DT
1 - 0 0 4 4
2 1 1 4 2 6 ATi = AT i-1 + IATi
DT =SSt + ST
3 1 2 6 5 11
SST = Max(DT i-1, AT i)
4 6 8 11 4 15
5 3 11 15 1 16
6 7 18 18 5 23
Initialization Step
• Clock at time 0.
• LQ =0.
• LS=1.
• All statistics = 0.
• Generate Arrival Event and Departure
Algorithm Steps:
• In case of an Arrival Event:
• Check LS: If ( LS ==1) :
• LQ++
• Generate new arrival event
• If( LS !=1) :
• Set LS to 1
• Generate new departure event
• Generate new arrival event
In case of an Arrival Event:
Algorithm Steps(Cont.)
• In case of a Departure Event:
• Check LQ: If( LQ >0):
• LQ--.
• Generate new departure.
• If( LQ ==0):
• Set LS to 0
• Update Statistics.
In case of a Departure Event:
Step2: Simulation Table
clock Event LQ(t) LS(t) Checkout line Future Event List S N F
0 A1 0 1 (c1,0) (A2,1),(D1,4),(E,60) 0 0 0
1 A2 1 1 (c1,0)-(c2,1) (A3,2),(D1,4) ,(E,60) 0 0 0
2 A3 2 1 (c1,0)-(c2,1)-(c3,2) (D1,4),(A4,8) ,(E,60) 0 0 0
4 D1 1 1 (c2,1)-(c3,2) (D2,6),(A4,8) ,(E,60) 4 1 0
6 D2 0 1 (c3,2) (A4,8),(D3,11) ,(E,60) 9 2 1
8 A4 1 1 (c3,2)-(c4,8) (A5,11),(D3,11) ,(E,60) 9 2 1
11 A5/D3 1 1 (c4,8)-(c5,11) (D4,15),(A6,18) ,(E,60) 18 3 2
15 D4 0 1 (c5,11) (D5,16),(A6,18) ,(E,60) 25 4 3
16 D5 0 0 - (A6,18) ,(E,60) 30 5 4
18 A6 0 1 (c6,18) (D6,23) ,(E,60) 30 5 4
23 D6 0 0 - (E,60) 35 6 5
Important Rules
• Server utilization=total server busy time (B) / total
time (TE).
• The average response time= S / 𝑁𝐷
• The observed proportion of customers who spent
specific time or more in the system = F/ 𝑁𝐷
• MQ= Max(LQ[i], MQ[i-1])
• F, S and 𝑁𝐷 changes only when departure event
occur
• in case (Ls[i])=1 (server busy), B →( clock[i] –
clock[i-1] + B[i-1] )
• Then number of customers who
spend 5 or more minutes= 5
• The average response time
= S / 𝑁𝐷 = 35/6=5.8 mins
• The observed proportion of
customers who spent 5 mins or
more in the system = F/ 𝑁𝐷
=5/6=0.83
Example 2:
• Prepare a simulation table using time advance
algorithm for single channel queue with 6 customers.
• Find number of customers who spend more than 4 mins
in the system.
IAT - 1 1 8 6 8
ST 4 2 3 4 1 2
Step1: Calculate Departure time
NO. IAT AT SST ST DT
1 - 0 0 4 4
2 1 1 4 2 6
3 1 2 6 3 9
4 8 10 10 4 14
5 6 16 16 1 17
6 8 24 24 2 26
Step2: Simulation Table
clock Event LQ(t) LS(t) Checkout line Future Event List S N F
0 A1 0 1 (c1,0) (A2,1),(D1,4) 0 0 0
1 A2 1 1 (c1,0)-(c2,1) (A3,2),(D1,4) 0 0 0
2 A3 2 1 (c1,0)-(c2,1)-(c3,2) (D1,4),(A4,10) 0 0 0
4 D1 1 1 (c2,1)-(c3,2) (D2,6),(A4,10) 4 1 0
6 D2 0 1 (c3,2) (D3,9),(A4,10) 9 2 1
9 D3 0 0 - (A4,10) 16 3 2
10 A4 0 1 (c4,10) (D4,14),(A5,16) 16 3 2
14 D4 0 0 _ (A5,16) 20 4 2
16 A5 0 1 (c5,16) (D5,17),(A6,24) 20 4 2
17 D5 0 0 - (A6,24) 21 5 2
24 A6 0 1 (c6,24) (D6,26) 21 5 2
26 D6 0 0 - - 23 6 2
• Then number of
customers who spend
more than 4 minutes= 2
Assignment 4
• Implement Event Scheduling algorithm.
• Get number of customers input from the user.
• All random digits must be randomly generated.
• Print the simulation schedule and all statistics.
• The deadline and discussion time will be announced on
moodle.