Académique Documents
Professionnel Documents
Culture Documents
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
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
a =1
16
350
14
300
12
250
10
200
8
150
6
100
4
50
200
400
600
800
1000
1200
10
12
14
16
18
20
a =1
14
350
12
300
10
250
200
150
100
50
100
200
300
400
500
600
700
800
900
1000
10
12
14
16
18
20
a =1
350
300
10
250
200
150
5
100
50
200
400
600
800
1000
1200
10
12
14
16
18
20
180
25
a =1
160
b =1.1
140
20
120
15
100
60
40
5
20
200
400
600
800
1000
1200
10
15
20
25
30
35
40
180
30
a =1
160
b =1.1
25
140
120
20
100
15
10
60
40
5
20
100
200
300
400
500
600
700
800
900
1000
10
15
20
25
30
35
40
180
a =1
20
160
b =1.1
140
15
120
100
80
60
40
20
200
400
600
800
1000
1200
10
15
20
25
30
35
40