LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_kt.m
1%{
2%{
3 % @file pfqn_kt.m
4 % @brief Knessl-Tier asymptotic expansion for normalizing constant.
5%}
6%}
7
8%{
9%{
10 % @brief Knessl-Tier asymptotic expansion for normalizing constant.
11 % @fn pfqn_kt(L, N, Z)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector (default: zeros).
15 % @return G Normalizing constant.
16 % @return lG Logarithm of normalizing constant.
17 % @return X System throughput.
18 % @return Q Mean queue lengths.
19%}
20%}
21function [G,lG,X,Q]=pfqn_kt(L,N,Z)
22% Knessl-Tier asymptotic expansion, fixed to include the IS/think-time term
23% (defect G18) and to evaluate the exponent at the exact saddle point.
24%
25% Derivation. In LINE's convention the generating function of G over the
26% population vector is
27% sum_N G(N) prod_r u_r^N_r = exp(sum_r Z_r u_r) prod_k (1-sum_r L_kr u_r)^-1
28% so Cauchy extraction and steepest descent on
29% F(u) = sum_r Z_r u_r - sum_k log(1-U_k) - sum_r N_r log u_r, U_k = L(k,:)*u
30% give
31% G ~ (2 pi)^{-R/2} det(H)^{-1/2} exp(F(u*)) / prod_r u*_r
32% H_rs = delta_rs N_r/u_r^2 + sum_k L_kr L_ks/(1-U_k)^2
33% where u* solves N_r = u_r Z_r + sum_k u_r L_kr/(1-U_k) (asymptotic MVA
34% fixed point). This is Knessl-Tier Result 2 rewritten in LINE's convention:
35% their rho_k absorbs the think rate and the factor exp(sum_r Z_r u_r) is
36% contained in Psi(1,y*) via the M!/(M-n)! Stirling terms. Stock pfqn_kt
37% dropped the linear think term (it is absent from both the exponent and the
38% Hessian) and evaluated the exponent at the AQL throughput.
39if isempty(L) || isempty(N) || sum(N)==0
40 G = 1;
41 lG = 0;
42 X = [];
43 Q = [];
44 return;
45end
46if nargin<3
47 Z = N*0;
48end
49[Morig,Rorig] = size(L); %#ok<ASGLU>
50% fix self-looping customers as they would yield Uk=1
51slcdemandfactor = 0;
52if Rorig>1
53 isslc = false(1,Rorig);
54 for r=1:Rorig
55 if nnz(L(:,r))==1
56 if Z(r)==0
57 ist = find(L(:,r)>0);
58 L = [L; repmat(L(ist,:),N(r),1)];
59 isslc(r) = true;
60 slcdemandfactor = N(r)*log(L(ist,r));
61 end
62 end
63 end
64 L(:,isslc)=[];
65 Z(:,isslc)=[];
66 N(:,isslc)=[];
67end
68[M,R] = size(L);
69Ntot = sum(N);
70if Ntot <= 4
71 [X,Q] = pfqn_bs(L,N,Z);
72else
73 [X,Q] = pfqn_aql(L,N,Z);
74end
75% Solve the saddle-point equations by damped Newton, starting from X:
76% g_r(u) = u_r*(Z_r + sum_k L_kr/(1-U_k)) - N_r = 0
77u = X(:);
78Zc = Z(:); Nc = N(:);
79Uk = L*u;
80if max(Uk) >= 1
81 u = u * (1-1e-6)/max(Uk);
82end
83converged = false;
84for it=1:200
85 Uk = L*u;
86 D = 1./(1-Uk);
87 g = u.*(Zc + L'*D) - Nc;
88 if norm(g) <= 1e-12*Ntot
89 converged = true;
90 break;
91 end
92 J = diag(Zc + L'*D) + (u*ones(1,R)).*(L'*(D.^2.*L));
93 du = -J\g;
94 alpha = 1;
95 while any(u+alpha*du <= 0) || max(L*(u+alpha*du)) >= 1
96 alpha = alpha/2;
97 if alpha < 1e-12
98 break;
99 end
100 end
101 if alpha < 1e-12
102 break;
103 end
104 u = u + alpha*du;
105end
106Uk = L*u;
107D = 1./(1-Uk);
108if converged && norm(u.*(Zc + L'*D) - Nc) <= 1e-8*Ntot
109 us = u; % exact saddle point
110else
111 us = X(:); % fallback: AQL/BS throughput (stationarity limits the damage)
112end
113% Assemble the expansion at us
114Uk = L*us;
115D = 1./max(GlobalConstants.FineTol, 1-Uk);
116H = diag(Nc./us.^2) + L'*((D.^2).*L);
117F = Zc'*us - sum(log(max(GlobalConstants.FineTol,1-Uk))) - Nc'*log(us);
118lG = F - sum(log(us)) - (R/2)*log(2*pi) - 0.5*log(det(H)) + slcdemandfactor;
119G = exp(lG);
120end
Definition Station.m:245