Lecture 2
Lecture 2
Discrete-Event Simulation
Instructor: Eng. Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department
Outline
Introduction. Discrete even simulation (DES). Components and organization of DES. DES example: single server queue system.
What is an event? Instantaneous occurrence that may change the state of the system
Arrival of a customer Service completion (and departure) of a customer End of simulation (a fake event since no change in the status of the system takes place) Take some decision (also no change in system state here takes place). The Hashemite University
DES Milestones
Real system under study. Model of this system which contains:
Inputs. Processing or simulation flow as assumed in reality. Output (indications about the system performance).
The clock starts at 0 and it is advanced by a fixed increment and no skip of empty periods at which no events occur. There is no problem with events that occur at the fixed increment, they will be handled at time. However, Events occurring between time increments must be moved to an increment boundary (at the end of the interval in which it lie). Simple to implement, but has many drawbacks:
not an accurate realization of occurrence of events The model must define a technique to handle events that occur at the same time (due to movements to the end of time intervals). Rescheduling of events and the no skipping of empty period increase the 6 The Hashemite University simulation execution time.
Continue until stopping rule is satisfied (must be explicitly stated) Clock jumps from one event time to the next, and doesnt exist for times between successive events periods of inactivity are ignored so simulation execution time is shorter than the fixed increment approach. Clock jumps, most of the time, are not equal depending on the events sequence. Problem of simultaneous( ) events still exist but may be less than the fixed time increment.
The Hashemite University 7
Event list times of future events for each event type Statistical counters to accumulate performance measures
Waiting time in queue, server utilization,
Initialization routine
Start simulation at time 0 and initialize all variables and statistical counters in the system model
The Hashemite University 9
Event routines
carry out logic for each event type and update the system state accordingly.
Library routines
utility routines to generate random variates, etc.
Report generator
Subprogram that computes estimates of the required performance metrics from the statistical counters and write a report of them.
Main program
ties routines together, executes them in the correct order May check for termination of simulation and invoke the report generator (this task may be handled in the event routine).
The Hashemite University 10
Start
Initialization routine
1. Set simulation 0 clock=0 2. Initialize system state and statistical counters 3. Initialize event list
Main program
0. Invoke the initialization routine 1. Invoke the timing routine Repeatedly 2. Invoke event routine 2 Event routine i 1.Update system state 2.Update statistical counters 3.Generate future events and add to event list Is simulation over? Report generator No 1
Time routine
1. Determine the next event type, say, i 2. Advance the simulation clock
Arriving customer
Customers in queue
Server
Departing customer
13
Arriving customer
Customers in queue
Server
Departing customer
15
Arrows in the previous figure represent simulation clock advances based on the most imminent event principle.
The Hashemite University 16
As a figure. As multiple values in a table. As one composite value, e.g. max, min, average, 20 The Hashemite University etc.
Performance Measures I
First Metric: Expected average delay in queue (excluding service time) of the n customers completing their delays n ^
1 d (n) Di n i 1
Why expected? Since it is the average delay we expect a real customer will wait in the real system. This performance measure is discrete, since we can know the queueing delay of a customer at specified instances of time (countable) when customers enter service. And remember the simulation give us only estimates, for this purpose we put a hat (^) on the variable name to indicate that it is just an estimate of the actual value.
The Hashemite University 23
Performance Measures II
Second Metric: Expected average number of
customers in queue (excluding any in service)
A continuous-time average (at any instance of time you have a value for this quantity)
1 q ( n ) ipi iTi T ( n) i 1 i 1
^
Here q(n) is the weighted average. T(n) : The time required to observe the n delays in queue (simulation duration).
T(n) T0 T1 T2 ....
Ti : The total time during the simulation that the queue is of length i
The Hashemite University 24
Q(t)
0
e1=0.4
2
e2=1.6 e3=2.1
4
e8=4.0 e7=3.8
Arrivals
e11=5.8 e10=5.6
e12=7.2
e6=3.3
Departures
e4=2.4 e5=3.1 e9=4.9
e13=8.6=T(6)
26
Performance Measures IV
Lets calculate q(t) from the previous figure
Performance Measures V
Look deeply at the previous calculations, it is simply the area under the Q(t) curve integral. So:
1 q( n ) T ( n)
T ( n)
Q( t )
0
During simulation we will just accumulate the area under the Q(t) curve in the same manner used in the previous slide.
The Hashemite University 28
Performance Measures VI
Third Metric: Expected utilization
Another continuous-time average
1 u ( n) T ( n)
^
T (n)
B(t )
0
B(t)
0
e1=0.4
2
e2=1.6
4
e8=4.0
Arrivals
e3=2.1
e7=3.8
e11=5.8 e10=5.6
e12=7.2
e6=3.3
Departures
e4=2.4 e5=3.1 e9=4.9
e13=8.6=T(6)
Also we need to define the values of the statistical counters while simulation is running.
The Hashemite University 31
Before Starting
Lets explore the used variables to represent the different entities and their attributes in our system model.
32
Time = 0
Status shown is after all changes have been made in each case
0.4, 1.2, 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 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, 2.0, 0.7, 0.2, 1.1, 3.7, 0.6,
45
Time = 8.6
0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, 2.0, 0.7, 0.2, 1.1, 3.7, 0.6,
Final output performance measures: Average delay in queue = 5.7/6 = 0.95 min./customers Time-average number in queue = 9.9/8.6 = 1.15 customers Server utilization = 7.7/8.6 = 0.90 (dimensionless)
The Hashemite University 46
Self Reading
Subsection 1.4.7 Have a look at the C code of our simulation example. Also, have a look at sections 1.5 and 1.6 for additional examples of DES simulations.
48
Additional Notes
The lecture covers the following sections from the textbook:
Chapter 1:
Sections: 1.3, 1.4.1, 1.4.2, 1.4.3, and 1.4.7 Appendix 1A.
49