Docsity

Queuing Theory - Discrete Math Model - Notes | MATH 381, Study notes of Mathematics

Partial preview of the text

Download Queuing Theory - Discrete Math Model - Notes | MATH 381 and more Study notes Mathematics in PDF only on Docsity!

Queuing Theory

Tim Chartier

Department of Mathematics @

Math 381

Queuing Theory

Today we use Monte Carlo simulation to model queues. Think of the various ways you wait in line – on your feet, in your car, or on the phone. There are various types of queues: Independent lines such as a grocery store Next available server such as an airport

Creating our data

Given a and b , we want to know when people arrive and how long they are serviced as in Ross. One option is to break a day into N units and in each time unit determine if a customer arrived or not. Similarly, we could also determine if a customer was finished being serviced in each time unit..

a N

a N

a N ¡ ¡ ¡^

a N

Note, we would deal with how large to make N and how many experiments we need to get convergence of results. This is a lot of wasted computation as we have probabilities (derived last class period) that could produce this.

Leaning on the infinite

So, we lean on the infinite as N → ∞. What is the probability of the next arrival time larger than a time unit T? Keep in mind, we are saying that starting at time 0, what is the probability (based on a Poisson distribution) that there are 0 arrivals by time T? From last time, we see that

Probability that inter-arrival time is larger than T = e − aT^.

Recall Ross

Similar to your homework out of Ross, we can create an array of arrival times and an array of service times.

¡ ¡ ¡ (^) arrival times

¡ ¡ ¡ service times

Then, our task, just like your homework, is now to find the departure times for each customer.

Closer look at queue.m

Let us look at MATLAB code that performs this.

% Simple queuing theory simulation, M/M/1 queue % Single server, single queue:

What is M/M/1? M - arrival times are exponential distribution (or Markovian) M - service times are Markovian 1 - single server Note this implies that other queues are possible to model, which they are.

queue.m – arrival times

With several comments removed, let us look at the code that finds the arrival times.

% Generate random arrival times... r = rand(ncust,1); iat = -1/a * log(r); at(1) = iat(1);

for i=2:ncust at(i) = at(i-1) + iat(i); end

queue.m – service times

Similarly, we find the service times. The code below has several commenting statements removed.

r = rand(ncust,1); st = -1/b * log(r);

% Compute time each customer finishes: ft(1) = at(1)+st(1); % finish time for 1st customer for i=2:ncust % compute finish time for each customer % as the larger of arrival time plus % service time (if no wait) finish time % of previous customer plus service time (if wait) ft(i) = max(at(i)+st(i), ft(i-1)+st(i)); end

Running the Code

Using queue.m available on the course web page set a = 1 (average rate of arrival/min) b = 1 .5 (average number of people served/min) simulation runs for 1,000 customers Talk with a partner, what can you interpret from the graphs below?

(^00 200 400 600 800 1000 )

2

4

6

8

10

12

14

16

18 queue length vs. time

(^00 2 4 6 8 10 12 14 16 18 )

50

100

150

200

250

300

350

400 histogram of waiting timesa = b =1. average total time =2. average service time =0.

Observations

(^00 200 400 600 800 1000 )

2

4

6

8

10

12

14

16

18 queue length vs. time

(^00 2 4 6 8 10 12 14 16 18 )

50

100

150

200

250

300

350

400 histogram of waiting times a = b =1. average total time =2. average service time =0.

Note that the queue length can exceed 10 multiple times. Several people wait for over 8 minutes. Remember this is one run of a random process. We should run several more times to look for general patterns.

Observe and compare runs

(^00 100 200 300 400 500 600 700 800 900 )

2

4

6

8

10

12

14

16 queue length vs. time

(^00 2 4 6 8 10 12 14 16 18 )

50

100

150

200

250

300

350

400 histogram of waiting timesa = b =1. average total time =2. average service time =0.

We again see queue lengths over 10 minutes multiple times. This time several people wait over 10 minutes. We may want to run 100 or 200 more times. Ideas of how to do this without looking at the graphs every time?

Changing parameters

Now, let us reduce b from 1.5 to 1.1. Note that this implies that service time is approaching length of inter-arrival times. What do you expect to see in the resulting data?

To change the code, find the following line in queue.m :

b = 1.5; % average number of people served...

and change it to:

b = 1.1; % average number of people served...

Simulation results – yet again

For a second run with the settings: a = 1 (average rate of arrival/min) b = 1 .1 (average number of people served/min) simulation runs for 1,000 customers

(^00 100 200 300 400 500 600 700 800 900 )

5

10

15

20

25

30

35 queue length vs. time

(^00 5 10 15 20 25 30 35 )

20

40

60

80

100

120

140

160

180

200 histogram of waiting times a = b =1. average total time =11. average service time =0.

Remarks

Such results help to show how such queues may behave given the proper parameters! For example, in the previous example, decreasing your average service time will aid in your queue!

Markov chain theory can also help determine these values. In particular, we find for a < b , the expected waiting time is 1 /( b − a ).