LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
pfqn_mvams.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_PFQN_MVAMS_H
6#define LINE_API_PFQN_MVAMS_H
7
8/**
9 * @file
10 * @ingroup api_pfqn
11 * Exact Mean Value Analysis for mixed open/closed networks with multiserver
12 * stations.
13 *
14 * Templated port of matlab/src/api/pfqn/pfqn_mvams.m. That function is a
15 * dispatcher over four exact MVA variants, so the port carries them all:
16 *
17 * no multiserver, closed -> pfqn_mva (pfqn_mva.h, already ported)
18 * no multiserver, mixed -> pfqn_mvamx (below)
19 * multiserver, closed -> pfqn_mvams_closed (pfqn_mvams_closed.h)
20 * multiserver, mixed -> pfqn_mvaldms (below, via pfqn_mvaldmx)
21 *
22 * pfqn_mvald is the load-dependent MVA of Reiser and Lavenberg, carrying the
23 * marginal queue-length distribution pi(k|n) along the population lattice;
24 * pfqn_mvaldmx is the Bruell-Balbo-Ashfari mixed extension for limited load
25 * dependence, whose effective-capacity terms come from pfqn_ldmx_ec. A
26 * multiserver station with S servers is the load-dependent station with rates
27 * mu(i,k) = min(k, S), which is where the "ms" in the name comes from.
28 *
29 * Arithmetic. Every step of all four variants is an addition, a subtraction, a
30 * multiplication, a division or an integer power in the field of the inputs:
31 * the family is exact-capable end to end and needs no transcendental function.
32 * The only non-field step in MATLAB is the log used to accumulate lG, and the
33 * port does what pfqn_mva.h already does, accumulating the product of the
34 * reciprocal throughputs along the lattice path and taking the log once at the
35 * end of a value that is still exact.
36 *
37 * Contract notes (both follow MATLAB):
38 *
39 * 1. Utilization shape. Three of the four branches return an (M x R)
40 * per-class utilization, but the closed multiserver branch forwards
41 * pfqn_mvams_closed's UN, the (M x 1) busy probability 1 - P(station i
42 * empty) of one copy, as pfqn_mvald's UN was before. This port
43 * follows MATLAB and returns that (M x 1) column on the closed multiserver
44 * branch; callers needing a per-class law compute X(r) L(i,r) / S(i)
45 * themselves, as the solvers do.
46 *
47 * 2. Queue replicas with multiservers. MATLAB rejects mi > 1 for the mixed
48 * multiserver branch; the closed multiserver branch honours mi as
49 * pfqn_mva does (station i is mi[i] identical copies), since it runs
50 * pfqn_mvams_closed (Reiser 1981). This port does the same.
51 *
52 * Index conventions. An open class is marked by OPEN_CLASS in the population
53 * vector (MATLAB uses Inf, which an int vector cannot hold) and an infinite
54 * server station by INF_SERVERS in the server-count vector (MATLAB uses Inf).
55 */
56
57#include <algorithm>
58#include <cmath>
59#include <cstddef>
60#include <limits>
61#include <vector>
62
65#include "line/num/number.h"
66#include "line/util/error.h"
67#include "line/util/matrix.h"
69
70namespace line {
71namespace pfqn {
72
73/** Marks an open (infinite-population) class in a population vector. */
74constexpr int OPEN_CLASS = -1;
75
76/** Marks an infinite-server station in a server-count vector. */
77constexpr int INF_SERVERS = -1;
78
79/** True when the population entry denotes an open class. */
80inline bool is_open_class(int n) { return n < 0; }
81
82// ---------------------------------------------------------------------------
83// pfqn_mvald: exact MVA for closed load-dependent networks
84// ---------------------------------------------------------------------------
85
86/**
87 * Result of pfqn_mvald, mirroring the seven MATLAB outputs. It is deliberately
88 * not MvaResult: the load-dependent family reports an aggregate utilization
89 * and a per-class cycle time rather than per-station, per-class matrices, and
90 * it additionally exposes the marginal queue-length distribution.
91 */
92template <class T>
94 std::vector<T> XN; ///< (R) per-class throughput
95 Matrix<T> QN; ///< (M x R) mean queue length
96 std::vector<T> UN; ///< (M) utilization, 1 - P(station empty)
97 std::vector<T> CN; ///< (R) cycle time, exclusive of think time
98 Matrix<T> WN; ///< (M x R) residence time at the full population
99 Matrix<T> PI; ///< (M x (Nt+1)) marginal queue-length distribution at N
100 T G; ///< normalizing constant
101 double lG; ///< log of the normalizing constant
102 bool isNumStable; ///< false once a marginal probability had to be clamped
103};
104
105/**
106 * Exact MVA for a closed network of load-dependent stations.
107 *
108 * Port of matlab/src/api/pfqn/pfqn_mvald.m. The recursion over the population
109 * lattice is
110 *
111 * W(i,r|n) = sum_{k=1}^{|n|} L(i,r)/mu(i,k) * k * pi(i,k-1|n - e_r)
112 * X(r|n) = n_r / (Z_r + sum_i W(i,r|n))
113 * pi(i,k|n) = sum_r L(i,r)/mu(i,k) * X(r|n) * pi(i,k-1|n - e_r)
114 * pi(i,0|n) = 1 - sum_{k>=1} pi(i,k|n)
115 *
116 * @param L (M x R) service demands
117 * @param N (R) population per class, all finite and non-negative
118 * @param Z (K x R) think times, summed over rows; may be empty
119 * @param mu (M x Nt') service rates, Nt' >= sum(N); mu(i,k-1) is the
120 * rate of station i while it holds k jobs
121 * @param stabilize when true (the MATLAB default) a marginal probability that
122 * comes out negative is clamped to the double epsilon rather
123 * than propagated. The clamp is a floating-point guard: in
124 * exact arithmetic pi(i,0|n) of a well-posed product-form
125 * model is non-negative and the branch is never taken. The
126 * clamp value is a dyadic rational, so it is representable
127 * without rounding in every supported arithmetic.
128 */
129template <class T>
130MvaLdResult<T> pfqn_mvald(const Matrix<T>& L, const std::vector<int>& N, const Matrix<T>& Z,
131 const Matrix<T>& mu, bool stabilize = true) {
132 const std::size_t M = L.rows();
133 const std::size_t R = N.size();
134 if (!L.empty() && L.cols() != R)
135 throw InputError("pfqn_mvald: demand matrix and population vector disagree on the class count");
136
137 const T zero = num_traits<T>::from_int(0);
138 const T one = num_traits<T>::from_int(1);
139
140 MvaLdResult<T> res;
141 res.XN.assign(R, zero);
142 res.QN = Matrix<T>(M, R, zero);
143 res.UN.assign(M, zero);
144 res.CN.assign(R, zero);
145 res.WN = Matrix<T>(M, R, zero);
146 res.G = one;
147 res.lG = 0.0;
148 res.isNumStable = true;
149
150 long Nt = 0;
151 for (int v : N) {
152 // MATLAB returns all-zero metrics and lGN = -Inf for a negative population.
153 if (v < 0) {
154 res.PI = Matrix<T>(M, 1, zero);
155 res.G = zero;
156 res.lG = -std::numeric_limits<double>::infinity();
157 return res;
158 }
159 Nt += v;
160 }
161
162 if (mu.rows() != M)
163 throw InputError("pfqn_mvald: rate matrix and demand matrix disagree on the station count");
164 if (static_cast<long>(mu.cols()) < Nt)
165 throw InputError("pfqn_mvald: rate matrix needs one column per job in the total population");
166
167 std::vector<T> Zsum(R, zero);
168 if (!Z.empty()) {
169 if (Z.cols() != R) throw InputError("pfqn_mvald: Z and N disagree on the class count");
170 for (std::size_t k = 0; k < Z.rows(); ++k)
171 for (std::size_t r = 0; r < R; ++r) Zsum[r] += Z(k, r);
172 }
173
174 const std::size_t K = static_cast<std::size_t>(Nt) + 1; // queue lengths 0 ... Nt
175 const std::vector<std::size_t> prods = plane_sizes(N);
176 const std::size_t total = population_count(N);
177
178 // pi[(idx * M + i) * K + k] is P(station i holds k jobs | population idx).
179 std::vector<T> pi(total * M * K, zero);
180 const T tiny = num_traits<T>::from_double(std::numeric_limits<double>::epsilon());
181
182 std::vector<int> n(R, 0);
183 std::vector<T> x(R, zero);
184 bool more = true;
185 std::size_t visited = 0;
186 while (more) {
187 // Wall-clock budget, every 1024 populations: an exact recursion cut
188 // short has no valid partial result, so it raises (as pfqn_mva does).
189 if ((++visited & 1023u) == 0)
190 util::timeout_check("Exact load-dependent MVA (use an approximate method or raise the budget)");
191 const std::size_t idx = pop_index(n, prods);
192 long nsum = 0;
193 for (int v : n) nsum += v;
194
195 res.WN.fill(zero);
196 std::fill(x.begin(), x.end(), zero);
197
198 for (std::size_t s = 0; s < R; ++s) {
199 if (n[s] == 0) continue;
200 const std::size_t idx_s = idx - prods[s];
201 T ctot = Zsum[s];
202 for (std::size_t i = 0; i < M; ++i) {
203 T w = zero;
204 for (long k = 1; k <= nsum; ++k)
205 w += (L(i, s) / mu(i, static_cast<std::size_t>(k - 1))) *
207 pi[(idx_s * M + i) * K + static_cast<std::size_t>(k - 1)];
208 res.WN(i, s) = w;
209 ctot += w;
210 }
211 if (ctot == zero) throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvald: zero total residence time");
212 x[s] = num_traits<T>::from_int(n[s]) / ctot;
213 }
214
215 for (long k = 1; k <= nsum; ++k) {
216 for (std::size_t i = 0; i < M; ++i) {
217 T acc = zero;
218 for (std::size_t s = 0; s < R; ++s) {
219 if (n[s] == 0) continue;
220 const std::size_t idx_s = idx - prods[s];
221 acc += (L(i, s) / mu(i, static_cast<std::size_t>(k - 1))) * x[s] *
222 pi[(idx_s * M + i) * K + static_cast<std::size_t>(k - 1)];
223 }
224 pi[(idx * M + i) * K + static_cast<std::size_t>(k)] = acc;
225 }
226 }
227
228 for (std::size_t i = 0; i < M; ++i) {
229 T acc = zero;
230 for (long k = 1; k <= nsum; ++k) acc += pi[(idx * M + i) * K + static_cast<std::size_t>(k)];
231 T p0 = one - acc;
232 if (p0 < zero) {
233 // a p0 within round-off of zero (all servers busy) is clamped without calling the recursion unstable
234 if (p0 < -num_traits<T>::from_double(1e-14)) res.isNumStable = false;
235 if (stabilize) p0 = tiny;
236 }
237 pi[(idx * M + i) * K + 0] = p0;
238 }
239
240 // Normalizing constant along the lattice path that fills class 0, then
241 // class 1, and so on, exactly as in pfqn_mva.
242 long last_nnz = -1;
243 for (long r = static_cast<long>(R) - 1; r >= 0; --r)
244 if (n[r] != 0) {
245 last_nnz = r;
246 break;
247 }
248 if (last_nnz >= 0) {
249 bool prefixFull = true;
250 for (long r = 0; r < last_nnz; ++r)
251 if (n[r] != N[r]) {
252 prefixFull = false;
253 break;
254 }
255 bool suffixEmpty = true;
256 for (std::size_t r = static_cast<std::size_t>(last_nnz) + 1; r < R; ++r)
257 if (n[r] != 0) {
258 suffixEmpty = false;
259 break;
260 }
261 if (prefixFull && suffixEmpty) {
262 const T& xr = x[static_cast<std::size_t>(last_nnz)];
263 if (xr == zero) throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvald: zero throughput on the G path");
264 res.G /= xr;
265 }
266 }
267
268 more = next_pop(n, N);
269 }
270
271 // The loop leaves x, WN and the pi slice at the full population N.
272 const std::size_t idxN = total - 1;
273 res.XN = x;
274 res.PI = Matrix<T>(M, K, zero);
275 for (std::size_t i = 0; i < M; ++i)
276 for (std::size_t k = 0; k < K; ++k) res.PI(i, k) = pi[(idxN * M + i) * K + k];
277
278 for (std::size_t i = 0; i < M; ++i) {
279 for (std::size_t r = 0; r < R; ++r) res.QN(i, r) = res.WN(i, r) * res.XN[r];
280 res.UN[i] = one - res.PI(i, 0);
281 }
282 for (std::size_t r = 0; r < R; ++r) {
283 // An absent class has zero throughput, so N/X would be 0/0: MATLAB
284 // reports no cycle time for it rather than NaN.
285 if (N[r] > 0) res.CN[r] = num_traits<T>::from_int(N[r]) / res.XN[r] - Zsum[r];
286 }
287
289 return res;
290}
291
292// ---------------------------------------------------------------------------
293// pfqn_mvamx: exact MVA for mixed single-server networks
294// ---------------------------------------------------------------------------
295
296/**
297 * Exact MVA for a mixed open/closed network of single-server stations.
298 *
299 * Port of matlab/src/api/pfqn/pfqn_mvamx.m. The open classes are absorbed by
300 * inflating the closed demands, D_c(i,r) / (1 - sum_{open} lambda D), after
301 * which the closed subnetwork is solved by pfqn_mva; the open metrics then
302 * follow from the closed queue lengths.
303 *
304 * @param lambda (R) arrival rates, zero on closed classes
305 * @param D (M x R) service demands
306 * @param N (R) population, OPEN_CLASS on open classes
307 * @param Z (K x R) think times, summed over rows; may be empty
308 * @param mi (M) station multiplicities; empty for all ones
309 *
310 * G and lG describe the closed subnetwork on the inflated demands, and are set
311 * to 0 and NaN respectively when there is no closed class, as in MATLAB.
312 */
313template <class T>
314MvaResult<T> pfqn_mvamx(const std::vector<T>& lambda, const Matrix<T>& D,
315 const std::vector<int>& N, const Matrix<T>& Z,
316 const std::vector<int>& mi) {
317 const std::size_t M = D.rows();
318 const std::size_t R = N.size();
319 if (!D.empty() && D.cols() != R)
320 throw InputError("pfqn_mvamx: demand matrix and population vector disagree on the class count");
321 if (lambda.size() != R)
322 throw InputError("pfqn_mvamx: arrival-rate vector and population vector disagree on the class count");
323
324 const T zero = num_traits<T>::from_int(0);
325 const T one = num_traits<T>::from_int(1);
326
327 MvaResult<T> res;
328 res.XN.assign(R, zero);
329 res.QN = Matrix<T>(M, R, zero);
330 res.UN = Matrix<T>(M, R, zero);
331 res.CN = Matrix<T>(M, R, zero);
332 res.G = zero;
333 res.lG = std::numeric_limits<double>::quiet_NaN();
334
335 std::vector<std::size_t> openClasses, closedClasses;
336 for (std::size_t r = 0; r < R; ++r) {
337 if (is_open_class(N[r]))
338 openClasses.push_back(r);
339 else
340 closedClasses.push_back(r);
341 }
342 for (std::size_t r = 0; r < R; ++r)
343 if (lambda[r] > zero && !is_open_class(N[r]) && N[r] > 0)
344 throw InputError("pfqn_mvamx: arrival rate cannot be specified on a closed class");
345
346 std::vector<T> Zsum(R, zero);
347 if (!Z.empty()) {
348 if (Z.cols() != R) throw InputError("pfqn_mvamx: Z and N disagree on the class count");
349 for (std::size_t k = 0; k < Z.rows(); ++k)
350 for (std::size_t r = 0; r < R; ++r) Zsum[r] += Z(k, r);
351 }
352
353 for (std::size_t r : openClasses) {
354 for (std::size_t i = 0; i < M; ++i) res.UN(i, r) = lambda[r] * D(i, r);
355 res.XN[r] = lambda[r];
356 }
357
358 std::vector<T> UNt(M, zero);
359 for (std::size_t i = 0; i < M; ++i)
360 for (std::size_t r = 0; r < R; ++r) UNt[i] += res.UN(i, r);
361
362 const std::size_t nClosed = closedClasses.size();
363 Matrix<T> QNc;
364 if (nClosed > 0) {
365 Matrix<T> Dc(M, nClosed, zero);
366 for (std::size_t i = 0; i < M; ++i) {
367 // no throw at slack <= 0, as in pfqn_mvamx.m: callers flag the station unstable afterwards
368 const T slack = one - UNt[i];
369 for (std::size_t c = 0; c < nClosed; ++c) Dc(i, c) = D(i, closedClasses[c]) / slack;
370 }
371 std::vector<int> Nc(nClosed);
372 Matrix<T> Zc(1, nClosed, zero);
373 for (std::size_t c = 0; c < nClosed; ++c) {
374 Nc[c] = N[closedClasses[c]];
375 Zc(0, c) = Zsum[closedClasses[c]];
376 }
377 MvaResult<T> closed = pfqn_mva(Dc, Nc, Zc, mi);
378 QNc = closed.QN;
379 for (std::size_t c = 0; c < nClosed; ++c) {
380 const std::size_t r = closedClasses[c];
381 res.XN[r] = closed.XN[c];
382 for (std::size_t i = 0; i < M; ++i) {
383 res.QN(i, r) = closed.QN(i, c);
384 res.CN(i, r) = closed.CN(i, c);
385 }
386 }
387 res.G = closed.G;
388 res.lG = closed.lG;
389 }
390
391 for (std::size_t i = 0; i < M; ++i)
392 for (std::size_t c = 0; c < nClosed; ++c) {
393 const std::size_t r = closedClasses[c];
394 res.UN(i, r) = res.XN[r] * D(i, r);
395 }
396
397 for (std::size_t i = 0; i < M; ++i) {
398 T qc = zero;
399 for (std::size_t c = 0; c < nClosed; ++c) qc += QNc(i, c);
400 const T slack = one - UNt[i];
401 for (std::size_t r : openClasses) {
402 res.CN(i, r) = D(i, r) * (one + qc) / slack;
403 res.QN(i, r) = res.CN(i, r) * res.XN[r];
404 }
405 }
406 return res;
407}
408
409// ---------------------------------------------------------------------------
410// pfqn_ldmx_ec: effective-capacity terms of the mixed load-dependent MVA
411// ---------------------------------------------------------------------------
412
413namespace detail {
414
415/** Outputs of pfqn_ldmx_ec, with E and Eprime indexed by queue length 0 ... Nt. */
416template <class T>
417struct LdmxEc {
418 Matrix<T> EC; ///< (M x Nt) effective capacity, EC(i,k-1) for k jobs
419 Matrix<T> E; ///< (M x (Nt+1))
420 Matrix<T> Eprime; ///< (M x (Nt+1))
421 std::vector<T> Lo; ///< (M) open-class load at each station
422};
423
424/**
425 * Port of matlab/src/api/pfqn/pfqn_ldmx_ec.m. Computes the terms that let the
426 * mixed load-dependent MVA absorb the open classes into a station-dependent
427 * effective capacity, under the limited-load-dependence assumption that the
428 * rate saturates from the b(i)-th job onwards.
429 *
430 * Every step is a field operation or an integer power, so the routine is exact.
431 *
432 * @param lambda (R) arrival rates
433 * @param D (M x R) service demands
434 * @param mu (M x Nt) service rates
435 */
436template <class T>
437LdmxEc<T> pfqn_ldmx_ec(const std::vector<T>& lambda, const Matrix<T>& D, const Matrix<T>& mu) {
438 const std::size_t M = mu.rows();
439 const std::size_t Nt = mu.cols();
440 const std::size_t R = D.cols();
441 if (D.rows() != M)
442 throw InputError("pfqn_ldmx_ec: demand matrix and rate matrix disagree on the station count");
443 if (lambda.size() != R)
444 throw InputError("pfqn_ldmx_ec: arrival-rate vector and demand matrix disagree on the class count");
445
446 const T zero = num_traits<T>::from_int(0);
447 const T one = num_traits<T>::from_int(1);
448
449 LdmxEc<T> out;
450 out.Lo.assign(M, zero);
451 for (std::size_t i = 0; i < M; ++i)
452 for (std::size_t r = 0; r < R; ++r) out.Lo[i] += lambda[r] * D(i, r);
453
454 // b(i): first queue length at which the rate has reached its final value.
455 std::vector<std::size_t> b(M, 1);
456 std::size_t maxb = 1;
457 for (std::size_t i = 0; i < M; ++i) {
458 for (std::size_t j = 1; j <= Nt; ++j) {
459 if (mu(i, j - 1) == mu(i, Nt - 1)) {
460 b[i] = j;
461 break;
462 }
463 }
464 if (b[i] > maxb) maxb = b[i];
465 }
466
467 // C(i,j) = 1/mu(i,j), extended past Nt by repeating the saturated rate, so
468 // the F-recursions below can index up to Nt + 1 + maxb as MATLAB does.
469 const std::size_t Cn = Nt + 1 + maxb;
470 Matrix<T> C(M, Cn, zero);
471 for (std::size_t i = 0; i < M; ++i)
472 for (std::size_t j = 1; j <= Cn; ++j) {
473 const T& m = j <= Nt ? mu(i, j - 1) : mu(i, Nt - 1);
474 if (m == zero) throw InputError("pfqn_ldmx_ec: service rate must be nonzero");
475 C(i, j - 1) = one / m;
476 }
477
478 out.EC = Matrix<T>(M, Nt, zero);
479 out.E = Matrix<T>(M, Nt + 1, zero);
480 out.Eprime = Matrix<T>(M, Nt + 1, zero);
481
482 for (std::size_t i = 0; i < M; ++i) {
483 const std::size_t bi = b[i];
484 const T Cb = C(i, bi - 1);
485 const T slack = one - out.Lo[i] * Cb;
486 if (slack == zero)
487 throw NumericError(ErrorKind{"Instability"}, "pfqn_ldmx_ec: open-class load saturates a station, effective capacity diverges");
488 const T invSlack = one / slack;
489
490 // prod_{j=1}^{b-1} C(j)/C(b), shared by E1(0) and F3(0,0).
491 T ratioProd = one;
492 for (std::size_t j = 1; j + 1 <= bi; ++j) ratioProd *= C(i, j - 1) / Cb;
493
494 const long nb = static_cast<long>(bi) - 2; // last F-column index, -1 when b == 1
495 std::vector<T> E1(Nt + 1, zero);
496 T F3prev0 = zero;
497
498 for (std::size_t n = 0; n <= Nt; ++n) {
499 if (n >= bi) {
500 out.E(i, n) = num_pow_int(invSlack, static_cast<unsigned>(n + 1));
501 out.Eprime(i, n) = Cb * out.E(i, n);
502 continue;
503 }
504
505 if (n == 0)
506 E1[0] = invSlack * ratioProd;
507 else
508 E1[n] = invSlack * Cb / C(i, n - 1) * E1[n - 1];
509
510 T E2 = zero, E3 = zero, E2prime = zero;
511
512 T F2 = zero, F3 = zero, F2p = zero;
513 for (long n0 = 0; n0 <= nb; ++n0) {
514 if (n0 == 0) {
515 F2 = one;
516 F3 = (n == 0) ? ratioProd : Cb / C(i, n - 1) * F3prev0;
517 F2p = C(i, n); // C(n+1) in 1-based terms
518 } else {
519 const T fac = num_traits<T>::from_int(static_cast<long>(n) + n0) /
520 num_traits<T>::from_int(n0);
521 F2 = fac * out.Lo[i] * C(i, static_cast<std::size_t>(static_cast<long>(n) + n0) - 1) * F2;
522 F3 = fac * out.Lo[i] * Cb * F3;
523 F2p = fac * out.Lo[i] * C(i, static_cast<std::size_t>(static_cast<long>(n) + n0)) * F2p;
524 }
525 if (n0 == 0) F3prev0 = F3;
526 E2 += F2;
527 E3 += F3;
528 E2prime += F2p;
529 }
530 if (nb < 0) {
531 // b == 1: the F-sums are empty and F3(n,0) is never formed, so
532 // the carry-over stays at its unused zero, as in MATLAB.
533 F3prev0 = zero;
534 }
535
536 out.E(i, n) = E1[n] + E2 - E3;
537 if (n + 1 < bi)
538 out.Eprime(i, n) = Cb * E1[n] + E2prime - Cb * E3;
539 else
540 out.Eprime(i, n) = Cb * out.E(i, n);
541 }
542
543 // E UNDERFLOWS to zero at a saturated station, where Lo*C(b) > 1 drives
544 // the alternating geometric to nothing. MATLAB divides through and gets
545 // the IEEE infinity that solver_mva then caps; only an exact field, where
546 // division by zero is undefined, can refuse it.
547 for (std::size_t n = 1; n <= Nt; ++n) {
548 if (num_traits<T>::is_exact && out.E(i, n - 1) == zero)
549 throw NumericError(ErrorKind{"Degenerate"}, "pfqn_ldmx_ec: vanishing effective capacity");
550 out.EC(i, n - 1) = C(i, n - 1) * out.E(i, n) / out.E(i, n - 1);
551 }
552 }
553 return out;
554}
555
556} // namespace detail
557
558// ---------------------------------------------------------------------------
559// pfqn_mvaldmx / pfqn_mvaldms: mixed networks with load-dependent stations
560// ---------------------------------------------------------------------------
561
562/**
563 * Exact MVA for mixed open/closed networks with limited load dependence.
564 *
565 * Port of matlab/src/api/pfqn/pfqn_mvaldmx.m (Bruell, Balbo and Ashfari). The
566 * MATLAB signature carries a trailing server-count argument S that its body
567 * never reads; the port drops it, since pfqn_mvaldms is the caller that turns
568 * server counts into rates.
569 *
570 * @param lambda (R) arrival rates, zero on closed classes
571 * @param D (M x R) service demands
572 * @param N (R) population, OPEN_CLASS on open classes
573 * @param Z (K x R) think times, summed over rows; may be empty
574 * @param mu (M x Nc') rates, Nc' >= the total closed population
575 */
576template <class T>
577MvaResult<T> pfqn_mvaldmx(const std::vector<T>& lambda, const Matrix<T>& D,
578 const std::vector<int>& N, const Matrix<T>& Z, const Matrix<T>& mu) {
579 const std::size_t M = D.rows();
580 const std::size_t R = N.size();
581 if (!D.empty() && D.cols() != R)
582 throw InputError("pfqn_mvaldmx: demand matrix and population vector disagree on the class count");
583 if (lambda.size() != R)
584 throw InputError("pfqn_mvaldmx: arrival-rate vector and population vector disagree on the class count");
585 if (mu.rows() != M)
586 throw InputError("pfqn_mvaldmx: rate matrix and demand matrix disagree on the station count");
587
588 const T zero = num_traits<T>::from_int(0);
589 const T one = num_traits<T>::from_int(1);
590
591 std::vector<std::size_t> openClasses, closedClasses;
592 long Nct = 0;
593 for (std::size_t r = 0; r < R; ++r) {
594 if (is_open_class(N[r])) {
595 openClasses.push_back(r);
596 } else {
597 closedClasses.push_back(r);
598 Nct += N[r];
599 }
600 }
601 for (std::size_t r = 0; r < R; ++r)
602 if (lambda[r] > zero && !is_open_class(N[r]) && N[r] > 0)
603 throw InputError("pfqn_mvaldmx: arrival rate cannot be specified on a closed class");
604 if (static_cast<long>(mu.cols()) < Nct)
605 throw InputError(
606 "pfqn_mvaldmx: the load-dependent rates must be given for at least the maximum closed population");
607
608 // MATLAB appends one extra column so the recursion can look one job ahead.
609 Matrix<T> mux(M, mu.cols() + 1, zero);
610 for (std::size_t i = 0; i < M; ++i) {
611 for (std::size_t j = 0; j < mu.cols(); ++j) mux(i, j) = mu(i, j);
612 mux(i, mu.cols()) = mu(i, mu.cols() - 1);
613 }
614 const detail::LdmxEc<T> ec = detail::pfqn_ldmx_ec(lambda, D, mux);
615
616 // A station whose open load reaches its peak service rate, Lo(i) >=
617 // mu(i,end), is unstable: the series behind E converges only for
618 // Lo*C(i,b) < 1, so the finite values the recursion would produce there
619 // are not a solution. As in the solver-level saturation rule
620 // (NetworkSolver.getAvg), the open classes it serves get an infinite queue
621 // and response time and the uncapped utilization Lo/mu(i,end). The exact
622 // field has no infinity to carry that, so it refuses the model instead.
623 std::vector<char> saturated(M, 0);
624 for (std::size_t i = 0; i < M; ++i) {
625 if (ec.Lo[i] < mux(i, mux.cols() - 1)) continue;
626 for (std::size_t r : openClasses)
627 if (D(i, r) > zero) saturated[i] = 1;
628 if (saturated[i] && num_traits<T>::is_exact)
629 throw NumericError(ErrorKind{"Instability"},
630 "pfqn_mvaldmx: open-class load saturates a station, the model has no steady state");
631 }
632
633 MvaResult<T> res;
634 res.XN.assign(R, zero);
635 res.QN = Matrix<T>(M, R, zero);
636 res.UN = Matrix<T>(M, R, zero);
637 res.CN = Matrix<T>(M, R, zero);
638 res.G = one;
639 res.lG = 0.0;
640
641 const std::size_t Cc = closedClasses.size();
642 Matrix<T> Dc(M, Cc, zero);
643 std::vector<int> Nc(Cc, 0);
644 std::vector<T> Zc(Cc, zero);
645 for (std::size_t c = 0; c < Cc; ++c) {
646 const std::size_t r = closedClasses[c];
647 Nc[c] = N[r];
648 for (std::size_t i = 0; i < M; ++i) Dc(i, c) = D(i, r);
649 }
650 if (!Z.empty()) {
651 if (Z.cols() != R) throw InputError("pfqn_mvaldmx: Z and N disagree on the class count");
652 for (std::size_t k = 0; k < Z.rows(); ++k)
653 for (std::size_t c = 0; c < Cc; ++c) Zc[c] += Z(k, closedClasses[c]);
654 }
655
656 const std::vector<std::size_t> prods = plane_sizes(Nc);
657 const std::size_t total = population_count(Nc);
658 const std::size_t K = static_cast<std::size_t>(Nct) + 1;
659
660 // Pc[(idx * M + i) * K + k] is P(station i holds k closed jobs | idx).
661 std::vector<T> Pc(total * M * K, zero);
662 for (std::size_t i = 0; i < M; ++i) Pc[(0 * M + i) * K + 0] = one;
663 const T tiny = num_traits<T>::from_double(std::numeric_limits<double>::epsilon());
664
665 Matrix<T> w(M, Cc, zero);
666 std::vector<T> x(Cc, zero);
667 std::vector<int> nvec(Cc, 0);
668 bool more = true;
669 std::size_t visited = 0;
670 while (more) {
671 // Wall-clock budget, every 1024 populations: an exact recursion cut
672 // short has no valid partial result, so it raises (as pfqn_mva does).
673 if ((++visited & 1023u) == 0)
674 util::timeout_check("Exact load-dependent MVA (use an approximate method or raise the budget)");
675 const std::size_t idx = pop_index(nvec, prods);
676 long nc = 0;
677 for (int v : nvec) nc += v;
678
679 w.fill(zero);
680 std::fill(x.begin(), x.end(), zero);
681
682 for (std::size_t i = 0; i < M; ++i)
683 for (std::size_t c = 0; c < Cc; ++c) {
684 if (nvec[c] == 0) continue;
685 const std::size_t idx_c = idx - prods[c];
686 T acc = zero;
687 for (long k = 1; k <= nc; ++k)
688 acc += Dc(i, c) * num_traits<T>::from_int(k) *
689 ec.EC(i, static_cast<std::size_t>(k - 1)) *
690 Pc[(idx_c * M + i) * K + static_cast<std::size_t>(k - 1)];
691 w(i, c) = acc;
692 }
693
694 for (std::size_t c = 0; c < Cc; ++c) {
695 if (nvec[c] == 0) continue; // MATLAB forms 0/0 here and never reads it
696 T ctot = Zc[c];
697 for (std::size_t i = 0; i < M; ++i) ctot += w(i, c);
698 if (ctot == zero) throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvaldmx: zero total residence time");
699 x[c] = num_traits<T>::from_int(nvec[c]) / ctot;
700 }
701
702 for (std::size_t i = 0; i < M; ++i) {
703 for (long k = 1; k <= nc; ++k) {
704 T acc = zero;
705 for (std::size_t c = 0; c < Cc; ++c) {
706 if (nvec[c] == 0) continue;
707 const std::size_t idx_c = idx - prods[c];
708 acc += Dc(i, c) * ec.EC(i, static_cast<std::size_t>(k - 1)) * x[c] *
709 Pc[(idx_c * M + i) * K + static_cast<std::size_t>(k - 1)];
710 }
711 Pc[(idx * M + i) * K + static_cast<std::size_t>(k)] = acc;
712 }
713 T acc = zero;
714 for (long k = 1; k <= nc; ++k) acc += Pc[(idx * M + i) * K + static_cast<std::size_t>(k)];
715 T p0 = one - acc;
716 if (p0 < tiny) p0 = tiny; // MATLAB: max(eps, 1 - sum)
717 Pc[(idx * M + i) * K + 0] = p0;
718 }
719
720 long last_nnz = -1;
721 for (long c = static_cast<long>(Cc) - 1; c >= 0; --c)
722 if (nvec[c] != 0) {
723 last_nnz = c;
724 break;
725 }
726 if (last_nnz >= 0) {
727 bool prefixFull = true;
728 for (long c = 0; c < last_nnz; ++c)
729 if (nvec[c] != Nc[c]) {
730 prefixFull = false;
731 break;
732 }
733 bool suffixEmpty = true;
734 for (std::size_t c = static_cast<std::size_t>(last_nnz) + 1; c < Cc; ++c)
735 if (nvec[c] != 0) {
736 suffixEmpty = false;
737 break;
738 }
739 if (prefixFull && suffixEmpty) {
740 const T& xr = x[static_cast<std::size_t>(last_nnz)];
741 if (xr > zero) res.G /= xr;
742 }
743 }
744
745 more = next_pop(nvec, Nc);
746 }
747
748 const std::size_t idxN = total - 1;
749
750 for (std::size_t c = 0; c < Cc; ++c) {
751 const std::size_t r = closedClasses[c];
752 res.XN[r] = x[c];
753 for (std::size_t i = 0; i < M; ++i) {
754 res.CN(i, r) = w(i, c);
755 res.QN(i, r) = x[c] * w(i, c);
756 if (Nc[c] > 0) {
757 const std::size_t idx_c = idxN - prods[c];
758 T u = zero;
759 for (long k = 1; k <= Nct; ++k) {
760 const std::size_t kk = static_cast<std::size_t>(k - 1);
761 if (num_traits<T>::is_exact && ec.E(i, kk) == zero)
762 throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvaldmx: vanishing effective capacity");
763 u += Dc(i, c) * x[c] * ec.Eprime(i, kk) / ec.E(i, kk) * Pc[(idx_c * M + i) * K + kk];
764 }
765 res.UN(i, r) = u;
766 }
767 }
768 }
769
770 for (std::size_t r : openClasses) {
771 res.XN[r] = lambda[r];
772 for (std::size_t i = 0; i < M; ++i) {
773 T q = zero, u = zero;
774 for (long k = 0; k <= Nct; ++k) {
775 const std::size_t kk = static_cast<std::size_t>(k);
776 q += lambda[r] * D(i, r) * num_traits<T>::from_int(k + 1) * ec.EC(i, kk) *
777 Pc[(idxN * M + i) * K + kk];
778 if (num_traits<T>::is_exact && ec.E(i, kk + 1) == zero)
779 throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvaldmx: vanishing effective capacity");
780 u += lambda[r] * ec.Eprime(i, kk + 1) / ec.E(i, kk + 1) * Pc[(idxN * M + i) * K + kk];
781 }
782 res.QN(i, r) = q;
783 if (lambda[r] == zero)
784 throw NumericError(ErrorKind{"Degenerate"}, "pfqn_mvaldmx: an open class must have a positive arrival rate");
785 res.CN(i, r) = q / lambda[r];
786 res.UN(i, r) = u;
787 }
788 }
789
790 if constexpr (!num_traits<T>::is_exact) {
791 for (std::size_t i = 0; i < M; ++i) {
792 if (!saturated[i]) continue;
793 for (std::size_t r : openClasses) {
794 if (!(D(i, r) > zero)) continue;
795 res.QN(i, r) = std::numeric_limits<T>::infinity();
796 res.CN(i, r) = std::numeric_limits<T>::infinity();
797 res.UN(i, r) = lambda[r] * D(i, r) / mux(i, mux.cols() - 1);
798 }
799 }
800 }
801
802 res.lG = Cc > 0 ? num_traits<T>::log_as_double(res.G) : std::numeric_limits<double>::quiet_NaN();
803 return res;
804}
805
806/**
807 * Exact MVA for mixed open/closed networks with multiserver stations.
808 *
809 * Port of matlab/src/api/pfqn/pfqn_mvaldms.m: builds the multiserver rates
810 * mu(i,k) = min(k, S(i)), calls pfqn_mvaldmx and replaces its utilizations by
811 * the per-server utilization law U(i,r) = X(r) D(i,r) / S(i).
812 *
813 * @param S (M) servers per station, INF_SERVERS for an infinite server
814 * @param lambda (R) arrival rates, zero on the closed classes
815 * @param D (M x R) service demands
816 * @param N (R) populations, negative on the open classes
817 * @param Z (K x R) think times
818 */
819template <class T>
820MvaResult<T> pfqn_mvaldms(const std::vector<T>& lambda, const Matrix<T>& D,
821 const std::vector<int>& N, const Matrix<T>& Z, const std::vector<int>& S) {
822 const std::size_t M = D.rows();
823 const std::size_t R = N.size();
824 if (S.size() != M) throw InputError("pfqn_mvaldms: server-count vector has the wrong length");
825
826 const T zero = num_traits<T>::from_int(0);
827 long Nct = 0;
828 for (std::size_t r = 0; r < R; ++r)
829 if (!is_open_class(N[r])) Nct += N[r];
830
831 // pfqn_ldmx_ec reads the limited-load-dependence level b_i off the rate row
832 // -- the first column equal to the LAST one -- and treats every rate beyond
833 // it as saturated. A row cut at the CLOSED population therefore declares a
834 // c-server station saturated at min(n,c) with n<c whenever c exceeds that
835 // population, and with no closed class at all leaves the row flat at one
836 // server, so the open classes see a station with fewer servers than it has.
837 // Build the row out to the servers: at Nct = 0 the EC term is then exactly
838 // the M/M/c mean queue length, since E(0) = 1/p0 and E(1) = L/(p0 Lo).
839 long ncol = Nct > 1 ? Nct : 1;
840 for (std::size_t i = 0; i < M; ++i)
841 if (S[i] != INF_SERVERS && S[i] > ncol) ncol = S[i];
842
843 Matrix<T> mu(M, static_cast<std::size_t>(ncol), num_traits<T>::from_int(1));
844 for (std::size_t i = 0; i < M; ++i)
845 for (long k = 1; k <= ncol; ++k) {
846 const long c = S[i] == INF_SERVERS ? k : (k < S[i] ? k : S[i]);
847 mu(i, static_cast<std::size_t>(k - 1)) = num_traits<T>::from_int(c);
848 }
849
850 MvaResult<T> res = pfqn_mvaldmx(lambda, D, N, Z, mu);
851
852 for (std::size_t i = 0; i < M; ++i) {
853 for (std::size_t r = 0; r < R; ++r) {
854 const T rate = is_open_class(N[r]) ? lambda[r] : res.XN[r];
855 // An infinite server has no server count to divide by: the law
856 // degenerates to the mean number of busy servers, X * D.
857 res.UN(i, r) = S[i] == INF_SERVERS
858 ? T(rate * D(i, r))
859 : T(rate * D(i, r) / num_traits<T>::from_int(S[i]));
860 if (rate == zero) res.UN(i, r) = zero;
861 }
862 }
863 return res;
864}
865
866// ---------------------------------------------------------------------------
867// pfqn_mvams
868// ---------------------------------------------------------------------------
869
870/**
871 * General-purpose exact MVA for mixed networks with multiserver stations.
872 *
873 * @param lambda (R) arrival rates, zero on closed classes; may be empty when
874 * the model has no open class
875 * @param L (M x R) service demands
876 * @param N (R) population, OPEN_CLASS on open classes
877 * @param Z (K x R) think times, summed over rows; may be empty
878 * @param mi (M) station multiplicities; empty for all ones
879 * @param S (M) servers per station, INF_SERVERS for an infinite server;
880 * empty for all ones
881 *
882 * The returned CN is the (M x R) per-station residence time of the pfqn_mva
883 * contract in every branch, and UN the (M x R) per-class utilization except on
884 * the closed multiserver branch, where it is the (M x 1) per-station busy
885 * probability of pfqn_mvams_closed as
886 * in MATLAB; see the contract notes at the top of this header. In the mixed multiserver branch the normalizing
887 * constant is not available: G is 0 and lG is NaN, as in MATLAB.
888 *
889 * Standard arrival theorem throughout. For the interlocked-flow correction of
890 * Franks (1999), Ch. 4, Eq. (4.7), call pfqn_mvams_ilock instead.
891 */
892template <class T>
893MvaResult<T> pfqn_mvams(const std::vector<T>& lambda, const Matrix<T>& L,
894 const std::vector<int>& N, const Matrix<T>& Z, const std::vector<int>& mi,
895 const std::vector<int>& S) {
896 const std::size_t M = L.rows();
897 const std::size_t R = N.size();
898 if (!L.empty() && L.cols() != R)
899 throw InputError("pfqn_mvams: demand matrix and population vector disagree on the class count");
900 if (!mi.empty() && mi.size() != M)
901 throw InputError("pfqn_mvams: multiplicity vector has the wrong length");
902 if (!S.empty() && S.size() != M)
903 throw InputError("pfqn_mvams: server-count vector has the wrong length");
904
905 const T zero = num_traits<T>::from_int(0);
906
907 std::vector<int> Sv = S.empty() ? std::vector<int>(M, 1) : S;
908 std::vector<int> miv = mi.empty() ? std::vector<int>(M, 1) : mi;
909 std::vector<T> lam = lambda.empty() ? std::vector<T>(R, zero) : lambda;
910 if (lam.size() != R)
911 throw InputError("pfqn_mvams: arrival-rate vector and population vector disagree on the class count");
912
913 bool hasOpenClasses = false;
914 for (std::size_t r = 0; r < R; ++r)
915 if (is_open_class(N[r])) hasOpenClasses = true;
916 // An infinite server is not counted here, mirroring MATLAB's isfinite guard.
917 bool hasMultiServer = false;
918 for (std::size_t i = 0; i < M; ++i)
919 if (Sv[i] != INF_SERVERS && Sv[i] > 1) {
920 hasMultiServer = true;
921 break;
922 }
923 bool hasReplicas = false;
924 for (std::size_t i = 0; i < M; ++i)
925 if (miv[i] != 1) {
926 hasReplicas = true;
927 break;
928 }
929
930 if (!hasMultiServer) {
931 if (hasOpenClasses) return pfqn_mvamx(lam, L, N, Z, miv);
932 return pfqn_mva(L, N, Z, miv);
933 }
934
935 if (hasOpenClasses) {
936 // MATLAB rejects replicas on the mixed multiserver branch only; the
937 // closed multiserver branch below honours them through pfqn_mvams_closed.
938 if (hasReplicas)
939 throw InputError(ErrorKind{"Argument"}, "pfqn_mvams: queue replicas are not available in exact MVA for mixed models");
940 MvaResult<T> res = pfqn_mvaldms(lam, L, N, Z, Sv);
941 // MATLAB discards the normalizing constant on this branch.
942 res.G = zero;
943 res.lG = std::numeric_limits<double>::quiet_NaN();
944 return res;
945 }
946
947 // Reiser (1981) limited queue-dependent MVA: marginals only up to c_i-1, two
948 // population levels in memory, p_i(0|n) from the complement system rather
949 // than by subtraction. It returns the (M x R) residence time of the pfqn_mva
950 // contract, the per-station UN pfqn_mvald reported here before, and honours
951 // mi as pfqn_mva does (replicas), as MATLAB pfqn_mvams does since it
952 // delegates to pfqn_mvams_closed.
953 std::vector<T> miT(M);
954 for (std::size_t i = 0; i < M; ++i) miT[i] = num_traits<T>::from_int(miv[i]);
955 const MvamsClosedResult<T> c = pfqn_mvams_closed(L, N, Z, miT, Sv, false);
956
957 MvaResult<T> res;
958 res.XN = c.XN;
959 res.QN = c.QN;
960 res.UN = Matrix<T>(M, 1, zero);
961 for (std::size_t i = 0; i < M; ++i) res.UN(i, 0) = c.UN[i];
962 res.CN = c.CN;
963 res.G = c.G;
964 res.lG = c.lG;
965 return res;
966}
967
968/** Overload with unit multiplicities. */
969template <class T>
970MvaResult<T> pfqn_mvams(const std::vector<T>& lambda, const Matrix<T>& L,
971 const std::vector<int>& N, const Matrix<T>& Z, const std::vector<int>& S) {
972 return pfqn_mvams(lambda, L, N, Z, std::vector<int>(), S);
973}
974
975/** Overload with unit multiplicities and a single server everywhere. */
976template <class T>
977MvaResult<T> pfqn_mvams(const std::vector<T>& lambda, const Matrix<T>& L,
978 const std::vector<int>& N, const Matrix<T>& Z) {
979 return pfqn_mvams(lambda, L, N, Z, std::vector<int>(), std::vector<int>());
980}
981
982/**
983 * MVA entry point for models carrying the interlocked-flow correction.
984 *
985 * The interlock of Franks (1999), Ch. 4, Eq. (4.7) is defined only for closed
986 * single-server models, so that is the one shape accepted here; anything else is
987 * refused rather than served without the correction. Models with no interlock go to
988 * pfqn_mvams.
989 *
990 * @param IL (R x R) interlock matrix, see pfqn_mva_ilock. Required.
991 */
992template <class T>
993MvaResult<T> pfqn_mvams_ilock(const std::vector<T>& lambda, const Matrix<T>& L,
994 const std::vector<int>& N, const Matrix<T>& Z,
995 const std::vector<int>& mi, const std::vector<int>& S,
996 const Matrix<T>& IL) {
997 const std::size_t M = L.rows();
998 const std::size_t R = N.size();
999 if (IL.empty())
1000 throw InputError("pfqn_mvams_ilock: an interlock matrix is required; use pfqn_mvams for the standard arrival theorem");
1001 if (!L.empty() && L.cols() != R)
1002 throw InputError("pfqn_mvams_ilock: demand matrix and population vector disagree on the class count");
1003 if (!mi.empty() && mi.size() != M)
1004 throw InputError("pfqn_mvams_ilock: multiplicity vector has the wrong length");
1005 if (!S.empty() && S.size() != M)
1006 throw InputError("pfqn_mvams_ilock: server-count vector has the wrong length");
1007
1008 const T zero = num_traits<T>::from_int(0);
1009 std::vector<int> Sv = S.empty() ? std::vector<int>(M, 1) : S;
1010 std::vector<int> miv = mi.empty() ? std::vector<int>(M, 1) : mi;
1011 std::vector<T> lam = lambda.empty() ? std::vector<T>(R, zero) : lambda;
1012 if (lam.size() != R)
1013 throw InputError("pfqn_mvams_ilock: arrival-rate vector and population vector disagree on the class count");
1014
1015 for (std::size_t r = 0; r < R; ++r)
1016 if (is_open_class(N[r]) || lam[r] != zero)
1017 throw InputError("pfqn_mvams_ilock: the interlock correction is available in exact MVA "
1018 "for closed single-server models only; use an AMVA method");
1019 for (std::size_t i = 0; i < M; ++i)
1020 if (Sv[i] != INF_SERVERS && Sv[i] > 1)
1021 throw InputError("pfqn_mvams_ilock: the interlock correction is available in exact MVA "
1022 "for closed single-server models only; use an AMVA method");
1023
1024 return pfqn_mva_ilock(L, N, Z, miv, IL);
1025}
1026
1027} // namespace pfqn
1028} // namespace line
1029
1030#endif // LINE_API_PFQN_MVAMS_H
InputError(const std::string &what)
Definition error.h:105
void fill(const T &x)
Definition matrix.h:108
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
bool empty() const
Definition matrix.h:92
NumericError(const std::string &what)
Definition error.h:112
The exception types the port throws.
Dense matrix and non-owning view.
MvaResult< T > pfqn_mva(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi)
Exact Mean Value Analysis for closed product-form networks (Reiser and Lavenberg 1980).
Definition pfqn_mva.h:72
MvaResult< T > pfqn_mvams(const std::vector< T > &lambda, const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi, const std::vector< int > &S)
General-purpose exact MVA for mixed networks with multiserver stations.
Definition pfqn_mvams.h:893
constexpr int OPEN_CLASS
Marks an open (infinite-population) class in a population vector.
Definition pfqn_mvams.h:74
MvaResult< T > pfqn_mvamx(const std::vector< T > &lambda, const Matrix< T > &D, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi)
Exact MVA for a mixed open/closed network of single-server stations.
Definition pfqn_mvams.h:314
MvaLdResult< T > pfqn_mvald(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const Matrix< T > &mu, bool stabilize=true)
Exact MVA for a closed network of load-dependent stations.
Definition pfqn_mvams.h:130
MvaResult< T > pfqn_mvaldms(const std::vector< T > &lambda, const Matrix< T > &D, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &S)
Exact MVA for mixed open/closed networks with multiserver stations.
Definition pfqn_mvams.h:820
MvaResult< T > pfqn_mvaldmx(const std::vector< T > &lambda, const Matrix< T > &D, const std::vector< int > &N, const Matrix< T > &Z, const Matrix< T > &mu)
Exact MVA for mixed open/closed networks with limited load dependence.
Definition pfqn_mvams.h:577
constexpr int INF_SERVERS
Marks an infinite-server station in a server-count vector.
Definition pfqn_mvams.h:77
bool is_open_class(int n)
True when the population entry denotes an open class.
Definition pfqn_mvams.h:80
MvamsClosedResult< T > pfqn_mvams_closed(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< T > &mi, const std::vector< int > &S, bool wantP0=true)
Memory-bounded exact MVA for closed networks with multiserver stations (Reiser 1981).
MvaResult< T > pfqn_mva_ilock(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi, const Matrix< T > &IL)
Exact MVA recursion carrying the interlocked-flow correction.
Definition pfqn_mva.h:214
MvaResult< T > pfqn_mvams_ilock(const std::vector< T > &lambda, const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi, const std::vector< int > &S, const Matrix< T > &IL)
MVA entry point for models carrying the interlocked-flow correction.
Definition pfqn_mvams.h:993
void timeout_check(const char *where)
The raising checkpoint, for a computation with no valid partial result: throws LINE:numerical:Timeout...
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
std::size_t population_count(const std::vector< int > &N)
Number of population vectors n with 0 <= n <= N.
Definition population.h:38
std::vector< std::size_t > plane_sizes(const std::vector< int > &N)
Mixed-radix plane sizes: prods[r] = prod_{s<r} (N[s]+1).
Definition population.h:27
bool next_pop(std::vector< int > &n, const std::vector< int > &N)
Advance n to the next population vector in the lattice 0 <= n <= N, odometer order with the last clas...
Definition population.h:56
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition number.h:204
std::size_t pop_index(const std::vector< int > &n, const std::vector< std::size_t > &prods)
Index of n in the lattice, 0-based (MATLAB hashpop is 1-based).
Definition population.h:45
Number-type abstraction for the templated API port.
Exact Mean Value Analysis for closed product-form networks (Reiser and Lavenberg 1980).
Memory-bounded exact MVA for closed networks with multiserver stations.
Population-vector enumeration and combinatorics.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
Result of pfqn_mvald, mirroring the seven MATLAB outputs.
Definition pfqn_mvams.h:93
Matrix< T > WN
(M x R) residence time at the full population
Definition pfqn_mvams.h:98
double lG
log of the normalizing constant
Definition pfqn_mvams.h:101
Matrix< T > QN
(M x R) mean queue length
Definition pfqn_mvams.h:95
std::vector< T > XN
(R) per-class throughput
Definition pfqn_mvams.h:94
std::vector< T > UN
(M) utilization, 1 - P(station empty)
Definition pfqn_mvams.h:96
T G
normalizing constant
Definition pfqn_mvams.h:100
std::vector< T > CN
(R) cycle time, exclusive of think time
Definition pfqn_mvams.h:97
Matrix< T > PI
(M x (Nt+1)) marginal queue-length distribution at N
Definition pfqn_mvams.h:99
bool isNumStable
false once a marginal probability had to be clamped
Definition pfqn_mvams.h:102
std::vector< T > XN
(R) per-class throughput
Definition pfqn_mva.h:46
Matrix< T > QN
(M x R) mean queue length
Definition pfqn_mva.h:47
double lG
log of the normalizing constant
Definition pfqn_mva.h:51
Matrix< T > CN
(M x R) residence time
Definition pfqn_mva.h:49
T G
normalizing constant
Definition pfqn_mva.h:50
Matrix< T > UN
(M x R) utilization
Definition pfqn_mva.h:48
Return value of pfqn_mvams_closed, mirroring [XN,QN,UN,CN,lG,P0].
std::vector< T > UN
(M) busy probability 1-p_i(0|N) of one copy
std::vector< T > XN
(R) class throughputs
Matrix< T > CN
(M x R) residence times, aggregated over copies
double lG
log of the normalizing constant
Matrix< T > QN
(M x R) mean queue lengths, aggregated over copies