Vous êtes sur la page 1sur 5

Math 381 Handout 18

R. J. LeVeque December 2, 1998

A Simple Queuing Model using the Exponential Distribution


The matlab code on page 3 shows a simple simulation of a queue. Customer arrivals are modeled with a Poisson process with average rate per minute. They must wait in the queue until the single server is free. The amount of time required to serve them is also random, with average rate of people per minute. In this simulation this is also assumed to be Poisson process with probability of roughly that they will be nished in any small subunit of time 1 . This may not be very realistic. A better model might be that there is some minimal service time plus a random length of time after that, or some other distribution of service times. One could model this by splitting each minute up into subunits and generating a random number to determine whether a new customer arrives, and a second random number to determine whether the customer currently being served nishes. Instead, this simulation works by rst generating a set of arrival times and service times for each customer, and then computing the total time that each customer must wait on the basis of these times. The times are generated using an exponential distribution, for example Probability that inter-arrival time is larger than = ,aT This can be shown to be the proper distribution of service times for a Poisson distribution in the following manner. Suppose we split up the time since the last arrival into units 2 3 rather than minutes. Then in each unit the expected number of arrivals is . According to the Poisson distribution, the probability of exactly 0 arrivals in the rst of these periods is thus ,aT , but this is exactly the probability that the next arrival time is more than units later. To generate random numbers from an exponential distribution with parameter , we can rst generate a random number uniformly distributed in the interval 0 1 using rand in matlab, for example and then compute , 1 log 
a b b=N =N N T e : T; T; T; : : : aT e T a r ; a r :

The gures on page 4 show the results of three simulations using the parameters = 1 and = 1 5, for 1000 customers each. Two plots are shown for each simulation: on the left is the length of the queue as a function of time, and on the right is a histogram of the total time spend by each customer including both the time in line and the time being served. While the 3 simulations show variation in details, some similarities are observed. Note that although the server can handle 50 more customers than are arriving on average, the queue length can grow quite long due to the randomness of arrivals. In all three simulations the queue length is more than 10 at times. Also, looking at the histogram we see that there are some customers who have to wait as long as 10 or 12 minutes in each simulation, though the average total time is more like 2 minutes. On page 5 there is another set of simulations in which the parameter = 1 1 is used instead, in which case the average service time 1  0 91 is even closer to the average interarrival time.
a b : b : =b :

Again the details vary between simulations, but it is clear that now the queues will typically grow to be of length greater than 20 at times and the average waiting time is much longer. There are now typically some customers who have to wait more than 20 minutes. From comparing these sets of results it should be clear that such simulations can be e ectively used to predict how badly queues may behave if the proper parameters are estimated. One can also use Markov chain ideas to study the expected behavior of such systems and determine expected values for quantities such as the total waiting time. In fact it can be shown that for arbitary parameters , the expected total waiting time is 1  , . Note that this is consistent with what is observed in these simulations. We have only looked at the simplest situation of a single queue and a single server. This model is called an M M 1 queue. The rst M indicates that the arrival times are exponentially distributed or Markovian, the second M indicates that the service times are also Markovian, and the 1 indicates there is a single server. More complicated models would be required to model a bank or super market with multiple lines and servers, for example. Various modi cations of this model are possible. For example, we could assume a maximum queue length beyond which customers go away rather than joining the queue. In this case there are a nite set of states possible di erent queue lengths and it's easy to derive a Markov chain model of transitions. Many books discuss queuing theory, see Hillier and Lieberman's Introduction to Operations Research for one good introduction.
a b = b a

The code shown here is simpli ed and doesn't show the computation of the queue length which is plotted here. See the Handouts webpage for the full m- le.
 Simple queuing theory simulation,  Single server, single queue: M M 1 queue

a = 1;  average number of arrivals per minute b = 1.5;  average number of people served per minute ncust = 1000;  Notation:  at = arrival time of a person joining the queue  st = service time once they reach the front  ft = finish time after waiting and being served.   initialize arrays: at = zerosncust,1; ft = zerosncust,1;  Generate random arrival times assuming Poisson process: r = randncust,1; iat = -1 a * logr;  Generate inter-arrival times, exponential distribution at1 = iat1;  Arrival time of first customer for i=2:ncust ati = ati-1 + iati; end

 arrival times of other customers

 Generate random service times for each customer: r = randncust,1; st = -1 b * logr;  service times for each

 Compute time each customer finishes: ft1 = at1+st1;  finish time for first 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 fti = maxati+sti, fti-1+sti; end total_time = ft - at; wait_time = total_time - st;  total time spent by each customer  time spent waiting before being served

ave_service_time = sumst ncust ave_wait_time = sumwait_time ncust ave_total_time = sumtotal_time ncust  Plot histogram of waiting times: histtotal_time,0:.5:20

queue length vs. time


18

histogram of waiting times


400

a =1
16

350

b =1.5 average total time =2.1487

14

300

average service time =0.6786

12

250
10

200
8

150
6

100
4

50

200

400

600

800

1000

1200

10

12

14

16

18

20

queue length vs. time


16

histogram of waiting times


400

a =1
14

350

b =1.5 average total time =2.2084

12

300

average service time =0.6693

10

250

200

150

100

50

100

200

300

400

500

600

700

800

900

1000

10

12

14

16

18

20

queue length vs. time


15

histogram of waiting times


400

a =1
350

b =1.5 average total time =2.1234

300
10

average service time =0.67806

250

200

150
5

100

50

200

400

600

800

1000

1200

10

12

14

16

18

20

queue length vs. time


30

histogram of waiting times


200

180
25

a =1

160

b =1.1
140
20

120

average total time =6.2679

15

100

average service time =0.91675


80
10

60

40
5

20

200

400

600

800

1000

1200

10

15

20

25

30

35

40

queue length vs. time


35

histogram of waiting times


200

180
30

a =1

160

b =1.1
25

140

120
20

average total time =11.3831

100
15

average service time =0.88394


80

10

60

40
5

20

100

200

300

400

500

600

700

800

900

1000

10

15

20

25

30

35

40

queue length vs. time


25

histogram of waiting times


200

180

a =1

20

160

b =1.1
140

15

120

average total time =4.77

100

average service time =0.87122


10

80

60

40

20

200

400

600

800

1000

1200

10

15

20

25

30

35

40

Vous aimerez peut-être aussi