LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MG1_qlen_ETAQA.m
1function qlen=MG1_qlen_ETAQA(B,A,pi,n,varargin)
2%MG1_qlen_ETAQA returns the n-th moment of queue length of a
3%M/G/1 process using the ETAQA method [Riska, Smirni]
4%
5%
6% Usage:
7% qlen=MG1_qlen_ETAQA(B,A,pi,n) computes the n-th
8% moment of an M/G/1-type Markov chain with an
9% infinitesimal generator matrix of the form
10%
11% B0 B1 B2 B3 B4 ...
12% A0 A1 A2 A3 A4 ...
13% Q = 0 A0 A1 A2 A3 ...
14% 0 0 A0 A1 A3 ...
15% ...
16%
17% the input matrix A = [A0 A1 ... Aamax] and B = [B0 B1
18% B2 ... Bbmax], pi is the aggregated probability computed from ETAQA
19% method
20%
21% pi=MG1_qlen_ETAQA([],A,pi,n) computes the stationary
22% vector of an M/G/1-type Markov chain with an
23% infinitesimal generator matrix of the form
24%
25% A0 A1 A2 A3 A4 ...
26% A0 A1 A2 A3 A4 ...
27% Q = 0 A0 A1 A2 A3 ...
28% 0 0 A0 A1 A2 ...
29% ...
30%
31% Optional Parameters:
32%
33% Boundary: Allows solving the MG1 type Markov chain
34% with a more general boundary:
35% B0 B1 B2 B3 B4 ...
36% C0 A1 A2 A3 A4 ...
37% Q= 0 A0 A1 A2 A3 ...
38% 0 0 A0 A1 A2 ...
39% ...
40% the parameter value contains the matrix C0.
41% The matrices C0 and B1,B2,... need not to be
42% square. (default: C0=A0)
43%
44
45OptionNames = ['Boundary '];
46OptionTypes = ['numeric'];
47OptionValues = [];
48
49options=[];
50for i=1:size(OptionNames,1)
51 options.(deblank(OptionNames(i,:)))=[];
52end
53
54% Parse Optional Parameters
55options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
56
57% Sanity Checks
58m=size(A,1); % number of states for the repetitive structure
59dega=size(A,2)/m-1; % amax, # of A blocks - 1
60
61if (isempty(B))
62 mb=m; % number boudary states
63 degb=dega; % bmax
64 B=A;
65else
66 mb=size(B,1);
67 if (mod(size(B,2)-mb,m) ~= 0)
68 error('Matrix B has an incorrect number of columns');
69 end
70 degb = (size(B,2)-mb)/m; % bmax
71end
72
73if (isempty(options.Boundary))
74 C0 = A(:,1:m);
75else
76 C0 = options.Boundary;
77end
78
79if (isempty(options.Boundary) & mb ~= m)
80 error('The Boundary option must be used since the column size of B0 is not identical to A0');
81end
82
83if (~isempty(options.Boundary))
84 if (size(options.Boundary,1) ~= m | size(options.Boundary,2) ~= mb)
85 error('The boundary parameter value has an incorrect dimension');
86 end
87end
88
89if ( abs(sum(pi,2)-1) > 1e-10 )
90 error('The input probability vector does not sum up to 1');
91end
92
93if ( mod(size(pi,2)-mb,m) ~=0 )
94 error('Matlab:MG1_qlen_ETAQA:IncorrectDimension',...
95 'The probability vector has an incorrect number of columns');
96end
97pi0 = pi(:,1:mb);
98pi1 = pi(:,mb+1:mb+m);
99pistar = pi(:,mb+m+1:mb+2*m);
100
101
102% Provide the linear system r[k]*[(A0+A1+A2+...),(A(2)+2A(3)+3A(4)+...)*e]=[b[k],c[k]];
103% b[k] = - fhat(k) - f(k) - sum_l=(1 to k) binomial(k,l)*r[k-l]*(A1+sum_j=1 (j+1)^l*A(j+1))
104% c[k] = - fchat(k) - fc(k) - sum_l=1,k binomial(k,l)*r[k-l]*sum_j=1 j^l F(0,j)*e
105Asum = A(:,1:m);
106for i = 1:dega
107 Asum = Asum + A(:,i*m+1:(i+1)*m);
108end
109F11 = A(:,2*m+1:3*m);
110for i = 3:dega
111 F11=F11+(i-1)*A(:,i*m+1:(i+1)*m);
112end
113Asum = Asum(:,1:end-1);
114lsleft = [Asum,(F11-A(:,1:m))*ones(m,1)];
115
116
117
118% Fhat0(j) = sum_l=j B(l), j>=1
119Fhat0j=B(:,mb+(degb-1)*m+1:end);
120for j = degb-1:-1:1
121 temp = B(:,mb+(j-1)*m+1:mb+j*m) + Fhat0j(:,1:m);
122 Fhat0j = [temp,Fhat0j];
123end
124
125% F0(j) = sum_l=j A(l+1), j>=1
126F0j = A(:,dega*m+1:end);
127for j = dega-1:-1:2
128 temp = A(:,j*m+1:(j+1)*m) + F0j(:,1:m);
129 F0j = [temp,F0j];
130end
131
132r = pistar;
133
134% preparation for compute the repetitive part in the righthand side of the equation
135% frestsaver and fckrestsaver are the components reusable
136% frestsaver(l) = sum_j=1 (j+1)^l*A(j+1), l = 1:n
137% fckrestsaver(l) = sum_j=1 j^l*F0j(j), l = 1:n
138frestsaver = {};
139fcrestsaver = {};
140for l = 1:n
141 temp = zeros(m,m);
142 for j = 2:dega
143 temp = temp + j^l*A(:,j*m+1:(j+1)*m);
144 end
145 frestsaver{end+1} = temp;
146 temp = zeros(m,m);
147 for j = 1:dega
148 if (j <= size(F0j,2)/m)
149 temp = temp + j^l*F0j(:,(j-1)*m+1:j*m);
150 end
151 end
152 fcrestsaver{end+1} = temp;
153end
154
155for k = 1:n
156 % fhat(k) = pi0 * (sum_j=1 (j+1)^k*B(j))
157 fhatk = zeros(mb,m);
158 for j = 1:degb
159 fhatk = fhatk + (j+1)^k*B(:,mb+(j-1)*m+1:mb+j*m);
160 end
161 fhatk = pi0*fhatk;
162 % f(k) = pi1* (2^k*A(1) + sum_j=1 (j+2)^k*A(j+1))
163 fk = zeros(m,m);
164 for j = 2:dega
165 fk = fk + (j+1)^k*A(:,j*m+1:(j+1)*m);
166 end
167 fk = 2^k*A(:,m+1:2*m) + fk;
168 fk = pi1*fk;
169 % frest = sum_l=(1 to k) bino(k,l)r[k-l]*(A(1)+sum_j=1 (j+1)^l A(j+1))
170 frest = zeros(1,m);
171 for l = 1:1:k
172 frest = frest + bino(k,l)*r(k-l+1,:)*(A(:,m+1:2*m) + frestsaver{l});
173 end
174 % bktemp = -fhatk - fk - frest
175 % bk = bktemp - last column
176 bk = (-1)*fhatk + (-1)*fk + (-1)*frest;
177 bk = bk(:,1:end-1);
178 % fchatk = pi0*(sum_j=2 j^k Fhat0j(j)*e)
179 % fck = pi1*(sum_j=1 (j+1)^k*F0j(j)*e)
180 % fcrest = sum_l=1 (bino(k,l)r[k-l]*sum_j=1 j^l*F0j(j)*e)
181 fchatk= zeros(mb,m);
182 for j=2:degb
183 fchatk = fchatk + (j^k)*Fhat0j(:,(j-1)*m+1:j*m);
184 end
185 fchatk = pi0*fchatk*ones(m,1);
186 fck = zeros(m,m);
187 for j=1:(dega-1)
188 fck = fck + (j+1)^k*F0j(:,(j-1)*m+1:j*m);
189 end
190 fck = pi1*fck*ones(m,1);
191 fcrest = zeros(1,m);
192 for l=1:k
193 fcrest = fcrest + bino(k,l)*r(k-l+1,:)*fcrestsaver{l};
194 end
195 fcrest = fcrest*ones(m,1);
196 ck = - fchatk - fck - fcrest;
197 rside = [bk, ck];
198 rk = rside / lsleft;
199 r = [r;rk];
200end
201
202
203
204 function b = bino(n,k)
205 b = factorial(n)/(factorial(k)*factorial(n-k));
206 end
207
208%Compute Q length
209qlen = sum(r(end,:),2) + sum(pi1,2);
210
211
212
213end