1function [AoI_g,AoI_A,AoI_h,AoI_mean,AoI_var,PAoI_g,PAoI_A,PAoI_h,PAoI_mean,PAoI_var] = solveSingleBuffer(lambda,sigma,S,r)
2% solveSingleBuffer calculates parameters
for the distributions of AoI and
3% pAoI and their first and second moments with the means of MFQ
for single buffer systems.
5% Original source: aoi-fluid toolbox
6% Copyright (c) 2020, Ozancan Dogan, Nail Akar, Eray Unsal Atay
9% Integrated into LINE solver
for Age of Information analysis.
12% lambda : arrival rate
13% sigma,S : infitesimal generator and initial probability vector
14% of the service process
15% r : packet replacement probability
17% AoI_g,AoI_A,AoI_h : matrix exponential parameters of AoI
18% PAoI_g,PAoI_A,PAoI_h : matrix exponential parameters of pAoI
19% AoI_mean,AoI_var : mean and variance of AoI
20% PAoI_mean,PAoI_var : mean and variance of pAoI
22l = size(S,2); % size of the service matrix
24z = l+2; % z
is the system size of waiting matrix
25a = 2; % a
is the number of negative drift states
26b = l; % b
is the number of positive drift states
27% construction of the matrix Q in Eqn (16)
29 zeros(1,l),-lambda,lambda;
31% construction of the drift matrix R in Eqn (16)
35% Qtilde Construction in Eqn (16)
37 lambda*sigma,-lambda,0;
39% Steady state distribution of MFQ
42% construction of the orthogonal matrix
P
43% in Line 2 of Alg. 1 with Schur Algorithm
47A1 = QR+(x_R*x_L)/(x_L*x_R);
49[
P,~] = ordschur(U,TT,'rhp');
50% construction of the matrices A, H, and Qtildestar in Line 3 of Alg. 1
54Qtildestar = Qtilde(b+1:z,1:z);
55%solve for the vectors g and d in Line 4 of Alg. 1
56EqnMatrix = [H*R,-inv(A)*H*ones(z,1);-Qtildestar ones(a,1)];
57RightHandSide = [zeros(1,z) 1];
58Solution = mldivide(EqnMatrix',RightHandSide')';
59wait_g = Solution(1:b);
60wait_d = Solution(b+1:z);
61% We now have the ME representation in Eqn (8) for the MFQ X(t)
63wait_A = A-r*lambda*eye(l);
64wait_H = H*[zeros(l,1);1;r];
65n_1 = 1/(-wait_g/wait_A*wait_H + c_0);
68Mdiag = -wait_A\wait_H;
74% construction of the matrix Q in Eqn (19)
75z = 4*l+2; % z
is the system size
76a = 1; % a
is the number of negative drift states
77b = z-1; % b
is the number of positive drift states
79% construction of the matrix Q in Eqn (19)
80Q = [B,kron(psi,sigma),zeros(l,2*l+2);
81 zeros(l,l),S-lambda*eye(l),lambda*eye(l),nu,zeros(l,l+1);
82 zeros(l,2*l),S,zeros(l,1),kron(nu,sigma),zeros(l,1);
83 zeros(1,3*l),-lambda,lambda*sigma,zeros(1,1);
86% construction of the drift matrix R in Eqn (19)
89% Qtilde Construction in Eqn (19)
92Qtilde(z,l+1:2*l) = beta_0*sigma;
94% construction of the orthogonal matrix
P in Line 2 of Alg. 1
99P = eye(z)-(2*(u)*(u'))/(u'*u);
100% construction of the matrices A, H, and Qtildestar in Line 3 of Alg. 1
104Qtildestar = Qtilde(b+1:z,1:z);
105%solve for the vectors g and d in Line 4 of Alg. 1
106EqnMatrix = [H*R,-inv(A)*H*ones(z,1);-Qtildestar ones(a,1)];
107RightHandSide = [zeros(1,z) 1];
108Solution = mldivide(EqnMatrix',RightHandSide')';
111% We now have the ME representation in Eqn (8) for the MFQ X(t)
112% For AoI, restrict to states in Phases 4 and 5 only
113SelectedStates = [zeros(3*l,1);ones(l+1,1);0];
114AoI_h = H*SelectedStates;
115NormConstant = -g/A*AoI_h;
116AoI_g = g/NormConstant;
118% now we have the general form in Eqn (4)for the AoI distribution
119AoI_mean = AoI_g/(AoI_A^2)*AoI_h; % the moment expressions in Eqn (4)
120AoI_var = -2*AoI_g/(AoI_A^3)*AoI_h-AoI_mean^2;
121% For PAoI, restrict to states in Phase 5 scaled suitably by the entries of nu
122SelectedStates = [zeros(3*l+1,1);nu;0];
123PAoI_h = H*SelectedStates;
124NormConstant = -g/A*PAoI_h;
125PAoI_g = g/NormConstant;
127% now we have the general form in Eqn (4)for the AoI distribution
128PAoI_mean = PAoI_g/(PAoI_A^2)*PAoI_h; % the moment expressions again in Eqn (4)
129PAoI_var = -2*PAoI_g/(PAoI_A^3)*PAoI_h-PAoI_mean^2;