4 % @brief Moment linearizer: approximate mean queue lengths and their second
5 % moments (variance / covariance)
for large closed product-form
10function [Q,X,U,R,QVar,QCov,dQ] = pfqn_momlin(L,N,Z,tol,maxiter)
13 % @brief Approximate first and second queue-length moments of a closed
14 % product-form network, scalable to large populations and many classes
15 % where exact MVA (exponential in
the number of classes) and CoMoM
16 % (single-station) are infeasible.
18 % Means are obtained from
the Schweitzer-Bard AMVA fixed point. Second
19 % moments use
the exact product-form identity
20 % Cov[n_{i,r},n_{j,s}] = D_{j,s} dQ_{i,r}/dD_{j,s},
21 % with
the demand derivatives obtained by analytically linearizing
the
22 % AMVA fixed point (a
"moment linearizer" in
the sense of Strelen and
23 % Akyildiz, here developed per
class). Both moments carry
the AMVA
24 % approximation error and become exact only in
the limits where
25 % Schweitzer-Bard
is exact;
for exact moments on tractable models use
26 % pfqn_sens (differentiated MVA / CoMoM).
28 % @fn pfqn_momlin(L, N, Z, tol, maxiter)
29 % @param L Service demand matrix (M x R).
30 % @param N Closed population vector (1 x R).
31 % @param Z Think time vector (1 x R). Default: zeros.
32 % @param tol Convergence tolerance on
the queue-length fixed point. Default 1e-8.
33 % @param maxiter Maximum iterations. Default 1000.
34 % @
return Q Mean queue length (M x R).
35 % @
return X Throughput per
class (1 x R).
36 % @
return U Utilization (M x R).
37 % @
return R Residence time (M x R).
38 % @
return QVar Queue-length variance (M x R).
39 % @
return QCov Queue-length covariance tensor (M x R x M x R).
40 % @
return dQ Demand-derivative tensor, dQ(i,r,j,s) = dQ_{i,r}/dD_{j,s} (M x R x M x R).
45if nargin < 3 || isempty(Z), Z = zeros(1,R); end
47if nargin < 4 || isempty(tol), tol = 1e-8; end
48if nargin < 5 || isempty(maxiter), maxiter = 1000; end
50 line_error(mfilename,
'pfqn_momlin supports closed classes only.');
53% Schweitzer population-scaling coefficients c_s^{(r)} = (N_s-delta_{rs})/N_s
54% approximating Q_{i,s}(N-1_r) ~ c_s^{(r)} Q_{i,s}(N).
55c = ones(R,R); % c(r,s)
59 c(r,s) = (N(s) - (r==s)) / N(s);
66% ---- Schweitzer-Bard AMVA fixed point
for the means -------------------------
69 if N(r) > 0, Q(:,r) = N(r)/M; end % uniform initial guess
71X = zeros(1,R); Rmat = zeros(M,R);
75 if N(r) == 0, X(r) = 0; Rmat(:,r) = 0;
continue; end
77 Rmat(i,r) = L(i,r) * (1 + c(r,:) * Q(i,:)
');
79 X(r) = N(r) / (Z(r) + sum(Rmat(:,r)));
80 Q(:,r) = X(r) * Rmat(:,r);
82 if max(abs(Q(:)-Qold(:))) < tol, break; end
86 U(:,r) = X(r) * L(:,r);
89% ---- analytic linearization of the fixed point ------------------------------
90% For parameter theta = D_{j,s0}, differentiate
91% Rmat_{i,r} = D_{i,r}(1 + sum_s c(r,s) Q_{i,s})
92% X_r = N_r / (Z_r + sum_i Rmat_{i,r})
93% Q_{i,r} = X_r Rmat_{i,r}
94% giving a linear fixed point in dQ solved by iteration (converges, linear).
98 denom(r) = Z(r) + sum(Rmat(:,r));
102 if N(s0) == 0, continue; end % empty class: derivative 0
107 if N(r) == 0, continue; end
110 dDir = (i==j) && (r==s0);
111 dR(i) = dDir * (1 + c(r,:)*Q(i,:)') + L(i,r) * (c(r,:) * dq(i,:)
');
113 dXr = -(X(r)^2/N(r)) * sum(dR); % dZ/dtheta = 0
114 dq(:,r) = dXr * Rmat(:,r) + X(r) * dR;
116 if max(abs(dq(:)-dqold(:))) < tol, break; end
122% ---- second moments via the product-form covariance identity ----------------
123QCov = zeros(M,R,M,R);
128 QCov(i,r,j,s) = L(j,s) * dQ(i,r,j,s);
136 QVar(i,r) = QCov(i,r,i,r);
140R = Rmat; % assign residence-time output last (R held the class count above)