LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_momlin.m
1%{
2%{
3 % @file pfqn_momlin.m
4 % @brief Moment linearizer: approximate mean queue lengths and their second
5 % moments (variance / covariance) for large closed product-form
6 % queueing networks.
7%}
8%}
9
10function [Q,X,U,R,QVar,QCov,dQ] = pfqn_momlin(L,N,Z,tol,maxiter)
11%{
12%{
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.
17 %
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).
27 %
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).
41%}
42%}
43[M,R] = size(L);
44N = ceil(N(:)');
45if nargin < 3 || isempty(Z), Z = zeros(1,R); end
46Z = Z(:)';
47if nargin < 4 || isempty(tol), tol = 1e-8; end
48if nargin < 5 || isempty(maxiter), maxiter = 1000; end
49if any(isinf(N))
50 line_error(mfilename,'pfqn_momlin supports closed classes only.');
51end
52
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)
56for r = 1:R
57 for s = 1:R
58 if N(s) > 0
59 c(r,s) = (N(s) - (r==s)) / N(s);
60 else
61 c(r,s) = 0;
62 end
63 end
64end
65
66% ---- Schweitzer-Bard AMVA fixed point for the means -------------------------
67Q = zeros(M,R);
68for r = 1:R
69 if N(r) > 0, Q(:,r) = N(r)/M; end % uniform initial guess
70end
71X = zeros(1,R); Rmat = zeros(M,R);
72for it = 1:maxiter
73 Qold = Q;
74 for r = 1:R
75 if N(r) == 0, X(r) = 0; Rmat(:,r) = 0; continue; end
76 for i = 1:M
77 Rmat(i,r) = L(i,r) * (1 + c(r,:) * Q(i,:)');
78 end
79 X(r) = N(r) / (Z(r) + sum(Rmat(:,r)));
80 Q(:,r) = X(r) * Rmat(:,r);
81 end
82 if max(abs(Q(:)-Qold(:))) < tol, break; end
83end
84U = zeros(M,R);
85for r = 1:R
86 U(:,r) = X(r) * L(:,r);
87end
88
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).
95dQ = zeros(M,R,M,R);
96denom = zeros(1,R);
97for r = 1:R
98 denom(r) = Z(r) + sum(Rmat(:,r));
99end
100for j = 1:M
101 for s0 = 1:R
102 if N(s0) == 0, continue; end % empty class: derivative 0
103 dq = zeros(M,R);
104 for it = 1:maxiter
105 dqold = dq;
106 for r = 1:R
107 if N(r) == 0, continue; end
108 dR = zeros(M,1);
109 for i = 1:M
110 dDir = (i==j) && (r==s0);
111 dR(i) = dDir * (1 + c(r,:)*Q(i,:)') + L(i,r) * (c(r,:) * dq(i,:)');
112 end
113 dXr = -(X(r)^2/N(r)) * sum(dR); % dZ/dtheta = 0
114 dq(:,r) = dXr * Rmat(:,r) + X(r) * dR;
115 end
116 if max(abs(dq(:)-dqold(:))) < tol, break; end
117 end
118 dQ(:,:,j,s0) = dq;
119 end
120end
121
122% ---- second moments via the product-form covariance identity ----------------
123QCov = zeros(M,R,M,R);
124for i = 1:M
125 for r = 1:R
126 for j = 1:M
127 for s = 1:R
128 QCov(i,r,j,s) = L(j,s) * dQ(i,r,j,s);
129 end
130 end
131 end
132end
133QVar = zeros(M,R);
134for i = 1:M
135 for r = 1:R
136 QVar(i,r) = QCov(i,r,i,r);
137 end
138end
139
140R = Rmat; % assign residence-time output last (R held the class count above)
141end
Definition Station.m:245