0% found this document useful (0 votes)
38 views37 pages

Simulation Modeling: Dr. G. Suresh Kumar

1) Simulation modeling allows testing of systems that do not yet exist or whose behavior cannot be explained analytically by indirectly simulating the behavior. 2) Monte Carlo simulation is a method that uses random numbers to generate sample paths and estimates the mean and distribution of the system being modeled. 3) Advantages of Monte Carlo simulation include the ease of modeling complex systems and the ability to estimate system performance over a wide range of conditions. Disadvantages include the expense of developing and running the simulations.

Uploaded by

Shakeb Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views37 pages

Simulation Modeling: Dr. G. Suresh Kumar

1) Simulation modeling allows testing of systems that do not yet exist or whose behavior cannot be explained analytically by indirectly simulating the behavior. 2) Monte Carlo simulation is a method that uses random numbers to generate sample paths and estimates the mean and distribution of the system being modeled. 3) Advantages of Monte Carlo simulation include the ease of modeling complex systems and the ability to estimate system performance over a wide range of conditions. Disadvantages include the expense of developing and running the simulations.

Uploaded by

Shakeb Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Simulation Modeling

Dr. G. Suresh Kumar


Simulating Deterministic Behavior
Introduction
In many cases one of the following situations might occur:
The system that we need to test does not exist yet. For example, it
would be too expensive to create a system that we need to study.
In cases where the behaviour cannot be explained analytically or
data collected directly.
The modeller might simulate the behaviour indirectly in some
manner and then test the various alternatives to estimate how
each affects the behaviour.
A chance plays a part in the data.
Then the data can be collected. This is called simulation
Introduction
In all the cases, a model might be simulated and then test how a change
In data would impact the behaviour of the system. Such a model is refer
to as probabilistic or stochastic.

 There are lots of types of simulation, but we will focus on Monte Carlo
Simulation. This method uses a large number of random numbers
to generate a model.

Using this method even a complex systems can be easily be described.


However, sometimes it may require a lot of time and computer memory
to be performed.
Advantage and Disadvantage of Monte Carlo Simulation
Some advantages of Monte Carlo Simulation:
1. relative ease with which it can sometimes be used to approximate very complex
probabilistic systems
2. provides performance estimation over a wide range conditions rather than a very
restricted range as often required by an analytic model
3. particular sub model can be changed easily (which has the potential of conducting a
sensitivity analysis)
4. modeller has control over the level of detail in a simulation
Some disadvantages of Monte Carlo Simulation:
1. typically expensive to develop and operate : often requires many hours to construct;
large amounts of computer time and memory to run.
2. probabilistic nature of simulation model limits the conclusions that can be drawn
from
a particular run unless a sensitivity analysis is conducted.
Examples:
The phrase “A sequence of random numbers uniformly distributed in an interval m to n”
means a set of numbers with no apparent pattern, where each number between m and n
can appear with equal likelihood.
Example. If you toss a six-sided die 100 times and wrote down the numbers showing on
the die each time, you would end up with a sequence of 100 random integers uniformly
distributed between 1 and 6.
Probabilistic processes are processes with an element of chance involved. The opposite
of probabilistic is deterministic. Monte Carlo simulation is a probabilistic model.

Examples:
The area under a curve is deterministic (even if we can’t find it precisely).
The time between arrivals of customers at an elevator on a particular day is probabilistic.
Observed behaviour can be deterministic or probabilistic. A model can be deterministic or
probabilistic.
Area Under a Curve
Area Under a Curve
Problem: Find an approximate value to the area under a nonnegative curve.
Solution:
Suppose y = f(x) is some given continuous function
satisfying 0 ≤f(x) ≤M over the closed interval a ≤x ≤ b.
Here M is an upper bound for f(x).

We select a point P(x, y) at random from within the


rectangular region. We do this by
generating two random numbers, x and y, satisfying
a≤x ≤b and 0 ≤y ≤M.

Once P(x, y) is selected, we test whether it lies within the


region below the curve. Does y satisfy 0 ≤f(x) ≤M?

Then count P by adding 1 to some counter. We count the total number of points generated
and we count the number of points that lie below the curve.
Then we can calculate an approximate value for the area under the curve.
Formula:
area under the curve /area of the rectangle ≈ number of points counted below curve /total
number of random points
Conti..

Figure : The area under the nonnegative curve y = f(x) over a ≤x ≤ b is contained within the
rectangle of height M and base length b - a.

Monte Carlo technique is probabilistic and typically requires a large number of trials before
the deviation between the predicted and true values becomes small.

Note: the number of trials needed to ensure a predetermined level of confidence requires more
knowledge of statistics.

The general rule is that in order to double accuracy of the result, four times as many experiments
are necessary.
Monte Carlo Area Algorithm
Input: Total number of n of random points to be generated in the
simulation.
Output: Approximate area under the specified curve y = f(x) over
the given interval a ≤x ≤b where 0 ≤f(x) ≤M.
Step 1: Initialize COUNTER=0
Step 2: for i = 1 to n
• Step 2a: calculate random coordinates xi and yi that satisfy a≤xi ≤b
and 0 ≤ yi ≤ M
• Step 2b: calculate f(xi ) for the random xi coordinate
• Step 2c: if yi ≤ f(xi ) , then increment COUNTER by 1
Step 3: Calculate the area A = M(b − a) ×COUNTER/n
Step 4: Output A.
Example:
obtain the area under the curve y = cos x over the interval

Monte Carlo approximation to the area under

 
Monte Carlo technique can be extended to functions of several variables
and becomes more practical in that situation.
Generating Random Numbers
Generating Random Numbers:
An important part of simulation is the generation of random numbers.

we can use the Maple function rand to generate random numbers.

A computer does not really generate random numbers because


computers employ deterministic processes.

Computers generate a pseudorandom numbers.

We will look two methods for generating pseudorandom numbers


ourselves.
.
Example:
n Xn Square Xn
Middle-Square Method:

1. Start with a four-digit number x0, called the seed. 0 2041 04165681
1 1656 02742336
2. Square it to obtain an eight-digit number (add a
leading zero if necessary) 2 7423 55100929

3 1009 01018081
3. Take the middle four digits as the next random
number. 4 0180 00032400
5 0324 00104976
Continuing , we obtain a sequence that appears
6 1049 01100401
random over the integers from 0 to 9999. These
integers can be scaled to any interval a to b. 7 1004 01008016
8 0080 00006400
9 0064 00004096
One disadvantage: this method has a tendency to 10 0040 00001600
degenerate to zero. 11 0016 00000256
12 0002 00000004
Linear Congruence Method:
Choose three integers a, b and c
Given an initial seed x0, we generate a sequence using the rule
xn+1 = (axn+b) mod c. modc means to obtain the remainder after
dividing
the quantity axn+b by c.

Example. Let a = 1, b = 7 and c = 10. Then xn+1 = (1·xn+ 7) mod 10


If xn= 115, then xn+1 = remainder(115 + 7)/10= remainder(122/10)= 2.

One problem with any algorithm for generating pseudorandom numbers


is cycling. Cycling is when out sequence of random numbers repeats
itself.
This linear congruence method produces a sequence of integers
between 0 and c − 1.
Cycling is guaranteed with at most c random numbers in the sequence.
To combat this, we choose c very large.
Simulating Probabilistic Behavior
Flipping a Fair Coin:
Here, we will create simulation models for simple probabilistic
behaviour. This type of simulation can be extended to more complex
probabilistic behaviour.
Flipping a Fair Coin:
The probability of obtaining heads or tails on a flip of a coin is 1/2 .
What happens when we actually flip a coin? Will one out of every two
slips be tails?
Probability is a long run average. Thus, in the long run, the ratio of the
number of tails to the number of flips approaches 0.5.
Define P(x) as follows where x is a random number between [0, 1]:

SO, P(x) assigns either “heads” or “tails” to a number between [0, 1].
Monte Carlo Fair Coin Algorithm:
Input: Total number n of random flips of a fair coin to be
generated in the simulation
Output: Probability of getting “tails” when we flip a fair coin.
Step 1: Initialize: COUNTER=0
Step 2: for i = 1 to n
• Step 2a: generate a random number xi between 0 and 1
• Step 2b: if 0.5 < x ≤1, then COUNTER=COUNTER+1
Step 3: Calculate P(tails) = COUNTER/n
Step 4: Output Probability of tails, P(tails).
Rolling a Fair Die:
The probability of the event of rolling a ‘1’ is 1/6 .

The probability of a particular number appearing on the die is number


of occurrences of the particular number total number of trials.

Monte Carlo Roll of a Fair Die Algorithm:

Input: Total number n of random rolls of a die to be generated in the


simulation.

Output: Probability of rolling a {1, 2, 3, 4, 5, 6}.

Step 1: Initialize COUNTER1 through to COUNTER6 to zero


Step 2: for i = 1 to n

•Step 2a: generate a random number xi between 0 and 1

•Step 2b: if xi belongs to these intervals, then increment the appropriate counter

0 ≤ xi ≤ 1/6 COUNTER1 = COUNTER1 + 1

1/6< xi ≤ 2/6 COUNTER2 = COUNTER2 + 1

2/6< xi ≤ 3/6 COUNTER3 = COUNTER3+ 1

3/6< xi ≤ 4/6 COUNTER4 = COUNTER4 + 1

4/6< xi ≤ 5/6 COUNTER5 = COUNTER5 + 1

5/6< xi ≤1 COUNTER6 = COUNTER6 + 1


.
Step 3: Calculate probability of each roll j = {1, 2, 3, 4, 5, 6} by COUNTER(j)/n

Step 4: Output probabilities.


Roll of an Unfair Die
Let's consider a probability model in which the events are not all equally likely. Assume
the die is loaded or biased according to the following empirical distribution:

Roll P(Roll) The cumulative occurrences for the function to be used in


value our algorithm would be
1 0.1
Roll P(Roll)
2 0.1 value
3 0.2 (0,0.1] ONE
4 0.3 (0.1,0.2] TWO
5 0.2 (0.2,0.4] THREE
6 0.1 (0.4,0.7] FOUR
(0.7,0.9] FIVE
(0.9,1.0] SIX
Monte Carlo Roll of an Unfair Die Algorithm
Input: Total number n of random rolls of a die in the simulation.
Output: The percentage or probability for rolls {1, 2, 3, 4, 5, 6}

Step 1: Initialize COUNTER 1 through COUNTER 6 to zero.


Step 2: For i = 1, 2, … , n do Steps 3 and 4.
Step 3: Obtain a random number satisfying 0 ≤ xi ≤ 1.
Step 4: If xi belongs to these intervals, then increment the appropriate
COUNTER.
0 ≤ xi ≤ 0:1 COUNTER 1 = COUNTER 1 + 1
0:1 < xi ≤ 0:2 COUNTER 2 = COUNTER 2 + 1
0:2 < xi ≤ 0:4 COUNTER 3 = COUNTER 3 + 1
0:4 < xi ≤ 0:7 COUNTER 4 = COUNTER 4 + 1
0:7 < xi ≤ 0:9 COUNTER 5 = COUNTER 5 +1
0:9 < xi ≤ 1:0 COUNTER 6 = COUNTER 6 + 1
Step 5: Calculate probability of each roll j = {1, 2, 3, 4, 5, 6} by COUNTER (j)/=n.
Step 6: OUTPUT probabilities.
Problem

A train should leave a station at precisely 1 pm. However, it


happens that the train is late some times. The train is on
time in about 70% of cases, it is 5 minutes late in about 20%
of cases and it is 10 minutes late in about 10% of cases. You
are getting on the train at the next station. The train journey
time is about 30 minutes with variations of 2 minutes. You
are arriving to your station exactly at 1:30 in 40% of cases,
at 1:28 in 30% of cases, at 1:32 in 20% of cases and at 1:34
in 10% of cases. Find the probability that you will catch the
train.
Solution
Let t1 stands for the departure time of the train
t2 for the journey time and
t3 for your arrival time to the station.
The favourable event is when t1+t2 > t3
For simplicity, let us consider time 1:00 pm as t = 0 and let
us measure time in minutes.
An algorithm for simulating this situation is as follows:

1. Input: number of events n

2. Output: the probability that you will catch the train = the number of favourable events
divided by the total number of events n.

3. Initially set counter c of favourable events to 0.

4. t1 is a discrete random variable that takes value 0 in 70% of cases, 5 in 20% of cases
and 10 in 10% of cases. For t2 we can assume the normal distribution with mean 30 and
deviation 2. t3 is a discrete random variable that takes value 28 in 30% of cases, 30 in
40% of cases, 32 in 20% of cases and 34 in 10% of cases. Thus,

t1 0 5 10 t3 28 30 32 34
frequency .7 .2 .1 frequency .3 .4 .2 .1

5. For i = 1 to n; repeat the following steps: calculate t1; t2 and t3 and increase the counter
by 1 if t1+t2 > t3
6. Calculate the quotient of c and n.
Inventory Model
Gasoline and Consumer Demand:
 Previously, we discussed modelling probabilistic behaviours using Monte Carlo simulation.

 Now, we will learn a method to approximate more probabilistic processes. Additionally, we will
check to determine how well the simulation duplicates the process under examination. We begin
by considering an inventory control problem.

Problem: Minimize the average daily cost of delivering and storing sufficient gasoline at each
station to meet consumer demand.

 After discussing the relative importance of the various factors determining the average
daily cost, we develop the following model:

average daily cost = f (storage costs, delivery costs, demand rate)

 we argue that although the cost of storage may vary with the amount stored, it is reasonable
to assume the cost per unit stored would be constant over the range of values under
consideration.
 Similarly, the delivery cost is assumed constant per delivery, independent of the amount
delivered, over the range of values under consideration.
Graphs:
 The daily demand for gasoline at a particular station shown in Figure 5.4a.
 The frequency of each demand level over a fixed time period (e.g., 1 year)
shown in Figure 5.4b.
 Figure 5.4c, where the slope of the line represents the constant daily
demand.
History of demand at a particular gasoline
station
Probability of the occurrence of each demand level

The relative frequency of each of the Demand intervals


Monte Carlo approximation of the demand
submodel
Summary of Monte Carlo Inventory Algorithm Terms

› Q =Delivery quantity of gasoline in gallons


› T =Time between deliveries in days
› I =Current inventory in gallons
› d= Delivery cost in dollars per delivery
› s =Storage cost per gallon per day
› C =Total running cost
› c =Average daily cost
› N =Number of days to run the simulation
› K =Days remaining in the simulation
› xi =A random number in the interval [0,1]
› qi =A daily demand
› Flag =An indicator used to terminate the algorithm
Monte Carlo Inventory Algorithm

› Input Q, T , d , s, N
› Output c
› Step 1: Initialize: K =N, I = 0, C = 0, Flag = 0
› Step 2: Begin the next inventory cycle with a delivery:
I = I +Q, C = C +d
› Step 3: Determine if the simulation will terminate during this cycle:
If T ≥K, then set T=K and Flag =1
› Step 4: Simulate each day in the inventory cycle (or portion
remaining): For
i=1, 2, . . . , T , do Steps 5–9
› Step 5: Generate the random number xi .
› Step 6: Compute qi using the demand sub model.
Conti..

› Update the current inventory: I =I-qi


› Step 8: Compute the daily storage cost and total running cost,
unless the inventory has been depleted:
› If I ≤ 0, then set I =0 and GOTO Step 9.
› Else C = C + I s.
› Step 9: Decrement the number of days remaining in the simulation:
› K =K - 1
› Step 10: If Flag = 0, then GOTO Step 2. Else GOTO Step 11.
› Step 11:Compute the average daily cost: c = C/N.
› Step 12: Output c.
STOP
Problems:
1. Write a program in Mat lab that calculates the volume under a surface f(x,y) for a≤ x
≤b, c≤ y ≤d if 0≤z ≤M using n random points. Test the validity of the program by
comparing the outputs with the area obtained using double integrals.
2. Write an algorithm or program in Mat lab that calculates an approximation of by
considering that the quotient between a quarter of the unit circle in the first quadrant and
the unit square in the first quadrant is
3. An experiment consists of 5 trials of the same event. The experiment is considered
successful just if all five trials yield a favourable outcome. Write down a simulation
program that calculates the probability of success in the experiment if a trial is successful
in 70% of cases.
4. Assume that you are looking at the outcomes of the two experiments. The first
experiment is successful in 70% of cases and the second experiment can be run just if
the outcome of the first experiment is favourable. If the second experiment is conducted,
it is successful in 80% of cases. Write down a simulation program that calculates the
probability of success in both experiments.
5. Modify the inventory algorithm to keep track of unfilled demands and the total number
of days that the gasoline station is without gasoline for at least part of the day.
Thank you

You might also like