cs433 modeling and simulation lecture 11 monté carlo simulation dr. anis koubâa 05 jan 2009...
TRANSCRIPT
CS433Modeling and Simulation
Lecture 11
Monté Carlo Simulation
Dr. Anis Koubâa
http://10.2.230.10:4040/akoubaa/cs433/
05 Jan 2009
Al-Imam Mohammad Ibn Saud UniversityAl-Imam Mohammad Ibn Saud University
Reading
Required
Lemmis Park, Discrete Event Simulation -
A First Course,
Chapter 8: Section8.2, Monte Carlo
Estimation
Goals of Today
Understand the concept of Monté Carlo
Simulation
Learn how to use Monté Carlo Simulation
to make good decisions
Learn how to use Monté Carlo Simulation
for estimating complex integrals
What is Monte Carlo Simulation ?
Monte Carlo methods are a widely used class of computational algorithms for simulating the behavior of various physical and mathematical systems, and for other computations.
Monte Carlo algorithm is often a numerical Monte Carlo method used to find solutions to mathematical problems (which may have many variables) that cannot easily be solved, (e.g. integral calculus, or other numerical methods)
What is Monte Carlo Simulation ?
A Monte Carlo simulation is a statistical simulation technique that provides approximate solutions to problems expressed mathematically. It utilizes a sequence of random numbers to perform the simulation.
This technique can be used in different domains: complex integral computations, economics, making decisions in specific complex problems, …
General Algorithm of Monte Carlo Simulation
In general, Monte Carlo Simulation is roughly composed of five steps:1. Set up probability distributions: what is the
probability distribution that will be considered in the simulation
2. Build cumulative probability distributions3. Establish an interval of random numbers for
each variable4. Generate random numbers: only accept
numbers that satisfies a given condition. 5. Simulate trials
Examples
Example 1 and Example 2: using Monte Carlo simulation for the analysis of real systems
Example 3: using Monte Carlo simulation to evaluate an integral.
Example 1. HERFY Cake Shop
Example 1. HERFY Cake Shop
The cake seller HERFY shop sells a random number of
cakes each day. HERFY manager wants to determine
a policy for managing his inventory of cakes (e.g.
how many cakes should he prepare in 10 days).
We can use Monte Carlo simulation to analyze HERFY
inventory…
Demand Frequency Probability for cakes 0 10 0.05 1 20 0.1 2 40 0.2 3 60 0.3 4 40 0.2 5 30 0.15 200 1.00
=10/200
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
Example 1. HERFY Cake Shop
Step 1: Set up the probability distribution for cake sales.
Using historical data HERFY Shop determined that 5% of the time 0 cakes were demanded, 10% of the time 1 cake was demanded, etc…
P(1) = 10%
Example 1. HERFY Cake Shop
Step 2: Build a Cumulative Probability Distribution
15% of the time the demand was 0 or 1 cake P(0) = 5% + P(1) = 10%
Example 1. HERFY Cake Shop
Dem
and
Freq
uen
cy
Pro
bab
ility
Cu
mula
tive
Pro
bab
ilit
y Ran
dom
N
um
ber
Inte
rval
0 10 0.05 0.05 01 - 05
1 20 0.10 0.15 06 - 15
2 40 0.20 0.35 16 - 35
3 60 0.30 0.65 36 - 65
4 40 0.20 0.85 66 - 85
5 30 0.15 1.00 86 - 00
Step 3: Establish an interval of random numbers.
Mus
t be
in c
orre
ct p
ropo
rtio
n
Note: 5% of the time 0 cakes are demanded, so the random number interval contains 5% of the numbers between 1 and 100
Example 1. HERFY Cake Shop
Step 4: Generate random numbers.
5237826998963350889050274581667430
0663570294526933323048881402830534
5028683690622750183661214601148287
8802284936872195502418623278748201
5374057106491113626985691382279374
3035949978566044578223644974760911
1024033223599534345108486697039646
4703111067238962567454316237333382
9929277589786864623017127445115259
3760792185714839313512734131977894
6674909529721755153680028694591325
9185879021908929408569689899810634
3590929425573430900124009242722832
3273413873010964345584169849003023
0059099769989349519292168427649417
8455257134575044956416465464612301
5717367285314430260949133389133758
0760774976955116148559854042523973
Example 1. HERFY Cake Shop
Step 5: Simulate a series of trials.
Using random number table on previous slide, simulated demand for 10 days is:
Random number: 52 06 50 88 53 30 10 47 99 37Simulated demand: 3 1 3 5 3 2 1 3 5 3
Tires Interval ofDemanded Random Numbers
0 01 - 051 06 - 152 16 - 353 36 - 654 66 - 855 86 - 100
1
2
3
Example 1. HERFY Cake Shop
Create lookup table using cumulative probability
Generate a random number and look it up in the table
Example 1. HERFY Cake Shop
Example 2. SEC Power Company
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
Example 2. SEC Power Company
SEC provides power to Riyadh city. The company is concerned about generator failures
because a breakdown costs about 75 SAR per hour versus a 30 SAR per hour salary for repairpersons who work 24 hours a day, seven days a week.
Management wants to evaluate the service maintenance cost, simulated breakdown cost, and total cost.
We can use Monte Carlo simulation to analyze SEC system costs.
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
Example 2. SEC Power Company
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
½ 5 0.05 0.05 01 - 051 6 0.06 0.11 06 - 11
1 ½ 16 0.16 0.27 12 - 272 33 0.33 0.60 28 - 60
2 ½ 21 0.21 0.81 81 - 813 19 0.19 1.00 82 - 00
Tim
e B
etw
een
Bre
akd
ow
ns
(Hr s
)
Num
ber
of
Tim
es
Obse
rved
Pro
babili
ty Cum
ula
tive
Pro
babili
ty
Random
N
um
ber
Inte
rval
Steps 1-3: Determine probability, cumulative probability, and random number interval - BREAKDOWNS.
Total 100 1.00
Example 2. SEC Power Company
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
1 28 0.28 0.28 01 - 28
2 52 0.52 0.80 29 - 80
3 20 0.20 1.00 81 - 00
Repair
Tim
e
Requir
ed
(Hours
)
Num
ber
of
Tim
es
Obse
rved
Pro
babili
ty
Cum
ula
tiv
e
Pro
babili
ty
Random
N
um
ber
Inte
rval
Steps 1-3: Determine probability, cumulative probability, and random number interval - REPAIRS.
Example 2. SEC Power Company
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
1 57 2 2:00 2:00 7 1 3:00 1
2 17 1.5 3:30 3:30 60 2 5:30 2
3 36 2 5:30 5:30 77 2 7:30 2
4 72 2.5 8:00 8:00 49 210:0
0 2
5 85 3 11:0011:0
0 76 213:0
0 2
: : : : : : : : :
14 89 3 4:00 6:00 42 2 8:00 4
15 13 1.5 5:30 8:00 52 210:0
0 4.5
Sim
ula
tion
Tri
al
Random
N
um
ber
Tim
e R
epair
Can B
egin
Random
N
um
ber
Tim
e R
epair
Ends
Repair
Tim
e
No. of
hrs
.M
ach
ine is
dow
n
Tim
e b
/tB
reakd
ow
ns
Tim
e o
fB
reakd
ow
n
Example 2. SEC Power Company
Example inspired from: To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna
© 2006 by Prentice Hall, Inc.
Upper Saddle River, NJ 07458
Cost Analysis
Service maintenance =
34 hrs of worker service X 30 SAR per hr =
1,020 SAR
Simulate machine breakdown costs =
44 total hrs of breakdown X $75 lost per hr of
downtime = 3,300 SAR
Total simulated maintenance cost of the
current system = service cost + breakdown
costs = $1,020 + $3,300
= $4,320
Example 3. Computation of Integrals
Example 3. Computation of Integrals The Monte Carlo method can be used to
numerically approximate the value of an
integral
Pick n randomly distributed points x1, x2, …, xn in the
interval [a,b]
Determine the average value of the function
Compute the approximation to the integral
An estimate for the error is
Where
1
1 n
ii
f f xn
b
a
f x dx b a f
b
a
f x dx
22b aError f f
n
2 2
1
1 n
ii
f f xn
Algorithm . Estimation of = 3.1416
% Matlab Program to Find Pi using Random Numbers % Tom Huber, June 15, 1996 Nrand = input('How Many Random Numbers '); NInside = 0; for nloops=1:Nrand Xrand = rand; % Generate Random XY Point Yrand = rand; Rrand = Xrand^2 + Yrand^2; % Find its distance from origin if (Rrand <= 1) NInside = NInside + 1; end end disp(['Total Generated: ' num2str(Nrand) ' Inside Pts: ' num2str(NInside)]); piapprox = 4*NInside/Nrand; disp([' Approximation to pi = ' num2str(piapprox)]);