You are on page 1of 11

2012

MS SYSTEMS ENGINEERING

Group (2):
Azmat Tanveer
Danish Nadeem
Faheem Ashraf
Fouwad Jamil Mir
Ghulam Mustafa

[ PREMPTIVE MARKOV
CHAIN ANALYSIS 1 ]
Lab Report

Premptive Markov chain analysis 1

TABLE OF CONTENTS
Markov process ............................................................................................................................................. 3
Task 1 ............................................................................................................................................................ 3
Theoretical Probability .............................................................................................................................. 3
Matlab Results .......................................................................................................................................... 3
Matlab Code.............................................................................................................................................. 3
FlowChart .................................................................................................................................................. 4
Task2 ............................................................................................................................................................. 5
Theoretical probability .............................................................................................................................. 5
Matlab results ........................................................................................................................................... 5
Matlab code .............................................................................................................................................. 5
Flowchart .................................................................................................................................................. 7
Task 3,Task4 .................................................................................................................................................. 8
Theoretical probability .............................................................................................................................. 8
Matlab results ........................................................................................................................................... 8
Matlab code .............................................................................................................................................. 8
Flowchart ................................................................................................................................................ 10

Premptive Markov chain analysis 1

MARKOV PROCESS
In probability theory and statistics, a Markov process, named after the Russian mathematician
Andrey Markov, is a time-varying random phenomenon for which a specific property (the Markov
property) holds. In a common description, a stochastic process with the Markov property, or
memorylessness, is one for which conditional on the present state of the system, its future and past
are independent.

TASK 1
Given a single server, determine the probability the server remains busy.
Assume the packet arrival time is distributed by Poisson Distribution and service time is
distributed by Exponential Distribution.
THEORETICAL PROBABILITY
( )
for =5 and =15 ,P(1)=0.25
( )
=5 and =15 ,P(0)=0.75
MATLAB RESULTS
p_1 =0.2605
p_0 =0.7395
MATLAB CODE
clear all
clc
lambda=5;
A=exprnd(lambda,1,5001);
P(1)=A(1);
for i=2:5001 P(i)=A(i)+P(i-1);%Poisson dist from exp
end
arrival=P;
%inter arrival time
service=exprnd(15,1,5000);
%exponential distribution
[l m]=size(arrival);

Premptive Markov chain analysis 1


n=0;
for i=1:m-1
A=arrival(i)+service(i);
if A<(arrival(i+1));
n=n+1;
end
end
p_1=n/m
p_0=1-p_1

FLOWCHART

Premptive Markov chain analysis 1

TASK2
If 4 number of servers are available, and packets arrive through a single channel, what is
the probability 4 number of servers remain busy simultaneously.
THEORETICAL PROBABILITY
theoretical probability for multiple servers with single stream of packets is found by formula

j / j!
Pj s
,
k
/ k!

j 0, 1, 2, , s .

k 0

=5 and =5

P(0)=0.369, P(1)=0.369, P(2)=0.1845, P(3)= 0.0615

MATLAB RESULTS
p0 =0.3440
p1 = 0.3840
p2 =0.1940
p3 =0.0540

MATLAB CODE
clear all
close all
clc
lambda=5;
A=exprnd(lambda,1,500);
P(1)=A(1);
for i=2:50
P(i)=A(i)+P(i-1); %Poisson dist from exp
end
arrival=P;
service=exprnd(5,1,500);
[l m]=size(arrival);
%% initialization
%first element=arrival time
%2nd element=service time
%3rd element=busy
S1=[arrival(1) service(1) 1];
S2=zeros(1,3);
S3=zeros(1,3);
S4=zeros(1,3);
sum=1;
%number of server busy( sum of flags of servers)
n1=0;
n2=0;

Premptive Markov chain analysis 1


n3=0;
n4=0;
b=0
%% Execution
for i=2:m-1
t=arrival(i)+service(i-1);
if S1(3)==1
if (S1(1)+S1(2))<arrival(i)
S1(3)=0;
disp('S1 is free')
end
end
if S2(3)==1
if (S2(1)+S2(2))<arrival(i)
S2(3)=0;
disp('S2 is free')
end
end
if S3(3)==1
if (S3(1)+S3(2))<arrival(i)
S3(3)=0;
disp('S3 is free')
end
end
if S4(3)==1
if (S4(1)+S4(2))<arrival(i)
S4(3)=0;
disp('S4 is free')
end
end
sum=S1(3)+S2(3)+S3(3)+S4(3);
if sum==3
n1=n1+1;
elseif sum==2
n2=n2+1;
elseif sum==1
n3=n3+1;
elseif sum==0
n4=n4+1;
end
%% Assigning data to free server
D=[S1(3) S2(3) S3(3) S4(3)];
j=find(D==0);
if ((isempty(j)))
disp('all server are busy')
b=b+1;
elseif j(1)==1
S1(1)=arrival(i);
S1(2)=service(i);
S1(3)=1;
disp('S1 is bze')
elseif j(1)==2
S2(1)=arrival(i);
S2(2)=service(i);
S2(3)=1;
disp('S2 is bze')
elseif j(1)==3
S3(1)=arrival(i);
S3(2)=service(i);
S3(3)=1;
disp('S3 is bze')
elseif j(1)==4
S4(1)=arrival(i);
S4(2)=service(i);
S4(3)=1;
disp('S4 is bze')
end

Premptive Markov chain analysis 1


end
%% diplaying Probability
p0=n4/m
p1=n3/m
p2=n2/m
p3=n1/m

FLOWCHART

Premptive Markov chain analysis 1


TASK 3,TASK4
Suppose, 3 number of servers are available, and packets arrive through two channels,
channel A and channel B, with packets from B given a higher priority. What is the
probability that packets from channel A are
i.
ii.

blocked due to unavailability of servers?


forced terminated due to preemption?
THEORETICAL PROBABILITY

The calculations are done by following formulas

MATLAB RESULTS
prem = 0
true =0

MATLAB CODE
clear all
close all
clc
lambda1=5;
a=exprnd(lambda1,1,10000);
P(1)=a(1);
for i=2:10000
P(i)=a(i)+P(i-1);%Poisson dist from exp
end
arrival1=P;
A=exprnd(5,1,10000);
lambda2=5;
a1=exprnd(lambda2,1,10000);
P2(1)=a1(1);
for i=2:10000
P2(i)=a1(i)+P2(i-1);%Poisson dist from exp
end
arrival2=P2;
B=exprnd(5,1,5000);
[l m]=size(A);
% A has higher priority than B
%%% 1st element arrival
%%% 2nd element service time

Premptive Markov chain analysis 1


%%% 3rd element flag 1 for A, 2 for B & 0 for free
S1=[0 0 0 ];
S2=[0 0 0 ];
S3=[0 0 0 ];
Arrival=[0 0];
block=0;kickout=0;
%%% A has higher priority while B has lower priority
for i=1:1:m
if arrival1(i)>arrival2(i)
Arrival(1)=arrival2(i); %assignment of time which is less
Arrival(2)=2;
else
Arrival=arrival1(i);
Arrival(2)=1;
end
if (S1(3)~=0)
if Arrival(1)<(S1(1)+S1(2))
S1(3)=0;
end
end
if (S2(3)~=0)
if Arrival(1)<(S2(1)+S2(2))
S2(3)=0;
end
end
if (S3(3)~=0)
if Arrival(1)<(S3(1)+S3(2))
S3(3)=0;
end
end
D=[S1(3) S2(3) S3(3)];
j=find(D==0);
if (S1(3)==1 && S2(3)==1 && S3(3)==1) %if all server having data from A
disp('all server have data from A');
block=block+1;
elseif(isempty(j)) %if no server is busy
j1=find(D==2);
if(isempty(j))
elseif j(1)==1 %%checking for the server with data from B for
kickout
S1(1)=Arrival(1);
kickout=kickout+1;
if Arrival(2)==1
S1(2)=A(i);
S1(3)=1;
else
S1(2)=B(i);
S1(3)=2;
end
elseif j(1)==2
S2(1)=Arrival(1);
kickout=kickout+1;
if Arrival(2)==1
S2(2)=A(i);
S2(3)=1;

Premptive Markov chain analysis 1


else
S2(2)=B(i);
S2(3)=2;
end
elseif j(1)==3
S3(1)=Arrival(1);
kickout=kickout+1;
if Arrival(2)==1
S3(2)=A(i);
S2(3)=1;
else
S3(2)=B(i);
S3(3)=2;
end
end
elseif j(1)==1
S1(1)=Arrival(1);
if Arrival(2)==1
S1(2)=A(i);
S1(3)=1;
else
S1(2)=B(i);
S1(3)=2;
end
elseif j(1)==2
S2(1)=Arrival(1);
if Arrival(2)==1
S2(2)=A(i);
S2(3)=1;
else
S2(2)=B(i);
S2(3)=2;
end
elseif j(1)==3
S3(1)=Arrival(1);
if Arrival(2)==1
S3(2)=A(i);
S2(3)=1;
else
S3(2)=B(i);
S3(3)=2;
end
end
end
prem=kickout/m
true=kickout/(m-block)

FLOWCHART

10

Premptive Markov chain analysis 1

11

You might also like