Sunteți pe pagina 1din 17

2014 Spring Semester EE505

Exp2 Week3
Queue Simulation
Final Report








Electrical Engineering
20143084
20143667
20143668






EE505 Exp2 Week3. Queue Simulation

I. Objective
It is possible to build a queuing model between arrival and departure of packets in a server or servers. An aforementioned
model can be explained by M/M/1 queuing model whose arrival and service rate have exponential distribution. Therefore, we
need to understand why this model is proper to describe its characteristics. And then examine thoroughly its attributes by
gathering and analyzing data in MATLAB.
II. Background
In order to comprehend the meaning of M/M/1 Queuing System, we need to understand following theories above all.
A. Kendalls Notation
Before starting the investigations of our simulation result let us introduce a notation originated by Kendall to describe a
queuing system.
Let us denote a system by
A / B / m / K / n/ D,
where
A: distribution function of the inter-arrival times,
B: distribution function of the service times,
m: number of servers,
K: capacity of the system, the maximum number of customers in the system including the one being serviced,
n: population size, number of sources of customers, D: service discipline.
Exponentially distributed random variables are notated by M, meaning Markovain or memoryless.
Furthermore, if the population size and the capacity are infinite, the service discipline is FIFO, and then they are omitted.
Hence M/M/1 denotes a system with Poisson arrivals, exponentially distributed service times and a single server. M/G/m
denotes an m-server system with Poisson arrivals and generally distributed service times. M/M/r/K/n stands for a system
where the customers arrive from a finite-source with n elements where they stay for an exponentially distributed time, the
service times are exponentially distributed, the service is carried out according to the requests arrival by r severs, and the
system capacity is K.
B. Poisson Process
The M/M/1 system is made of a Poisson arrival, one exponential (Poisson) server, FIFO (or not specified) queue of unlimited
capacity and unlimited customer population. Note that these assumptions are very strong, not satisfied for practical systems
(the worst assumption is the exponential distribution of service duration - hardly satisfied by real servers). Nevertheless the
M/M/1 model shows clearly the basic ideas and methods of Queuing Theory. Next two chapters summarize the basic
properties of the Poisson process and give derivation of the M/M/1 theoretical model.
Poisson Process
The Poisson process satisfies the following assumptions, where P[x] means "the probability of x":
1) P[one arrival in the time interval (, +), for 0] = h, where l is a constant.
2) P[more than one arrivals in the interval (, + ), for 0] 0.
3) The above probabilities do not depend on t ("no memory" property = time independence = stationarity).
EE505 Exp2 Week3. Queue Simulation
Let

() = P[n arrivals in the time interval (0, t)]. Using the above assumptions 1) and 2), it is possible to express the
probability

( + ), 0:

( + ) =

()[1 ] +
1
() ( n arrivals by t, no more arrival or n-1 arrivals by t, one more arrival)

0
( +) =
0
()[1 ] ( no arrival by t, no more arrival) (1)
The equations (1) may be written in this way:

(+)

()

() +
1
(),

(+)

()

=
0
() (2)
Because of small h the terms at the left sides of (2) may be considered as derivatives:

()

() +
1
(),

0
()

=
0
() (3)
Equations (3) represent a set of differential equations. To solve them lets start by p
0
(t):

() =

(to prove it, compute the derivative of p


0
(t) and compare with (3) )
Using p
0
(t) it is possible to compute p
1
(t):

1
() =

(prove by computing the derivative and inserting to (3) with p


0
(t) )
Or generally (can be proved by mathematical induction):

() =
()

(4)
Because of the assumption 3) the formula (4) holds for any interval (s, s+t), in other words the probability of n arrivals during
some time interval depends only on the length of this time interval (not on the starting time of the interval).
Number of arrivals

during some time interval is a discrete random variable associated with the Poisson process. Having
the probabilities of the random values - (4), it is possible to find the usual parameters of the random variable

. Let [] be
the mean (average) value of the random variable x:
[

] =

=0
()

()
1
( 1)!
=

=1
(5)


(5) gives the interpretation of the constant , that is the average number of arrivals per time unit. Thats why the is called
Arrival rate.
Another random variable associated with the Poisson process is the random interval between two adjacent arrivals. Let x be
the random interval. To find its distribution, lets express the Distribution function F(x):
()= P[interval < x] = P[at least one arrival during the interval x] = 1
0
() = 1



Because the interval is a continuous random variable, it is possible to compute the Probability density as a derivative of the
Distribution function:
() =
()


These two functions define the probability distribution:
() = 1

, () =

(6)
The distribution (6) is called Exponential Distribution. Its parameters are:
EE505 Exp2 Week3. Queue Simulation
[] =

=
1

0
(7)

(7) gives another interpretation of the constant .
C. Traffic ratio
Another very important parameter of queuing systems is the ratio of the arrival and the service rates called Utilization
factor.
=

(8)
The value of shows how "busy" is the server. It is obvious, that for > 1 the queue will grow permanently.

D. The System M/M/1
The M/M/1 system is made of a Poisson arrival (Arrival rate ), one exponential server (Service rate ), unlimited FIFO (or
not specified queue), and unlimited customer population. Because both arrival and service are Poisson processes, it is possible
to find probabilities of various states of the system, that are necessary to compute the required quantitative parameters. System
state is the number of customers in the system. It may be any nonnegative integer number.
Let

() = P[n customers in the system at time t]. Like with the Poisson process, by using the assumptions 1) and 2), it is
possible to express the probability

( + ) =

( + ), 0 in this way:

( + ) =

()[1 ][1 ] (n customers at t, no came, no left)

()[][] + (n customers at t, one came, one left)

1
()[][1 ] + (n-1 customers at t, one came, no left)

+1
()[1 ][] + (n+1 customers at t, no came, one left )

0
( +) =
0
()[1 ] + (no customer at t, no came)

1
()[1 ][] (one customer at t, no came, one left)
(9)
The above equations may be written in the following way, where the terms with
2

are omitted because they are relatively
very small ( 0):

( + )

()

= ( + )

() +
1
() +
+1
()

0
( + )
0
()

=
0
() +
1
() (10)
Because of small h the terms at the left sides of (10) may be considered as derivatives:

()

= ( + )

() +
1
() +
+1
()

0
()

=
0
() +
1
() (11)
Equations (11) represent a set of differential equations called Kolmogorov Differential Equations. Their solution is a set of
equations showing how each probability changes with time. Fortunately we actually do not need these functions. Because of
the third assumption (stationarity) after some transition period the system will become stable. Of course the state will
permanently change, but the probabilities of various numbers of customers in the system will be constant. So the functions

() become constants

. Constant functions have zero derivatives, so the set (11) becomes a set of algebraic equations for
Figure 1]The transition diagram of a birth/death pr
ocess looks like this diagram.
EE505 Exp2 Week3. Queue Simulation
the stable state:

+1
( +)

+
1
= 0
1

0
= 0 (12)
By dividing the equations (12) by we get this set of equations that contain the only parameter - the utilization factor:

In the set (15)
1
is expressed by
0
. By inserting
1
and
0
to the equation for
2
, we get:

2
= (1 +)
1

0
= (1 + )
0

0
=
2

0

Similarly
2
and
1
may by used to express
3
, etc. which gives the general formula for

0
= (

0
(13)
The value
0
can be computed by using the obvious requirement, that the sum of all probabilities must be equal to 1:

=
0

=
0
1
1

=0

=0
giving:
0
= 1 (14)
In (14) the sum of geometric progression has been used. From (14) it is also obvious that the utilization factor must be less
than 1, otherwise the sum of probabilities would not be 1 (not even limited). Inserting (14) to (13) gives the general formula
for

(1 ) = (

(1

) (15)
The equations (15) represent a very important result used later to obtain all the characteristics of the M/M/1 system. The
relatively simple derivation of (15) was enabled by the Poisson process assumptions used when expressing the probabilities in
(9). The equations (15) may be used directly to express these probabilities:
P[service idle] = P[not queuing on arrival] =
0
= 1 - = 1 - /
P[service busy] = P[queuing on arrival] = 1
0
= = /
P[n customers in the system] =

(1 )
P[n or more customers in the system] =


P[less than n customers in the system] = 1


The derivation of P[n or more customers in the system]:

(1 ) =
+
(1 ) =

(1 )

(1 )
1
1
=

=0

=0

=

Now the formula (15) will be used to derive quantitative characteristics of the M/M/1 system. (15) actually represents a
distribution of a discrete random variable Number of customers in the system (probabilities of all possible random values). So
it is possible to compute the mean value, that is the average number of customers in the system:

(1 ) = (

+1
) = 1(
2
) + 2(
2

3
) + 3(
3

4
) +

=0

=0

=0

= +
2
+
3
+
4
+ = (1 + +
2
+
3
+ )

1
(16)
In (16) the formula for geometric progression has been used. This formula gives us the information to compute average queue
EE505 Exp2 Week3. Queue Simulation
length for M/M/1 queuing system.

III. Result & analysis
A. Part1
We conducted the simulation of Queue with some fixed conditions that are described as followings.
Average Service Time :
1

= 1 second.
Customer Arrival Rate : =[0.5 0.9] arrival per second (with 0.1 interval).
Confidence Level = 1 = 0.95.
Number of simulation Runs = = 20
1. verse Average Queue length except the customers in service time













This overlap graph consists of simulation value and expected theoretical value graph. We can see former value as dot having
red color and latter value as line graph having blue color. In addition, the error bar graph shows the margin of error of
simulation value. We can see average queue length becoming large as increase. Its natural that this graph looks like
monotonically increasing. As we know, the value of is customer arrival rate. Namely, it means that the more value has,
the more customers arrive. Moreover, under the condition of fixed =1, the capacity of server cannot increase. Therefore,
these conditions have the average queue length drive to increase.
The theoretical value

written in lecture material on page 7 includes the customer in service. Therefore, an immediate
comparing

with average queue length is not meaningful. The theoretical average queue length can be derived from littles
result.
For an M/M/1 queue,

= /(1 ). The average of service time is


1

. (For exponential distribution, [] = 1/)


For any queuing system,

is the average number of customer in the system.


EE505 Exp2 Week3. Queue Simulation
is the average arrival rate of customers to the system.

is the average amount of time spent in the system by a customer.

= 1/,

) =

is the average of service time.


is the average waiting time.


is the average of queue length.


Therefore, we can compare the results derived from the simulation with calculated theoretical value by using

.
Meanwhile, we can define the margin of error as below.
Margin of error=
2


Because already knowing and degree of freedom, we can calculated
2
from the student T-distribution. In addition,
sample standard deviation also can be derived easily from the samples.
=

)
2
1

In case 20 simulation runs, the margin of error was measured as below table.


0.5 0.6 0.7 0.8 0.9
The margin of error 0.0479 0.1021 0.2138 0.5689 1.905

If the margin of error needs to be less then current value conducting, we should increase the number of simulation runs. When 30
more simulation conducting than before, we can see that the margin of error is less than 1.0.


0.5 0.6 0.7 0.8 0.9
The margin of error 0.0273 0.0471 0.1362 0.2944 0.9739

2. Time verse Queue size (Stair Graph) when = .










Figure 2] Queue size graph when = .
EE505 Exp2 Week3. Queue Simulation


This result simulated conditions taking = 0.75 and 50 departures. The graph shows the average queue length according to
time increasing. Though the theoretical average queue length is fixed, we can see that the shape is fluctuating in interval.
Moreover, the queue length does not diverge because utilization factor =

is less than 1.0


3. verse Average waiting time (both M/M/1 & M/D/1)


In order to compare measured values with thoeretical value, we need to find out the formula about averag
e waiting time in case M/M/1 and M/D/1 queue. These two formula can be easily derived from Littles Res
ult and Pollaczek-Khinchin formula.
For M/M/1 queue

1
)
For M/D/1 queue

1
2
2
)
The following table shows the theoretical value for each case from = 0.5 to = 0.9 with 0.1 interval.
0.5 0.6 0.7 0.8 0.9
M/M/1 queue 1.0000 1.5000 2.3333 4.0000 9.0000
M/D/1 queue 0.5000 0.7500 1.1667 2.0000 4.5000
Figure 4] M/D/1 Queue
Figure 3] M/M/1 Queue
EE505 Exp2 Week3. Queue Simulation
From above table, we can see the average waiting time value of M/D/1 queue
is less than that of M/M/1. Though these cases of average waiting time value
is same, the distribution of each case is entirely different. M/D/1 queue has
fixed service time, while M/M/1 queue has exponential distribution with
value. From the CDF of exponential distribution graph, we can comprehend
why these differences occurred. In case of = 0.8, the probability over 1
second is a quite considerable value. Therefore, the average waiting time of
M/D/1 queue is less than that of M/M/1 queue when average service time is
same.

IV. Demo Questions
A. Explain about Littles Result
The number in system

forms a stochastic process. Its


average value over a long period of time t can be calculated
by dividing the shaded area in the figure by the length of the
period .
On average, each customer contributes to the area by the amount

.
The average number of customers arriving in interval is .
The area is thus

= ()

= .
It is very straightforward result. As we know, we also can calculate average wait time by using this result and pollaczek-
khinchin formula.


B. Explain about M/M/K/K queuing system
Kendalls Notation for Queues
A/B/C/D/E
It is shorthand notation where A, B, C, D, E describe the queue and can be applicable to a large number of simple queuing
scenarios.
A: Inter-arrival time distribution
B: Service time distribution
C: Number of servers
D: Maximum number of jobs that can be there in the system (waiting and in service)
Default for infinite number of waiting positions
E: Queueing Discipline (FCFS, LCFS, SIRO etc.) Default is FCFS
Therefore, M/M/K/K means Inter-arrival time and service time distribution are exponential and the system has K servers and
finite waiting room for K customers.
Figure 5] The CDF of exponential distribution with = .
M: exponential
D: deterministic
E
k
:

Erlangian (order k)
G: general

EE505 Exp2 Week3. Queue Simulation

C. Explain about Memoryless Propery
In probability and statistics, memorylessness is a property of certain probability distributions: the exponential distributions of
non-negative real numbers and the geometric distributions of non-negative integers.
The memoryless property makes it easy to reason about the average behavior of exponentially distributed items in queuing
systems. Suppose were observing a stream of events with exponentially distributed inter-arrival times. Because of the
memoryless property, the expected time until the next event is always 1/, no matter how long weve been waiting for a new
arrival to occur.
This behavior is a bit counterintuitive. We might expect that arrivals get more likely the longer we wait. For example, if the
bus is supposed to come every ten minutes, and we have been waiting for nine minutes without seeing a bus, we expect that
the next bus should be along very soon. If the time between bus arrivals is exponentially distributed, however, the memoryless
property tells us that our waiting time no matter how long its been is of no use in predicting when the next bus will arrive.
Memory-less Property of the Exponential
An exponential random variable X has the property that the future is independent of the past"
i.e. the fact that it hasn't happened yet, tells us nothing about how much longer it will take before it does happen.
In mathematical terms
( > + | > ) = ( > ) , > 0
Proof:
( > + | > ) =
( > +, > )
( > )

=
( > +)
( > )
=

(+)

= ( > )
Memory-less Property of the Geometric
( = + | > )
=
( ( = + ) ( > ))
( > )
=
( = + )
( > )
=
(1 )
+1
(1 )
1
+1

(1 )
+1
(1 )

= (1 )
1

= ( = )
D. Explain about Show the relationship of waiting, system, and service time.



at(2)
EE505 Exp2 Week3. Queue Simulation

For M/M/1 queue, this system can deal with only one packet during service time because one server can accept one packet only.
If the server have been processing (n-1)th packet when n-th packet arrived, the n-th packet should wait for the service until (n-1)th
packet finish. Therefore, we can define the relation ship of waiting time, system, and service time as following forms.
() = max( ( 1) + (), () + () )
() = () ()
() = () ()



E. Explain about Class of service, Priority with two Queue and on server and How does it work?
For practical case, the weights of all packets are not same. Some kinds
of packets may need to be processed with higher priority than the others
above all. In order to handle these packets, the system has to the policy
describing which one is more important. For example, if there are two
kind of queue for video streaming packets and packets for file download,
the system should have higher priority to video packets for real time
communication than the other. Unless this policy ensure, the end-user
using this service may often suffer from bad quality of service. Moreover, the queue size of system is not infinity so we should
concern this characteristic when we design the system having queue. If the queue overflow occurs, we cannot recover the lost
packets. Therefore, we make sure when impending overflow, the queue nearly full of packets should be handled above
everything else.

F. Explain about Pollaczek-Khinchin Formula
In queuing theory, a discipline within the mathematical theory of probability, the PollaczekKhinchin formula states a
relationship between the queue length and service time distribution Laplace transforms for an M/G/1 queue (where jobs arrive
according to a Poisson process and have general service time distribution). The term is also used to refer to the relationships
between the mean queue length and mean waiting/service time in such a model.
For an M/G/1 queue, the average queue length is

= +
2
1 +

2
2(1 )

where =

that is called utilization and should be in under condition < 1 in order to prevent from growing
permanently.

the of the service time.


For an M/M/1 queue, the standard deviation

= 1 which can be easily calculated. We already know the formula of variance


and mean for exponential distribution: () =
1

2
, () =
1

(when the system has the average rate )


So, we can have these formula arranged neatly as following forms.
Figure 2] The system having two kinds of classes.
EE505 Exp2 Week3. Queue Simulation

=
1/
1/
= 1,

1

In similar manner again, we can also derive

for an M/D/1 queue case.


For an M/D/1 queue, the variance of service time is 0 because the service time is deterministic.

= 0,

1
2
2

As mentioned earlier, we can also derive the relation ship of waiting, system, and service time using this result and littles
result.



G. Explain about What is the meaning of the Event driven method in this experiment
For this experiment, the event driven method is preferred. Actually, there are two methods to get results. The one way, we
have to pick all of arrival and service time in advance. In this case, we need to check all of intervals whether packets are wait
for service or not. Moreover, we cannot help sampling for this interval because time is not countable. So, some terrible case in
which we miss change of queue length can happen when there are variations in short time interval that is small then sampling
time. The following graph shows the problem of sampling.









But, the other is an aforementioned way the event driven method. Under this way, the simulation of queue in matlab can be
working like actual queue in which the packets come in one by one. In this manner, we can easily calculate the relationship of
waiting, system and service time by just comparing latter packet with former packet. When current packet arrives but need to
wait for service, we just add 1 to the current queue length and also need to save this time when this variation happened.
Besides, we should subtract 1 from the queue length if that of length is over 0 whenever the service time of packets finish.
Eventually, we can plot the queue length graph like as [Figure 2] by using these collected data.

IV. References

http://en.wikipedia.org/wiki/Little's_law
Queue length is changing suddenly from 9 to 6.
The deviation of queue length must occur with increments of
1.
Figure 6] this graph shows a problem of sampling method.
EE505 Exp2 Week3. Queue Simulation
http://en.wikipedia.org/wiki/Memorylessness
http://pages.cs.wisc.edu/~dsmyers/cs547/
http://en.wikipedia.org/wiki/Pollaczek%E2%80%93Khinchine_formula
Sztrik, Dr. Jnos. Basic Queueing Theory . University of Debrecen, Faculty of Informatics.
http://www.mathcs.emory.edu/~cheung/Courses/558/Syllabus/00/queueing/birth-death.html





V. Appendix. Source Code
The followings are our source codes.
mm1.m Explanation
function [wait_time_avg, n_average, queue_average] = mm1(lambda, mu,
n_departures, display)
at(1) = -1/lambda * log(1- rand() );
st(1) = -1/mu * log(1-rand() );
ft(1) = at(1) + st(1);

last_pt=1;
u=2;
time = 0;
q_length = 0;

time_packet = [0 at(1)];
numofpacket = [0 1];

while(1)
at(u) = at(u-1) -1/lambda * log(1-rand());
st(u) = -1/mu * log(1-rand());
ft(u) = max( ft(u-1) + st(u), at(u) + st(u) );

if( at(u) > ft(last_pt) )
current_pt = last_pt;
while(1)
if(ft(current_pt) > at(u) )
last_pt = current_pt;
break;
end
time_packet(length(time_packet)+1) = ft(current_pt);
numofpacket(length(numofpacket)+1) =
max(numofpacket(length(numofpacket))-1,0);

time(length(time)+1) = ft(current_pt);
q_length(length(q_length)+1) =
max(q_length(length(q_length))-1,0);
current_pt = current_pt +1;
end
end

time_packet = [time_packet at(u)];
We had implement the queue as mm1
function. This function needs to some
parameters that are , , the number of
departure packets, and display value. Display
value determines whether a stair graph shows
or not.
We can get the sample value from the CDF of
exponential distribution.
In order to see the number of customers in this
system, we set the variables time_packet and
numofpacket. Each variable saves the number
of customers and arrival time of that. In last
part of this code, this variable can be used for
calculation of average customer length with
given interval.

ft(u) means the time at end of processing for
u-th packet. If the previous u-1 packet does
not yet finish, the u-th packet needs to wait for
next turn until server is ready to handle
packets. It can be easily implemented by using
max() matlab built-in function.
When u-th packet needs to wait for next its
own turn, the queue length should increase by
1. Moreover, if queue length is over 0, the
queue length needs to subtract by one per
every finish time of packets.




EE505 Exp2 Week3. Queue Simulation





numofpacket = [numofpacket numofpacket(length(numofpacket))+1];


if( at(u) < ft(u-1) )
time(length(time)+1) = at(u);
q_length(length(q_length)+1) = q_length(length(q_length)) + 1;
end

u = u+1;

if( u==n_departures + 1)
for p = last_pt:n_departures
time = [time ft(p)];
q_length = [q_length max(q_length(length(q_length))-1, 0)];
time_packet = [time_packet ft(p)];
numofpacket = [numofpacket ,
max(numofpacket(length(numofpacket))-1, 0)];
end
break;
end %if end

end

area_sum = 0;
for i=1:length(time)
if( i+1 <= length(time))
area_sum = area_sum + ( time(i+1)-time(i) ) * q_length(i);
end
end
queue_average = area_sum / time(length(time));

area_sum = 0;
for i=1:length(time_packet)
if( i+1 <= length(time_packet))
area_sum = area_sum + ( time_packet(i+1)-time_packet(i) ) *
numofpacket(i);
end
end
n_average = area_sum / time_packet(length(time_packet));

total_time = ft - at; % total time spent by each customer
wait_time = total_time - st; % time spent waiting before being served

wait_time_avg = sum(wait_time)/n_departures;

if( nargin == 4)
stairs(time, q_length);
xlabel('time');
ylabel('length of queue');
title(['length of queue with ', num2str(n_departures), ' departures']);
end

end






Because last packet is waiting for next arrival,
we need to some manipulation to solve this
problem. Just putting additional packet at last
time of finish packet, we can have this
problem solved.




In order to compute the average of queue
length, we set the variable declared as
area_sum which is used for summation one by
one. This result of summation divided by
interval time shows the average of queue
length.




We already know the relation ship of waiting,
system, and service time. From this, we can
compute these values of each packet.

If the number of input parameter is 4, the stair
graph related to the length of queue show up.

NOTE
If we need md1 queuing system, it can easily
implement by replacing service time function
with constant value.

EE505 Exp2 Week3. Queue Simulation









Below codes are used for mm1 function.
test1.m Explanation
EE505 Exp2 Week3. Queue Simulation
clear; close all; clc;
lambda = 0.5:0.1:0.9;
mu = 1;
n_departure = 1000;
n_samples = 20;

alpha = 1 - 0.95;
z_halfalpha = tinv(1-alpha/2,n_samples-1);
w_avg=[];
n_avg=[];
q_avg=[];
margin_of_err = [];
for j=1:length(lambda)
w_avg_temp = zeros(n_samples,1);
n_avg_temp = zeros(n_samples,1);
q_avg_temp = zeros(n_samples,1);
for i =1:n_samples
[wait_time_avg, n_length_avg, q_length_avg] = mm1(lambda(j), mu,
n_departure);
w_avg_temp(i) = wait_time_avg;
n_avg_temp(i) = n_length_avg;
q_avg_temp(i) = q_length_avg;
end



w_avg(j) = sum(w_avg_temp)/n_samples;
n_avg(j) = sum(n_avg_temp)/n_samples;
q_avg(j) = sum(q_avg_temp)/n_samples;

s_square = 0;
for i=1:n_samples
s_square = s_square + (q_avg_temp(i) - q_avg(j)).^2;
end
s_square = s_square / (n_samples -1);


margin_of_err(j) = z_halfalpha * sqrt(s_square)/sqrt(n_samples);
end

q_bar =[];
for i=1:length(lambda)
rho = lambda(i)/mu;
q_bar(i) = (rho/(1-rho)/lambda(i) - 1/mu).*lambda(i);
end

errorbar(lambda,q_avg,margin_of_err, 'r*');
hold on;
plot(lambda, q_bar);
legend('Simulation value','expected theoretical value');
xlabel('\lambda values');
ylabel('The number of waiting customers for service');
Clear previous data and figure.

In order to get
/2
, we can use student t-
distribution and degree of freedom.








From the results of mm1 queue, we can compute
the average length of queue.



At above line we already computed
/2
that is
used for margin of error.


We already know it can be possible to compute
average queue by using theories littles result and
pollaczek-khinchin formula. This arranged result
could be used to calculate theoretical values.
Plot the graph with error bar that displays margin of
error on same plane.



The following code is used for md1 function.
EE505 Exp2 Week3. Queue Simulation
test2.m Explanation
clear; close all; clc;
lambda = 0.5:0.1:0.9;
mu = 1;
n_departure = 1000;
n_samples = 20;

alpha = 1 - 0.95;
z_halfalpha = tinv(1-alpha/2,n_samples-1);
w_avg=[];
n_avg=[];
q_avg=[];
margin_of_err = [];
for j=1:length(lambda)
w_avg_temp = zeros(n_samples,1);
n_avg_temp = zeros(n_samples,1);
q_avg_temp = zeros(n_samples,1);
for i =1:n_samples
[wait_time_avg, n_length_avg, q_length_avg] = md1(lambda(j), mu,
n_departure);
w_avg_temp(i) = wait_time_avg;
n_avg_temp(i) = n_length_avg;
q_avg_temp(i) = q_length_avg;
end



w_avg(j) = sum(w_avg_temp)/n_samples;
n_avg(j) = sum(n_avg_temp)/n_samples;
q_avg(j) = sum(q_avg_temp)/n_samples;

s_square = 0;
for i=1:n_samples
s_square = s_square + (w_avg_temp(i) - w_avg(j)).^2;
end
s_square = s_square / (n_samples -1);


margin_of_err(j) = z_halfalpha * sqrt(s_square)/sqrt(n_samples);
end

average_wait_time =[];
for i=1:length(lambda)
rho = lambda(i)/mu;
average_wait_time(i) = (rho/(1-rho)*(2-rho)/2/lambda(i) - 1/mu);
end

errorbar(lambda,w_avg, margin_of_err,'r*');
hold on;
plot(lambda, average_wait_time);
legend('Simulation value','expected theoretical value');
xlabel('\lambda values');
ylabel('The number of waiting customers for service');

Clear previous data and figure.

In order to get
/2
, we can use student t-
distribution and degree of freedom.








From the results of mm1 queue, we can compute
the average length of queue.



At above line we already computed
/2
that is
used for margin of error.


We already know it can be possible to compute
average queue by using theories littles result and
pollaczek-khinchin formula. This arranged result
could be used to calculate theoretical values.
Plot the graph with error bar that displays margin
of error on same plane.

S-ar putea să vă placă și