Markov Chain-System Engineering-Lab Report, Exercises of Systems Engineering

This lab report is for System Engineering course. It was submitted to Katyayani Yatindra at Bengal Engineering and Science University. It includes: Markov, Chain, System, Transitions, Memorylessness, Algorithm, Server, Packets, Random, Variable

Typology: Exercises

2011/2012

Uploaded on 07/17/2012

gaggandeep
gaggandeep 🇮🇳

4.6

(40)

100 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
2
Markov Chain:
A Markov chain, named after Andrey Markov, is a mathematical system that undergoes transitions
from one state to another, between a finite or countable number of possible states. It is a random
process characterized as memoryless: the next state depends only on the current state and not on
the sequence of events that preceded it. This specific kind of "memorylessness" is called the Markov
property. Markov chains have many applications as statistical models of real-world processes.
Task 1:
Consider a case of single server, take average packet arrival rate as and average processing rate as
, then finds the probability the server will be utilized (processing the packets) and the probability
the server will be free. Also find the number of packets being blocked.
Algorithm:
Generate exponential random variable for average packet arrival rate
Generate another exponential random variable for average processing rate.
Generate the time at which the packets will arrive from the packet arrival rate
At each time a packet is arrived
o Check if the server is busy then
the packet is blocked
Increment the number of packets being blocked
o If the server is free then
assign the packet to the server
Add the current packet time to time for which server is being used
Probability for which the server is used is found by dividing the time for which server is used
by total time.
Results:
N=10,000
P(0) : Probability that the server will be free
P(1) : Probability that the server will be busy
lamda
mu
P(0)
P(1)
Packets Blocked
(out of 10,000)
1
1
0.5062
0.4938
4992
2
1
0.3312
0.6687
6621
1
2
0.6698
0.3302
3315
Code:
N=10000;
lambda=1;
mu=2;
s=exprnd(1/lambda,[1 N]);
a=exprnd(1/mu,[1 N+1]);
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Markov Chain-System Engineering-Lab Report and more Exercises Systems Engineering in PDF only on Docsity!

Markov Chain:

A Markov chain, named after Andrey Markov, is a mathematical system that undergoes transitions

from one state to another, between a finite or countable number of possible states. It is a random

process characterized as memoryless: the next state depends only on the current state and not on

the sequence of events that preceded it. This specific kind of "memorylessness" is called the Markov

property. Markov chains have many applications as statistical models of real-world processes.

Task 1:

Consider a case of single server, take average packet arrival rate as and average processing rate as

, then finds the probability the server will be utilized (processing the packets) and the probability

the server will be free. Also find the number of packets being blocked.

Algorithm:

 Generate exponential random variable for average packet arrival rate

 Generate another exponential random variable for average processing rate.

 Generate the time at which the packets will arrive from the packet arrival rate

 At each time a packet is arrived

o Check if the server is busy then

 the packet is blocked

 Increment the number of packets being blocked

o If the server is free then

 assign the packet to the server

 Add the current packet time to time for which server is being used

 Probability for which the server is used is found by dividing the time for which server is used

by total time.

Results:

N=10,

P(0) : Probability that the server will be free

P(1) : Probability that the server will be busy

lamda mu P(0) P(1) Packets Blocked

(out of 10,000)

Code:

N=10000;

lambda=1; mu=2; s=exprnd(1/lambda,[1 N]); a=exprnd(1/mu,[1 N+1]);

t(1)=0; for i=1:N t(i+1)=t(i)+s(i); end packet=0; block=0; sertime=a(1); inittime=t(1); P(1)=0; for i=1:N if inittime+sertime > t(i+1) block=block+1; if i==N totaltime=inittime+sertime; end end if inittime+sertime < t(i+1) P(1)=P(1)+sertime; sertime=a(i+1); inittime=t(i+1); if i==N totaltime=t(i+1)+a(i+1); end end end P(1)=P(1)/(totaltime); P(2)=1-P(1) block

Task2:

In this case take multiple servers (e.g. 3) , when a packet is arrived it is assigned randomly to any free

server. If none of the server is free then the packet is blocked, find the probability P(k) where k is

the no of busy servers.

Algorithm:

 Generate exponential random variable for average packet arrival rate

 Generate another exponential random variable for average processing rate.

 Generate the time at which the packets will arrive from the packet arrival rate

 At each time a packet is arrived

o Check how many servers are busy

o If one or more servers are free then

 Assign the packet to any of the free server

o If all the servers are busy then

 Packet is blocked

else itime(k)=t(i); stime(k)=a(i); serocc(k)=2; end end end for k=1:totalservers if serocc(k)==1 || serocc(k)== if itime(k)+stime(k) < t(i+1) time(k)=itime(k)+stime(k); itime(k)=0; stime(k)=0; serocc(k)=0; ts=[ts;time(k)]; else tg=tg+1; serocc(k)=1; end end end pmin=-min(ts(1:length(ts))); q=0; tpr=t(i); if length(ts) > 0 for k=1:length(ts) P(length(ts)+tg-q)=P(length(ts)+tg-q)+nmin-pmin-tpr; tpr=0; if ts(k) > min(ts(k:length(ts))) temp=ts(k); for qa=k:length(ts) if ts(qa)==min(ts(k:length(ts))) break; end end ts(k)=ts(qa); ts(qa)=temp; end nmin=min(ts(k+1:length(ts))); q=q+1; pmin=min(ts(k:length(ts))); end end if length(ts)==0 && tg > 0 P(length(ts)+tg-q)=P(length(ts)+tg-q)+t(i+1)-t(i); elseif length(ts)==q && tg> P(length(ts)+tg-q)=P(length(ts)+tg-q)+t(i+1)-max(ts); end end P=P/(t(N+1)); sum=0; for i=totalservers+1:-1: P(i)=P(i-1) ; sum=sum+P(i); end P(1)=1-sum; P

Task3:

In this case we have multiple servers but two types of packets are arriving, type A and type B. Type B

packet has higher priority than the packet A. We have to find the perception probability, actual

probability, no of packets blocked and the no of packets terminated.

Algorithm:

 Generate exponential random variable for average packet arrival rate named sA.

 Generate another exponential random variable for average packet arrival rate named sB.

 Generate exponential random variable for average processing rate for packet A.

 Generate another exponential random variable for average processing rate for packet B.

 Generate the time at which the packets will arrive from the packet arrival rate of both the

packets

 At each time a packet is arrived

o Check if the packet arrived is packet A then

 Check whether there is a free server or not

 If a free server is found then

 Packet A is assigned to that free server

 If all the servers are busy then

 Packet is blocked

o If the packet arrived is packet B then

 Check whether there is a free server or not

 If a free server is found

 Packet B is assigned to that free server

 If all the servers are busy then

 Check whether any of the server is processing packet A

 If any of the server is processing packet A

o Assign Packet B to that server

o Packet A is terminated

 If all the servers are processing packet B then

o Packet B is blocked

 Perception probability is found by dividing the packets terminated by total packets

 Actual probability is found by dividing the packets terminated by the difference between the

total packets and the packets being blocked.

Note:

The objective was achieved in two different ways

1) Packets were assigned arbitrarily to the servers

2) packetA was assigned to the server from one side while packetB was assigned from the

other side

Results:

These results are for the following data

N=9999 , A = A = B = B = 1 , no of servers =

Then

Case 1:

 Perception probability = 0.

a(i)=aB(iB); iB=iB+1; packet(i)=2; end end if iA == N+ if iB < N+ t(i)=tB(iB); iB=iB+1; end elseif iB == N+ if iA < N+ t(i)=tA(iA); iA=iA+1; end end end block=0; terminate=0; for i=1:(2*(N+1)) if packet(i) == 1 busy=0; for k=1:totalservers if ptype(k) == 0 ptype(k)=1; itime(k)=t(i); stime(k)=a(i); busy=1; break; end end if busy == 0 block=block+1; end elseif packet(i) == 2 busy=0; for k=1:totalservers if ptype(k) == 0 ptype(k)=2; itime(k)=t(i); stime(k)=a(i); busy=1; break; end end if busy == 0 for k=1:totalservers if ptype(k) == 1 ptype(k)=2; itime(k)=t(i); stime(k)=a(i); busy=2; break; end end end

if busy == 0 block=block+1; elseif busy == 2 terminate=terminate+1; end end for k=1:totalservers if i < (2(N+1)) if itime(k)+stime(k) < t(i+1) ptype(k)=0; end else ptype(k)=0; end end end perception=terminate/(2(N+1)) actual=terminate/((2*(N+1))-block) block terminate

Task4:

In this case we have multiple servers but two types of packets are arriving, type A and type B. Type B

packet has higher priority than the packet A. We have to find the average packet length for the

packet A.

Code:

totalservers=3; itime=zeros(1,totalservers); stime=zeros(1,totalservers); ptype=zeros(1,totalservers); lambdaA=1; muA=1; lambdaB=1; muB=1; N=9999; sA=exprnd(1/lambdaA,[1 N]); sB=exprnd(1/lambdaB,[1 N]); aA=exprnd(1/muA,[1 N+1]); aB=exprnd(1/muB,[1 N+1]); tA(1)=0; tB(1)=.1; for i=1:N tA(i+1)=tA(i)+sA(i);

for k=1:totalservers if ptype(k) == 0 ptype(k)=2; itime(k)=t(i); stime(k)=a(i); busy=1; break; end end if busy == 0 for k=1:totalservers if ptype(k) == 1 ptype(k)=2; itime(k)=t(i); stime(k)=a(i); busy=2; break; end end end if busy == 0 block=block+1; elseif busy == 2 terminate=terminate+1; end end for k=1:totalservers if i < (2(N+1)) if itime(k)+stime(k) < t(i+1) if ptype(k) == 1 timeA=[timeA;stime(k)]; end ptype(k)=0; end else ptype(k)=0; end end end perception=terminate/(2(N+1)); actual=terminate/((2(N+1))-block); A_packets_blocked=block-terminate A_packets_terminated=terminate A_packets_serviced=sum(timeA)/(t(-1+2(N+1))) Average_packet_length_A=sum(timeA)/(N-terminate+1) hist(sA,100) title('actual distribution of A') figure hist(timeA,100) title('distribution of packet A which were served')

prob = (N+1-terminate-block)/(N+1-block) Results:

 A_packets_blocked =

 A_packets_terminated =

 A_packets_serviced =0.

 Average_packet_length_A =0.

 prob =0.