All in One Simulation Notes
All in One Simulation Notes
Simulation
Banks, Carson, Nelson & Nicol
Discrete-Event System Simulation
Outline
Definition
Mathematical Methods
Probability
is simple
It is useful for complex system
human behavior
Advantages of simulation
Disadvantages of simulation
10
Areas of application
Manufacturing Applications
Semiconductor Manufacturing
Construction Engineering and project management
Military application
Logistics, Supply chain and distribution application
Transportation modes and Traffic
Business Process Simulation
Health Care
Automated Material Handling System (AMHS)
Risk analysis
Insurance, portfolio,...
Computer Simulation
CPU, Memory,
Network simulation
11
: Arrival orders
Banks
: arrival of customers
12
Components of system
Entity
Attribute
Endogenous
A collection of variables that describe the system in any time : status of machine
(busy, idle, down,)
Event
State
Activity
Exogenous
13
14
15
Model of a System
16
Types of Models
17
Deterministic or Stochastic
Does
Static or Dynamic
Is
Continuous or Discrete
Does
18
19
Model Taxonomy
20
21
Conceptual
Very high level
How comprehensive should the model be?
What are the state variables, which are dynamic, and which are
important?
Specification
On paper
May involve equations, pseudocode, etc.
How will the model receive input?
Computational
A computer program
General-purpose PL or simulation language?
22
Verification
Computational
Validation
Computational
Steps in Simulation
Study
24
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 9
Verification and Validation of Simulation Models
Verification
Purpose: ensure the conceptual model is reflected accurately in the
computerized representation.
Many common-sense suggestions, for example:
Have someone else check the model.
Make a flow diagram that includes each logically possible action a
system can take when an event occurs.
Closely examine the model output for reasonableness under a variety of
input parameter settings.
Print the input parameters at the end of the simulation, make sure they
have not been changed inadvertently.
Make the operational model as self-documenting as possible.
If the operational model is animated, verify that what is seen in the
animation imitates the actual system.
Use the debugger.
If possible use a graphical representation of the model.
Chapter 9. Verification and Validation of Simulation Models
Use of a trace
A detailed printout of the state of the simulation model over time.
- Can be very labor intensive if the programming language does not
support statistic collection.
- Labor can be reduced by a centralized tracing mechanism
- In object-oriented simulation framework, trace support can be
integrated into class hierarchy. New classes need only to add little for
the trace support.
Trace - Example
Simple queue from Chapter 2
Trace over a time interval [0, 16]
Allows the test of the results by pen-and-paper method
Definition of Variables:
CLOCK = Simulation clock
EVTYP = Event type (Start, Arrival, Departure, Stop)
NCUST = Number of customers in system at time CLOCK
STATUS = Status of server (1=busy, 0=idle)
State
CLOCK
CLOCK
CLOCK
CLOCK
CLOCK
CLOCK
...
There is a customer,
but the status is 0
Validation: the overall process of comparing the model and its behavior to the
real system.
Calibration: the iterative process of comparing the model to the real system
and making adjustments.
Comparison of the model to
real system
Subjective tests
- People who are
knowledgeable about
the system
Objective tests
- Requires data on the
real systems behavior
and the output of the
model
10
Typically few data sets are available, in the worst case only one, and the
model is only validated for these.
Solution: If possible collect new data sets
The modeler must weigh the possible, but not guaranteed, increase in
model accuracy versus the cost of increased validation effort.
11
12
13
One possible approach: use historical data that have been reserved
for validation purposes only.
Criteria: use the main responses of interest.
Input
System
Output
Model is viewed as an
input-output
transformation
Input
Model
14
Output
Bank Example
Example: One drive-in window serviced by one teller, only one or two
transactions are allowed.
Data collection: 90 customers during 11 am to 1 pm.
- Observed service times {Si, i = 1,2, , 90}.
- Observed interarrival times {Ai, i = 1,2, , 90}.
15
Input variables
Uncontrolled
variables, X
Controlled
Decision
variables, D
Possion arrivals
= 45/hr: X11, X12,
Services times,
N(D2, 0.22): X21, X22,
Model
black box
f(X,D) = Y
D1 = 1 (one teller)
D2 = 1.1 min
(mean service time)
D3 = 1 (one line)
16
Primary interest:
Y1 = tellers utilization
Y2 = average delay
Y3 = maximum line length
Secondary interest:
Y4 = observed arrival rate
Y5 = average service time
Y6 = sample std. dev. of
service times
Y7 = average length of time
Dr. Mesut Gne
Compare the average delay from the model Y2 with the actual delay
Z2:
Average delay observed, Z2 = 4.3 minutes, consider this to be the true
mean value 0 = 4.3.
When the model is run with generated random variates X1n and X2n, Y2
should be close to Z2.
17
Replication
Y4
Arrivals/Hour
Y5
Service Time [Minutes]
Y2
Average Delay [Minutes]
51
1.07
2.79
40
1.12
1.12
45.5
1.06
2.24
50.5
1.10
3.45
53
1.09
3.13
49
1.07
2.38
Sample mean
2.51
Standard deviation
0.82
18
Hypothesis Testing
Compare the average delay from the model Y2 with the actual delay Z2
Null hypothesis testing: evaluate whether the simulation and the real
system are the same (w.r.t. output measures):
19
Hypothesis Testing
Conduct the t test:
Chose level of significance ( = 0.5) and sample size (n = 6).
Compute the same mean and sample standard deviation over
the n replications:
n
1 n
Y2 = Y2i = 2.51 minutes
n i =1
S=
(Y
i =1
2i
Y2 ) 2
n 1
= 0.82 minutes
Y2 0
2.51 4.3
=
= 5.34 > tcritical = 2.571 (for a 2 - sided test)
S/ n
0.82 / 6
20
Hypothesis Testing
Similarly, compare the model output with the observed output for
other measures:
Y4 Z4, Y5 Z5, and Y6 Z6
21
Type II Error
For validation, the power of the test is:
Probability[ detecting an invalid model ] = 1
= P(Type II error) = P(failing to reject H0 | H1 is true)
Consider failure to reject H0 as a strong conclusion, the modeler would
want to be small.
Value of depends on:
- Sample size, n
- The true difference, , between E(Y) and :
E (Y )
22
Type II Error
Operating characteristics curve
(OC curve).
Graphs of the probability of a
Type II Error () versus for a
given sample size n
23
Statistical Terminology
Modeling Terminology
Associated Risk
24
Y t ,n1
2
25
S
n
26
S
n
0.82
2.51 2.571
6
Y t0.025,5
27
28
29
Summary
Model validation is essential:
Model verification
Calibration and validation
Conceptual validation
30
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 10
Output Analysis for a Single Model
Purpose
Objective: Estimate system performance via simulation
If is the system performance, the precision of the estimator can
be measured by:
The standard error of .
The width of a confidence interval (CI) for .
Outline
Distinguish the two types of simulation:
transient vs.
steady state
Type of Simulations
Terminating versus non-terminating simulations
Terminating simulation:
Runs for some duration of time TE, where E is a specified event that
stops the simulation.
Starts at time 0 under well-specified initial conditions.
Ends at the stopping time TE.
Bank example: Opens at 8:30 am (time 0) with no customers present
and 8 of the 11 teller working (initial conditions), and closes at 4:30 pm
(Time TE = 480 minutes).
The simulation analyst chooses to consider it a terminating system
because the object of interest is one days operation.
Type of Simulations
Non-terminating simulation:
Runs continuously, or at least over a very long period of time.
Examples: assembly lines that shut down infrequently, hospital
emergency rooms, telephone systems, network of routers, Internet.
Initial conditions defined by the analyst.
Runs for some analyst-specified period of time TE.
Study the steady-state (long-run) properties of the system, properties
that are not influenced by the initial conditions of the model.
Waiting line
Chapter 10. Output Analysis for a Single Model
2
2
=
LQ =
( ) 1
Server
7
1, Y1j
3.61
3.21
2.18
6.92
2.82
3.75
Batch, j
1
2
3
4
5
Replication
2, Y2j
2.91
9.00
16.15
24.53
25.19
15.56
3, Y3j
7.67
19.53
20.36
8.11
12.62
13.66
Measures of performance
Consider the estimation of a performance parameter, (or ), of a
simulated system.
Discrete time data: [Y1, Y2, , Yn], with ordinary mean:
Continuous-time data: {Y(t), 0 t TE} with time-weighted mean:
Point estimation for discrete time data.
The point estimator:
n
1
= Yi
n i =1
E () =
Desired
Point Estimator
Point estimation for continuous-time data.
The point estimator:
=
TE
TE
Y (t )dt
10
Point Estimator
Performance measure that does not fit:
quantile or percentile: Pr{Y } = p
Estimating quantiles: the inverse of the problem of estimating a proportion
or probability.
Consider a histogram of the observed values Y:
- Find such that 100p% of the histogram is to the left of (smaller than) .
A widely used used performance meausure is the median, which is the
0.5 quantile or 50-th percentile.
11
Confidence-Interval Estimation
To understand confidence intervals fully, it is important to distinguish
between measures of error, and measures of risk, e.g., confidence
interval versus prediction interval.
Suppose the model is the normal distribution with mean , variance 2
(both unknown).
Let Yi. be the average cycle time for parts produced on the i-th replication
of the simulation (its mathematical expectation is ).
Average cycle time will vary from day to day, but over the long-run the
average of the averages will be close to .
Sample variance across R replications:
1 R
S =
(Yi. Y.. ) 2
R 1 i =1
2
12
Confidence-Interval Estimation
Confidence Interval (CI):
A measure of error.
Where Yi are normally distributed.
Y.. t , R 1
2
Quantile of the t
distribution with R-1
degrees of freedom.
S
R
We cannot know for certain how far Y.. is from but CI attempts to bound
that error.
A CI, such as 95%, tells us how much we can trust the interval to actually
bound the error between Y.. and .
The more replications we make, the less error there is in Y.. (converging
to 0 as R goes to infinity).
13
Confidence-Interval Estimation
Prediction Interval (PI):
A measure of risk.
A good guess for the average cycle time on a particular day is our
estimator but it is unlikely to be exactly right.
PI is designed to be wide enough to contain the actual average cycle time
on any particular day with high probability.
Normal-theory prediction interval:
1
Y.. t / 2, R 1S 1 +
R
The length of PI will not go to 0 as R increases because we can never
simulate away risk.
PIs limit is: z / 2
14
15
Statistical Background
Important to distinguish within-replication data from across-replication
data.
For example, simulation of a manufacturing system
Two performance measures of that system: cycle time for parts and work
in process (WIP).
Let Yij be the cycle time for the j-th part produced in the i-th replication.
Across-replication data are formed by summarizing within-replication
data Yi. .
Within-Replication Data
Across-Replication
Data
Y11
Y12
Y1n 1
Y1 , S 12 , H 1
Y 21
Y 22
Y 2n 2
Y 2 , S 22 , H 2
Y R1
YR 2
Y Rn R
Y R , S 2R , H R
16
Statistical Background
Across Replication:
For example: the daily cycle time averages (discrete time data)
-
1 R
The average: Y.. = Yi.
R i =1
1 R
2
The sample variance: S =
(Yi. Y.. ) 2
R 1 i =1
H = t / 2, R 1
S
R
Within replication:
For example: the WIP (a continuous time data)
1 TEi
Yi (t )dt
0
T Ei
1 TEi
2
2
(Yi (t ) Yi. ) dt
The sample variance: S i =
0
T Ei
- The average:
-
Yi. =
17
Statistical Background
Overall sample average, Y.., and the interval replication sample
averages, Yi., are always unbiased estimators of the expected daily
average cycle time or daily average WIP.
Across-replication data are independent (different random numbers)
and identically distributed (same model), but within-replication data
do not have these properties.
18
H = t / 2, R 1
S
R
S2 is the sample
variance
R is the # of
replications
P Y.. < 1
19
z S
R / 2 0 , z / 2 is the standard normal distribution.
2
t / 2, R 1S 0
Y.. t / 2, R 1
Chapter 10. Output Analysis for a Single Model
20
S
R
Dr. Mesut Gne
Call Center Example: estimate the agents utilization over the first 2 hours of
the workday.
Initial sample of size R0 = 4 is taken and an initial estimate of the population variance
is S02 = (0.072)2 = 0.00518.
The error criterion is = 0.04 and confidence coefficient is 1- = 0.95, hence, the final
sample size must be at least:
2
2
z0.025 S0 1.96 * 0.00518
= 12.14
=
0.042
t 0.025, R-1
(t / 2, R1S 0 / )
13
14
15
2.18
2.16
2.14
15.39
15.1
14.83
21
Quantiles
Here, a proportion or probability is treated as a special case of a
mean.
When the number of independent replications Y1, ,YR is large
enough that t/2,n-1 = z/2, the confidence interval for a probability p is
often written as:
p (1 p )
R 1
p z / 2
The sample proportion
22
Quantiles
The best way is to sort the outputs and use the (R*p)-th smallest value,
i.e., find such that100p% of the data in a histogram of Y is to the left of
.
Example: If we have R=10 replications and we want the p = 0.8 quantile,
first sort, then estimate by the (10)(0.8) = 8-th smallest value (round if
necessary).
5.6 sorted data
7.1
8.8
8.9
9.5
9.7
10.1
12.2 this is our point estimate
12.5
12.9
23
Quantiles
Confidence Interval of Quantiles: An approximate (1-)100%
confidence interval for can be obtained by finding two values l
and u.
l cuts off 100pl% of the histogram (the Rpl smallest value of the sorted
data).
u cuts off 100pu% of the histogram (the Rpu smallest value of the sorted
data).
where pl = p z / 2
p (1 p )
R 1
pu = p + z / 2
p (1 p )
R 1
24
Quantiles
Example: Suppose R = 1000 reps, to estimate the p = 0.8 quantile
with a 95% confidence interval.
First, sort the data from smallest to largest.
Then estimate of by the (1000)(0.8) = 800-th smallest value, and the
point estimate is 212.03.
A portion of the 1000
And find the confidence interval:
pl = 0.8 1.96
.8(1 .8)
= 0.78
1000 1
.8(1 .8)
= 0.82
1000 1
The c.i. is the 780 th and 820 th smallest values
pu = 0.8 + 1.96
25
sorted values:
Output
Rank
180.92
779
188.96
780
190.55
781
208.58
799
212.03
800
216.99
801
250.32
819
256.79
820
256.99
821
The single run produces observations Y1, Y2, ... (generally the samples of
an autocorrelated time series).
Performance measure:
1 n
= lim Yi ,
n n i =1
1
= lim
TE TE
TE
Y (t )dt ,
(with probability 1)
(with probability 1)
26
Any bias in the point estimator that is due to artificial or arbitrary initial
conditions (bias can be severe if run length is too short).
Desired precision of the point estimator.
Budget constraints on computer resources.
One replication (or run), the output data: Y1, Y2, Y3,
With several replications, the output data for replication r: Yr1, Yr2, Yr3,
27
Initialization Bias
Methods to reduce the point-estimator bias caused by using artificial
and unrealistic initial conditions:
Intelligent initialization.
Divide simulation into an initialization phase and data-collection phase.
Intelligent initialization
28
Initialization Bias
Divide each simulation into two phases:
System has reached steady state: the probability distribution of the system
state is close to the steady-state probability distribution (bias of response
variable is negligible).
29
Initialization Bias
M/G/1 queueing example: A total of 10 independent replications were
made.
Ensemble averages:
1 R
Y. j = Yrj
R r =1
R replications
30
Initialization Bias
A plot of the ensemble averages, Y ..(n, d ) , versus 1000j,
for j = 1,2, ,15.
31
Initialization Bias
Cumulative average sample mean (after deleting d observations):
1
Y.. (n, d ) =
nd
j = d +1
.j
It is apparent that downward bias is present and this bias can be reduced
by deletion of one or more observations.
Chapter 10. Output Analysis for a Single Model
32
Initialization Bias
No widely accepted, objective and proven technique to guide how
much data to delete to reduce initialization bias to a negligible level.
Plots can, at times, be misleading but they are still recommended.
33
Error Estimation
If {Y1, , Yn} are not statistically independent, then S2/n is a biased
estimator of the true variance.
1 n
Y = i =1 Yi
n
Variance of Y is very hard to estimate.
For systems with steady state, produce an output process that is
approximately covariance stationary (after passing the transient phase).
- The covariance between two random variables in the time series depends
only on the lag, i.e. the number of observations between them.
34
Error Estimation
For a covariance stationary time series, {Y1, , Yn}:
Lag-k autocovariance is:
k =
k
2
1 k 1
V (Y ) =
Y is:
k
1
2
+
1 k
n
n
k =1
n 1
S2
E = B V (Y ),
n
Chapter 10. Output Analysis for a Single Model
n / c 1
where B =
n 1
35
Error Estimation
a)
b)
c)
36
Error Estimation
The expected value of the variance estimator is:
S2
E = B V (Y ),
n
where B =
n / c 1
and V (Y ) is the variance of Y
n 1
37
Replication Method
38
Replication Method
Each replication is regarded as a single sample for estimating .
For replication r:
1
Yr . (n, d ) =
nd
j = d +1
rj
1 R
Y.. (n, d ) = Yr . (n, d )
R r =1
and
39
Replication Method
To estimate the standard error of Y.. , the sample variance and
standard error:
1 R
1 R 2
2
2
(
)
=
S =
Y
Y
Y
R
Y
r. .. R 1
..
r.
R 1 r =1
r =1
Mean of the
undeleted
observations
from the r-th
replication.
Mean of
and
s.e.(Y.. ) =
S
R
Standard error
40
Replication Method
Length of each replication (n) beyond deletion point (d):
( n d ) > 10d or
TE > 10T0
Number of replications (R) should be as many as time permits, up to
about 25 replications.
For a fixed total sample size (n), as fewer data are deleted (d):
CI shifts: greater bias.
Standard error of Y.. ( n, d ) decreases: decrease variance.
Reducing
bias
Trade off
41
Increasing
variance
Replication Method
and
Y.. t / 2, R 1S / R Y.. + t / 2, R 1S / R
8.43 2.26(1.59) LQ 8.42 + 2.26(1.59)
A high degree of confidence that the long-run mean queue length is between 4.84
and 12.02 (if d and n are large enough).
42
Sample Size
To estimate a long-run performance measure, , within
with confidence 100(1- )%.
M/G/1 queueing example (cont.):
We know: R0 = 10, d = 2 and S02 = 25.30.
To estimate the long-run mean queue length, LQ, within = 2 customers
with 90% confidence ( = 10%).
Initial estimate:
2
z0.05 S0 1.645 (25.30)
R
= 17.1
=
2
2
43
Sample Size
An alternative to increasing R is to increase total run length T0+TE
within each replication.
Approach:
- Increase run length from (T0+TE) to (R/R0)(T0+TE), and
- Delete additional amount of data, from time 0 to time (R/R0)T0.
44
Batch means: divide the output data from 1 replication (after appropriate
deletion) into a few large batches and then treat the means of these batches
as if they were independent.
1 jm
Yj =
Y (t + T0 )dt
j
m
(
1
)
m
A discrete-time process, {Yi, i = d+1,d+2, , n}:
k batches of size m = (n d)/k, batch means:
jm
1
Yj =
Yi + d
m i =( j 1) m +1
Chapter 10. Output Analysis for a Single Model
45
Y1
Yk
Y2
S
1
=
k
k
j =1
(Y j Y )2 =
k 1
j =1
Y j2 kY 2
k (k 1)
46
Summary
47
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 11
Comparison and Evaluation of Alternative System Designs
Purpose
Purpose: comparison of alternative system designs.
Approach: discuss a few of many statistical methods that can be
used to compare two or more system designs.
Statistical analysis is needed to discover whether observed
differences are due to:
Differences in design or
The random fluctuation inherent in the models
Outline
For two-system comparisons:
Independent sampling.
Correlated sampling (common random numbers).
Metamodels
The station performs 3 jobs: (1) brake check, (2) headlight check, and (3) steering
check.
Vehicles arrival: Possion with rate = 9.5/hour.
Present system:
Alternative system:
Performance measure: mean response time per vehicle (total time from vehicle
arrival to its departure).
- Three stalls in parallel (one attendant makes all 3 inspections at each stall).
- Service times for the 3 jobs: normally distributed with means 6.5, 6.0 and 5.5 minutes,
respectively.
- Each attendant specializes in a single task, each vehicle will pass through three work
stations in series
- Mean service times for each job decreases by 10% (5.85, 5.4, and 4.95 minutes).
Degree
of
freedom
Standard error
of the estimator
All three techniques assume that the basic data Yir are approximately
normally distributed.
Y1 Y2 t , s.e.(Y1 Y2 ) 1 2 Y1 Y2 + t , s.e.(Y1 Y2 )
2
V (Y.i ) i2
V Y.i =
=
,
Ri
Ri
( )
i = 1,2
) ( ) ( )
10
12
R1
22
R2
Dr. Mesut Gne
Y.1 Y.2
1 Ri
1 Ri 2
2
2
(Yri Y.i ) =
S =
Yri RiY.i
Ri 1 r =1
Ri 1 r =1
2
i
S p2
( R1 1) S12 + ( R2 1) S 22
=
,
R1 + R2 2
1
1
+
R1 R2
11
(S
/ R1 + S 22 / R2
=
S 2 / R 2 / (R 1) + S 2 / R
1
2 2
1 1
2
1
S12 S 22
+
R1 R2
) / (R
2
1)
, round to an interger
12
) ( ) ( )
12
Correlation:
12 is positive
2 12 1 2
=
+
R
R
R
Chapter 11. Comparison and Evaluation of Alternative Designs
22
13
VCRN
2 12 1 2
= VIND
R
14
1 R
1 R 2
2
2
(
)
S =
D
D
D
R
D
r
r
R 1 r =1
R 1 r =1
2
D
where Dr = Yr1-Yr 2
Standard error:
1 R
and D = Dr , with degress of freedom = R-1
R r =1
15
SD
R
16
17
Model 1
18
with = 17, t 0.05,17 = 2.11, S12 = 118.9 and S 22 = 244.3, CI : -18.1 1-2 7.3
CRN without synchronization: Y.1 Y.2 = 1.9 minutes
19
t / 2, R 1S D
R
t / 2, R0 1S D
t
t
Since / 2, R 1 / 2, R0 1 , a conservation estimate of R is: R
20
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 2
Simulation Examples
Introducing simulation by
Inputs
xi1
Response
yi
1
2
:
n
Three steps
3. For each repetition i, generate a value for each of the p inputs xij and
calculate the response yi.
Calling population
Waiting line
Server
System
Events
inter-arrival time
distribution
Server
stable system
- Arrival of a unit
- Departure of a unit
unstable system
Calling population
ti+1
ti
Arrivals
Waiting line
Server
Departure Event
Interarrival times
Service times
{1,...,6}
{1,...,4}
Interarrival
Time
Arrival Time
on Clock
Service
Time
15
Customer
Number
Arrival Time
[Clock]
Time Service
Begins [Clock]
Service Time
[Duration]
Time Service
Ends [Clock]
11
11
12
15
15
19
Customer
Number
Event
Type
Number of
customers
Arrival
Departure
Arrival
Departure
Arrival
Arrival
Departure
Arrival
11
Departure
12
Departure
15
Arrival
19
Departure
Interarrival
Time
Probability
0.125
0.125
0.125
0.250
0.125
0.375
0.125
0.500
0.125
0.625
0.125
0.750
0.125
0.875
0.125
1.000
Problems/Simplifications
Service
Time
Probability
Cumulative
Probability
Cumulative
Probability
0.10
0.10
0.20
0.30
0.30
0.60
0.25
0.85
0.10
0.95
0.05
1.00
Dr. Mesut Gne
Interarrival
Time
[Minutes]
Arrival Time
[Clock]
Service
Time
[Minutes]
Time
Service
Begins
[Clock]
Time
Service
Ends
[Clock]
Waiting
Time in
Queue
[Minutes]
Time
Customer
in System
[Minutes]
Idle Time
of Server
[Minutes]
11
11
15
11
15
16
18
18
23
416
418
174
491
101
...
100
Total
415
415
2
317
10
w=
p( wait ) =
p(idle server) =
s=
Number of customers
100
Service time
Number of customers
418
317
= 3.17 min
100
E (s ) =
s=0
Number of arrivals - 1
E ( ) =
wwaited =
t=
99
a + b 1+ 8
=
= 4.5 min
2
2
174
= 3.22 min
54
100
11
Average of 50 Trials
manager, but
18
17
Some interpretations
16
14
12
10
8
4
2
1
0
15
1
0
4,5
0
0
0,5
1,5
2,5
3,5
>4.5
12
Summary
This chapter introduced simulation concepts my means of
examples
Example simulation were performed on a table manually
Use a spreadsheet for large experiments (Excel, OpenOffice)
Input data is important
Random variables can be used
Output analysis important and difficult
The used tables were of ad hoc, a more methodic approach is
needed
13
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 3
General Principles
System
A collection of entities that interact together over time to accomplish one or more
goals.
Model
System state
A collection of variables that contain all the information necessary to describe the
system at any time.
Entity
An object in the system that requires explicit representation in the model, e.g., people,
machines, nodes, packets, server, customer.
Attributes
List, Set
Event
Event notice
A record of an event to occur at the current or some future time, along with any
associated data necessary to execute the event.
A list of event notices for future events, ordered by time of occurrence; known as the
future event list (FEL).
Always ranked by the event time
Activity
Delay
A duration of time of unspecified indefinite length, which is not known until it ends.
Customers delay in waiting line depends on the number and service times of other
customers.
Typically a desired output of the simulation run.
Clock
Delay
Delay is known as conditional wait
Delays are managed by placing the entity on another list, e.g.,
representing a waiting line
Completion of delay is a secondary event, but they are not
placed in the future event list
Delay
Delay
Activity2
Activity1
t
A1
A2
D1
A3
D2
A model consists of
Events
- How does each event affect system state, entity attributes, and set contents?
Activities
- How are activities defined?
- What event marks the beginning or end of each activity?
- Can the activity begin regardless of system state, or is its beginning conditioned on the
system being in a certain state?
Delays
- Which events trigger the beginning (and end) of each delay?
- Under what condition does a delay begin or end?
System state
(x, y, z, ...)
...
...
Entities and
attributes
Set 1
Set 2
...
Statistics
...
...
...
...
...
Event-scheduling/Time-advance algorithm
Future event list (FEL)
10
Event-scheduling/Time-advance algorithm
Old system snapshot at time t
Event-scheduling/Time-advance algorithm
Clock
State
(5,1,6)
State
t1
(5,1,5)
...
(2,tn) Type 2 event to occur at tn
11
Event-scheduling/Time-advance algorithm
System snapshot at time 0
Initial conditions
Generation of exogenous events
- Exogenous event, is an event which happens outside the system,
but impinges on the system, e.g., arrival of a customer
12
Event-scheduling/Time-advance algorithm
Generation of events
Arrival of a customer
- At t=0 first arrival is generated and scheduled
- When the clock is advanced to the time of the
first arrival, a second arrival is generated
- Generate an interarrival time a*
- Calculate t* = clock + a*
- Place event notice at t* on the FEL
13
Bootstrapping
Event-scheduling/Time-advance algorithm
Generation of events
Service completion of a customer
-
14
Event-scheduling/Time-advance algorithm
Generation of events
Alternate generation of runtimes and downtimes
- At time 0, the first runtime will be generated and an end-of-runtime
event will be scheduled
- Whenever an end-of-runtime event occurs, a downtime will be
generated, and a end-of-downtime event will be scheduled
- At the end-of-downtime event, a runtime is generated and an endof-runtime event is scheduled
- Runtimes and downtimes are activities
- end-of-runtime and end-of-downtime are primary events
runtime
downtime
runtime
Time
Time 0
Chapter 3. General Principles
15
Event-scheduling/Time-advance algorithm
Stopping a simulation
1. At time 0, schedule a stop simulation event at a specified future
time TE Simulation will run over [0, TE]
2. Run length TE is determined by the simulation itself.
16
World Views
World view
A world view is an
orientation for the model
developer
Simulation packages
typically support some
world views
Here, only world views for
discrete simulations
Discrete Simulation
Event-scheduling
17
Process-interaction
Activity-scanning
World Views
Start
Event-scheduling
Focus on events
Identify the entities and their
attributes
Identify the attributes of the
system
Define what causes a change
in system state
Write a routine to execute for
each event
Variable time advance
Initialization
Select next event
Event
routine 1
Event
routine 2
No
Event
routine n
Terminate?
Yes
Output
End
18
World Views
Process-interaction
19
World Views
Start
Activity-scanning
Initialization
Activity 2
Condition
Actions
Other condition
satisfied?
Activity n
Condition
Actions
Yes
No
No
Terminate?
Yes
Output
End
20
World Views
Start
Three-phase approach
Initialization
Activity 2
Condition
Actions
Other condition
satisfied?
Activity n
Condition
Actions
Yes
No
No
Terminate?
Yes
Output
End
Chapter 3. General Principles
21
World Views
P2
E4
E3
A3
A4
P4
E8
E7
A7
P3
P1
E2
E1
A1
E6
E5
A5
A8
A6
A2
Time
22
Activities
Arrival (A)
Departure (D)
Stopping event (E)
Event notices
Events
Entities
Interarrival time
Service time
Delay
23
Server
Dr. Mesut Gne
Arrival
Departure
24
Initial conditions
First customer arrives at t=0
and gets service
An arrival and a departure
event is on FEL
25
In the example
No information about particular customer
If needed, the model has to be extended
26
Event notices
- (A, t, Ci) arrival of customer Ci at t
- (D, t, Cj) departure of customer Cj at t
Set
- Checkout Line set of customers currently at the checkout counter ordered
by time of arrival
Statistics
- S: sum of customer response times for all customers who have departed by
the current time
- F: total number of customers who spend 5 time units
- ND: number of departures up to the current simulation time
27
LQ(t)
(C1,0)
(A,1,C2) (D,4,C1)(E,60)
(C1,0)(C2,1)
(A,2,C3)(D,4,C1)(E,60)
(C1,0)(C2,1)(C3,2)
(D,4,C1)(A,8,C4)(E,60)
(C2,1)(C3,2)
(D,6,C2)(A,8,C4)(E,60)
(C3,2)
(A,8,C4)(D,11,C3)(E,60)
(C3,2)(C4,8)
(D,11,C3)(A,11,C5)(E,60)
11
(C4,8)(C5,11)
(D,15,C4)(A,18,C6)(E,60)
18
15
(C5,11)
(D,16,C4)(A,18,C6)(E,60)
25
16
(A,18,C6)(E,60)
30
18
(C6,18)
(D,23,C6)(A,23,C7)(E,60)
30
23
(C7,23)
(A,25,C8)(D,27,C7)(E,60)
35
response time =
LS(t)
Statistics
Checkout Line
35
S
=
= 5.83
6
ND
N 5 =
28
ND
5
F
= = 0.83
ND 6
Dr. Mesut Gne
29
30
CDF
0.30
0.30
10
0.50
0.80
15
0.20
1.00
Weighing Time
CDF
12
0.70
0.70
16
0.30
1.00
Delays
Activities
Loading Time
Lists
Entities
Event notices
CDF
40
0.40
0.40
60
0.30
0.70
80
0.20
0.90
100
0.10
1.00
Activity times
Both loaders
are busy!
Lists
Loader Queue
Statistics
Clock
LQ(t)
L(t)
WQ(t)
W(t)
Weigh Queue
DT5, DT6
DT3
10
DT6
10
12
20
24
BS
10
DT3, DT2
(EL,10,DT4) (EW,12,DT1)
(EL,10+10,DT5)
20
10
(EW,12,DT1) (EL,20,DT5)
(EL,10+15,DT6)
20
10
DT2, DT4
(EL,20,DT5) (EW,12+12,DT3)
(EL,25,DT6) (ALQ,12+60,DT1)
24
12
40
20
DT4, DT5
(EL,25,DT6) (EW,24+12,DT2)
(ALQ,72,DT1) (ALQ,24+100,DT3)
44
24
BL
31
Simulation in Java
Simulation in Java
Again the grocery example
Object-oriented
Calling population
ti+1
ti
Arrivals
Waiting line
33
Server
Simulation in Java
System state
queueLength
numberInService
Entity attributes
customers
futureEventList
Activity durations
meanInterArrivalTime
meanServiceTime
meanInterarrivalTime
meanServiceTime
totalCustomers
34
exponential(mu)
Methods
Input parameters
rho = BusyTime/Clock
avgr = Average response time
pc4 = Number of customers who spent
more than 4 minutes
Help functions
clock
lastEventTime
totalBusy
maxQueueLength
sumResponseTime
Statistics
Simulation variables
initialization
processArrival
processDeparture
reportGeneration
Simulation in Java
Overall structure of the Java program
35
36
numberOfCustomers,
queueLength,
numberInService,
totalCustomers,
numberOfDepartures,
longService;
37
argv[]) {
= 4.5;
= 3.2;
= 1000;
= Long.parseLong(argv[0]);
initialization();
// Loop until first totalCustomers" have departed
while( numberOfDepartures < totalCustomers ) {
Event event = (Event)futureEventList.getMin(); // Get imminent event
futureEventList.dequeue();
// Be rid of it
clock = event.getTime();
// Advance simulation time
if( event.getType() == arrival ) {
processArrival(event);
}
else {
processDeparture(event);
}
}
reportGeneration();
}
38
39
40
41
reportGeneration() {
totalBusy/clock;
sumResponseTime/totalCustomers;
((double)longService)/totalCustomers;
System.out.println( "SINGLE SERVER QUEUE SIMULATION - GROCERY STORE CHECKOUT COUNTER ");
System.out.println( "\tMEAN INTERARRIVAL TIME
" + meanInterArrivalTime );
System.out.println( "\tMEAN SERVICE TIME
" + meanServiceTime );
System.out.println( "\tNUMBER OF CUSTOMERS SERVED
" + totalCustomers );
System.out.println();
System.out.println( "\tSERVER UTILIZATION
" + rho );
System.out.println( "\tMAXIMUM LINE LENGTH
" + maxQueueLength );
System.out.println( "\tAVERAGE RESPONSE TIME
" + avgr + " Time Units");
System.out.println( "\tPROPORTION WHO SPEND FOUR ");
System.out.println( "\t MINUTES OR MORE IN SYSTEM
" + pc4 );
System.out.println( "\tSIMULATION RUNLENGTH
" + clock + " Time Units");
System.out.println( "\tNUMBER OF DEPARTURES
" + totalCustomers );
}
42
0.718
13.0
9.563
0.713
4485.635
1000
43
Package core
45
Package core
SimEvent
SimEntity
SimQueue
SimControl
Package rng
RNG
46
47
48
49
50
51
52
MM1Generator
Generates new
customer
MM1Server
Serves customer
53
54
Simulation
Simulation
Theory
6
Queueing Time
System Time
Queueing Time
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.1
0.9
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
rho
rho
0.9
Simulation
p0 Probability that
a customer finds the
system idle
Theory
p0
0.8
0.7
System Time
Theory
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
rho
55
Summary
Introduced a general framework for discrete event
simulations
Event-scheduling and time-advance algorithm
Generation of events
World views for discrete simulations
Introduced manual discrete event simulation
Introduced simulation in Java
Object-oriented simulation framework in Java
56
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 4
Statistical Models in Simulation
In this chapter:
Review several important probability distributions
Present some typical application of these models
1. p( xi ) 0, for all i
2.
i =1
p( xi ) = 1
P(a X b) = f ( x)dx
a
1. f ( x) 0 , for all x in R X
2.
f ( x)dx = 1
RX
3. f ( x) = 0, if x is not in RX
Properties
x0
1. P ( X = x0 ) = 0, because f ( x)dx = 0
x0
1 x / 2
e , x0
f ( x) = 2
0,
otherwise
Lifetime in Year
1 3 x / 2
P(2 x 3) = e dx = 0.14
2 2
Chapter 4. Statistical Models in Simulation
If X is discrete, then
F ( x) = p ( xi )
xi x
If X is continuous, then
F ( x) = f (t )dt
Properties
1. F is nondecreasing function. If a b, then F (a ) F (b)
2. lim F ( x) = 1
x
3. lim F ( x) = 0
x
1 x t / 2
F ( x) = e dt = 1 e x / 2
2 0
The probability that the device lasts for less than 2 years:
Expectation
E ( x) = xi p ( xi )
all i
E ( x) = x f ( x)dx
If X is continuous
If X is discrete
Definition:
V(X) = E( (X E[X])2 )
Also,
V(X) = E(X2) ( E(x) )2
A measure of the spread or variation of the possible values of X around the
mean
10
Expectations
Example: The mean of life of the previous inspection device is:
1
x / 2
x / 2
E ( X ) = xe dx = xe
+ e x / 2 dx = 2
0
2 0
0
1 2 x / 2
x / 2
2
E ( X ) = x e dx = x e
+ e x / 2 dx = 8
0
2 0
0
2
V (X ) = 8 2 = 4
= V (X ) = 2
Chapter 4. Statistical Models in Simulation
11
Expectations
1 x / 2
x / 2
E ( X ) = xe dx = xe
+ e x / 2 dx = 2
0
2 0
0
1
x / 2
+ e x / 2 dx = 2
E ( X ) = xe x / 2 dx = xe
0
2 0
0
Partial Integration
u ' ( x) = 1
v( x) = 2e x / 2
1 x/ 2
1
x/ 2
E ( X ) = xe dx = ( x (2e ) 1 (2e x / 2 )dx)
0
2 0
2
0
Chapter 4. Statistical Models in Simulation
12
Queueing systems
Inventory and supply-chain systems
Reliability and maintainability
Limited data
13
14
15
16
Other distribution:
Bernoulli
Binomial
Hyperexponential
17
Discrete Distributions
Discrete random variables are used to describe random
phenomena in which only integer values can occur.
In this section, we will learn about:
18
xj =1
p,
p j ( x j ) = p( x j ) =
,
=
=
q
:
1
p
,
x
0
j
j = 1,2,..., n
Bernoulli process:
The n Bernoulli trials where trails are independent:
p(x1,x2,, xn) = p1(x1)p2(x2) pn(xn)
Chapter 4. Statistical Models in Simulation
19
Binomial Distribution
The number of successes in n Bernoulli trials, X, has a binomial
distribution.
n x n x
p q , x = 0,1,2,..., n
p( x) = x
0,
otherwise
The number of
outcomes having the
required number of
successes and
failures
Probability that
there are
x successes and
(n-x) failures
20
Geometric Distribution
Geometric distribution
The number of Bernoulli trials, X, to achieve the 1st success:
q x 1 p, x = 0,1,2,..., n
p ( x) =
otherwise
0,
E(x) = 1/p, and V(X) = q/p2
21
y 1 y k k
q p , y = k , k + 1, k + 2,...
p ( x) = k 1
0,
otherwise
y 1 y k k 1
q p {p
p ( x) =
k 1
1
442443 k th success
(k-1 ) successes
22
Poisson Distribution
Poisson distribution describes many random processes quite
well and is mathematically quite simple.
where > 0, pdf and cdf are:
p( x) = x! e , x = 0,1,...
0,
otherwise
i e
i =0
i!
F ( x) =
E(X) = = V(X)
23
Poisson Distribution
Example: A computer repair person is beeped each
time there is a call for service. The number of beeps per
hour ~ Poisson( = 2 per hour).
The probability of three beeps in the next hour:
p(3)
= 23/3! e-2 = 0.18
also,
p(3)
= F(3) F(2) = 0.857-0.677=0.18
The probability of two or more beeps in a 1-hour period:
p(2 or more)
= 1 ( p(0) + p(1) )
= 1 F(1)
= 0.594
24
Continuous Distributions
Continuous random variables can be used to describe
random phenomena in which the variable can take on any
value in some interval.
In this section, the distributions studied are:
Uniform
Exponential
Weibull
Normal
Lognormal
25
Uniform Distribution
A random variable X is uniformly distributed on the interval
(a, b), U(a, b), if its pdf and cdf are:
x<a
0,
x a
F ( x) =
, a x<b
b a
xb
1,
, a xb
f ( x) = b a
0,
otherwise
Properties
26
Exponential Distribution
A random variable X is exponentially distributed with parameter
> 0 if its pdf and cdf are:
x<0
0,
F ( x ) = x t
x
0 e dt = 1 e , x 0
e x , x 0
f ( x) =
elsewhere
0,
E(X) = 1/ V(X) = 1/2
27
Exponential Distribution
Used to model interarrival
times when arrivals are
completely random, and to
model service times that are
highly variable
For several different
exponential pdfs (see figure),
the value of intercept on the
vertical axis is , and all pdfs
eventually intersect.
28
Exponential Distribution
Memoryless property
For all s and t greater or equal to 0:
P(X > s+t | X > s) = P(X > t)
Example: A lamp ~ exp( = 1/3 per hour), hence, on average, 1
failure per 3 hours.
- The probability that the lamp lasts longer than its mean life is:
P(X > 3) = 1-(1-e-3/3) = e-1 = 0.368
- The probability that it lasts for another hour given it is operating for
2.5 hours:
P(X > 3.5 | X > 2.5) = P(X > 1) = e-1/3 = 0.717
29
Exponential Distribution
Memoryless property
P( X > s + t )
P( X > s + t | X > s) =
P( X > s)
e ( s +t )
= s
e
= e t
= P( X > t )
30
Weibull Distribution
A random variable X has a Weibull distribution if its pdf has the form:
x 1
x
exp
, x
f ( x) =
0,
otherwise
3 parameters:
( < < )
Location parameter: ,
Scale parameter: , ( > 0)
Shape parameter. , (> 0)
Example: = 0 and = 1:
31
Weibull Distribution
Weibull Distribution
x 1
x
exp
, x
f ( x) =
0,
otherwise
For = 1, =0
1
x
1
f ( x) = exp , x
0,
otherwise
When = 1,
X ~ exp( = 1/)
32
Normal Distribution
A random variable X is normally distributed if it has the pdf:
1 x 2
1
f ( x) =
exp
, < x <
2
2
Mean: < <
2
Variance: > 0
Denoted as X ~ N(,2)
Special properties:
f ( x) = 0, and lim f ( x) = 0
xlim
x
f(-x)=f(+x); the pdf is symmetric about .
The maximum value of the pdf occurs at x = ; the mean and mode are
equal.
33
Normal Distribution
Evaluating the distribution:
Use numerical methods (no closed form)
Independent of and , using the standard normal distribution:
Z ~ N(0,1)
Transformation of variables: let Z = (X - ) / ,
F ( x ) = P ( X x ) = P Z
( x ) /
1 z2 / 2
=
e
dz
2
=
( x ) /
( z )dz = ( x )
34
, where ( z ) =
1 t 2 / 2
e
dt
2
Normal Distribution
Example: The time required to load an oceangoing vessel, X, is
distributed as N(12,4), =12, =2
The probability that the vessel is loaded in less than 10 hours:
10 12
F (10) =
= (1) = 0.1587
2
- Using the symmetry property, (1) is the complement of (-1)
35
Lognormal Distribution
A random variable X has a lognormal distribution if its pdf has
the form:
1
(ln x ) 2
exp
, x > 0
2
f ( x) = 2 x
2
0,
otherwise
=1,
2=0.5,1,2.
Mean E(X) = e+ /2
2
2
Variance V(X) = e2+ /2 (e - 1)
2
36
Poisson Distribution
Definition: N(t) is a counting function that represents the
number of events occurred in [0,t].
A counting process {N(t), t>=0} is a Poisson process with
mean rate if:
Arrivals occur one at a time
{N(t), t>=0} has stationary increments
{N(t), t>=0} has independent increments
Properties
( t ) n t
P[ N (t ) = n] =
e ,
n!
37
The 1st arrival occurs after time t iff there are no arrivals in the interval [0,t],
hence:
P(A1 > t) = P(N(t) = 0) = e-t
P(A1 <= t) = 1 e-t
[cdf of exp()]
Interarrival times, A1, A2, , are exponentially distributed and independent with
mean 1/
Arrival counts
~ Poisson()
Interarrival time
~ Exp(1/)
Memoryless
38
p
(1-p)
N1(t) ~ Poisson[p]
N2(t) ~ Poisson[(1-p)]
Pooling:
Suppose two Poisson processes are pooled together
N1(t) + N2(t) = N(t), where N(t) is a Poisson processes with rates 1 + 2
N1(t) ~ Poisson[1]
N2(t) ~ Poisson[2]
Chapter 4. Statistical Models in Simulation
1 + 2
N(t) ~ Poisson(1 + 2)
2
39
40
Summary
The world that the simulation analyst sees is probabilistic, not
deterministic.
In this chapter:
Reviewed several important probability distributions.
Showed applications of the probability distributions in a simulation context.
41
Simulation Techniques
Dr. Mesut Gne
Chapter 7
Queueing Models
Purpose
Simulation is often used in the analysis of queueing models.
A simple but typical queueing model
Calling population
Waiting line
Server
Outline
Discuss some well-known models
Not development of queueing theory, for this see other class!
Customers
Server
Reception desk
People
Receptionist
Hospital
Patients
Nurses
Airport
Airplanes
Runway
Production line
Cases
Case-packer
Road network
Cars
Traffic light
Grocery
Shoppers
Checkout station
Computer
Jobs
CPU, disk, CD
Network
Packets
Router
Calling Population
Calling population: the population of potential customers, may be
assumed to be finite or infinite.
Finite population model: if arrival rate depends on the number of
customers being served and waiting, e.g., model of one corporate jet, if it
is being repaired, the repair arrival rate becomes zero.
n-1
System Capacity
System Capacity: a limit on the number of customers that may
be in the waiting line or system.
Limited capacity, e.g., an automatic car wash only has room for 10 cars
to wait in line to enter the mechanism.
Waiting line
Server
Unlimited capacity, e.g., concert ticket sales with no limit on the number
of people allowed to wait to purchase tickets.
Waiting line
Server
Arrival Process
For infinite-population models:
In terms of interarrival times of successive customers.
Random arrivals: interarrival times usually characterized by a probability
distribution.
- Most important model: Poisson arrival process (with rate ), where An
represents the interarrival time between customer n-1 and customer n, and is
exponentially distributed (with mean 1/).
Arrival Process
For finite-population models:
Customer is pending when the customer is outside the queueing system,
e.g., machine-repair problem: a machine is pending when it is
operating, it becomes not pending the instant it demands service from
the repairman.
Runtime of a customer is the length of time from departure from the
queueing system until that customers next arrival to the queue, e.g.,
machine-repair problem, machines are customers and a runtime is time
to failure (TTF).
Let A1(i), A2(i), be the successive runtimes of customer i, and S1(i), S2(i)
be the corresponding successive system times:
First-in-first-out (FIFO)
Last-in-first-out (LIFO)
Service in random order (SIRO)
Shortest processing time first (SPT)
Service according to priority (PR)
10
11
12
13
14
Example
Candy production line
Three machines separated by buffers
Buffers have capacity of 1000 candies
Assumption:Allways
sufficient supply of
raw material.
Chapter 7. Queueing Models
15
A
B
c
N
K
N, K
M
D
Ek
H
G
Examples
M/M/1// same as M/M/1: Single-server with unlimited capacity and callpopulation. Interarrival and service times are exponentially distributed
G/G/1/5/5: Single-server with capacity 5 and call-population 5.
16
Queueing Notation
Primary performance measures of queueing systems:
Pn
Pn(t)
An
Sn
Wn
WnQ
L(t)
LQ(t)
L
LQ
w
wQ
17
Number of
customers in the
system
Time
18
1
T
L =
iTi =
i i
T i =0
T
i =0
1
L =
T
1
iTi =
T
i =0
L(t )dt
0
L=
T
L(t )dt T
L
19
1
1
Q
LQ = iTi =
T i =0
T
LQ (t )dt T
LQ
G/G/1/N/K example: consider the results from the queueing system (N> 4,
K > 3).
L = [0(3) + 1(12) + 2(4) + 3(1)] / 20
= 23 / 20 = 1.15 cusomters
if L(t) = 0
0,
LQ (t ) =
L(t ) 1, if L(t) 1
0(15) + 1(4) + 2(1)
LQ =
= 0.3 customers
20
20
w=
N
W
i =1
where W1, W2, , WN are the individual times that each of the N
customers spend in the system during [0,T].
w as N
For stable systems: w
If the system under consideration is the queue alone:
1 N Q
w Q = Wi wQ
N i =1
as
w =
21
L = w
Average
System time
Arrival rate
L = w as T and N
Holds for almost all queueing systems or subsystems (regardless of the
number of servers, the queue discipline, or other special circumstances).
G/G/1/N/K example (cont.): On average, one arrival every 4 time units
and each arrival spends 4.6 time units in the system. Hence, at an
arbitrary point in time, there is (1/4)(4.6) = 1.15 customers present on
average.
22
Server Utilization
Definition: the proportion of time that a server is busy.
Observed server utilization, , is defined over a specified time interval
[0,T].
Long-run server utilization is .
For systems with long-run stability: as T
23
Server Utilization
For G/G/1// queues:
Any single-server queueing system with average arrival rate
customers per time unit, where average service time E(S) = 1/
time units, infinite queue capacity and calling population.
Conservation equation, L = w, can be applied.
For a stable system, the average arrival rate to the server, s,
must be identical to .
The average number of customers in the server is:
Ls =
T
(
T
T T0
L(t ) LQ (t ) dt =
T
24
Server Utilization
In general, for a single-server queue:
Ls = T
Ls =
and
= E (s) =
<1
25
Server Utilization
For G/G/c// queues:
A system with c identical servers in parallel.
If an arriving customer finds more than one server idle, the
customer chooses a server without favoring any particular server.
For systems in statistical equilibrium, the average number of busy
servers, Ls, is: Ls, = E(s) = /.
The long-run average server utilization is:
Ls
=
, where < c for stable systems
c c
26
27
S3 = 9, S4 = 9, S5 = 9, .
28
System incurs a cost for each customer in the queue, say at a rate of $10
per hour per customer.
WjQ is the time
- The average cost per customer is:
customer j spends
N
$10 W jQ
j =1
in queue
= $10 w Q
- If customers per hour arrive (on average), the average cost per
hour is:
L
$
10
customer $10 w Q
Q
= $10 w Q =
hour customer
hour
29
Markovian models:
P ( L(t ) = n) = Pn (t ) = Pn
Mathematical models in this chapter can be used to obtain approximate
results even when the model assumptions do not strictly hold, as a
rough guide.
Simulation can be used for more refined analysis, more faithful
representation for complex systems.
Chapter 7. Queueing Models
30
31
L=
nP
n =0
w=
wQ = w
LQ = wQ
=
<1
c
Chapter 7. Queueing Models
32
M/G/1 Queues
P0 = 1
2 (1 + 2 2 )
L=+
2(1 )
The particular
distribution is not
known!
2 (1 + 2 2 )
LQ =
2(1 )
(1 / 2 + 2 )
w= +
2(1 )
1
(1 / 2 + 2 )
wQ =
2(1 )
Chapter 7. Queueing Models
33
M/G/1 Queues
There are no simple expression for the steady-state probabilities P0,
P1,
L LQ = is the time-average number of customers being served.
Average length of queue, LQ, can be rewritten as:
2 2
+
LQ =
2(1 ) 2(1 )
If and are held constant, LQ depends on the variability, 2, of the
service times.
34
M/G/1 Queues
Example: Two workers competing for a job, Able claims to be faster than
Baker on average, but Baker claims to be more consistent,
= 20%.
(1 / 30) 2 [252 + 4]
LQ =
= 2.097 customers
2(1 5 / 6)
- The proportion of arrivals who find Baker idle and thus experience no delay is P0 = 1- =
1/6 = 16.7%.
35
M/M/1 Queues
Suppose the service times in an M/G/1 queue are exponentially
distributed with mean 1/, then the variance is 2 = 1/2.
M/M/1 queue is a useful approximate model when service times
have standard deviation approximately equal to their means.
The steady-state parameters
=
Pn = (1 ) n
L=
P0 = 1
2
2
=
LQ =
( ) 1
w=
wQ =
Chapter 7. Queueing Models
1
1
=
(1 )
=
( ) (1 )
36
M/M/1 Queues
Single-chair unisex hair-styling shop
Interarrival and service times are exponentially distributed
=2 customers/hour and =3 customers/hour
=
2
=
3
L=
1
3
P0 = 1 =
1
n =0
2
= 2 Customers
3 2
4
4
2
LQ =
=
= Customers
( ) 3(3 2) 3
4 2
L = LQ + = + = 2 Customers
3 3
1 2
4
P2 = =
3 3
27
P 4 = 1 Pn =
2
= 1 hour
2
1
1 2
wQ = w = 1 = hour
3 3
w=
1 2 2
P1 = =
3 3 9
16
81
37
M/M/1 Queues
Example: M/M/1 queue with
service rate =10 customers
per hour.
5,0
6,0
7,2
8,6
10,0
0,5
1,0
0,6
1,5
0,7
2,6
0,9
6,4
1,0
0,2
0,3
0,4
0,7
20
L
18 w
Number of Customers
16
14
12
10
8
6
4
2
0
0.5
0.6
0.7
0.8
0.9
rho
38
(cv) 2 =
V (X )
[E ( X )]2
The larger cv is, the more variable is the distribution relative to its
expected value
For exponential service times with rate
- E(X)=1/
- V(X)=1/2
cv=1
Chapter 7. Queueing Models
39
1
2
LQ for M/M/1
queue
Corrects the M/M/1
formula to account
for a non-exponential
service time distn
40
Multiserver Queue
M/M/c// queue: c servers operating in parallel
Arrival process is poisson with rate
Each server has an independent and identical exponential service-time
distribution, with mean 1/.
To achieve statistical equilibrium, the offered load (/) must satisfy /<c,
where /(c) = is the server utilization.
Calling population
1
Waiting line
c
Chapter 7. Queueing Models
41
Multiserver Queue
c 1 ( / ) n c 1 c
P0 =
+
n =0 n! c! c
(c ) c P0
P (L ( ) c ) =
c!(1 )
Probability
that all servers
are busy
(c ) c +1 P0
P (L ( ) c )
c
L = c +
=
+
1
c(c!)(1 ) 2
L
w=
P (L ( ) c )
LQ =
1
L LQ = c
Chapter 7. Queueing Models
42
Multiserver Queue
Probability of empty system
43
Multiserver Queue
Other common multiserver queueing models
2 1 + (cv) 2
LQ =
2
1
LQ for M/M/1
queue
M/G/c/: general service times and c parallel server. The parameters can
be approximated from those of the M/M/c// model.
M/G/: general service times and infinite number of servers.
M/M/c/N/: service times are exponentially distributed at rate and c
servers where the total system capacity is N c customer. When an arrival
occurs and the system is full, that arrival is turned away.
Chapter 7. Queueing Models
44
Multiserver Queue
M/G/: general service times and infinite number of servers
- customer is its own server
- service capacity far exceeds service demand
- when we want to know how many servers are required so that
customers are rarely delayed
Pn = e
P0 = e
w=
()
n!
, n = 0,1, K
wQ = 0
L=
LQ = 0
Chapter 7. Queueing Models
45
Multiserver Queue
How many users can be logged in simultaneously in a computer
system
L = = 500 3 = 1500
46
Multiserver Queue
M/M/c/N/: service times are exponentially distributed at rate and
c servers where the total system capacity is N c customer
when an arrival occurs and the system is full, that arrival is turned away
Effective arrival rate e is defined as the mean number of arrivals per
time unit who enter and remain in the system
1
P0
PN
LQ
a n a c N n c
= 1 + +
!
!
n
c
1
1
=
=
+
n
n
c
aN
=
P0
c!c N c
P0 a c
1 N c ( N c) N c (1 )
=
c!(1 )
= (1 PN )
wQ =
LQ
w = wQ +
L = e w
Chapter 7. Queueing Models
47
Multiserver Queue
Single-chair unisex hair-styling shop (again!)
Space only for 3 customers:
one in service and two waiting
First computer P0
P0 =
1
2 2 3 2 n 1
1 + +
3 3 n = 2 3
Queue time
wQ =
= 0.415
PN = P3 =
()
1!1
P0 =
w = wQ +
8
= 0.123
65
28
= 0.246
114
66
= 0.579
114
Expected number of
customers in shop
L = e w =
66
= 1.015
65
1 P0 = e = 0.585
8 114
e = 21 =
= 1.754
65 65
P(system is full)
2 3
3
2
LQ
48
When the calling population is small, the presence of one or more customers in
the system has a strong effect on the distribution of future arrivals.
The time between the end of one service visit and the next call for service is
exponentially distributed with mean = 1/.
Service times are also exponentially distributed with mean 1/.
c parallel servers and system capacity is K.
K Customers
1
Waiting line
c
Chapter 7. Queueing Models
49
!
K
( K n)!c!c n c , n = c, c + 1,...K
L = nPn ,
n =0
w = L / e ,
e
c
where e is the long run effective arrival rate of customers to queue (or entering/exiting service)
K
e = ( K n)Pn
n =0
50
)!
2
!
2
20
n =0
n=2
= 0.065
Then, we can obtain the other Pn, and can compute the
expected number of machines in system:
10
L=
nP
= 3.17 machines
n =0
51
Networks of Queues
Many systems are naturally modeled as networks of single queues
customers departing from one queue may be routed to another
52
Networks of Queues
The overall arrival rate into queue j:
j = aj +
p
i
ij
all i
Arrival rate
from outside
the network
If queue j has cj < parallel servers, each working at rate j, then the
long-run utilization of each server is j=j /(cj) (where j < 1 for stable
queue).
If arrivals from outside the network form a Poisson process with rate aj
for each queue j, and if there are cj identical servers delivering
exponentially distributed service times with mean 1/j, then, in steady
state, queue j behaves likes an M/M/cj queue with arrival rate
j = aj +
p
i
ij
all i
53
Network of Queues
Customer
Population
80 cust
hour
0.4
c=
c=1
0.6
54
Summary
55
Simulation Techniques
Dr. Mesut Gne
Chapter 7
Queueing Models
Purpose
Simulation is often used in the analysis of queueing models.
A simple but typical queueing model
Calling population
Waiting line
Server
Outline
Discuss some well-known models
Not development of queueing theory, for this see other class!
Customers
Server
Reception desk
People
Receptionist
Hospital
Patients
Nurses
Airport
Airplanes
Runway
Production line
Cases
Case-packer
Road network
Cars
Traffic light
Grocery
Shoppers
Checkout station
Computer
Jobs
CPU, disk, CD
Network
Packets
Router
Calling Population
Calling population: the population of potential customers, may be
assumed to be finite or infinite.
Finite population model: if arrival rate depends on the number of
customers being served and waiting, e.g., model of one corporate jet, if it
is being repaired, the repair arrival rate becomes zero.
n-1
System Capacity
System Capacity: a limit on the number of customers that may
be in the waiting line or system.
Limited capacity, e.g., an automatic car wash only has room for 10 cars
to wait in line to enter the mechanism.
Waiting line
Server
Unlimited capacity, e.g., concert ticket sales with no limit on the number
of people allowed to wait to purchase tickets.
Waiting line
Server
Arrival Process
For infinite-population models:
In terms of interarrival times of successive customers.
Random arrivals: interarrival times usually characterized by a probability
distribution.
- Most important model: Poisson arrival process (with rate ), where An
represents the interarrival time between customer n-1 and customer n, and is
exponentially distributed (with mean 1/).
Arrival Process
For finite-population models:
Customer is pending when the customer is outside the queueing system,
e.g., machine-repair problem: a machine is pending when it is
operating, it becomes not pending the instant it demands service from
the repairman.
Runtime of a customer is the length of time from departure from the
queueing system until that customers next arrival to the queue, e.g.,
machine-repair problem, machines are customers and a runtime is time
to failure (TTF).
Let A1(i), A2(i), be the successive runtimes of customer i, and S1(i), S2(i)
be the corresponding successive system times:
First-in-first-out (FIFO)
Last-in-first-out (LIFO)
Service in random order (SIRO)
Shortest processing time first (SPT)
Service according to priority (PR)
10
11
12
13
14
Example
Candy production line
Three machines separated by buffers
Buffers have capacity of 1000 candies
Assumption:Allways
sufficient supply of
raw material.
Chapter 7. Queueing Models
15
A
B
c
N
K
N, K
M
D
Ek
H
G
Examples
M/M/1// same as M/M/1: Single-server with unlimited capacity and callpopulation. Interarrival and service times are exponentially distributed
G/G/1/5/5: Single-server with capacity 5 and call-population 5.
16
Queueing Notation
Primary performance measures of queueing systems:
Pn
Pn(t)
An
Sn
Wn
WnQ
L(t)
LQ(t)
L
LQ
w
wQ
17
Number of
customers in the
system
Time
18
1
T
L =
iTi =
i i
T i =0
T
i =0
1
L =
T
1
iTi =
T
i =0
L(t )dt
0
L=
T
L(t )dt T
L
19
1
1
Q
LQ = iTi =
T i =0
T
LQ (t )dt T
LQ
G/G/1/N/K example: consider the results from the queueing system (N> 4,
K > 3).
L = [0(3) + 1(12) + 2(4) + 3(1)] / 20
= 23 / 20 = 1.15 cusomters
if L(t) = 0
0,
LQ (t ) =
L(t ) 1, if L(t) 1
0(15) + 1(4) + 2(1)
LQ =
= 0.3 customers
20
20
w=
N
W
i =1
where W1, W2, , WN are the individual times that each of the N
customers spend in the system during [0,T].
w as N
For stable systems: w
If the system under consideration is the queue alone:
1 N Q
w Q = Wi wQ
N i =1
as
w =
21
L = w
Average
System time
Arrival rate
L = w as T and N
Holds for almost all queueing systems or subsystems (regardless of the
number of servers, the queue discipline, or other special circumstances).
G/G/1/N/K example (cont.): On average, one arrival every 4 time units
and each arrival spends 4.6 time units in the system. Hence, at an
arbitrary point in time, there is (1/4)(4.6) = 1.15 customers present on
average.
22
Server Utilization
Definition: the proportion of time that a server is busy.
Observed server utilization, , is defined over a specified time interval
[0,T].
Long-run server utilization is .
For systems with long-run stability: as T
23
Server Utilization
For G/G/1// queues:
Any single-server queueing system with average arrival rate
customers per time unit, where average service time E(S) = 1/
time units, infinite queue capacity and calling population.
Conservation equation, L = w, can be applied.
For a stable system, the average arrival rate to the server, s,
must be identical to .
The average number of customers in the server is:
Ls =
T
(
T
T T0
L(t ) LQ (t ) dt =
T
24
Server Utilization
In general, for a single-server queue:
Ls = T
Ls =
and
= E (s) =
<1
25
Server Utilization
For G/G/c// queues:
A system with c identical servers in parallel.
If an arriving customer finds more than one server idle, the
customer chooses a server without favoring any particular server.
For systems in statistical equilibrium, the average number of busy
servers, Ls, is: Ls, = E(s) = /.
The long-run average server utilization is:
Ls
=
, where < c for stable systems
c c
26
27
S3 = 9, S4 = 9, S5 = 9, .
28
System incurs a cost for each customer in the queue, say at a rate of $10
per hour per customer.
WjQ is the time
- The average cost per customer is:
customer j spends
N
$10 W jQ
j =1
in queue
= $10 w Q
- If customers per hour arrive (on average), the average cost per
hour is:
L
$
10
customer $10 w Q
Q
= $10 w Q =
hour customer
hour
29
Markovian models:
P ( L(t ) = n) = Pn (t ) = Pn
Mathematical models in this chapter can be used to obtain approximate
results even when the model assumptions do not strictly hold, as a
rough guide.
Simulation can be used for more refined analysis, more faithful
representation for complex systems.
Chapter 7. Queueing Models
30
31
L=
nP
n =0
w=
wQ = w
LQ = wQ
=
<1
c
Chapter 7. Queueing Models
32
M/G/1 Queues
P0 = 1
2 (1 + 2 2 )
L=+
2(1 )
The particular
distribution is not
known!
2 (1 + 2 2 )
LQ =
2(1 )
(1 / 2 + 2 )
w= +
2(1 )
1
(1 / 2 + 2 )
wQ =
2(1 )
Chapter 7. Queueing Models
33
M/G/1 Queues
There are no simple expression for the steady-state probabilities P0,
P1,
L LQ = is the time-average number of customers being served.
Average length of queue, LQ, can be rewritten as:
2 2
+
LQ =
2(1 ) 2(1 )
If and are held constant, LQ depends on the variability, 2, of the
service times.
34
M/G/1 Queues
Example: Two workers competing for a job, Able claims to be faster than
Baker on average, but Baker claims to be more consistent,
= 20%.
(1 / 30) 2 [252 + 4]
LQ =
= 2.097 customers
2(1 5 / 6)
- The proportion of arrivals who find Baker idle and thus experience no delay is P0 = 1- =
1/6 = 16.7%.
35
M/M/1 Queues
Suppose the service times in an M/G/1 queue are exponentially
distributed with mean 1/, then the variance is 2 = 1/2.
M/M/1 queue is a useful approximate model when service times
have standard deviation approximately equal to their means.
The steady-state parameters
=
Pn = (1 ) n
L=
P0 = 1
2
2
=
LQ =
( ) 1
w=
wQ =
Chapter 7. Queueing Models
1
1
=
(1 )
=
( ) (1 )
36
M/M/1 Queues
Single-chair unisex hair-styling shop
Interarrival and service times are exponentially distributed
=2 customers/hour and =3 customers/hour
=
2
=
3
L=
1
3
P0 = 1 =
1
n =0
2
= 2 Customers
3 2
4
4
2
LQ =
=
= Customers
( ) 3(3 2) 3
4 2
L = LQ + = + = 2 Customers
3 3
1 2
4
P2 = =
3 3
27
P 4 = 1 Pn =
2
= 1 hour
2
1
1 2
wQ = w = 1 = hour
3 3
w=
1 2 2
P1 = =
3 3 9
16
81
37
M/M/1 Queues
Example: M/M/1 queue with
service rate =10 customers
per hour.
5,0
6,0
7,2
8,6
10,0
0,5
1,0
0,6
1,5
0,7
2,6
0,9
6,4
1,0
0,2
0,3
0,4
0,7
20
L
18 w
Number of Customers
16
14
12
10
8
6
4
2
0
0.5
0.6
0.7
0.8
0.9
rho
38
(cv) 2 =
V (X )
[E ( X )]2
The larger cv is, the more variable is the distribution relative to its
expected value
For exponential service times with rate
- E(X)=1/
- V(X)=1/2
cv=1
Chapter 7. Queueing Models
39
1
2
LQ for M/M/1
queue
Corrects the M/M/1
formula to account
for a non-exponential
service time distn
40
Multiserver Queue
M/M/c// queue: c servers operating in parallel
Arrival process is poisson with rate
Each server has an independent and identical exponential service-time
distribution, with mean 1/.
To achieve statistical equilibrium, the offered load (/) must satisfy /<c,
where /(c) = is the server utilization.
Calling population
1
Waiting line
c
Chapter 7. Queueing Models
41
Multiserver Queue
c 1 ( / ) n c 1 c
P0 =
+
n =0 n! c! c
(c ) c P0
P (L ( ) c ) =
c!(1 )
Probability
that all servers
are busy
(c ) c +1 P0
P (L ( ) c )
c
L = c +
=
+
1
c(c!)(1 ) 2
L
w=
P (L ( ) c )
LQ =
1
L LQ = c
Chapter 7. Queueing Models
42
Multiserver Queue
Probability of empty system
43
Multiserver Queue
Other common multiserver queueing models
2 1 + (cv) 2
LQ =
2
1
LQ for M/M/1
queue
M/G/c/: general service times and c parallel server. The parameters can
be approximated from those of the M/M/c// model.
M/G/: general service times and infinite number of servers.
M/M/c/N/: service times are exponentially distributed at rate and c
servers where the total system capacity is N c customer. When an arrival
occurs and the system is full, that arrival is turned away.
Chapter 7. Queueing Models
44
Multiserver Queue
M/G/: general service times and infinite number of servers
- customer is its own server
- service capacity far exceeds service demand
- when we want to know how many servers are required so that
customers are rarely delayed
Pn = e
P0 = e
w=
()
n!
, n = 0,1, K
wQ = 0
L=
LQ = 0
Chapter 7. Queueing Models
45
Multiserver Queue
How many users can be logged in simultaneously in a computer
system
L = = 500 3 = 1500
46
Multiserver Queue
M/M/c/N/: service times are exponentially distributed at rate and
c servers where the total system capacity is N c customer
when an arrival occurs and the system is full, that arrival is turned away
Effective arrival rate e is defined as the mean number of arrivals per
time unit who enter and remain in the system
1
P0
PN
LQ
a n a c N n c
= 1 + +
!
!
n
c
1
1
=
=
+
n
n
c
aN
=
P0
c!c N c
P0 a c
1 N c ( N c) N c (1 )
=
c!(1 )
= (1 PN )
wQ =
LQ
w = wQ +
L = e w
Chapter 7. Queueing Models
47
Multiserver Queue
Single-chair unisex hair-styling shop (again!)
Space only for 3 customers:
one in service and two waiting
First computer P0
P0 =
1
2 2 3 2 n 1
1 + +
3 3 n = 2 3
Queue time
wQ =
= 0.415
PN = P3 =
()
1!1
P0 =
w = wQ +
8
= 0.123
65
28
= 0.246
114
66
= 0.579
114
Expected number of
customers in shop
L = e w =
66
= 1.015
65
1 P0 = e = 0.585
8 114
e = 21 =
= 1.754
65 65
P(system is full)
2 3
3
2
LQ
48
When the calling population is small, the presence of one or more customers in
the system has a strong effect on the distribution of future arrivals.
The time between the end of one service visit and the next call for service is
exponentially distributed with mean = 1/.
Service times are also exponentially distributed with mean 1/.
c parallel servers and system capacity is K.
K Customers
1
Waiting line
c
Chapter 7. Queueing Models
49
!
K
( K n)!c!c n c , n = c, c + 1,...K
L = nPn ,
n =0
w = L / e ,
e
c
where e is the long run effective arrival rate of customers to queue (or entering/exiting service)
K
e = ( K n)Pn
n =0
50
)!
2
!
2
20
n =0
n=2
= 0.065
Then, we can obtain the other Pn, and can compute the
expected number of machines in system:
10
L=
nP
= 3.17 machines
n =0
51
Networks of Queues
Many systems are naturally modeled as networks of single queues
customers departing from one queue may be routed to another
52
Networks of Queues
The overall arrival rate into queue j:
j = aj +
p
i
ij
all i
Arrival rate
from outside
the network
If queue j has cj < parallel servers, each working at rate j, then the
long-run utilization of each server is j=j /(cj) (where j < 1 for stable
queue).
If arrivals from outside the network form a Poisson process with rate aj
for each queue j, and if there are cj identical servers delivering
exponentially distributed service times with mean 1/j, then, in steady
state, queue j behaves likes an M/M/cj queue with arrival rate
j = aj +
p
i
ij
all i
53
Network of Queues
Customer
Population
80 cust
hour
0.4
c=
c=1
0.6
54
Summary
55
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 5
Random-Number Generation
1, 0 x 1
f ( x) =
0, otherwise
2
x
E ( R) = xdx =
0
2
1
1
=
2
Figure: pdf for
random numbers
4
Fast
Portable to different computers
Have sufficiently long cycle
Replicable
Closely approximate the ideal statistical properties of uniformity and
independence.
The
modulus
The
increment
Ri =
Xi
, i = 1,2,...
m
7
R1 = 0.02;
R2 = 0.77;
R3 = 0.52;
R3 = 0.27;
[0,1]
Maximum Period
Random-Numbers in Java
Defined in java.util.Random
private final static long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL;
private final static long mask = (1L << 48) - 1;
protected int next(int bits) {
long oldseed, nextseed;
...
oldseed = seed.get();
nextseed = (oldseed * multiplier + addend) & mask;
...
return (int)(nextseed >>> (48 - bits));
}
10
11
k
j 1
X i = (1) X i , j mod m1 1
j =1
Xi
m ,
Hence, Ri = 1
m 1
1 ,
m1
Xi > 0
Xi = 0
The coefficient:
Performs the
subtraction Xi,1-1
12
Step 3:
Step 4:
Return
X j +1
2,147,483,
563
R j +1 =
2,147,483,562
2,147,483,563 ,
X j +1 > 0
X j +1 = 0
13
X, Y, Z {1,...,30000}
X = X 171 mod 30269
Y = Y 172 mod 30307
Z = Z 170 mod 30323
Y
Z
X
R =
+
+
mod 1.0
30269 30307 30323
It is stated that this method produces more than 10^13
numbers
14
Random-Numbers Streams
Refers to a starting seed taken from the sequence X0, X1, , XP.
If the streams are b values apart, then stream i could defined by starting seed:
A random-number stream:
i = 1,2, K , Pb
S i = X b ( i 1)
15
H0: Ri ~ U[0,1]
H1: Ri ~/ U[0,1]
- Failure to reject the null hypothesis, H0, means that evidence of nonuniformity has not been detected.
16
Types of tests:
Theoretical tests: evaluate the choices of m, a, and c without actually
generating any numbers
Empirical tests: applied to actual sequences of numbers produced.
- Our emphasis.
17
Frequency Tests
Test of uniformity
Two different methods:
Kolmogorov-Smirnov test
Chi-square test
18
Kolmogorov-Smirnov Test
Compares the continuous cdf, F(x), of the uniform distribution with
the empirical cdf, SN(x), of the N sample observations.
We know: F ( x) = x, 0 x 1
If the sample from the RN generator is R1, R2, , RN, then the empirical
cdf, SN(x) is:
S N ( x) =
Number of Ri where Ri x
N
19
Kolmogorov-Smirnov Test
The test consists of the following steps
Step 1: Rank the data from smallest to largest
R(1)R(2)... R(N)
Step 2: Compute
D + = max R( i )
1i N N
i 1
D = max R( i )
1i N
N
20
Kolmogorov-Smirnov Test
Example: Suppose N=5 numbers: 0.44, 0.81, 0.14, 0.05, 0.93.
i
Step 1:
Step 2:
R(i)
0.05
0.14
0.44
0.81
0.93
i/N
0.20
0.40
0.60
0.80
1.00
i/N R(i)
0.15
0.26
0.16
0.07
R(i) (i-1)/N
0.05
0.04
0.21
0.13
21
Chi-square test
Chi-square test uses the sample statistic:
n is the # of classes
n
02 =
i =1
(Oi Ei )
Ei
Ei is the expected
# in the i-th class
Oi is the observed
# in the i-th class
22
Chi-square test
Example
100 numbers from [0,1]
=0.05
10 intervals
X20.05,9=16.9
Accept, since
Interval
Upper Limit
0.1
10
0.2
Oi-Ei
(Oi-Ei)^2
(Oi-Ei)^2/Ei
10
10
-1
0.1
0.3
10
-5
25
2.5
0.4
10
-4
16
1.6
0.5
16
10
36
3.6
0.6
13
10
0.9
0.7
10
10
0.8
10
-3
0.9
0.9
10
10
10
1.0
14
10
16
1.6
100
100
11.2
Oi
Ei
X20=11.2
23
24
H 0 : im = 0,
H 1 : im 0,
25
im
Z0 =
im
1 M
im =
R
i + km
i +(k +1 )m 0.25
M + 1 k =0
im =
13M + 7
12(M + 1 )
High random numbers tend to be followed by high ones, and vice versa.
Low random numbers tend to be followed by high ones, and vice versa.
26
Example
Test whether the 3rd, 8th, 13th, and so on, for the numbers on Slide
24.
Hence, = 0.05, i = 3, m = 5, N = 30, and M = 4
35 =
= 0.1945
13( 4) + 7
= 0.128
35 =
12( 4 + 1 )
0.1945
= 1.516
Z0 =
0.1280
z0.025 = 1.96 hence, the hypothesis is not rejected.
27
Shortcomings
The test is not very sensitive for small values of M, particularly when
the numbers being tested are on the low side.
Problem when fishing for autocorrelation by performing numerous
tests:
If = 0.05, there is a probability of 0.05 of rejecting a true hypothesis.
If 10 independence sequences are examined,
- The probability of finding no significant autocorrelation, by chance
alone, is 0.9510 = 0.60.
- Hence, the probability of detecting significant autocorrelation when it
does not exist = 40%
28
Summary
In this chapter, we described:
Generation of random numbers
Testing for uniformity and independence
Caution:
Even with generators that have been used for years, some of which still
in used, are found to be inadequate.
This chapter provides only the basic
Also, even if generated numbers pass all the tests, some underlying
pattern might have gone undetected.
29
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 6
Random-Variate Generation
Preparation
It is assumed that a source of uniform [0,1] random numbers
exists.
Linear Congruential Method
1 0 x 1
f R ( x) =
0 otherwise
CDF
0 x < 0
FR ( x) = x 0 x 1
1 x > 1
Inverse-transform Technique
The concept:
For CDF function: r = F(x)
Generate r from uniform (0,1), a.k.a U(0,1)
Find x,
x = F-1(r)
F(x)
F(x)
1
r = F(x)
r = F(x)
r1
r1
x
x1
x1
Chapter 6. Random-Variate Generation
Inverse-transform Technique
Exponential Distribution
Exponential Distribution
f ( x ) = e
1 e X = R
e X = 1 R
X = ln(1 R)
ln(1 R)
X=
ln(1 R)
X =
CDF
F ( x ) = 1 e x
Simplification
X =
ln(R)
X = F 1 ( R)
Exponential Distribution
Exponential Distribution
Example: Generate 200 variates Xi with distribution exp(= 1)
Generate 200 Rs with U(0,1), the histogram of Xs become:
0,7
0,6
0,5
0,4
0,3
0,2
0,1
0
0,5
1,5
2,5
3,5
Empirical Histogram
4,5
5,5
6,5
Theor. PDF
P ( X 1 x0 ) = P ( R1 F ( x0 )) = F ( x 0 )
Other Distributions
Examples of other distributions for which inverse CDF works
are:
Uniform distribution
Weibull distribution
Triangular distribution
10
Uniform Distribution
Random variable X uniformly distributed over [a, b]
F(X ) = R
X a
=R
ba
X a = R(b a )
X = a + R (b a )
11
Weibull Distribution
The Weibull Distribution is
described by
The variate is
F(X ) = R
1 e
1 ( )
f ( x) = x e
( X
( X
=R
= 1 R
( X ) = ln(1 R)
CDF
F ( X ) = 1 e
(x )
= ln(1 R )
X = ln(1 R )
x = ln(1 R )
X = ln(1 R )
12
Triangular Distribution
The CDF of a Triangular
Distribution with endpoints (0, 2)
is given by
0
x2
2
F ( x) =
(2 x) 2
1
2
For 0 X 1
x0
X2
R=
2
and for 1 X 2
0 < x 1
1< x 2
(2 X ) 2
R = 1
2
x>2
X is generated by
2R
X =
2 2(1 R)
Chapter 6. Random-Variate Generation
0 R
1
2
1
2
< R 1
13
Set x(0)=0
Assign the probability 1/n to each interval x (i-1)
The slope of each line segment is defined as
x(i ) x(i 1)
x(i ) x(i 1)
=
ai =
1 / n (i 1) / n
1/ n
The inverse CDf is given by
x x (i)
(i 1)
X = F 1 ( R) = x(i 1) + ai R
14
Interval
Probability
Cumulative Probability
Slope ai
0.2
0.2
4.00
0.2
0.4
2.20
0.2
0.6
1.05
0.2
0.8
1.90
0.2
1.0
4.65
R1 = 0.71
X 1 = x( 41) + a4 ( R1 (4 1) / n)
= 1.45 + 1.90(0.71 0.6)
= 1.66
Chapter 6. Random-Variate Generation
15
ai =
ci cumulative probability of
the first i intervals
x(i ) x(i 1)
ci ci 1
i 1
16
)
Dr. Mesut Gne
Interval
(Hours)
Frequency
Relative
Frequency
0.25 x 0.5
31
0.31
0.31
0.81
0.5 x 1.0
10
0.10
0.41
5.0
1.0 x 1.5
25
0.25
0.66
2.0
1.5 x 2.0
34
0.34
1.00
1.47
Consider R1 = 0.83:
c3 = 0.66 < R1 < c4 = 1.00
X1 = x(4-1) + a4(R1 c(4-1))
= 1.5 + 1.47(0.83-0.66)
= 1.75
17
18
Discrete Distribution
All discrete distributions can be generated via inverse-transform
technique
Method: numerically, table-lookup procedure, algebraically, or a
formula
Examples of application:
Empirical
Discrete uniform
Gamma
19
Discrete Distribution
Example: Suppose the number of shipments, x, on the
loading dock of a company is either 0, 1, or 2
Data - Probability distribution:
x
p(x)
F(x)
0
1
2
0.50
0.30
0.20
0.50
0.80
1.00
F ( xi 1 ) = ri 1 < R ri = F ( xi )
Set X1 = xi
20
Discrete Distribution
Method - Given R, the
generation scheme
becomes:
R 0.5
0,
Consider R1 = 0.73:
F(xi-1) < R <= F(xi)
F(x0) < 0.73 <= F(x1)
Hence, x1 = 1
i Input ri Output xi
1
0.5
0.8
1.0
21
Acceptance-Rejection technique
Useful particularly when inverse cdf does not exist in closed form, a.k.a.
thinning
Illustration: To generate random variates, X ~ U(1/4, 1)
Generate R
Procedures:
no
Condition
yes
Output R
R does not have the desired distribution, but R conditioned (R) on the
event {R } does.
Efficiency: Depends heavily on the ability to minimize the number of
rejections.
Chapter 6. Random-Variate Generation
22
Poisson Distribution
PMF of a Poisson Distribution
P ( N = n) =
n!
Exactly n arrivals during one time unit
A1 + A2 + L + An 1 < A1 + A2 + L + An + An +1
Since interarrival times are exponentially distributed we can set
Ai =
ln( Ri )
23
Poisson Distribution
Substitute the sum by
n
Simplify by
ln( Ri )
i =1
n +1
1<
ln( Ri )
i =1
n +1
i =1
i =1
i =1
i =1
i =1
n +1
> Ri
i =1
24
Poisson Distribution
25
Poisson Distribution
exp(-0.2) = 0.8187
Variate 1
Variate 2
Variate 3
26
Poisson Distribution
It took five random numbers to generate three Poisson
variates
In long run, the generation of Poisson variates requires some
overhead!
N Rn+1
Accept/Reject
Result
Accept
N=0
Accept
N=0
Reject
Reject
Accept
27
N=2
Special Properties
Based on features of particular family of probability
distributions
For example:
Direct Transformation for normal and lognormal distributions
Convolution
Beta distribution (from gamma distribution)
28
Direct Transformation
Z1 = (2 ln R )1/ 2 cos(2R2 )
Z 2 = (2 ln R)1/ 2 sin(2R2 )
Chapter 6. Random-Variate Generation
29
Direct Transformation
Approach for N(,2):
Generate Zi ~ N(0,1)
Xi = + Zi
Yi = eXi
30
Summary
Principles of random-variate generation via
Inverse-transform technique
Acceptance-rejection technique
Special properties
31
Simulation
Discrete-Event System Simulation
Dr. Mesut Gne
Chapter 8
Input Modeling
Data Collection
One of the biggest tasks in solving a real problem
GIGO Garbage-In-Garbage-Out
Raw Data
System
Performance
simulation
Input
Data
Output
Data Collection
Histograms
Scatter Diagrams
Selecting families of distribution
Parameter estimation
Goodness-of-fit tests
Fitting a non-stationary process
Histograms
A frequency distribution or histogram is useful in determining
the shape of a distribution
The number of class intervals depends on:
The number of observations
The dispersion of the data
Suggested number of intervals: the square root of the sample size
Histograms
Same data
with different
interval sizes
There are ample data, so the histogram may have a cell for each possible
value in the data range
Histograms Example
Life tests were performed on electronic components at 1.5
times the nominal voltage, and their lifetime was recorded
23
3x<6
10
6x<9
9 x < 12
12 x < 15
42 x < 45
1
9
Histograms Example
Stanford University Mobile Activity Traces (SUMATRA)
Available traces
BALI Characteristics
10
Histograms Example
1800
1600
1400
People
1200
User group
1000
800
600
400
200
50
0 40
30
lls
Ca
0
5
20
10
nts
eme
Mov
15
10
20
0
25000
Number of People
20000
Interesting characteristic
15000
10000
5000
-1 0
9 10 11 12 13 14 15 16 17 18 19
Number of Movements
11
Scatter Diagrams
A scatter diagram is a quality tool that can show the
relationship between paired data
Random Variable X = Data 1
Random Variable Y = Data 2
Draw random variable X on the x-axis and Y on the y-axis
Strong Correlation
Chapter 8. Input Modeling
Moderate Correlation
12
No Correlation
Dr. Mesut Gne
Scatter Diagrams
Linear relationship
13
14
15
16
Quantile-Quantile Plots
Q-Q plot is a useful tool for evaluating distribution fit
If X is a random variable with CDF F, then the q-quantile of X is the
such that
F( ) = P(X ) = q,
n
where j is the ranking or order number
17
Quantile-Quantile Plots
18
Quantile-Quantile Plots
Example: Door installation times of a robot follows a normal
distribution.
The observations are ordered from the smallest to the largest:
j
1
2
3
4
5
Value
99.55
99.56
99.62
99.65
99.79
j
6
7
8
9
10
Value
99.98
100.02
100.06
100.17
100.23
j
11
12
13
14
15
Value
100.26
100.27
100.33
100.41
100.47
yj are plotted versus F-1( (j-0.5)/n) where F has a normal distribution with
the sample mean (99.99 sec) and sample variance (0.28322 sec2)
19
Quantile-Quantile Plots
100,8
100,6
100,4
100,2
Straight line,
supporting the
hypothesis of a
normal distribution
100
99,8
99,6
99,4
99,2
99,2
99,4
99,6
99,8
100
100,2
100,4
100,6
100,8
0,35
0,3
0,25
0,2
Superimposed
density function of
the normal
distribution
0,15
0,1
0,05
0
99,4
20
99,6
99,8
100
100,2
100,4
100,6
Quantile-Quantile Plots
Consider the following while evaluating the linearity of a Q-Q plot:
21
Parameter Estimation
Parameter Estimation: Next step after selecting a family of
distributions
If observations in a sample of size n are X1, X2, , Xn (discrete or
continuous), the sample mean and variance are:
i=1 X i
n
X=
2
2
X
n
X
i=1 i
n
S2 =
n 1
j =1 f j X j
X=
S2
2
2
f
X
n
X
j
j
j =1
n 1
22
Parameter Estimation
When raw data are unavailable (data are grouped into class
intervals), the approximate sample mean and variance are:
j =1 f j m j
c
X=
S2
2
2
f
m
n
X
j
j
j =1
n 1
23
Parameter Estimation
and
25
20
Frequency
364
X=
= 3.64
100
2080 100 (3.64) 2
2
S =
99
= 7.63
15
10
0
0
10
11
24
Parameter Estimation
Parameter Estimator
Poisson
Exponential
= X
=
1
X
Gamma
Normal
, 2
= X , 2 = S 2
Lognormal
, 2
= X , 2 = S 2
, =
1
X
After taking ln
of data.
Chapter 8. Input Modeling
25
Goodness-of-Fit Tests
Conduct hypothesis testing on input data distribution using
Kolmogorov-Smirnov test
Chi-square test
Statistical
Decision
H0 False
Reject H0
Type I Error
Correct
Accept H0
Correct
Type II Error
26
Chi-Square Test
Intuition: comparing the histogram of the data to the shape of
the candidate density or mass function
Valid for large sample sizes when parameters are estimated
by maximum-likelihood
Arrange the n observations into a set of k class intervals
The test statistic is:
02
i =1
(Oi Ei ) 2
Ei
Observed Frequency
in the i-th class
Expected Frequency
Ei = n*pi
where pi is the theoretical
prob. of the i-th interval.
Suggested Minimum = 5
degrees of freedom
s = number of parameters of the hypothesized distribution
estimated by the sample statistics.
Chapter 8. Input Modeling
27
Chi-Square Test
The hypothesis of a chi-square test is
H0: The random variable, X, conforms to the distributional
2
2
H0 is rejected if 0 > ,k s 1
pi = p(xi ) = P(X = xi )
Chapter 8. Input Modeling
28
Chi-Square Test
If the distribution tested is continuous:
pi =
ai
ai1
f ( x) dx = F (ai ) F (ai 1 )
where ai-1 and ai are the endpoints of the i-th class interval
f(x) is the assumed pdf, F(x) is the assumed cdf
Recommended number of class intervals (k):
Sample Size, n
20
50
5 to 10
100
10 to 20
n1/2 to n/5
> 100
29
Chi-Square Test
Vehicle Arrival Example (continued):
H0: the random variable is Poisson distributed.
H1: the random variable is not Poisson distributed.
xi
Observed Frequency, Oi
Expected Frequency, Ei
0
1
2
3
4
5
6
7
8
9
10
> 11
12
10
19
17
19
6
7
5
5
3
3
1
100
2.6
9.6
17.4
21.1
19.2
14.0
8.5
4.4
2.0
0.8
0.3
0.1
100.0
22
17
12.2
(Oi - Ei)2/Ei
7.87
0.15
0.8
4.41
2.57
0.26
7.6
11.62
27.68
Ei = np ( x)
e x
=n
x!
Combined because
of the assumption of
min Ei = 5, e.g.,
E1 = 2.6 < 5, hence
combine with E2
30
Kolmogorov-Smirnov Test
Intuition: formalize the idea behind examining a Q-Q plot
Recall
31
32
33
34
(t ) =
Cij
nt j =1
Number of Arrivals
Day 1
Day 2
Day 3
Estimated Arrival
Rate (arrivals/hr)
8:00 - 8:30
12
14
10
24
8:30 - 9:00
23
26
32
54
9:00 - 9:30
27
18
32
52
9:30 - 10:00
20
13
12
30
35
For instance,
1/3(0.5)*(23+26+32)
= 54 arrivals/hour
36
Interval (Sales)
0,1
0,10
0,65
0,75
0,24
0,99
0,01
1,00
1,20
1,00
0,80
0,60
Cumulative
Frequency, ci
0,40
0,20
0,00
1000 <= X <= 2000
37
38
( X 1 1 ) = ( X 2 2 ) +
is a random
variable with mean 0
and is independent
of X2
cov( X 1 , X 2 ) = E[( X 1 1 )( X 2 2 )] = E ( X 1 X 2 ) 1 2
Covariance between X1 and X2:
where
= 0
cov( X 1 , X 2 )< 0
> 0
= 0
< 0
> 0
39
= corr( X 1 , X 2 ) =
where
= 0
corr ( X 1 , X 2 )< 0
> 0
cov( X 1 , X 2 )
1 2
= 0
< 0
> 0
40
Notice
41
1 n
cov( X 1 , X 2 ) =
( X 1 j X 1 )( X 2 j X 2 )
n 1 j =1
The sample correlation is
=
Chapter 8. Input Modeling
cov( X 1 , X 2 )
1 2
42
Sample deviation
Dr. Mesut Gne
(X1)
6,5
103
4,3
83
X 2 = 101.8, 2 = 9.93
6,9
116
6,0
97
csample = 8.66
6,9
112
6,9
104
5,8
106
7,3
109
4,5
92
6,3
96
X 1 = 6.14, 1 = 1.02
Covariance
8.66
= 0.86
1.02 9.93
Before accepting this model, lead time and demand should be checked
individually to see whether they are represented well by normal
distribution.
43
h = corr( X t , X t + h ) = h ,
for h = 1,2,...
44
X t = + ( X t 1 ) + t ,
for t = 2,3,...
= X ,
= (1 2 ) ,
2
cov( X t , X t +1 )
=
2
45
with probability
X t 1 ,
Xt =
X t 1 + t , with probability 1-
for t = 2,3,...
To estimate , :
= 1 / X ,
cov( X t , X t +1 )
= =
2
46
Summary
47