MGS 3100
MGS 3100
Business Analysis
y
Chapter 9
Monté Carlo Simulation
Simulation
What Is Simulation?
• A model/process used to duplicate or mimic the real • A model/process used to duplicate or mimic the real
system
Types of Simulation Models
Types of Simulation Models
• Physical simulation • Computer simulationComputer simulation
When to Use (Computer) Simulation Models?
P bl / t t l t b l d
• Problems/systems are too complex to be analyzed mathematically
• There are random components in the system
2 Simulation
There are random components in the system
Simulation
Benefits of Simulation Model
• It is relatively straightforward and generally easier toIt is relatively straightforward and generally easier to understand
• It can model a wide range of problems and answer
“ h if” f i i h ll
“what-if” types of questions without actually changing or building a real system
• It is generally cheaper quicker and safer toIt is generally cheaper, quicker, and safer to experiment with than a real system
Limitations
• It can be expensive and time consuming to develop • There is no guarantee that it will give optimal or
3 Simulation
exact solution to the problem
Monte Carlo Simulation
Key element is randomness
• Assume that some inputs are random variables
M d li d b ti d
• Modeling randomness by generating random variables from their probability distributions
• Since some inputs to the model are random, outputs p p from the model are random too.
Simulation Modeling Process
• Develop the basic model that “behaves like” the real problem, with a special consideration of the random or probabilistic input variables
or probabilistic input variables
• Conduct a series of computer runs (called trials) to learn the behavior of the simulation model
4
• Compute the summary (output) statistics and make inferences about the real problem
Monte Carlo Simulation
Simulation process is similar to statistical
inference process
inference process
• Statistics: start with a population, sampling from the population, and then based on sample information to infer population
• Simulation: start with a basic model to represent real problem replicating the basic model and then based problem, replicating the basic model, and then based on the replication results to help solve real problem • The larger the number of trials (sample size), the more
reliable will be the simulation result!
5 Simulation
Example
Basic Model:
Profit =
f
(demand)
I t R l ti hi O t t
Input:
Demand
Relationship:
functionf
Output:
Profit
How simulation works:
Step 1: basic model development: generate one possible random Demand and find the corresponding Profit Step 2: basic model replication: generate many possible
l f D d d fi d di P fit values of Demand and find corresponding Profits Step 3: result summarization: calculate summarized
statistics on the Profit such as average min max etc
6 Simulation
statistics on the Profit such as average, min, max etc.
How Simulation Works
What Do We Need Know for Simulation?
• What variable is to be simulatedWhat variable is to be simulated
• Is the variable discrete or continuous?
• The distribution of the variable – values it can take on d th b biliti f th l i
and the probabilities of those values occurring.
How to Generate Variables?
• Step 1: Generate random numbers
• Step 1: Generate random numbers.
• Step 2: Create a rule to map the random numbers to
values of the variable desired in the right proportion, and apply the rule
and apply the rule.
Random Numbers
Uniformly distributed between 0 and 1
• Each number in [0,1] is equally likely
The “building blocks” of all simulation models
• Other random variables can be generated from random b
numbers
In Excel, “=RAND()” generates random numbers
Wh th f l i i d t th ll diff t • When the formula is copied to other cells, different
random numbers are generated
• Press F9 (recalculate) key or do any change in thePress F9 (recalculate) key or do any change in the spreadsheet, all random numbers will change
• You can “freeze” the random numbers by using Copy d P t S i l | V l d
Types of Variables in Simulation
yp
Discrete
Discrete
• Take only limited specific values or specific points. Example: number of defects answer to T/F questions
• Example: number of defects, answer to T/F questions.
Continuous
• Can take any value (between specific points)
• Example: time between machine breakdown, filling volume in a coke’s bottling assembly line
9 Simulation
Generating Random Variables
General Two-Step Approach
• first, generate random numbers (u)
• second, transform random numbers via CDF to random variables (x) with desired probability distribution
F(x)
u
Inverse transformation method
10 Simulation
x=F-1(u)
method
Example
p
: generate discrete r.v.
g
Suppose monthly demand follows the
f ll
i
di t ib ti
following distribution
Demand (x)
p(x)
5
0.10
20
0.40
30
0.30
50
0.20
We want to generate 12 random demands
(may be for next 12 months). How?
11 Simulation
(
y
)
Example
: generate discrete r.v.
Demand (x) p(x) F(x)
5 0.1 0.1
20 0 4 0 5
First find CDF:
20 0.4 0.5 30 0.3 0.8
50 0.2 1
¾ The CDF (F(x)) essentially establishes a rule that maps a demand to a random number range
Demand 5 20 30 50
0 0 1 0 0 8 1
R d # 0 0.1 0.5 0.8 1
Rand #
What is the probability that a random number will be i [0 0 1] [0 1 0 5] [0 5 0 8] [0 8 1]?
12 Simulation
Example
: generate discrete r.v.
That is, we have the following rule:
p
g
If the random number Then the corresponding
falls in demand is
0 – 0.1 5
0.1 – 0.5 20
0 5 0 8 30
0.5 – 0.8 30
0.8 – 1.0 50
S if
t
d
b
0 1537 th
So if we get a random number, say 0.1537, then
we know we find a demand of 20
13 Simulation
N if d t i l t 12 ti h t
Example
: generate discrete r.v.
Now if we need to simulate 12 times, what we
need to do is to generate 12 random numbers and then follow the rule to get 12 demand levels
Replication Random number Demand
1 0.76269 30
then follow the rule to get 12 demand levels
2 0.93813 50
3 0.57897 30
4 0.25200 20
5 0.14009 20
6 0.98889 50
7 0.07436 5
8 0.47831 20
9 0.66928 30
10 0.19625 20
14 Simulation
11 0.55519 30
12 0.45593 20
Manual Simulation: 1. Coin Toss
Tossing two coins at one time. If both are heads up, then
you win $4, if only one head up, then you win $1, if both
Random Random # of Cumulative
you win $4, if only one head up, then you win $1, if both
are tails, then you lose $6. Simulate this game 5 times
. GameRandom # 1
Random # 2
# of
Heads Win
Cumulative Win
1
0 5473 0 6513
1
2
3
0.5473
0.9244
0 0736
0.6513
0.2163
0 1758
3
4
5
0.0736
0.3852
0 5584
0.1758
0.8958
0 1721
5
0.5584 0.1721
2. Machine Failures
Simulate machine failures for the next 5 months based
on the historical data given in the table on the left.
on the historical data given in the table on the left.
Number
of Failures
Frequency
(# f
th
Number of
of Failures
per month
(# of months
this occurred)
0
36
Random #
Failures
0.3451
0
1
2
36
20
3
0.3451
0.0085
0 9853
2
3
3
1
T
l
60
0.9853
0.8788
0 5694
3. Coke Weight
Cans from a Coke production line follow the
following distribution regarding their weights.
f
g
g
g
g
Simulate the process on the next page and find what
percentage of cans are at or above 12 oz.
Weight Percentage
Cumulative
Percentage
g
g
g
11.8 oz. or less
11.9 oz.
10%
20%
10%
30%
12.0 oz.
12.1 oz.
12 2
40%
20%
10%
70%
90%
100%
Simulation 17
12.2 oz. or more
10%
100%
3. Coke Weight
Can #
Random
#
Weight
≥
12 oz.?
Can #
#
Weight
≥
12 oz.?
1 2
0.7457 0.0929 3
4 5
0.7477 0.0497 0 9258 5
6 7
0.9258 0.3816 0.5874 8
9 10
0.8700 0.9336 0 6682
Simulation 18
10 0.6682
Generating Random Variables
I E
l
In Excel
Generating Discrete r.v. with Excel
g
• Use VLOOKUP function
Generating Continuous r v with Excel
Generating Continuous r.v. with Excel
• Uniform between aand b: “= a+(b-a)*RAND()”
• Normal with meanμand standard deviationσ • Normal with mean μand standard deviation σ
“= NORMINV(RAND(), μ, σ)”
• Exponential with meanμ:“= μ*LN(RAND())”
• Exponential with mean μ: = -μ LN(RAND())
Using Excel’s Features in
Tools|Data Analysis|
R
d
N
b
G
ti
19 Simulation
Random Number Generation
Generating Discrete r v in Excel
First find cumulative distribution of the r v
Generating Discrete r.v. in Excel
First, find cumulative distribution of the r.v.
Second, generate random numbers by
“=
RAND()
”
Fi
ll
VLOOKUP f
ti
Finally, use VLOOKUP function
(Note: the 2ndand 3rdsteps can be combined as one step)
20 Simulation
A B C D E F G
An Example
C G
1Generating discrete random variables with VLOOKUP function
2
3Random number range Demand
4 0 0.1 5 5 0.1 0.5 20 6 0.5 0.8 30 7 0.8 1 50 8
9Random number Outcome
10 0.474424547 20 11 0 713128343 30
The range A4:C7 has been range-named TABLE
11 0.713128343 30 12 0.844783096 50 13 0.826109451 50 14 0.432246824 20 15 0.307382727 20 16 0 01709212 5
named TABLE
16 0.01709212 5 17
18
A B C D E F G 9Random number Outcome
10 =RAND() =VLOOKUP(A10,TABLE,3) 11 =RAND() =VLOOKUP(A11,TABLE,3) 12 =RAND() =VLOOKUP(A12,TABLE,3) 13 =RAND() =VLOOKUP(A13,TABLE,3) 14 =RAND() =VLOOKUP(A14,TABLE,3)
The second column in the TABLE range (A4:C7) is not necessary. Without it (only two columns in the TABLE range), the VLOOKUP function will be VLOOKUP(A10,TABLE,2)
21 Simulation
15 =RAND() =VLOOKUP(A15,TABLE,3) 16 =RAND() =VLOOKUP(A16,TABLE,3) 17
18 *** TABLE in VLOOKUP is the range name for cell range A4:C7
will be VLOOKUP(A10,TABLE,2)
Simulation with Spreadsheet
Simulation with Spreadsheet
Coin Toss
Newsboy Problem Walton’s Bookstore
Newsboy Problem - Walton’s Bookstore
Capital Budgeting (textbook pp 167 174)
Capital Budgeting (textbook pp. 167 - 174)
Queuing (Waiting Line) Model
Queuing (Waiting Line) Model
22 Simulation
Appendix
R
d
V i bl & P b bilit
Random Variable & Probability
Distribution — A Quick Review
Random Variable (r.v.)
• A variable that has many possible values, but exactly which one it will take is unknown • Discrete r.v. vs. Continuous r.v.
Probability Distribution
• Mathematical mechanism used to characterize the b bili ti tt /b h i f d i bl probabilistic pattern/behavior of a random variable • Two types of probability distribution: probability
density functiony (pdf) (p )and cumulative distribution function (CDF)
Probability Distributions
y
probability density function for discrete r.v.
• A list of all possible values of a discrete r.v., X, andA list of all possible values of a discrete r.v., X, and their associated probabilities, p(x) ≡P(X = x), where x is a particular value the r.v. X may take.
• Example: X = # of cars sold per day in a car shop x p(x)
0 3 p(x)
0 0.10
1 0.20
2 0.30 0.2
0.3
3 0.20
4 0.10
5 0 10
0.1
5 0.10
Probability Distributions
y
probability density function for continuous r.v.
• For continuous r.v., a pdf itself is not a probability.For continuous r.v., a pdf itself is not a probability. Rather, any area under the curve pdf curve is the probability
E l X Th fl id f 12
• Example: X = The exact fluid content of a 12-ounce coke randomly selected from the production line
f( ) f(x)
P(a ≤X ≤b) f(x)
25 Simulation
a b x
Probability Distributions
Cumulative Distribution Function
(CDF)
• CDF (or F(x)) is the cumulative form of the pdf • CDF (or F(x)) is the cumulative form of the pdf
For any r.v. X, F(x) = P(X ≤x) Example:X = # of cars sold per day
Example: X = # of cars sold per day
x p(x) F(x)=P(X ≤x)
0 0 10 0 10
0 0.10 0.10
1 0.20 0.30
2 0.30 0.60
3 0 20 0 80
CDF
3 0.20 0.80
4 0.10 0.90
5 0.10 1.00
26 Simulation
1.00
Useful Discrete Distributions
The Binomial Distribution
• Used to model the number of “successes” in a series of independent experiments, each of which has only two possible outcomes: “success” and “failure” • Examples: the number of workers absent in a • Examples: the number of workers absent in a
department of 10 employees on any day; the
number of American-made cars in a parking lot of 30 spaces; the number of defective items in a sample of 10
• pmf: p p x n
n x X
P( ) ⎟⎟ x(1− )n x, =0,1,2,...,
⎠ ⎞ ⎜⎜ ⎝ ⎛ =
= −
• pmf:
where n= number of trials, p= prob. of success
p p
x ( ) , , , , ,
)
( ⎟
⎠ ⎜ ⎝
27 Simulation
,p p
X = number of successes in ntrials
Useful Discrete Distributions
The Poisson Distribution
• Used to model the number of events that occur in certain amount of time or space
• Examples: the number of people arriving at a bank during lunch hour; the number of misspelled words during lunch hour; the number of misspelled words on a page of your textbook
• pmf:
2 1 0 )
(
−
e X
P
x
λ λ
p
where λ= average number of occurrences,
... , 2 , 1 , 0 , ! )
( = = x= x
x X P
e = 2.71828
X = number of occurrences
28 Simulation
Useful Continuous Distributions
Uniform Distribution between 0 and 1
• Any value in the range [0, 1] is equally likely • pdf: f(x) = 1, if 0 ≤x ≤1
= 0, if x < 0 or x > 1 • CDF: F(x) = x if 0≤x≤1 • CDF: F(x) = x, if 0 ≤x ≤1
= 0, if x < 0 or x > 1
Uniform pdf
f(x)
1
Uniform CDF
F(x)
1 1
29 Simulation
x
0 1 x
1 0
Useful Continuous Distributions
Normal Distribution
• The most important probability distribution in St ti ti d th li ti
Statistics and other applications
• Symmetric around the mean and bell shaped • pdf: = − − −∞< <∞
x e
x
f( ) 1 (xμ)2/2σ2
pdf:
• If X ∼N(μ, σ2), then Z=(X -μ)/σ ∼N(0, 1)
∞ < < ∞ −
= e x
x
f ,
2 ) (
2 πσ
f(x)
CDF CDF
30 Simulation μ
x
Useful Continuous Distributions
Triangular Distribution
• The pdf has a triangular shape • The pdf has a triangular shape
• Used when we only know the minimum, maximum and most likely values of a r.v., but no other information
f(x) f(x)
a - minimum
b - most likely i
x
b
c - maximum
c
a b
Useful Continuous Distributions
Exponential Distribution
• Useful for modeling the time between two successiveUseful for modeling the time between two successive random events
• Examples in queuing systems: inter-arrival times of i i
customers, service times
f(x)
μ
μ
x
e x
f
−
= 1
)
( , μ: mean f(x)