Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Simulation

• Create the effect or appearance of something.


OR
• Imitate (mimic) the operation of an entire process
or system using a computer.
– Randomly generating and recording the outcomes
which drive the system as if it were actual operating.

• Flight simulators used to train Pilots.


• New Product Development
Purpose of Simulation
• Simulation of a newly designed system is necessary
to avoid
- Danger, Cost, Time
• To Determine
Optimum operating policies
Optimum parameter values
Performance characteristics
• Analytical Methods are not always adequate
M/G/s G/G/1 Queuing Systems
• Large Systems - Too Complex for analytical methods
• Networks of queues
Example
• A coin tossing game
- You pay Re.1 for each toss
- Get back Rs. 8 when |H-T| = 3, and the
game ends
• Should you play this game?
• What is the expected gain or loss if you play the
game?
• What is the average number, N, of tosses before |
H-T| = 3?
• If N >> 8, should you play the game?
• How can we simulate the game on a computer?
Example (contd.)
• Suppose the computer can generate uniform(0,1)
random numbers.
• Can we simulate coin tosses using uniform(0,1)
random numbers?
• 0.0 < RN < 0.5 : Head
0.5 < RN < 1.0 : Tail
0.82 0.11 0.34 0.75 0.14 0.68 0.52 0.67 0.74
T H H T H T T T T
1 0 1 0 1 0 1 2 3
N = 9, Loss : Re. 1
0.93 0.04 0.15 0.44 0.39
T H H H H
1 0 1 2 3
N = 5, Gain : Rs. 3

• Conduct multiple runs


• Compute average value of N
• Similar to sampling
• Larger the sample size, better the estimate.
Generating Random Numbers from Other Distributions
• How to generate random numbers from any given
distribution?
• A random number with U(0,1) distribution can be
transformed into any other distribution.
• How did we simulate the coin toss?
• Example: Discrete distribution.

x f(x)
0 0.10
1 0.30
2 0.40
3 0.20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Problem
• The Dynaco Manufacturing Company produces a product in a process
consisting of operations of five machines. The probability distribution of the
number of machines that will break down in a week follows:
Machines Break Down per week 0 1 2 3 4 5
Probability .10 .10 .20 .25 .30 .05

• Every time a machine breaks down at the company, either 1, 2, or 3 hours


are required to fix it, according to the following probability distribution.
Repair Time (hr) Probability
1 0.3
2 0.5
3 0.2

• Simulate the repair time for 7 weeks and then compute the average weekly
repair time. Use the following U(0, 99) numbers for simulation. Use r1 for
number of breakdowns and r2 for repair time.
r1 20, 31, 98, 24, 01, 56, 48
r2 58, 47, 23, 69, 35, 21, 41, 14, 59, 28, 13, 09, 20, 73, 77, 29, 50
Week r1 Breakdowns r2 Repair time Total repair time

1 20 2 58 2
47 2 4
2 31 2 23 1
69 2 3
3 98 5 35 2
21 1
41 2
14 1
59 2 8
4 24 2 28 1
13 1 2
5 1 0 0
6 56 3 9 1
20 1
73 2 4
7 48 3 77 2
29 1
50 2 5

Average Weekly Repair Time = 26/7


Simulation of an M/M/1 queue
• What is the state of the system?
– No. of customers
• What are the possible events?
– customer arrival
– service completion
• How to simulate?
– mimic customer arrivals. How?
• Generate random numbers that realistically
represent inter-arrival times coming from a given
distribution.
• How?
Simulation of M/M/1 Queue
• Mimic the arrival process by generating inter-arrival
times.
• Generate the service time from appropriate
distribution.
• Develop the logic of simulation program.
• Simulation clock moves from one event to next.
• One event of each kind should always be in the
pipeline.
• Should always know the time of next arrival.
• If a service is in progress, should know its completion
time.
• When to generate the random numbers?
• When to advance the clock?
• What data to gather?
Generate next arrival Generate next arrival
Advance clock to next event Generate service completion time
Advance clock to next event
Generate next arrival
Generate service completion time
Advance clock to next event
Generate next arrival
Advance clock to next event

Generate service completion time


Advance clock to next event
Advance clock to next event
M/M/1 Queue,  = 0.03,  = 0.05

Clock N Arr. Serv. Next Arr Next Dep Next E. Time in system

0 0 80 -- 80 -- 80 A

80 1 10 27 90 107 90 A

90 2 37 -- 127 107 107 D 27

107 1 -- 5 127 112 112 D 22

112 0 -- -- 127 -- 127 A

127 1 21 92 148 219 148 A

148 2 35 -- 183 219 183 A

183 3 5 -- 188 219 188 A

188 4 36 -- 224 219 219 D 92

219 3 -- 32 224 251 224 A


Performance Measures
Customer Name Waiting Time in Service Time Time Customer in
Queue System
1 0 27 27

2 17 5 22

3 0 92 92

4 71 32 103

Total 88 156 244

Average waiting time in Queue = 88/4 = 22


Average waiting time in System = 244/4 = 61
Problem
• We wish to simulate a pair of queues operating in series.
Customers arrive as a Poisson process of rate 0.1 per minute to
queue A, which has only one server. The service times at queue
A (in minutes) are uniformly distributed on [1, 8]. After leaving
queue A, customers join queue B immediately, which also has
one server. The service times at queue B are exponentially
distributed with mean 2 minutes. Simulate this queuing system
and compute 8 rows of the simulation table using the following
uniform random numbers:
 For arrival (ra): 0.20, 0.77, 0.50, 0.41, 0.35 ~ U(0,1)
 For Service in queue A: 6, 8, 3, 5 ~U(1,8)
 For Service in queue B (rs2): 0.13, 0.01, 0.37 ~U(0,1)
Queue 1 Queue 2
Next Next
Clock N1 ra Arr. Serv1 Next Dep. N2 rs2 Serv2 Dep. Next
Arr. Q Q2 Event
1
Queue 1 Queue 2
Next Next
Clock N1 ra Arr. Serv1 Next Dep. N2 rs2 Serv2 Dep. Next
Arr. Q Q2 Event
1

0 0 0.20 16 16 0 16 A
Queue 1 Queue 2
Next Next
Clock N1 ra Arr. Serv1 Next Dep. N2 rs2 Serv2 Dep. Next
Arr. Q Q2 Event
1

0 0 0.20 16 16 0 16 A
16 1 0.77 3 6 19 22 0 19 A
Queue 1 Queue 2
Next Next
Clock N1 ra Arr. Serv1 Next Dep. N2 rs2 Serv2 Dep. Next
Arr. Q Q2 Event
1

0 0 0.20 16 16 0 16 A
16 1 0.77 3 6 19 22 0 19 A
19 2 0.50 7 26 22 0 22 D1
22 1 8 26 30 1 0.13 4 26 26 A D2
26 2 0.41 9 35 30 0 30 D1
30 1 3 35 33 1 0.01 9 39 33 D1
33 0 35 2 39 35 A
35 1 0.35 10 5 45 40 2 39 39 D2
39 1 45 40 1 0.37 2 41 40 D1

You might also like