Lecture_2
Lecture_2
Simulation
Outline
Systems
Performance Metrics
Hand Simulation
Additional Readings
The branch remains open between 9 a.m. and 5 p.m. The arrival of customers is
random (20 customers per hour). Two attendants (one young and a second senior,
more experienced and therefore faster).
If the number of waiting customers reaches 3, a second (senior) agent leaves his
activities elsewhere in the branch to open a third counter.
The latter returns to its tasks when, by finishing with a customer, the number of
waiting customers is 1 or 0.
Average Junior Senior
service time Probability Probability
1 0,05 0,1
2 0,1 0,25
The bank wants to predict customer waiting times 3 0,2 0,15
4 0,15 0,2
and wonders about the relevance of other forms of 5 0,2 0,15
organization. 6 0,15
7 0,07
8 0,05
9 0,03
Solution
States:
Entities:
Go to bank
• customers
• employees Out Client wait
Events:
• Arrival Service
• Start of service
employee
• Start service (+) If service
• end of service finished, or Idle If three
less than 3 customers
customers waiting
waiting Extra employee
out
Detailed description of events
Time-persistent statistics
time-based average, minimum, maximum
Example 1: Drill Press System
Objective: determine whether we should
run the drill press at a higher speed
Drilling Center
Drill Press
Arriving Departing
Blank Finished
Parts Parts
Queue
Part in
Process
Drill Press: Metric 1
Total production (# of parts that
complete production and leave) during
20 minutes
denote by N
since it is an accumulated sum, this is an
example of a counter statistic
Arena preview: called
a counter statistic!
©
Drill Press: Metric 2
Average waiting time in the queue
Let Wqi be the waiting time of part i
The average is
Since averaging over data which is
countable, this is an example of discrete-
time or tally statistic (there is a natural fi
rst,second, . . . Observation)
Arena preview: called a tally
statistic!
34
Metric interpretation
Why?
Is the teller efficient?
Do we need more tellers?
Single-Server Queue
Step through time using lists of
interarrival and service times
Display system, state variables, clock,
event list, statistical counters… all
after execution of each event
Stop when number of delays hits n = 6,
compute output performance measure
Hand Simulation
We will try to simulate a system ”by
hand” (on paper or in Excel)
Hand Simulation
Interarrival times:
0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9
Status
shown is
Hand Simulation
after all
changes
have
been
made in
each
case …
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Arrival
time +
service
time
=
0.4 +
2.0
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Q(t) = [the previous value of Q(t)] +[number in Queue in previous page]*[the time since the last event] =
0+0 *(1.6 - 0.4) = 0
Customer Arrive Served
B(t) = 1 * (1.6-0.4) = 1.2
1 0.4 0.4
2 1.6 ?
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
The delay counters (total delay) are unchanged, since this is not the end of anyone’s delay
in queue
Customer Arrive Served
Q(t) = 0 + 1(2.1-1.6) = 0.5
1 0.4 0.4
B(t) = 1.2 + (2.1 – 1.6) = 1.7 2 1.6 ?
3 2.1 ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1
Departure of customer 1 at 2.4
2.4+0.7=3.1
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
Q(t) = 1.8 +[ 0 * (4.0-3.8)] = 1.8 (based on 1 0.4 0.4 0 2.4
previous queue array) 2 1.6 2.4 0.8 3.1
3 2.1 3.1 1 3.3
B(t) = 2.9+ [1 * (4.0 – 3.8)] = 3.1
4 3.8 3.8 0 4.9
5 4.0 ? ? ?
6 5.6 ? ? ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1 41
Departure of customer 4 at 4.9
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
Q(t) = 1.8 +[ 1 * (4.9-4.0)] = 2.7 1 0.4 0.4 0 2.4
2 1.6 2.4 0.8 3.1
3 2.1 3.1 1 3.3
B(t) = 3.1+ [1 * (4.9-4.0)] = 4.0
4 3.8 3.8 0 4.9
5 4.0 4.9 0.9 8.6
6 5.6 ? ? ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1 42
Arrival of customer 6 at 5.6
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
1 0.4 0.4 0 2.4
Q(t) = 2.7 +[ 0 * (5.6-4.9)] = 2.7
2 1.6 2.4 0.8 3.1
3 2.1 3.1 1 3.3
B(t) = 4.0+ [1 * (5.6-4.9)] = 4.7
4 3.8 3.8 0 4.9
5 4.0 4.9 0.9 8.6
6 5.6 ? ? ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1 43
7 5.8
Arrival of customer 7 at 5.8
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
1 0.4 0.4 0 2.4
2 1.6 2.4 0.8 3.1
Q(t) = 2.7 +[ 1 * (5.8-5.6)] = 2.9 3 2.1 3.1 1 3.3
4 3.8 3.8 0 4.9
B(t) = 4.7+ [1 * (5.8-5.6))] = 4.9 5 4.0 4.9 0.9 8.6
6 5.6 ? ? ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1 44
7 5.8 ? ? ?
8 7.2
Arrival of customer 8 at 7.2
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
1 0.4 0.4 0 2.4
2 1.6 2.4 0.8 3.1
Q(t) = 2.9 +[ 2 * (7.2-5.8)] = 5.7 3 2.1 3.1 1 3.3
4 3.8 3.8 0 4.9
B(t) = 4.9+ [1 * (7.2-5.8))] = 6.3 5 4.0 4.9 0.9 8.6
6 5.6 ? ? ?
Hand Simulation
Interarrival times: 0.4, 1.2, 0.5, 1.7, 0.2, 1.6, 0.2, 1.4, 1.9, …
Service times: 2.0, 0.7, 0.2, 1.1, 3.7, 0.6, …
Customer Arrive Served Delay Left
1 0.4 0.4 0 2.4
2 1.6 2.4 0.8 3.1
Q(t) = 5.7 +[ 3 * (8.6-7.2)] = 9.9 3 2.1 3.1 1 3.3
4 3.8 3.8 0 4.9
5 4.0 4.9 0.9 8.6
B(t) = 6.3+ [1 * (8.6-7.2))] = 7.7
6 5.6 8.6 3 ?
7 5.8 ? ? ?
A. M. Law, Simulation Modeling and Analysis, Chapter 1 8 7.2 ? ? 46
?
9 9.1 ? ? ?
Final output performance
measures:
Drilling Center
Drill Press
Arriving Departing
Blank Finished
Parts Parts
Queue
Part in
Process
One-Day Input
Metric
Total
Scenarios
5 3 6 2 3
production
Avg. waiting 2.53 1.19 1.03 1.62 0
time in queue
Avg. total time 6.44 5.10 4.16 6.71 4.26
in system
Time-avg. # in 0.79 0.18 0.36 0.16 0.05
queue
Utilization 0.92 0.59 0.90 0.51 0.70
independent, and
IID
statistically-identical
Starts/stops
according to the
same rules and
uses the same
input settings
Questions?
Random numbers?
Why “statistical”?
What are “input
settings”?
How many
replications
should we
have?
Modelling Randomness
We need a structured way to create
multiple scenarios, i.e., to run multiple
replications
Randomness is captured by
Random variables
Distributions
Generation of
Random Numbers
Given a distribution, can generate a
sequence of random #s (a particular
scenario!)
Random variables are usually denoted using capital letters, such as X, Y, and
Z, whereas small letters, such as x, y, z, a, b, c, and so on, are used to denote
particular values of random variables written as P(X = x).
Random Variable:
S
P(D=0) = 0.5
P(D=2) = 0.25
P(D=-2) = 0.25
P(D>=0) = 0.75
Discrete Random Variable:
A random variable X which can take a value from an infinite set of values
is called a continuous random variable.
x f(x) F(x)2
0 0.18 0.18
1 0.39 0.57
2 0.24 0.81
3 0.14 0.95
4 0.04 0.99
5 0.01 1
Expected Value, Variance, and
Standard Deviation of a Discrete
Random Variable
Expected value (or mean) of a discrete random variable is
given by
E(x) =
(0*0.18) + (1*0.39)+(2*0.24)+
(3*014)+(4*0.04)+(5*0.01) = 1.5
The arrival rate of customers does not depend on the time of day,
etc. (stationary)
Poisson distribution
N(t) is the number of events that occur over a period of time t or in [0, t].
The parameter is the mean number of occurrences per unit time
t is the mean number of occurrences in an interval [0, t].
We also assume that the events are independent.
Example:
Poisson Processes Example
Exponential distribution
Poisson Processes: relation between
exponential and Poisson distribution