Simulation Modeling: Dr. G. Suresh Kumar
Simulation Modeling: Dr. G. Suresh Kumar
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.
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).
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 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.
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.
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 .
•Step 2b: if xi belongs to these intervals, then increment the appropriate counter
2. Output: the probability that you will catch the train = the number of favourable events
divided by the total number of events n.
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:
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
› 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..