









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lab report is for System Engineering course. It was submitted to Katyayani Yatindra at Bengal Engineering and Science University. It includes: Markov, Chain, Analysis, Priority, Distributed, Packets, Stochastic, Process, Utilization, Channel
Typology: Exercises
1 / 15
This page cannot be seen from the preview
Don't miss anything!










INTRODUCTION
A Markov analysis looks at a sequence of events, and analyzes the tendency of one event to
be followed by another. Using this analysis, you can generate a new sequence of random but
related events, which will look similar to the original. A Markov process is useful for
analyzing dependent random events - that is, events whose likelihood depends on what
happened last. It would not be a good way to model a coin flips, for example, since every
time you toss the coin, it has no memory of what happened before. The sequence of heads
and tails are not inter-related. They are independent events.
A Markov process is a stochastic process with the following properties:
The number of possible outcomes or states is finite. The outcome at any stage depends only on the outcome of the previous stage. The probabilities are constant over time.
Markov processes arise in probability and statistics in one of two ways. A stochastic process,
defined via a separate argument, may be shown mathematically to have the Markov property,
and as a consequence to have the properties that can be deduced from this for all Markov
processes. Alternately, in modeling a process, one may assume the process to be Markov, and
take this as the basis for a construction. In modeling terms, assuming that the Markov
property holds is one of a limited number of simple ways of introducing statistical
dependence into a model for a stochastic process in such a way that allows the strength of
dependence at different lags to decline as the lag increases.
Markov property is stated as state of the system at time t +1 depends only on the state of the
system at time t as shown below.
Theoretical Probabilities
Probability that the server is idle
( )
Probability that the server is busy
( )
MATLAB Simulations
λ μ P(0) P(1) Packets Blocked 1 1 0.4978 0.5022 4979 2 1 0.3286 0.6714 3281 3 2 0.3994 0.6006 3945 5 3 0.3694 0.6306 3777
LAB TASK 2
Consider the case of multiple servers; say 3 which are available to process the packets
arriving according to random processes. The arrival rate at each server is independent and is
described by Poisson distribution with rate ‘λ’ and departure rate from each server is
described by exponential distribution with rate ‘μ’. Find
Channel Utilization
Number of blocked requests
Probabilities of states of process i.e. P(0), P(1), P(2), P(3)
Theoretical Probabilities
( )
( ) ( )
( )
( ) ( )
( )
( )
( ) ( )
( )
( )
( ) ( )
, 0 , 1 , 2 , ,.
/!
/!
0
j s
k
j P (^) s
k
k
j
j
MATLAB Simulations
Total Arrivals = 1000
λ μ Theoretical Simulated Blocked
P(0) P(1) P(2) P(3) P(0) P(1) P(2) P(3) 1 1 0.3750 0.3750 0.1875 0.0625 0.3997 0.3555 0.1836 0.0611 64
2 1 0.1579 0.3158 0.3158 0.2105 0.1568 0.3123 0.3288 0.2021 186
clc clear all Tf = 1000; Lam= 2; mu = 1; % exponential distribution for interval spacing a = exprnd(Lam,1,Tf); block = 0; % exponential distribution for serving time Serv1 = exprnd(mu,1,Tf); Serv2 = exprnd(mu,1,Tf); Serv3 = exprnd(mu,1,Tf);
% servers intial and final points serv1_if = zeros(2,1); serv2_if = zeros(2,1); serv3_if = zeros(2,1);
% server is idle initially s_s = zeros(1,3); serv_tn = zeros(1,3); P_act = 0; % counter c = 1; % Total time Tt = 0; available = 0; while(c <= Tf)
% block if server is busy if(serv_tn(1) <= Tt) s_s(1) = 0; end if(serv_tn(2) <= Tt) s_s(2) = 0; end if(serv_tn(3) <= Tt) s_s(3) = 0; end
idles = 3 - sum(s_s); if(idles == 0) block = block +1; end if(idles > 0) use = zeros(1,3); while(sum(use) == 0) d = randi(3); if(s_s(d) == 0) use(d) = 1;
end end
if(use(1) == 1) % server is idle % pick serv time Si = Serv1(1,c); serv_tn(1) = Tt+Si; s_s(1) = 1; serv1_if = cat(2,serv1_if,[Tt;serv_tn(1)]); end if(use(2) == 1) % server is idle % pick serv time Si = Serv2(1,c); serv_tn(2) = Tt+Si; s_s(2) = 1; serv2_if = cat(2,serv2_if,[Tt;serv_tn(2)]);
end if(use(3) == 1) % server is idle % pick serv time Si = Serv3(1,c); serv_tn(3) = Tt+Si; s_s(3) = 1; serv3_if = cat(2,serv3_if,[Tt;serv_tn(3)]);
end
end Tt = Tt + a(1,c); c=c+1; end
% create time t = 0:0.001:Tt; serv1_channel = zeros(1,length(t)); % create server1 time span for j = 2:length(serv1_if) current_time = 0; for i = 1:length(t) if current_time >= serv1_if(1,j) && current_time <= serv1_if(2,j) serv1_channel(1,i) = 1; end current_time = t(i); end
end
serv2_channel = zeros(1,length(t)); % create server1 time span for j = 2:length(serv2_if) current_time = 0; for i = 1:length(t) if current_time >= serv2_if(1,j) && current_time <= serv2_if(2,j) serv2_channel(1,i) = 1; end current_time = t(i); end end serv3_channel = zeros(1,length(t));
for j = 2:length(serv3_if) current_time = 0; for i = 1:length(t) if current_time >= serv3_if(1,j) && current_time <= serv3_if(2,j) serv3_channel(1,i) = 1; end current_time = t(i); end end
P = zeros(1,4); for i = 1:length(t) index = serv1_channel(1,i)+serv2_channel(1,i)+ serv3_channel(1,i); P(index+1) = P(index+1)+1; end Prob = P/length(t) total = sum(Prob)
% intakes and outtakes block total_accept = length(serv1_if)+length(serv2_if)+leng th(serv3_if)- 3 Total_in = -3 + block + length(serv1_if)+length(serv2_if)+leng th(serv3_if)
% analytically ke = Lam/mu P_0 = 1/(1+ke + 0.5ke^2 + 1/6ke^3) P_1 = ke/(1+ke + 0.5ke^2 + 1/6ke^3) P_2 = 0.5ke^2/(1+ke + 0.5ke^2 + 1/6ke^3) P_3 = (1/6)ke^3/(1+ke + 0.5ke^2 + 1/6ke^3)
Flowchart for Case 1
Start
Generate exponentially distributed
arrivals at rate ‘λA’ and ‘λB’
Generate exponentially distributed
service time corresponding to each
arrival at rate μ
Take an arrival randomly from
stream A or B
Choose a random idle server and
process for service time
Check if any
server is free
Arrivals <total
arrivals
Calculate total forced terminations
end
No
Yes
No
Yes
Increment total time
Any server with
stream ‘B’
Terminate and process
stream from A
Yes
Block arrival
No
Flowchart for Case 2
Start
Generate exponentially distributed
arrivals at rate ‘λA’ and ‘λB’
Generate exponentially distributed
service time corresponding to each
arrival at rate μ
Take an arrival randomly from
stream A or B
Choose randomly an idle server or
terminate B process
Any server idle or having B stream
Arrivals <total
arrivals
Calculate total forced terminations
end
No
Yes
No
Yes
Increment total time
Block Arrival
Si = Serv(1,c); serv_tn(2) = Tt+Si; s_s(2) = 1; if(overcome==1) [m,n]=size(serv1_if); serv2_if(1,n) = Tt; serv2_if(2,n) = serv_tn(2); overcome=0; else serv2_if = cat(2,serv2_if,[Tt;serv_tn(2)]); end ar_st(2)=arrival_time; end if(use(3) == 1) % server is idle % pick serv time Si = Serv(1,c); serv_tn(3) = Tt+Si; s_s(3) = 1; if(overcome==1) [m,n]=size(serv3_if);
serv3_if(1,n) = Tt; serv3_if(2,n) = serv_tn(1); overcome=0; else serv3_if = cat(2,serv1_if,[Tt;serv_tn(3)]); end ar_st(3)=arrival_time; end
end arrival_time=randi(2); if(arrival_time==1) Tt = Tt + a(1,c); else Tt = Tt + b(1,c); end c=c+1; end overcome_number
Case 2:
Total number of arrivals = 1000
λA = 2, λB = 2, μA=1, μB=
Forced Terminations of B = 468
Code
clc clear all close all
Tf = 1000; Lam1=2; Lam2=2; Mu1=1; Mu2= % exponential distribution for interval spacing a = exprnd(Lam1,1,Tf); b = exprnd(Lam2,1,Tf); block = 0; % exponential distribution for serving time Serva = exprnd(Mu1,1,Tf); Servb = exprnd(Mu2,1,Tf);
% servers intial and final points serv1_if = zeros(2,1); serv2_if = zeros(2,1); serv3_if = zeros(2,1);
% server is idle initially
s_s = zeros(1,3); serv_tn = zeros(1,3); P_act = 0; % counter c = 1; % Total time Tt = 0; available = 0; arrival_time=1; ar_st=[2 2 2]; overcome=0; overcome_number=0; select_server=1; normal_arrival=1; while(c <= Tf)
% block if server is busy if(serv_tn(1) <= Tt) s_s(1) = 0; end if(serv_tn(2) <= Tt) s_s(2) = 0;
end if(serv_tn(3) <= Tt) s_s(3) = 0; end
idles = 3 - sum(s_s); if(idles == 0) if(arrival_time==2) block = block +1; else if(sum(ar_st)==3) block = block +1; else
while(ar_st(select_server)==1) select_server=randi(3); end overcome=1;
overcome_number=overcome_number+1; idles=idles+1; normal_arrival=0; s_s(select_server)=0; end end
end if(idles > 0) use = zeros(1,3); if(normal_arrival==1) while(sum(use) == 0) d = randi(3); if(s_s(d) == 0||ar_st(d)==2) use(d) = 1; if(ar_st(d)==2) overcome=1;
overcome_number=overcome_number+1; end end end else use(select_server)=1; normal_arrival=1; end
if(use(1) == 1) % server is idle % pick serv time Si = Serv(1,c); serv_tn(1) = Tt+Si; s_s(1) = 1; if(overcome==1) [m,n]=size(serv1_if); serv1_if(1,n) = Tt;
serv1_if(2,n) = serv_tn(1); overcome=0; else serv1_if = cat(2,serv1_if,[Tt;serv_tn(1)]); end ar_st(1)=arrival_time; end if(use(2) == 1) % server is idle % pick serv time Si = Serv(1,c); serv_tn(2) = Tt+Si; s_s(2) = 1; if(overcome==1) [m,n]=size(serv2_if); serv2_if(1,n) = Tt; serv2_if(2,n) = serv_tn(2); overcome=0; else serv2_if = cat(2,serv2_if,[Tt;serv_tn(2)]); end ar_st(2)=arrival_time; end if(use(3) == 1) % server is idle % pick serv time Si = Serv(1,c); serv_tn(3) = Tt+Si; s_s(3) = 1; if(overcome==1) [m,n]=size(serv3_if); serv3_if(1,n) = Tt; serv3_if(2,n) = serv_tn(1); overcome=0; else serv3_if = cat(2,serv1_if,[Tt;serv_tn(3)]); end ar_st(3)=arrival_time; end
end arrival_time=randi(2); if(arrival_time==1) Tt = Tt + a(1,c); else Tt = Tt + b(1,c); end c=c+1; end overcome_number