1function [G,lG] = pfqn_conv(L, N, Z, cdscaling, options)
2% [G,LG] = PFQN_CONV(L, N, Z, CDSCALING, OPTIONS)
4% Multichain convolution algorithm
for closed queueing networks with
5%
class-dependent service rates.
7% Implements
the convolution algorithm of Sauer (1983), Section 5.2,
8%
"Computational Algorithms for State-Dependent Queueing Networks",
9% ACM TOCS, Vol. 1, No. 1, pp. 67-92.
11% The algorithm computes G(N) = (X_1 * X_2 * ... * X_M)(N) where X_m(n)
13% multivariate discrete convolution:
14% A(n) = sum_{i: 0<=i<=n} B(i) * C(n-i)
16% For
class-dependent stations, X_m(n)
is computed recursively via Sauer
18% X_m(n) = (u_km / mu_km(n)) * X_m(n - e_k)
19% where mu_km(n) = (n_k/|n|) *
beta_{m,k}(n) and beta
is the DIMENSIONLESS
20% class-dependent scaling of
the service demand supplied by CDSCALING{m}: a
21% handle of
the per-class population vector n at station m, returning either a
22% scalar (shared by every class) or a length-R vector. Equivalently
23% X_m(n) = (|n|/n_k) * (L(m,k)/
beta_{m,k}(n)) * X_m(n - e_k),
24% which at beta = 1
is exactly
the load-independent multinomial form, so a unit
25% scaling means
"no correction". This
is the same convention AMVA and CTMC use
26% (effective service time ST/beta). Any saturation/cutoff
is applied inside
the
29% For standard (load-independent) stations, X_m(n) reduces to
the
30% multinomial form and
the convolution uses
the efficient recurrence:
31% G_m(n) = G_{m-1}(n) + sum_r L(m,r) * G_m(n - e_r)
34% L - Service demand matrix (M x R)
35% N - Population vector (1 x R), must be finite (closed network)
36% Z - Think time vector (1 x R), or empty
37% cdscaling - Cell array {M,1} of class-dependence handles beta_m(n);
38% empty entries denote load-independent stations
39% options - Solver options (optional)
42% G - Normalizing constant G(N)
45% Copyright (c) 2012-2026, Imperial College London
50if nargin < 3 || isempty(Z)
53if nargin < 4 || isempty(cdscaling)
54 cdscaling = cell(M, 1);
58 line_error(mfilename,
'Convolution algorithm requires finite (closed) populations.');
61% Total state space size
62stateSpaceSize = prod(N + 1);
64% Identify which stations carry a
class-dependence function
67 isCd(ist) = ~isempty(cdscaling{ist});
70% --- Precompute X_m(n) tables
for class-dependent stations ---
71% For
class-dependent stations, X_m(n)
is built via Sauer eq. (40):
72% X_m(n) = (u_km / mu_km(n)) * X_m(n - e_k), X_m(0) = 1
73% where u_km = L(m,k) (relative utilization) and mu_km(n) =
beta_{m,k}(n)
is
74%
the service RATE for chain k at station m with population n. From eq. (40),
80 Xm{ist} = zeros(stateSpaceSize, 1);
81 Xm{ist}(1) = 1; % X_m(0) = 1
83 % Enumerate all population vectors and build X_m(n) recursively
90 % Use eq. (40): X_m(n) = (u_km / mu_km(n)) * X_m(n-e_k)
91 % Pick first class k with n(k) > 0
94 % Get service rate mu_km(n) from
the class-dependence handle
95 %
beta_{ist,r}(n)
is a DIMENSIONLESS scaling of
the
96 % service demand:
the effective demand of class r at
97 % station ist in state n
is L(ist,r)/beta. The handle
98 % returns either a scalar (shared by every class) or a
100 bval = cdscaling{ist}(n);
107 % X_m(n) = (|n|/n_r) * (L(m,r)/beta) * X_m(n - e_r).
108 % This
is Sauer
's eq. (40) with mu_km(n) =
109 % (n_r/|n|) * beta_{m,r}(n), i.e. the processor-sharing
110 % share of the station scaled by beta. At beta = 1 it
111 % reduces to the load-independent multinomial recurrence,
112 % so a unit scaling means "no correction".
116 idx_prev = hashpop(n, N);
119 Xm{ist}(idx) = (tot / nr) * (L(ist, r) / beta) * Xm{ist}(idx_prev);
133% G_0(n) = F_Z(n) (delay contribution)
134% G_m(n) = (G_{m-1} * X_m)(n) for class-dependent stations
135% G_m(n) = G_{m-1}(n) + sum_r L(m,r) * G_m(n-e_r) for LI stations
137G_curr = zeros(stateSpaceSize, 1);
139% Initialize G_0(n) = F_Z(n): delay server contribution
143 G_curr(idx) = Fz(Z, n);
147% Convolve one station at a time
150 % class-dependent station: direct convolution sum
151 % G_new(n) = sum_{i: 0<=i<=n} X_m(i) * G_old(n-i)
153 G_curr = zeros(stateSpaceSize, 1);
157 idx_n = hashpop(n, N);
160 % Inner loop: enumerate all i from 0 to n
163 idx_i = hashpop(i, N);
164 nmi = n - i; % n - i (component-wise)
165 idx_nmi = hashpop(nmi, N);
166 conv_sum = conv_sum + Xm{ist}(idx_i) * G_old(idx_nmi);
170 G_curr(idx_n) = conv_sum;
174 % Load-independent station: efficient recurrence
175 % G_m(n) = G_{m-1}(n) + sum_r L(m,r) * G_m(n - e_r)
178 idx_n = hashpop(n, N);
179 % G_curr(idx_n) already has G_{m-1}(n) from previous iteration
183 idx_n1r = hashpop(n, N);
185 G_curr(idx_n) = G_curr(idx_n) + L(ist, r) * G_curr(idx_n1r);
193G = G_curr(end); % G(N) is at the last index (hashpop(N,N) = prod(N+1))
197%% --- Local functions ---
199function idx = hashpop(n, N)
200% HASHPOP Map population vector to linear index (1-based)
201% idx = 1 + n(1) + n(2)*(N(1)+1) + n(3)*(N(1)+1)*(N(2)+1) + ...
205 idx = idx + prod(N(1:r-1) + 1) * n(r);
209function [n] = pprod(n, N)
210% PPROD Sequentially generate all vectors n: 0 <= n <= N
211% n = pprod(N) - initialize to zeros
212% n = pprod(n, N) - advance to next vector, returns n(1)=-1 when done
226while s > 0 && n(s) == N(s)
236% FZ Delay server unnormalized probability factor
237% F = (Z(1)^n(1) / n(1)!) * ... * (Z(R)^n(R) / n(R)!)
246 f = f + log(Z(r)) * n(r);
247 f = f - gammaln(1 + n(r));