You are on page 1of 63

SIMULATION

By Dr.T.V.Subramanian

Monte Carlo Simulation


Select numbers randomly from a probability distribution
Use these values to observe how a model performs over time Random numbers each have an equal likelihood of being selected at random

Distribution Of Demand
Cases demanded Frequency of per week, x Demand
14 15 16 17 18 20 40 20 10 10 100

Probability of Demand P(x)


0.20 0.40 0.20 0.10 0.10 1.00

Roulette Wheel Of Demand


0 90 x = 18 80 x = 17 x = 14 20

x = 16

x = 15

60

Random Number Table


39 73 72 75 37 65 71 18 12 17 76 23 47 25 79 45 70 33 69 88 45 90 84 17 74 19 65 51 17 63 90 97 67 95 52 69 60 47 21 06 64 12 97 78 34 61 11 19 58 30

Generating Demand From Random Numbers


Demand x 14 15 16 17 18 Ranges of Random Numbers r 0-19 20-59 r = 39 60-79 80-89 90-99

15 Weeks Of Demand
Week 1 2 3 r 39 73 72 Demand (x) 15 16 16 Week 9 10 11 r 10 47 93 Demand (x) 14 15 18

4 5 6 7 8

75 37 02 87 98

16 15 14 17 18

12 13 14 15

21 95 97 69

15 18 18 16 S = 241

Average demand = 241/15 = 16.1 cases per week

Computing Expected Demand


E(x) = (0.20) 14 + (0.40) 15 + (0.20) 16 + (0.10) 17 + (0.10)18 = 15.5 cases per week Close to simulated result of 16.1 cases Difference is due to small sample size

Inventory Simulation
Demand for VCRs

Probability

Lead Time Weeks Probability

0 1 2 3 4

0.10 0.15 0.30 0.25 0.20 1.00

1 2 3

0.35 0.45 0.20 1.00

Random Number Ranges


RN Range 1-10
11-25 26-55 56-80 81-99

Demand 0 1 2 3 4

Prob 0.10 0.15 0.30 0.25 0.20 1.00

Lead time 1
2 3

RN Prob Range 0.35 1-35


0.45 0.20 1.00 36-80 81-99

Simulation For Inventory


Time Period 1 2 3 4 Beg Inv 5 3 5 5 RN 44 92 02 12 Dem 2 4 0 1 Sold 2 3 0 1 End Inv 3 0 5 4 Lost Sales 0 1 0 0 Place Order? YES No No No RN 17 Lead Time 1 0 0 0

5 6 7 8 9 10

4 3 0 5 3 7

25 93 46 34 22 79

1 4 2 2 1 3

1 3 0 2 1 3

3 0 0 3 2 *4 24

0 1 2 0 0 0 4

Yes No No Yes No No

53 21 -

2 0 0 1 0 0

Summary Statistics
Average lost sales = 4/10 = 0.4 units/week
Average ending inventory = 24/10 = 2.4 units/week

Transient vs. Steady State Operation


Transient Conditions Current level of work-in-process in a manufacturing system Expected value of the work - in - process output variable
[Warmup period]

Steady-State* Conditions

*[If steady-state is reached]

Simulated time

Discrete event simulation logic


Cumulative frequency functions
Within any interval of the distribution, values of the function are uniformly distributed. Interpret cumulative frequency functions as a series of straight-line segments that connect the function defined ordered pairs of points.
Interarrival time in Cumulative frequency hours (time between with which these arriving ships) times occur 0 to 6 0.1 6 to 12 0.2 12 to 18 0.9 18 to 24 1.0

IAT0 = IAT1 + (rand0 - cfreq1) x ( (IAT2 - IAT1) / (cfreq2 - cfreq1) ) if rand0 = 0.7414 = 12 + (0.7414 - .2) x ((18 - 12) / (.9 - .2) ) = 16.6

Simulation of a Queuing System


In queuing systems time itself is a random variable. Therefore, we use the next event simulation approach. The simulated data are updated each time a new event takes place (not at a fixed time periods.) The process interactive approach is used in this kind of simulation (all relevant processes related to an item as it moves through the system, are traced and recorded).

CAPITAL BANK An example of queuing system simulation


Capital Bank is considering opening the bank on Saturdays morning from 9:00 a.m. Management would like to determine the waiting time on Saturday morning based on the following data:

CAPITAL BANK
Data:
There are 5 teller positions of which only three will be staffed.
Ann Doss is the head teller, experienced, and fast. Bill Lee and Carla Dominguez are associate tellers less experienced and slower.

CAPITAL BANK
Data:
Service time distributions:
Anns Service Time Distribution Distribution
Service Time Probability

Bill and Carlas Service Time


Service Time Probability

.5 minutes 1 1.5 2 2.5 3 3.5

.05 .10 .20 .30 .20 .10 .05

1 minute 1.5 2 2.5 3 3.5 4 4.5

.05 .15 .20 .30 .10 .10 .05 .05

CAPITAL BANK
Data:
Customer inter-arrival time distribution inter-arrival time Probability .5 Minutes .65 1 .15 1.5 .15 2 .05 Service priority rule is first come first served

A simulation model is required to analyze the service .

CAPITAL BANK Solution

Calculating expected values:


E(inter-arrival time) = .5(.65)+1(.15+1.5(.15)+2(.05) = .80 minutes [75 customers arrive per hour on the average, (60/.8=75)] E(service time for Ann) = .5(.05)+1(.10)++3.5(.05) = 2 minutes [Ann can serve 60/2=30 customers per hour on the average] E(Service time for Bill and Carla) = 1(.05)+1.5(.15)++4.5(.05) = 2.5 minutes [Bill and Carla can serve 60/2.5=24 customers per hour on the average].

CAPITAL BANK Solution

To reach a steady state the bank needs to employ all the three tellers (30+2(24) = 78 > 75).

CAPITAL BANK The Simulation logic


If no customer waits in line, an arriving customer seeks service by a free teller in the following order: Ann, Bill, Carla. If all the tellers are busy the customer waits in line and takes then the next available teller. The waiting time is the time a customer spends in line, and is calculated by

[Time service begins] minus [Arrival Time]

CAPITAL Simulation Demonstration

1.5 1.5

1.5

1.5 1.5

1.5 1.5 Bill 1.5 Ann 1.5

3.5

Mapping Interarrival time 80 94 1.5 minutes

Mapping Anns Service time 35 64 2 minutes

CAPITAL Simulation Demonstration

Bill Ann 1.5

3.5

5.5

Mapping Interarrival time 80 94 1.5 minutes

Mapping Bills Service time 40 69 2.5 minutes

CAPITAL Simulation Demonstration

3 Waiting time 3.5

CAPITAL 1000 Customer Simulation


Average Waiting Time in Line = Average Waiting Time in System = 1.670 3.993 Ann Bill Carla Waiting Waiting Random Arrival Random Time Time Customer Number Time Number Start Finish Start Finish Start Finish Line System 1 2 3 4 5 6 7 8 0.87 0.18 0.49 0.86 0.54 0.61 0.91 0.64 1.5 2.0 2.5 4.0 4.5 5.0 6.5 7.0 0.96 0.76 0.78 0.49 0.85 0.55 0.90 0.62 1.5 5 2 5 7 5 7 10 8 10.5 8.5 5.5 8 5 2.5 5.5 0 0 0 1 0.5 0.5 0.5 1 3.5 3.0 3.0 3.0 4.0 3.0 3.5 3.5

CAPITAL 1000 Customer Simulation


Average Waiting Time in Line = Average Waiting Time in System = 1.670 3.993 Ann Bill Carla Waiting Waiting Random Arrival Random Time Time Customer Number Time Number Start Finish Start Finish Start Finish Line System

This simulation estimates two performance measures:

1 2 3 4 5 6 7 8

0.87 1.5 0.96 1.5 5 0 3.5 Average inter-arrival Average waiting time in line (Wq) = 1.67 minutes 0.18 2.0 0.76 2 5 0 3.0 Average waiting time in the system W = 3.993 minutes 5.5 time =0.80 minutes. 0.49 2.5 0.78 2.5 3.0 0.86 4.0 7 1 3.0 To determine the 0.49 performance measures, we can use other 5 0.54 4.5 5 8.5 0.5 4.0 Littles formulas: 0.85 0.61 5.0 0.55 5.5 8 0.5 3.0

Average 6.5 number of customers in line Lq =(1/.80)(1.67) = 2.0875 3.5 0.91 0.90 7 10 0.5 customers 0.64 7.0 0.62 8 10.5 1 3.5 Average number of customers in the system = (1/.80)(3.993) = 4.99 customers.

Mapping for Continuous Random Variables


Example
The Explicit inverse distribution method can be used to generate a random number X from the exponential distribution with m = 2 (i.e. service time is exponentially distributed, with an average of 2 customers per minute).
Randomly select a number from the uniform distribution between 0 and 1. The number selected is Y = .3338. Solve the equation: X = F-1(Y) = (1/m)ln(1 Y) = (1/2)ln(1-.3338) = .203 minutes.

Mapping for Continuous Random Variables Using Excel

=RAND() Drag to cell B13

=-LN(1-B4)/$B$1 Drag to cell C13

Random numbers and Excel

Excel can generate continuously distributed random numbers for various distribution.
Normal =NORMINV Beta: =BETAINV Chi squared: =CHIINV Gamma: =GAMMAINV

Random numbers Normally distributed by Excel


=NORMINV(RAND(),$B$1,$B$2) Drag to cell B24

Simulation of an M / M / 1 Queue
Applying the process interaction approach we have:
New arrival time = Previous arrival time + Random interarrival time.

Service finish time = Service start time + Random service time.


A customer joins the line if there is a service in progress (its arrival time < current service finish time ). A customer gets served when the server becomes idle. Waiting times and number of customers in line and in the system are continuously recorded.

LANFORD SUB SHOP An example of the M/M/1 queuing simulation


Lanford Sub Shop sells sandwiches prepared by its only employee, the owner Frank Lanford. Frank can serve a customer in 1 minute on the average according to an exponential distribution. During lunch time, 11:30 a.m. to 1:30 p.m., an average of 30 customers an hour arrive at the shop according to a Poisson distribution.

LANFORD SUB SHOP

Using simulation, Frank wants to determine the average time a customer must wait for service

LANFORD SUB SHOP - Solution


Input Data l = 30, m = 60. Data generated by the simulation:
C# = The number of the arriving customer. R#1 = The random number used to determine interarrivals. IAT = The interarrival time. AT = The arrival time for the customer. TSB = The time at which service begins for the customer. WT = The waiting time a customer spends in line. R#2 = The random number used to determine the service time.

ST = The service time. TSE = The time at which service end for the customer

LANFORD SUB SHOP Simulation for first 10 Customers


C# 1 2 3 4 5 6 (0 + 7 8 9 10

Time Service Begins Service Time R#1 IAT AT TSB WT R#2 0.6506 2.10 2.10 2.10 0 0.7761 0.6170 1.92 4.02 4.02 0 0.8800 0.4211 1.09 5.11 6.14 1.03 0.7452 0.1182 0.25 5.36 7.51 2.15 0.4012 0.0335 0.07 5.43 2.59 0.6299 Average waiting time = 8.02 0.5482 1.59 7.02 9.01 1.99 0.1085 0 +1.03 + ... +2.04)7.39 = 1.59 1.73 / 10 9.12 0.1698 0.37 0.6969 0.1696 0.37 7.76 10.31 2.55 0.0267 0.3175 0.76 8.52 10.34 1.82 0.7959 0.4958 1.37 9.89 11.93 2.04 0.4281

Arrival Time

Time Service Ends ST TSE 1.5 3.6 2.12 6.14 1.37 7.51 0.51 8.02 0.99 9.01 0.11 9.12 1.19 10.31 0.03 10.34 1.59 11.93 0.56 12.49

The interarrival time = - ln(1-0.4211) / 30 = 0.0182 hours = 1.09 minutes End of service = 6.14+1.37 The explicit inverse method Waiting time = 6.14 - 5.11

Arrival time of customer 3 = Arrival time of customer 2 + 1.09 = 4.02 + 1.09

LANFORD SUB SHOP Simulation for first 1000 Customers

Harbor Simulation
Initialize model Advance clock
ship arrivals unloading completions yes

Random number 200th ship? no Is ship waiting?


yes no

Arrival time Print statistics


no

Unload open?
yes

Stop

Random number Unloading time

Random number Unloading time

Harbor Simulation
Order Drawn 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Random 0-24 hrs Number IAT 0.2068 12.1 0.7295 16.5 0.3441 13.2 0.5436 14.9 0.3091 12.9 0.2276 12.2 0.4833 14.4 0.7414 16.6 0.7666 16.9 0.0273 1.6 0.0700 4.2 0.6489 15.8 0.9564 21.4 0.2389 12.3 12-16 hrs UNLOAD 12.8 14.9 13.4 14.2 13.2 12.9 13.9 15.0 15.1 12.1 12.3 14.6 15.8 13.0

Harbor Simulation
SCHEDULE
Queue Ship 0 0 0 1 0 2 1 1 0 3 0 2 1 4 0 3 1 5 0 4 1 6 0 5 1 7 Clock Event Arrival at Begin Unload 0.0 Initialize 12.1 12.1 Arrive 25.3 12.1 25.3 Arrive 40.2 27.0 Depart 27.0 40.2 Arrive 52.4 40.2 Depart 40.2 52.4 Arrive 69.0 54.1 Depart 54.1 69.1 Arrive 70.7 69.2 Depart 69.1 70.6 Arrive 86.4 81.5 Depart 81.5 86.4 Arrive 98.7 IAT Unload Depart Wait 12.1 14.9 13.2 27.0 0.0 14.9 13.2 40.2 1.7 12.2 13.9 54.1 0.0 16.6 15.1 69.2 1.7 1.6 12.3 81.4 0.1 15.8 15.8 97.3 10.8 12.3 Total waiting time 14.3 Average waiting time 2.4

Statistical analysis of simulation output


Trade-off between number of berths and waiting time Utilization of berth capacity Maximum number of ships waiting Mean waiting time (23.69 hours transient only) Std Dev (14.36 hours transient only) 95% Confidence interval vs point estimate 23.69-1.96 x (14.36 / 100^.5) = 22.33 23.69+1.96 x (14.36 / 100^.5) = 25.05

Example: Probablistics, Inc.


The price change of shares of Probablistics, Inc. has been observed over the past 50 trades. The frequency distribution is as follows:
Price Change -3/8 -1/4 -1/8 0 +1/8 +1/4 +3/8 Number of Trades 4 2 8 20 10 3 2

Example: Probablistics, Inc.


Relative Frequency Distribution and Random Number Mapping Price Change Relative Frequency Random Numbers
-3/8 .08 00 - 07

-1/4 -1/8 0 +1/8 +1/4 +3/8 +1/2

.04 .16 .40 20 06 .04 .02

08 - 11 12 - 27 28 - 67 68 - 87 88 - 93 94 - 97 98 - 99

Example: Probablistics, Inc.

If the current price per share of Probablistics is 23, use random numbers to simulate the price per share over the next 10 trades. Use the following stream of random numbers: 21, 84, 07, 30, 94, 57, 57, 19, 84, 84

Example: Probablistics, Inc.


Simulation Worksheet Trade Random Number Number 1 21 2 84 3 07 4 30 5 94 6 57 7 57 8 19 Price Change -1/8 +1/8 -3/8 0 +3/8 0 0 -1/8 Stock Price 22 7/8 23 225/8 225/8 23 23 23 22 7/8

Example: Probablistics, Inc.


A B C D E 1 Lower Upper Trade Price 2 Spreadsheet for Price Price Simulation Random Random Stock Number Change 3 Number Number Change 1 0.000 4 0.00 0.08 -0.375 2 -0.250 5 0.08 0.12 -0.250 3 0.000 6 0.12 0.28 -0.125 4 0.000 7 0.28 0.68 0.000 5 0.000 8 0.68 0.88 0.125 6 -0.125 9 0.88 0.94 0.250 7 -0.250 10 0.94 0.98 0.375 8 -0.125 11 0.98 1.00 0.500 9 0.125 12 10 0.250 F Stock Price 23.000 22.750 22.750 22.750 22.750 22.625 22.375 22.250 22.375 22.625

Example: Probablistics, Inc.


Theoretical Results and Observed Results
Based on the probability distribution, the expected

price change per trade can be calculated by:


(.08)(-3/8) + (.04)(-1/4) + (.16)(-1/8) + (.40)(0) + (.20)(1/8) + (.06)(1/4) + (.04)(3/8) + (.02)(1/2) = +.005 The expected price change for 10 trades is (10)(.005) = .05. Hence, the expected stock price after 10 trades is 23 + .05 = 23.05. Compare this ending price with the spreadsheet simulation and manual simulation results on the

Example: Wayne International Aiport


Wayne International Airport primarily serves domestic air traffic. Occasionally, however, a chartered plane from abroad will arrive with passengers bound for Wayne's two great amusement parks, Algorithmland and Giffith's Cherry Preserve.

Whenever an international plane arrives at the airport the two customs inspectors on duty set up operations to process the passengers. Incoming passengers must first have their passports and visas checked. This is handled by one inspector. The time required to check a passenger's passports and visas can be described by the probability distribution on the next slide.

Example: Wayne International Aiport


Time Required to Check a Passenger's Passport and Visa Probability

20 seconds
40 seconds 60 seconds

.20
.40 .30

80 seconds

.10

Example: Wayne International Aiport


After having their passports and visas checked, the passengers next proceed to the second customs official who does baggage inspections. Passengers form a single waiting line with the official inspecting baggage on a first come, first served basis. The time required for baggage inspection has the following probability distribution: Time Required For Baggage Inspection Probability No Time .25 1 minute 2 minutes 3 minutes .60 .10 .05

Example: Wayne International Aiport


Random Number Mapping
Time Required to Check a Passenger's Passport and Visa Probability 20 seconds .20 40 seconds .40 60 seconds 80 seconds .30 .10 Random Numbers 00 - 19 2059 6089 9099

Example: Wayne International Aiport


Random Number Mapping
Time Required For Random Baggage Inspection Probabi Numbers No Time 1 minute 2 minutes 3 minutes .25 .60 .10 .05 00 - 24 25 - 84 85 - 94 95 - 99

Example: Wayne International Aiport


Next-Event Simulation Records
For each passenger the following information must be recorded:
When his service begins at the passport control inspection The length of time for this service

When his service begins at the baggage inspection The length of time for this service

Example: Wayne International Aiport


Time Relationships
Time a passenger begins service by the passport inspector = (Time the previous passenger started passport service) + (Time of previous passenger's passport service)

Example: Wayne International Aiport


Time Relationships

Time a passenger begins service by the baggage inspector ( If passenger does not wait in line for baggage inspection) = (Time passenger completes service with the passport control inspector) (If the passenger does wait in line for baggage inspection) = (Time previous passenger completes service with the baggage inspector)

Example: Wayne International Aiport


Time Relationships
Time a customer completes service at the baggage inspector = (Time customer begins service with baggage inspector) + (Time required for baggage inspection)

Example: Wayne International Aiport


A chartered plane from abroad lands at Wayne Airport with 80 passengers. Simulate the processing of the first 10 passengers through customs.
Use the following random numbers: For passport control:

93, 63, 26, 16, 21, 26, 70, 55, 72, 89


For baggage inspection: 13, 08, 60, 13, 68, 40, 40, 27, 23, 64

Simulation Worksheet (partial)

Example: Wayne International Aiport

Passport Control Baggage Inspections Pass. Time Rand. Service Time Time Rand. Service Time Num . Begin Num. Time 1 0:00 93 End Begin Num. Time 1:20 13 End 0:1:20

1:20

1:20

2 3 4 5

1:20 2:20 3:00 3:20

63 26 16 21

1:00 :40 :20 :40

2:20 3:00 3:20 4:00

2:20 3:00 4:00 4:00

08 60 13 68

0:2:20 1:4:00 0:4:00 1:5:00

Simulation Worksheet (continued)

Example: Wayne International Aiport

Passport Control Baggage Inspections Pass. Time Rand. Service Time Time Rand. Service Time Num . Begin Num. Time 6 4:00 26 End Begin Num. Time 5:00 40 End 1:6:00

:40

4:40

7 8 9 10

4:40 5:40 6:20 7:20

70 55 72 89

1:00 :40 1:00 1:00

5:40 6:20 7:20 8:20

6:00 7:00 8:00 8:20

40 27 23 64

1:7:00 1:8:00 0:8:00 1:9:20

Example: Wayne International Aiport


Explanation For example, passenger 1 begins being served by the passport ontrol inspector immediately. His service time is 1:20 (80 seconds) at which time he goes immediately to the baggage inspector who waves him through without inspection.

Passenger 2 begins service with passport inspector 1:20 minutes (80 seconds) after arriving there (as this is when passenger 1 is finished) and requires 1:00 minute (60 seconds) for passport inspection. He is waved through baggage inspection as well. This process continues in this manner.

Example: Wayne International Aiport


Question
How long will it take for the first 10 passengers to clear customs?

Answer
Passenger 10 clears customs after 9 minutes and 20 seconds.

Example: Wayne International Aiport Question


What is the average length of time a customer waits before having his bags inspected after he clears passport control? How is this estimate biased? Answer For each passenger calculate his waiting time: (Baggage Inspection Begins) - (Passport Control Ends) =0+0+0+40+0+20+20+40+40+0 = 120 seconds.

120/10 = 12 seconds per passenger. This is a biased estimate because we assume that the simulation began with the system empty. Thus, the results tend to underestimate the average

Areas Of Simulation Application


Waiting lines/service Inventory management Production & manufacturing systems Capital investment & budgeting Logistics Service operations Environmental & resource analysis

You might also like