LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solveSingleBuffer.m
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.
4%
5% Original source: aoi-fluid toolbox
6% Copyright (c) 2020, Ozancan Dogan, Nail Akar, Eray Unsal Atay
7% BSD 2-Clause License
8%
9% Integrated into LINE solver for Age of Information analysis.
10
11% Inputs:
12% lambda : arrival rate
13% sigma,S : infitesimal generator and initial probability vector
14% of the service process
15% r : packet replacement probability
16% Outputs:
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
21
22l = size(S,2); % size of the service matrix
23nu = -S*ones(l,1);
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)
28Q = [S,nu,zeros(l,1);
29 zeros(1,l),-lambda,lambda;
30 zeros(1,l+2)];
31% construction of the drift matrix R in Eqn (16)
32R = eye(z);
33R(z-1,z-1) = -1;
34R(z,z) = -1;
35% Qtilde Construction in Eqn (16)
36Qtilde=[zeros(l,l+2);
37 lambda*sigma,-lambda,0;
38 sigma,0,-1];
39% Steady state distribution of MFQ
40e = ones(z,1);
41pik = e'/(Q+e*e');
42% construction of the orthogonal matrix P
43% in Line 2 of Alg. 1 with Schur Algorithm
44QR = Q/R;
45x_R = R*e;
46x_L = pik;
47A1 = QR+(x_R*x_L)/(x_L*x_R);
48[U,TT] = schur(A1);
49[P,~] = ordschur(U,TT,'rhp');
50% construction of the matrices A, H, and Qtildestar in Line 3 of Alg. 1
51Ae = P'*QR*P;
52A = Ae(a+1:z,a+1:z);
53H = P(1:z,a+1:z)';
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)
62c_0 = wait_d(1);
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);
66wait_g = n_1*wait_g;
67% Lemma 1
68Mdiag = -wait_A\wait_H;
69M = diag(Mdiag);
70B = M\wait_A*M;
71beta = wait_g*M;
72beta_0 = 1-sum(beta);
73psi = -B*ones(l,1);
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
78
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);
84 zeros(l,3*l+1),S,nu;
85 zeros(1,4*l+2)];
86% construction of the drift matrix R in Eqn (19)
87R = eye(z);
88R(z,z) = -1;
89% Qtilde Construction in Eqn (19)
90Qtilde = Q;
91Qtilde(z,1:l) = beta;
92Qtilde(z,l+1:2*l) = beta_0*sigma;
93Qtilde(z,z) = -1;
94% construction of the orthogonal matrix P in Line 2 of Alg. 1
95QR = Q/R;
96u1 = [ones(z-1,1);-1];
97u2 = [1;zeros(z-1,1)];
98u = u1-norm(u1,2)*u2;
99P = eye(z)-(2*(u)*(u'))/(u'*u);
100% construction of the matrices A, H, and Qtildestar in Line 3 of Alg. 1
101Ae = P'*(QR)*P;
102A = Ae(a+1:z,a+1:z);
103H = P(1:z,a+1:z)';
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')';
109g = Solution(1:b);
110d = Solution(b+1:z);
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;
117AoI_A = A;
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;
126PAoI_A = A;
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;
130end