LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
GIM1_qlen_ETAQA.m
1function qlen=GIM1_qlen_ETAQA(B,A,R,pi, n,varargin)
2%GIM1_qlen_ETAQA returns the n-th moment of queue length of a
3%GIM1/M/1 process using the ETAQA method [Riska, Smirni]
4%
5%
6% Usage:
7% qlen=GIM1_qlen_ETAQA(B,A,pi,R,n) computes the n-th
8% moment of an GI/M/1-type Markov chain with an
9% infinitesimal generator matrix of the form
10%
11%
12% B1 A0 0 0 0 ...
13% B2 A1 A0 0 0 ...
14% Q =B3 A2 A1 A0 0 ...
15% B4 A3 A2 A1 A0 ...
16% ...
17%
18% the input matrix R is the minimal nonnegative solution to the
19% matrix equation 0 = A0 + R A1 + R^2 A2 + ... + R^maxa Amaxa
20% The input matrix B equals [B1; B2; ...; Bmaxb], the input
21% matrix A equals [A0;A1;A2; ...; Amaxa]
22%
23%
24% Optional Parameters:
25%
26% Boundary: B0, which allows solving the GI/M/1 Type CTMC
27% with a more general boundary states block
28%
29% B1 B0 0 0 0 ...
30% B2 A1 A0 0 0 ...
31% Q = B3 A2 A1 A0 0 ...
32% B4 A3 A2 A1 A0 ...
33% ...
34% The matrices B0 need not to be
35% square. (default: B0=A0)
36
37OptionNames = ['Boundary '];
38OptionTypes = ['numeric'];
39OptionValues = [];
40
41options=[];
42for i=1:size(OptionNames,1)
43 options.(deblank(OptionNames(i,:)))=[];
44end
45
46% Parse Optional Parameters
47options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
48
49m=size(R,1);
50mb=size(B,2);
51
52if (mod(size(B,1)-mb,m) ~= 0)
53 error('MATLAB:GIM1_qlen_ETAQA: input matrix B has incorrect number of rows');
54else
55 degb = (size(B,1)-mb)/m;
56end
57
58if (mod(size(A,1),m) ~= 0)
59 error('MATLAB:GIM1_qlen_ETAQA: input matrix A has incorrect number of rows');
60else
61 dega = (size(A,1))/m-1;
62end
63
64temp=(eye(m)-R)^(-1);
65if( max(temp<-100*eps))
66 error('MATLAB:GIM1_qlen_ETAQA:InvalidRInput',...
67 'The spectral radius of R is not below 1: GIM1 is not pos. recurrent');
68end
69
70if (~isempty(options.Boundary))
71 B0 = options.Boundary;
72 testmb = size(B0,1);
73 testm = size(B0,2);
74 if (testmb ~= mb)
75 error('MATLAB:GIM1_qlen_ETAQA:input options.Boundary has incorrect number of rows');
76 end
77 if (testm ~= m)
78 error('MATLAB:GIM1_qlen_ETAQA:input options.Boundary has incorrect number of columns');
79 end
80else
81 B0 = A(1:m,:);
82end
83
84pi0 = pi(1:mb);
85pi1 = pi(mb+1:mb+m);
86pistar = pi(mb+m+1:mb+2*m);
87
88if (n==0)
89 qlen = 1;
90 return;
91end
92
93test = B(1:mb,:)+B0;
94
95if abs((sum(test,2) - ones(mb,1))'*ones(mb,1)) < 1e-10
96 % transform from DTMC to CTMC
97 B(1:mb,:) = B(1:mb,:) - eye(mb);
98 A(m+1:2*m,:) = A(m+1:2*m,:) - eye(m);
99
100end
101
102k = 1;
103Rpower = eye(m);
104lsum = A(1:m,:) + A(m+1:2*m,:);
105for i = 2:dega
106 lsum = lsum + Rpower*A(i*m+1:(i+1)*m,:);
107 Rpower = R*Rpower;
108end
109
110
111
112
113leftr = zeros(m,mb);
114leftr_part1 = zeros(m,m);
115leftr_part2 = zeros(m,m);
116if degb >= 2 && dega >= 2
117 Rpower = R;
118 leftr_part1 = A(3);
119 for i = 1:dega-2
120 leftr_part1 = leftr_part1 + Rpower*A((i+2)*m+1:(i+3)*m,:);
121 leftr_part2 = leftr_part2 + i*Rpower*A((i+2)*m+1:(i+3)*m,:);
122 Rpower = R*Rpower;
123 end
124
125 leftr = leftr_part1*ones(m,1) + leftr_part2*ones(m,1) - A(1:m,:)*ones(m,1);
126
127else
128 if (degb == 1 && dega ~= 1)
129 Rpower = eye(m);
130 for i = 2:dega
131 leftr = leftr + (i-1)*Rpower*A(i*m+1:(i+1)*m,:);
132 Rpower = R*Rpower;
133 end
134 leftr = leftr*ones(m,1) - A(1:m,:)*ones(m,1);
135 else
136 error('MATLAB:GIM1_qlen_ETAQA: the number of A blocks is not enough, this is a reducible Markov Chain!');
137 end
138end
139
140
141
142
143% lsum is one matrix and leftr is one column
144lsleft = [lsum(:,1:end-1),leftr];
145
146
147
148r = pistar;
149
150% newly added here, calculate the unchanged part in the+ factor on the right
151% it is -sum_j=2 to inf {(j-1)*R^(j-1)*Bhat(j)}
152tempsum = zeros(m,mb);
153Rpower = R;
154for i=1:degb-1
155 tempsum = tempsum + i*Rpower*getVerticalBlock(B,m,(i+2));
156 Rpower = R*Rpower;
157end
158 rsidepart22 = pi1*(-tempsum*ones(mb,1));
159% compute the reusable part of the right hand side of this equation
160
161
162
163
164% have to check n to see if it is greater than 1
165% get the reusable array, every column corresponds to a vector, starting from j=1
166% F - sum_j=1 to inf {(sum_m=1 to j{m^l}) R^(j)*B^(j+1)}
167rsidepart2reuse = [];
168tempsum = zeros(m,m);
169Rpower = R;
170for i=1:degb-2
171 tempsum = tempsum + i*Rpower*getVerticalBlock(A,m,i+3);
172end
173
174
175
176
177
178for k = 1:n
179 % bk is the first part of the right side of the equation
180 bk = (-1)*(pi0*2^k*B0 + pi1*(2^k*A(m+1:2*m,:) + 3^k*A(1:m,:)));
181
182 for l = 1:k
183 bk = bk + (-1)*bino(k,l)*r(k-l+1,:)*(A(m+1:2*m,:) + 2^l*A(1:m,:));
184 end
185
186 bk = bk(:,1:end-1);
187
188 % now compute the second part of the equations system
189 tempsum = zeros(m,m);
190 Rpower = R;
191
192 for i=1:dega-2
193 temp = 0;
194 for z=1:i
195 temp = temp+z^(k);
196 end
197
198 tempsum = tempsum + temp*Rpower*getVerticalBlock(A,m,i+3);
199 Rpower = Rpower*R;
200
201 end
202 rsidepart2reuse(:,end+1)=(A(1:m,:)-tempsum)*ones(m,1);
203
204 ck = pi1*2^k*A(1:m,:)*ones(m,1);
205 tempsum2 = zeros(m,mb);
206 Rpower = R;
207 for i=2:degb
208 temp = 0;
209 for z=2:i
210 temp =temp + z^k;
211 end
212 tempsum2 = tempsum2 + temp*Rpower*B(mb + (i-1)*m+1:mb + (i)*m,:);
213 Rpower = R*Rpower;
214 end
215 ckresttemp = pi1*tempsum2*ones(mb,1);
216 ck = ck - ckresttemp;
217 ckrest = 0;
218
219 for l = 1:k
220
221 ckrest = ckrest + bino(k,l) * r(k-l+1,:)*(rsidepart2reuse(:,l));
222 end
223 ck = ck + ckrest;
224
225 rside = [bk,ck];
226 rk = rside / lsleft;
227 r = [r;rk];
228end
229
230qlen = sum(r(end,:),2) + sum(pi1,2);
231
232
233
234 function b = bino(n,k)
235 b = factorial(n)/(factorial(k)*factorial(n-k));
236 end
237
238 function m = getVerticalBlock(Mn,blockrow,i)
239
240
241 m = Mn(blockrow*(i-1)+1:blockrow*i,:);
242 end
243
244end