Professional Documents
Culture Documents
What is Simulation?
2
System
Entities
‒ Individuals, companies, machines, vehicles
Boundaries
‒ Physical, temporal or other
3
Model
Purpose
‒Evaluate impact of
• Changes in input values
• Manipulations of the system
‒Decision support, control
5
Modeling a System
Imitate
Input Input
Imitate
System Model
Evaluate
Output Output
6
Role of Simulation
Simple models
‒ Analytic solution
7
System Modeling Approaches
System
Physical Mathematical
model model
Analytical Simulation
8
Characteristics of simulation models
Role of time
Representation of system
Deterministic or stochastic
9
Role of time
Static
‒ Time plays no role or one point in time
‒ Steady state or equilibrium conditions
Dynamic
‒ System state changes over time
10
Representation of time
Continuous
‒ Variables change states continuously with time
‒ e.g., movement (speed) of a vehicle
‒ Must be discretized in computer implementation
Discrete event
‒ Variables change states instantaneously at discrete points
in time
‒ e.g., model of the length of a supermarket queue,
operations of a traffic light
11
Deterministic or stochastic
Deterministic
‒All inputs and processes deterministic
Implications
‒Output is random variable
‒Each run produces different results
• Interpretation of the results requires multiple replications
12
Traffic Simulation
https://www.traffic-simulation.de/
13
Random Number
14
True Random Number (TRN)
15
Pseudo Random Number (PRN)
Pseudo-random numbers
‒ Random” numbers produced on a computer or calculator are
not random at all
‒ Generated using a formula, so that the sequence produced is
actually predetermined
‒ Generated based on some initial value known as “SEED”
number
16
Properties of Random Number
1 , 0 x 1
f(x) = 0 , otherwise
1
E ( R ) xdx [ x 2 / 2]10 1 / 2
0
1
V ( R ) x 2 dx [ E ( R )]2
0
[ x 3 / 3] (1 / 2) 2 1 / 3 1 / 4
1
0
1 / 12 18
Generation of Pseudo Random Numbers
19
Techniques for generating PRN
The random integers are being generated [0,m-1], and to convert the
integers to random numbers:
21
Example 1
22
Example 2
Note that the period is exactly equal to 24, i.e. 2m, where m is the
base 2 log of the modulus
23
Example 3
Consider a = 5, c = 0, m = 37, and X0 = 1
1,5,25,14,33,17,11,18,16,6,30,2,10,13,28,29,34,22,36,32,12,23,4,
20,26,19,21,31,7,35,27,24,9,8,3,15, 1, 5, 25, ...
m a c
Borland C++ 232 22695477 1
Visual C++ 232 214013 2531011
Visual basic 224 1140671485 12820163
Java 248 25214903917 11
Random variables
PX x p X x P a X b f X x dx
a
FX x p X x p X x 1 FX x
p a X b FX b FX a
27
Mean and variance
The mean
E X xi p ( xi ) or xf ( x)dx
i -
The variance
‒ Measure of the dispersion of a RV about its mean
Var ( X ) E X E X E X 2 2
2 2
28
Example
Vehicles 1 2 3 4
1 1 1 1
xi p ( xi ) 1 2 + 3 4 2 12
i 6 3 3 6
1 2 1 2 1 2 1 2 3
E X = 1 2 + 3 4 2 2
2
2
2 1 2
6 3 3 6 4
29
Probability mass function
p(x)
0.35
0.30
0.25
0.20
0.15
0.10
0.05
x
0.00
1 2 3 4
30
Cumulative distribution function
F(x)
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0 x
0 1 2 3 4 5
31
Discrete Distribution: Poisson
Discrete RV
k e
pK (k )
k!
E(K )
Var ( K )
E( X ) 1/
Var ( X ) 1 / 2
f(x)
f F(x)
λ(
1
x
)
PDF CDF
0
34
x 0 x
Continuous Distribution: Normal
f ( x) 2
x
2
e
2
f (x )
0.35
0.30
0.25
0.20
0.15 Area =
0.10
0.68
0.05
0.00 x
-3.0
-2.0 -1.0
0.0 1.0 2.0 3.0
35
Drawing random variables
Two-step process
‒Random numbers generator
‒Random variables from a distribution
36
How does one transform a sample of the uniform[0,1] random
variable into a sample of a given distribution ?
Methods
‒Inverse transformation
‒Relationships
‒Acceptance -rejection
37
Inverse Transformation Method: Discrete variables
39
Discrete Distribution: Example
Algorithm
40
Inverse Transformation Method: Continuous variables
Algorithm
‒Get the CDF of random variable, F(X)
‒If only PDF is given, get CDF
‒Generate a uniform random number, U
‒Set F(X)=U
‒Solve for X in terms of U, X = 𝐹 −1 (𝑈)
Continuous Distribution: Example (Exponential)
1
Therefore, 𝑥 = − λ ln(𝑈)
Continuous Distribution: Example (Exponential)
1
Therefore, 𝑥 = − λ ln(𝑈)
Empirical Continuous Distribution
45