LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_nc_oi.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_SOLVERS_NC_SOLVER_NC_OI_H
6#define LINE_SOLVERS_NC_SOLVER_NC_OI_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Order-independent (OI) and pass-and-swap (P&S) normalizing-constant analysis.
12 *
13 * Ports `nc_is_oi_model.m`, `nc_is_pas_model.m`, `solver_nc_oi_analyzer.m` and
14 * `solver_nc_pas_is_analyzer.m`.
15 *
16 * An OI station is a load-dependent server whose total rate mu(n) is invariant
17 * under permutations of the ordered microstate, so it is a function of the
18 * per-class count vector alone. Such a station is product-form under balanced
19 * fairness (Bonald and Proutiere 2003) and the whole network's constant is
20 * assembled on the population lattice: `pfqn_ncoi` evaluates the OI stations
21 * together with the aggregated delay, and every ordinary BCMP station is folded
22 * in by lattice convolution of its load-dependent weight table. Mean queue
23 * lengths come from the OI functional-server identity of `pfqn_oi_fnc` (Casale,
24 * QEST 2006), E[f(n_i)] = G^+/G - 1 with G^+ the convolution of that station's
25 * FNC balance function against the full-network table.
26 *
27 * A P&S station with a NON-EMPTY swap graph is not order-independent: the
28 * ordered-state chain is reducible (Comte and Dorsman 2021) and only the
29 * recurrent communicating class carries a product form. Its constant has no
30 * exact lattice recursion here and is estimated by the auto-normalized
31 * importance sampler `pfqn_pas_is`, which reduces to `pfqn_oi_is` when the swap
32 * graph is empty.
33 *
34 * THE TWO ANALYZERS ARE NOT INTERCHANGEABLE and the dispatch order decides
35 * which a model gets: a pure-OI tandem on 'default'/'exact' is caught by the
36 * exact analyzer first, and only a genuine swap graph (or an explicit 'is' /
37 * 'sampling') reaches the sampler.
38 *
39 * Arithmetic: the OI analyzer needs `log` for lG and `exp`/`lgamma` for the
40 * BCMP weight table, so it is guarded on `has_transcendental`. The sampler needs
41 * a random stream and is guarded the same way through `pfqn_pas_is`.
42 *
43 * NOTE ON PRECISION AT `Real<N>`. `oi_ld_table` accumulates its weight in a
44 * DOUBLE logarithm, exactly as the reference's `gammaln`/`exp` do, so the BCMP
45 * factor is double precision whatever T is. Everything else -- the balanced-
46 * fairness fill, the lattice convolution, the FNC identity -- is field
47 * arithmetic in T. A higher-precision run therefore gains nothing on the BCMP
48 * stations; the table would have to be built as an exact multinomial product to
49 * change that, which is a different algorithm from the reference's.
50 */
51
52#include <cmath>
53#include <functional>
54#include <map>
55#include <memory>
56#include <vector>
57
67#include "line/util/error.h"
68
69namespace line {
70namespace nc {
71
72namespace detail {
73
74/** Column-major lattice descriptor for 0 <= n <= N, as `oi_lattice`. */
75inline void oi_lattice(const std::vector<int>& N, std::vector<std::size_t>& shp,
76 std::vector<std::size_t>& stride, std::size_t& total) {
77 const std::size_t R = N.size();
78 shp.assign(R, 0);
79 stride.assign(R, 1);
80 total = 1;
81 for (std::size_t d = 0; d < R; ++d) shp[d] = static_cast<std::size_t>(N[d]) + 1;
82 for (std::size_t d = 1; d < R; ++d) stride[d] = stride[d - 1] * shp[d - 1];
83 for (std::size_t d = 0; d < R; ++d) total *= shp[d];
84}
85
86/** Decode a 0-based linear lattice index to its count vector, as `oi_sub`. */
87inline std::vector<int> oi_sub(std::size_t i, const std::vector<std::size_t>& shp) {
88 std::vector<int> n(shp.size(), 0);
89 std::size_t li = i;
90 for (std::size_t d = 0; d < shp.size(); ++d) {
91 n[d] = static_cast<int>(li % shp[d]);
92 li /= shp[d];
93 }
94 return n;
95}
96
97/** Flatten a count vector to its 0-based lattice index. */
98inline std::size_t oi_idx(const std::vector<int>& n, const std::vector<std::size_t>& stride) {
99 std::size_t i = 0;
100 for (std::size_t d = 0; d < n.size(); ++d) i += stride[d] * static_cast<std::size_t>(n[d]);
101 return i;
102}
103
104/**
105 * The canonical ordered microstate holding n_r copies of class r, as
106 * `oi_microstate`: any ordering evaluates to the same rate at an OI station.
107 */
108inline std::vector<std::size_t> oi_microstate(const std::vector<int>& n) {
109 std::vector<std::size_t> c;
110 for (std::size_t r = 0; r < n.size(); ++r)
111 for (int a = 0; a < n[r]; ++a) c.push_back(r + 1);
112 return c;
113}
114
115/** Count vectors kept per memoized rank rate; a miss past it just recomputes. */
116const std::size_t OI_RANK_RATE_MEMO_LIMIT = 1u << 17;
117
118/**
119 * An OI rank rate on a per-class COUNT vector, MEMOIZED on that vector.
120 *
121 * Only the importance sampler should use this. It calls the rate 2(ell+1) times
122 * per sampled ordering and walks the same prefix occupancies over and over, so
123 * rebuilding the microstate -- and re-evaluating the balance function on it --
124 * dominated the estimator. The value depends on nothing but the counts, so the
125 * memo returns what the rebuild would have returned, bit for bit. The exact
126 * enumerating paths visit each count vector ONCE and must keep calling
127 * `oi_microstate` directly: there a memo is pure loss.
128 */
129template <class T>
130inline pfqn::OiRateFun<T> oi_rank_rate(
131 const std::function<T(const std::vector<std::size_t>&)>& f) {
132 std::shared_ptr<std::map<std::vector<int>, T> > memo(new std::map<std::vector<int>, T>());
133 return [f, memo](const std::vector<int>& n) -> T {
134 const typename std::map<std::vector<int>, T>::const_iterator it = memo->find(n);
135 if (it != memo->end()) return it->second;
136 const T v = f(oi_microstate(n));
137 if (memo->size() < OI_RANK_RATE_MEMO_LIMIT) (*memo)[n] = v;
138 return v;
139 };
140}
141
142/**
143 * Forward balanced-fairness fill of an OI balance function, as `oi_phi`:
144 * Phi(0) = 1 and Phi(n) = (1/mu(n)) sum_{r : n_r > 0} Phi(n - e_r).
145 */
146template <class T>
147std::vector<T> oi_phi(const std::function<T(const std::vector<int>&)>& oirate,
148 const std::vector<int>& N) {
149 std::vector<std::size_t> shp, stride;
150 std::size_t total = 0;
151 oi_lattice(N, shp, stride, total);
152 const std::size_t R = shp.size();
153 std::vector<T> Phi(total, num_traits<T>::from_int(0));
154 for (std::size_t i = 0; i < total; ++i) {
155 const std::vector<int> n = oi_sub(i, shp);
156 int tot = 0;
157 for (int v : n) tot += v;
158 if (tot == 0) {
159 Phi[i] = num_traits<T>::from_int(1);
160 continue;
161 }
162 T s = num_traits<T>::from_int(0);
163 for (std::size_t r = 0; r < R; ++r)
164 if (n[r] > 0) s += Phi[i - stride[r]];
165 Phi[i] = T(s / oirate(n));
166 }
167 return Phi;
168}
169
170/**
171 * The BCMP load-dependent weight table of one station, as `oi_ld_table`:
172 * W(n) = |n|!/prod(n_r!) prod_r D_r^{n_r} / prod_{k=1}^{|n|} beta(k), with
173 * beta(k) = min(k, c). A class with zero demand contributes nothing, so any
174 * lattice point that places a job there has weight zero.
175 */
176template <class T>
177std::vector<T> oi_ld_table(const std::vector<T>& Dq, double c,
178 const std::vector<std::size_t>& shp, std::size_t total) {
179 const std::size_t R = shp.size();
180 std::vector<T> W(total, num_traits<T>::from_int(0));
181 const double cc = (std::isfinite(c) && c > 0.0) ? c : 1.0;
182 for (std::size_t i = 0; i < total; ++i) {
183 const std::vector<int> n = oi_sub(i, shp);
184 int tot = 0;
185 for (int v : n) tot += v;
186 double logf = std::lgamma(static_cast<double>(tot) + 1.0);
187 bool ok = true;
188 for (std::size_t r = 0; r < R; ++r)
189 if (n[r] > 0) {
190 const double d = num_traits<T>::to_double(Dq[r]);
191 if (!(d > 0.0)) {
192 ok = false;
193 break;
194 }
195 logf += n[r] * std::log(d) - std::lgamma(static_cast<double>(n[r]) + 1.0);
196 }
197 if (!ok) continue;
198 for (int k = 1; k <= tot; ++k)
199 logf -= std::log(std::min(static_cast<double>(k), cc));
200 W[i] = num_traits<T>::from_double(std::exp(logf));
201 }
202 return W;
203}
204
205/** Lattice convolution C(m) = sum_{0<=a<=m} A(a) B(m-a), as `oi_conv`. */
206template <class T>
207std::vector<T> oi_conv(const std::vector<T>& A, const std::vector<T>& B,
208 const std::vector<std::size_t>& shp,
209 const std::vector<std::size_t>& stride, std::size_t total) {
210 const std::size_t R = shp.size();
211 std::vector<std::vector<int>> subs(total);
212 for (std::size_t i = 0; i < total; ++i) subs[i] = oi_sub(i, shp);
213 std::vector<T> C(total, num_traits<T>::from_int(0));
214 for (std::size_t i = 0; i < total; ++i) {
215 T acc = num_traits<T>::from_int(0);
216 for (std::size_t j = 0; j <= i; ++j) {
217 bool le = true;
218 for (std::size_t d = 0; d < R && le; ++d)
219 if (subs[j][d] > subs[i][d]) le = false;
220 if (!le) continue;
221 std::size_t off = 0;
222 for (std::size_t d = 0; d < R; ++d)
223 off += stride[d] * static_cast<std::size_t>(subs[i][d] - subs[j][d]);
224 acc += T(A[j] * B[off]);
225 }
226 C[i] = acc;
227 }
228 return C;
229}
230
231/** G^+ = sum_{0<=b<=N} Psi(b) G(N-b), as `oi_fnc_mean`. */
232template <class T>
233T oi_fnc_mean(const std::vector<T>& Psi, const std::vector<T>& Gfull,
234 const std::vector<std::size_t>& shp, const std::vector<std::size_t>& stride,
235 std::size_t total) {
236 const T zero = num_traits<T>::from_int(0);
237 T val = zero;
238 for (std::size_t i = 0; i < total; ++i) {
239 if (Psi[i] == zero) continue;
240 const std::vector<int> b = oi_sub(i, shp);
241 std::size_t off = 0;
242 for (std::size_t d = 0; d < shp.size(); ++d)
243 off += stride[d] * (shp[d] - 1 - static_cast<std::size_t>(b[d]));
244 val += T(Psi[i] * Gfull[off]);
245 }
246 return val;
247}
248
249/** Per-class visits normalized to the reference station, as both analyzers do. */
250template <class T>
251Matrix<T> oi_visits(const qn::NetworkStruct<T>& sn) {
252 const T zero = num_traits<T>::from_int(0);
253 const std::size_t M = sn.nstations, K = sn.nclasses;
254 Matrix<T> V(M, K, zero);
255 for (std::size_t r = 0; r < K; ++r) {
256 std::size_t chain = 0;
257 for (std::size_t c = 0; c < sn.nchains; ++c)
258 if (sn.chains[c][r]) chain = c + 1;
259 if (chain == 0) continue;
260 for (std::size_t i = 0; i < M; ++i)
261 V(i, r) = sn.visits[chain - 1](sn.stateful_of_station(i + 1) - 1, r);
262 const T vref = V(sn.classes[r].refstat - 1, r);
263 if (vref > zero)
264 for (std::size_t i = 0; i < M; ++i) V(i, r) = T(V(i, r) / vref);
265 }
266 return V;
267}
268
269/** True when the FCFS / SIRO rates at a station vary across populated classes. */
270template <class T>
271bool class_dependent_fcfs_rate(const qn::NetworkStruct<T>& sn, std::size_t i) {
272 double lo = 0.0, hi = 0.0;
273 bool any = false;
274 for (std::size_t r = 0; r < sn.nclasses; ++r) {
275 if (!(sn.classes[r].population > 0.0)) continue;
276 const double v = num_traits<T>::to_double(sn.rates(i, r));
277 if (!std::isfinite(v)) continue;
278 if (!any) {
279 lo = hi = v;
280 any = true;
281 } else {
282 lo = std::min(lo, v);
283 hi = std::max(hi, v);
284 }
285 }
286 return any && (hi - lo) > 1e-9 * hi;
287}
288
289} // namespace detail
290
291/**
292 * Port of `nc_is_oi_model.m`: a closed, open or mixed network with at least one
293 * OI station and nothing but BCMP product-form stations besides (plus the Source
294 * of an open or mixed model). Closed models go to the lattice convolution below,
295 * open ones to `solver_oi_open_analyzer` (pfqn_oi_open) and mixed ones to
296 * `solver_nc_oi_mixed` (pfqn_oi_mixed).
297 *
298 * The OI requirement is what keeps a pure-BCMP network on the ordinary (faster)
299 * normalizing-constant paths rather than the lattice one.
300 */
301template <class T>
303 using qn::SchedStrategy;
304 bool hasOI = false;
305 for (std::size_t i = 0; i < sn.nstations; ++i) {
306 const SchedStrategy s = sn.stations[i].sched;
307 if (s == SchedStrategy::INF || sn.stations[i].nodetype == qn::NodeType::Source) continue;
308 if (s == SchedStrategy::PAS || s == SchedStrategy::OI) {
309 if (!qn::station_swap_graph_is_zero(sn, i + 1)) return false; // genuine P&S
310 hasOI = true;
311 } else if (s == SchedStrategy::PS || s == SchedStrategy::LCFSPR ||
312 s == SchedStrategy::SIRO || s == SchedStrategy::FCFS) {
313 if ((s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) &&
314 detail::class_dependent_fcfs_rate(sn, i))
315 return false;
316 } else {
317 return false; // an unsupported (non-product-form) station
318 }
319 }
320 return hasOI;
321}
322
323/**
324 * Port of `nc_is_pas_model.m`: a closed two-station OI / P&S tandem.
325 *
326 * The swap graph may be empty, since an OI queue is exactly the P&S
327 * specialization with a zero graph and `pfqn_pas_is` reduces to `pfqn_oi_is`
328 * there; the exact analyzer is what keeps a pure-OI tandem off this path on
329 * 'default' and 'exact'.
330 */
331template <class T>
333 using qn::SchedStrategy;
334 for (const qn::JobClass& c : sn.classes)
335 if (std::isinf(c.population)) return false;
336 if (sn.nstations != 2) return false;
337 for (std::size_t i = 0; i < sn.nstations; ++i) {
338 const SchedStrategy s = sn.stations[i].sched;
339 if (s != SchedStrategy::PAS && s != SchedStrategy::OI) return false;
340 if (!sn.stations[i].svc_rate_fun) return false;
341 }
342 return true;
343}
344
345namespace detail {
346
347/** Multinomial delay factor prod_r Z_r^{c_r}/c_r! over the closed lattice, as `oi_delay_table`. */
348template <class T>
349std::vector<T> oi_mixed_delay_table(const std::vector<double>& Z,
350 const std::vector<std::size_t>& shp, std::size_t total) {
351 std::vector<T> W(total, num_traits<T>::from_int(0));
352 for (std::size_t k = 0; k < total; ++k) {
353 const std::vector<int> c = oi_sub(k, shp);
354 bool ok = true;
355 double lw = 0.0;
356 for (std::size_t a = 0; a < c.size(); ++a)
357 if (c[a] > 0) {
358 if (!(Z[a] > 0.0)) {
359 ok = false;
360 break;
361 }
362 lw += c[a] * std::log(Z[a]) - std::lgamma(c[a] + 1.0);
363 }
364 if (ok) W[k] = num_traits<T>::from_double(std::exp(lw));
365 }
366 return W;
367}
368
369/**
370 * Closed-lattice table of a c-server BCMP queue carrying open load rhoO, as
371 * `oi_bcmp_mixed_table`: the load-dependent factor summed over the open counts
372 * in closed form per open total, the series geometric with ratio
373 * rho_open/c beyond c and summed to machine precision. `stable` is false when
374 * the open load alone saturates the station.
375 */
376template <class T>
377bool oi_mixed_bcmp_table(const std::vector<double>& D, const std::vector<double>& rhoO, double csrv,
378 const std::vector<std::size_t>& shp, std::size_t total,
379 const std::vector<std::size_t>& closedIdx, std::size_t K,
380 std::vector<T>& W, Matrix<T>& H) {
381 W.assign(total, num_traits<T>::from_int(0));
382 H = Matrix<T>(total, K, num_traits<T>::from_int(0));
383 double ro = 0.0;
384 for (double v : rhoO) ro += v;
385 if (!(ro < csrv)) return false;
386 for (std::size_t k = 0; k < total; ++k) {
387 const std::vector<int> c = oi_sub(k, shp);
388 int n = 0;
389 bool ok = true;
390 for (std::size_t a = 0; a < c.size(); ++a) {
391 n += c[a];
392 if (c[a] > 0 && !(D[a] > 0.0)) ok = false;
393 }
394 if (!ok) continue;
395 double logb = std::lgamma(n + 1.0);
396 for (std::size_t a = 0; a < c.size(); ++a)
397 if (c[a] > 0) logb += c[a] * std::log(D[a]) - std::lgamma(c[a] + 1.0);
398 for (int j = 1; j <= n; ++j) logb -= std::log(std::min(static_cast<double>(j), csrv));
399 // series over the open total kk: t_kk = C(n+kk,kk) ro^kk / prod_{j=n+1}^{n+kk} min(j,c)
400 double s0 = 1.0, s1 = 0.0, t = 1.0;
401 int kk = 0;
402 if (ro > 0.0) {
403 while (true) {
404 t = t * (n + kk + 1) / (kk + 1) * ro / std::min(static_cast<double>(n + kk + 1), csrv);
405 ++kk;
406 s0 += t;
407 s1 += kk * t;
408 if (kk > csrv && t < 1e-17 * s0 &&
409 kk * t < 1e-17 * std::max(s1, std::numeric_limits<double>::min()))
410 break;
411 }
412 }
413 const double base = std::exp(logb);
414 const double wk = base * s0;
415 W[k] = num_traits<T>::from_double(wk);
416 std::vector<double> hrow(K, 0.0);
417 for (std::size_t a = 0; a < closedIdx.size(); ++a) hrow[closedIdx[a]] = c[a] * wk;
418 if (ro > 0.0)
419 for (std::size_t r = 0; r < K; ++r)
420 if (rhoO[r] > 0.0) hrow[r] += base * s1 * rhoO[r] / ro;
421 for (std::size_t r = 0; r < K; ++r) H(k, r) = num_traits<T>::from_double(hrow[r]);
422 }
423 return true;
424}
425
426} // namespace detail
427
428/**
429 * Port of `solver_nc_oi_mixed.m`: exact normalizing-constant analysis of a MIXED
430 * (open and closed) network of OI and BCMP product-form stations.
431 *
432 * OI queues are quasi-reversible (Berezner, Kriel, Krzesinski 1995), so the
433 * joint law is a product of station factors f_i(c_i, o_i). Summing each over
434 * its open counts gives a closed-lattice station table W_i(c), and the closed
435 * chains are analyzed by lattice convolution G = conv_i W_i over 0 <= c <= N:
436 * - OI station: `pfqn_oi_mixed` (open coordinates summed exactly);
437 * - INF: the multinomial delay factor prod_r Z_r^{c_r}/c_r! (the open classes
438 * are independent Poisson counts);
439 * - c-server BCMP queue: the load-dependent factor summed over the open
440 * counts per open total, a geometric tail beyond c.
441 * Per-class means follow from the mean-weight tables H_i and the complement
442 * G_{-i} = conv_{j != i} W_j: E[n_ir] = sum_c H_ir(c) G_{-i}(N - c) / G(N), for
443 * closed and open classes alike; closed throughputs are G(N - e_r)/G(N), open
444 * ones lambda_s V_is.
445 *
446 * CN, a matrix in the reference (it returns RN), is the per-class vector here
447 * as everywhere in this port: N_r/X_r for a closed class, the visit-weighted
448 * sum of the per-visit response times for an open one.
449 */
450template <class T>
452 using qn::SchedStrategy;
453 NcSolution<T> out;
454 if constexpr (!num_traits<T>::has_transcendental) {
455 (void)sn;
456 (void)opt;
457 throw UnsupportedError(ErrorKind{"Arithmetic"},
458 "solver_nc_oi_mixed: the delay and BCMP station tables are formed as exp(lgamma(...)), "
459 "lG as log(G) and an unstable station reports Inf; this backend has no transcendental "
460 "arithmetic");
461 } else {
462 const std::string why = nc_oi_refusal(sn, "oi");
463 if (!why.empty()) throw UnsupportedError(ErrorKind{"Structure"}, why);
464 const T zero = num_traits<T>::from_int(0);
465 const std::size_t M = sn.nstations, K = sn.nclasses;
466 std::vector<bool> isOpen(K, false);
467 std::vector<double> Nfull(K, 0.0);
468 std::vector<std::size_t> closedIdx;
469 std::vector<int> Nc;
470 for (std::size_t r = 0; r < K; ++r) {
471 Nfull[r] = sn.classes[r].population;
472 isOpen[r] = std::isinf(Nfull[r]);
473 if (!isOpen[r]) {
474 closedIdx.push_back(r);
475 Nc.push_back(static_cast<int>(std::llround(Nfull[r])));
476 }
477 }
478 std::vector<std::size_t> shp, stride;
479 std::size_t ncl = 0;
480 detail::oi_lattice(Nc, shp, stride, ncl);
481 std::vector<T> unit(ncl, zero);
482 unit[0] = num_traits<T>::from_int(1);
483
484 // ---- visits normalized to each class's reference station; open lambda
485 const Matrix<T> V = detail::oi_visits(sn);
486 std::vector<T> lam(K, zero);
487 for (std::size_t r = 0; r < K; ++r)
488 if (isOpen[r]) {
489 const std::size_t ref = sn.classes[r].refstat;
490 const double l = num_traits<T>::to_double(sn.rates(ref - 1, r));
491 if (std::isfinite(l) && l > 0.0) lam[r] = sn.rates(ref - 1, r);
492 }
493 Matrix<T> ST(M, K, zero);
494 for (std::size_t i = 0; i < M; ++i)
495 for (std::size_t r = 0; r < K; ++r) {
496 const double rate = num_traits<T>::to_double(sn.rates(i, r));
497 if (std::isfinite(rate) && rate > 0.0)
498 ST(i, r) = T(num_traits<T>::from_int(1) / sn.rates(i, r));
499 }
500
501 // ---- station tables over the closed lattice ------------------------
502 std::vector<std::vector<T>> Wt(M);
503 std::vector<Matrix<T>> Ht(M), St(M);
504 std::vector<int> kind(M, 0); // 0 source, 1 INF, 2 OI, 3 BCMP queue
505 std::vector<bool> unstableAt(M, false);
506 bool anyUnstable = false, trunc = false;
508 kopt.tol = opt.tol;
509 for (std::size_t i = 0; i < M; ++i) {
510 const qn::Station<T>& st = sn.stations[i];
511 if (st.nodetype == qn::NodeType::Source) {
512 kind[i] = 0;
513 Wt[i] = unit;
514 } else if (st.sched == SchedStrategy::INF) {
515 kind[i] = 1;
516 std::vector<double> Z(closedIdx.size(), 0.0);
517 for (std::size_t a = 0; a < closedIdx.size(); ++a)
518 Z[a] = num_traits<T>::to_double(T(V(i, closedIdx[a]) * ST(i, closedIdx[a])));
519 Wt[i] = detail::oi_mixed_delay_table<T>(Z, shp, ncl);
520 } else if (st.sched == SchedStrategy::OI || st.sched == SchedStrategy::PAS) {
521 kind[i] = 2;
522 std::vector<T> w(K, zero);
523 for (std::size_t r = 0; r < K; ++r)
524 w[r] = isOpen[r] ? T(lam[r] * V(i, r)) : V(i, r);
525 const pfqn::OiMixedResult<T> mr =
526 pfqn::pfqn_oi_mixed<T>(w, Nfull, detail::oi_open_rate(st), kopt);
527 if (mr.method == "oi.trunc") trunc = true;
528 if (!mr.stable) {
529 anyUnstable = true;
530 unstableAt[i] = true;
531 Wt[i] = unit;
532 } else {
533 Wt[i] = mr.W;
534 Ht[i] = mr.H;
535 St[i] = mr.S;
536 }
537 } else {
538 kind[i] = 3;
539 double csrv = st.nservers;
540 if (!std::isfinite(csrv) || csrv <= 0.0) csrv = 1.0;
541 std::vector<double> D(closedIdx.size(), 0.0), rhoO(K, 0.0);
542 for (std::size_t a = 0; a < closedIdx.size(); ++a)
543 D[a] = num_traits<T>::to_double(T(V(i, closedIdx[a]) * ST(i, closedIdx[a])));
544 for (std::size_t r = 0; r < K; ++r)
545 if (isOpen[r])
546 rhoO[r] = num_traits<T>::to_double(T(lam[r] * V(i, r) * ST(i, r)));
547 std::vector<T> Wi;
548 Matrix<T> Hi;
549 if (!detail::oi_mixed_bcmp_table<T>(D, rhoO, csrv, shp, ncl, closedIdx, K, Wi, Hi)) {
550 anyUnstable = true;
551 unstableAt[i] = true;
552 Wt[i] = unit;
553 } else {
554 Wt[i] = Wi;
555 Ht[i] = Hi;
556 }
557 }
558 }
559
560 // ---- network normalizing constant and closed throughputs ----------
561 std::vector<T> Gfull = unit;
562 for (std::size_t i = 0; i < M; ++i) Gfull = detail::oi_conv(Gfull, Wt[i], shp, stride, ncl);
563 const T G = Gfull[ncl - 1];
564 std::vector<T> X(K, zero);
565 for (std::size_t r = 0; r < K; ++r)
566 if (isOpen[r]) X[r] = lam[r];
567 for (std::size_t a = 0; a < closedIdx.size(); ++a)
568 if (Nc[a] > 0) X[closedIdx[a]] = T(Gfull[ncl - 1 - stride[a]] / G);
569
570 // ---- per-station means via the complement convolution -------------
571 Matrix<T> Q(M, K, zero), U(M, K, zero), Tp(M, K, zero), R(M, K, zero);
572 for (std::size_t i = 0; i < M; ++i)
573 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(V(i, r) * X[r]);
574 const T inf = num_traits<T>::from_double(std::numeric_limits<double>::infinity());
575 for (std::size_t i = 0; i < M; ++i) {
576 if (kind[i] == 0) continue;
577 if (unstableAt[i]) {
578 std::vector<double> load(K, 0.0);
579 double s = 0.0;
580 for (std::size_t r = 0; r < K; ++r) {
581 load[r] = num_traits<T>::to_double(T(Tp(i, r) * ST(i, r)));
582 s += load[r];
583 if (isOpen[r] && Tp(i, r) > zero) Q(i, r) = inf;
584 }
585 if (s > 0.0)
586 for (std::size_t r = 0; r < K; ++r) U(i, r) = num_traits<T>::from_double(load[r] / s);
587 continue;
588 }
589 if (kind[i] == 1) {
590 for (std::size_t r = 0; r < K; ++r) {
591 Q(i, r) = T(Tp(i, r) * ST(i, r));
592 U(i, r) = Q(i, r);
593 }
594 continue;
595 }
596 std::vector<T> Gm = unit;
597 for (std::size_t j = 0; j < M; ++j)
598 if (j != i) Gm = detail::oi_conv(Gm, Wt[j], shp, stride, ncl);
599 double csrv = sn.stations[i].nservers;
600 if (!std::isfinite(csrv) || csrv <= 0.0) csrv = 1.0;
601 const T cs = num_traits<T>::from_double(csrv);
602 for (std::size_t r = 0; r < K; ++r) {
603 T qa = zero, ua = zero;
604 for (std::size_t k = 0; k < ncl; ++k) {
605 const T& gf = Gm[ncl - 1 - k]; // G_{-i}(N - c)
606 qa += T(Ht[i](k, r) * gf);
607 if (kind[i] == 2) ua += T(St[i](k, r) * gf);
608 }
609 Q(i, r) = T(qa / G);
610 U(i, r) = kind[i] == 2 ? T(ua / G / cs) : T(Tp(i, r) * ST(i, r) / cs);
611 }
612 }
613 for (std::size_t i = 0; i < M; ++i)
614 for (std::size_t r = 0; r < K; ++r)
615 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
616
617 std::vector<T> C(K, zero);
618 for (std::size_t r = 0; r < K; ++r) {
619 if (isOpen[r]) {
620 for (std::size_t i = 0; i < M; ++i)
621 if (sn.stations[i].nodetype != qn::NodeType::Source && V(i, r) > zero)
622 C[r] += T(R(i, r) * V(i, r));
623 } else if (X[r] > zero) {
624 C[r] = T(num_traits<T>::from_double(Nfull[r]) / X[r]);
625 }
626 }
627 out.sol.Q = Q;
628 out.sol.U = U;
629 out.sol.R = R;
630 out.sol.Tp = Tp;
631 out.sol.X = X;
632 out.sol.C = C;
633 out.sol.iter = 1;
634 out.sol.lG = anyUnstable ? std::numeric_limits<double>::infinity()
636 out.sol.method = trunc ? "oi.trunc" : "oi";
637 out.actualmethod = out.sol.method;
638 return out;
639 }
640}
641
642/**
643 * Port of `solver_nc_oi_analyzer.m`.
644 *
645 * @param sn the refreshed struct
646 * @param opt solver controls; `tol` is the 'oi.trunc' tolerance of the open and
647 * mixed routes, the closed convolution is exact and reads nothing
648 */
649template <class T>
651 using qn::SchedStrategy;
652 NcSolution<T> out;
653 if constexpr (!num_traits<T>::has_transcendental) {
654 (void)sn;
655 (void)opt;
656 throw UnsupportedError(ErrorKind{"Arithmetic"},
657 "solver_nc_oi_analyzer: the BCMP weight table is formed as exp(lgamma(...)) and lG as "
658 "log(G); this backend has no transcendental arithmetic");
659 } else {
660 const T zero = num_traits<T>::from_int(0);
661 const std::size_t M = sn.nstations, K = sn.nclasses;
662
663 // Open and mixed networks have routes of their own (solver_nc_oi_analyzer.m):
664 // an open network decomposes station by station (shared with SolverMVA),
665 // a mixed one sums the open classes out into closed-lattice tables.
666 {
667 bool anyOpen = false, allOpen = true;
668 for (const qn::JobClass& c : sn.classes) {
669 if (std::isinf(c.population)) anyOpen = true;
670 else allOpen = false;
671 }
672 if (anyOpen && allOpen) {
673 out.sol = solver_oi_open_analyzer(sn, opt.tol);
674 out.actualmethod = out.sol.method;
675 return out;
676 }
677 if (anyOpen) return solver_nc_oi_mixed(sn, opt);
678 }
679
680 // The OI rank rates are indexed by RAW class, so a chain that merges
681 // several classes has no rate to evaluate.
682 for (std::size_t c = 0; c < sn.nchains; ++c)
683 if (sn.inchain[c].size() > 1)
684 throw UnsupportedError(ErrorKind{"ClassSwitch"},
685 "solver_nc_oi: requires one class per chain (no class switching)");
686 std::vector<int> N(K, 0);
687 for (std::size_t r = 0; r < K; ++r) {
688 if (std::isinf(sn.classes[r].population))
689 throw UnsupportedError(ErrorKind{"OpenClass"}, "solver_nc_oi: requires a closed queueing network");
690 N[r] = static_cast<int>(std::llround(sn.classes[r].population));
691 }
692
693 std::vector<bool> isOI(M, false), isINF(M, false), isQ(M, false);
694 for (std::size_t i = 0; i < M; ++i) {
695 const SchedStrategy s = sn.stations[i].sched;
696 if (s == SchedStrategy::INF) {
697 isINF[i] = true;
698 } else if (s == SchedStrategy::PAS || s == SchedStrategy::OI) {
700 throw UnsupportedError(ErrorKind{"SchedStrategy_PAS"},
701 "solver_nc_oi: supports OI stations only (PAS with a non-empty swap graph "
702 "is not order-independent)");
703 isOI[i] = true;
704 if (!sn.stations[i].svc_rate_fun)
705 throw UnsupportedError(ErrorKind{"Model"},
706 "solver_nc_oi: an OI station has no service rate function; set it via "
707 "setServiceRateFunction");
708 } else if (s == SchedStrategy::PS || s == SchedStrategy::LCFSPR ||
709 s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) {
710 isQ[i] = true;
711 if ((s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) &&
712 detail::class_dependent_fcfs_rate(sn, i))
713 throw UnsupportedError(ErrorKind{"ProductForm"},
714 "solver_nc_oi: a station has class-dependent FCFS/SIRO rates and is not "
715 "product form; class-independent rates are required");
716 } else {
717 throw UnsupportedError(ErrorKind{"SchedStrategy"},
718 "solver_nc_oi: supports only INF (delay), OI, PS, LCFS-PR, SIRO and "
719 "class-independent FCFS stations");
720 }
721 }
722
723 const Matrix<T> V = detail::oi_visits(sn);
724
725 // Delays aggregate into Z; every other BCMP queue keeps its own demand.
726 std::vector<T> Z(K, zero);
727 Matrix<T> D(M, K, zero);
728 for (std::size_t i = 0; i < M; ++i)
729 for (std::size_t r = 0; r < K; ++r) {
730 const double mu = num_traits<T>::to_double(sn.rates(i, r));
731 if (!std::isfinite(mu) || mu == 0.0) continue;
732 const T st = T(V(i, r) / sn.rates(i, r));
733 if (isINF[i]) Z[r] += st;
734 if (isQ[i]) D(i, r) = st;
735 }
736
737 for (std::size_t i = 0; i < M; ++i)
738 if (isOI[i])
739 for (std::size_t r = 0; r < K; ++r)
740 if (N[r] > 0 &&
741 std::fabs(num_traits<T>::to_double(V(i, r)) - 1.0) > 1e-9)
742 throw UnsupportedError(ErrorKind{"SchedStrategy_OI"},
743 "solver_nc_oi: requires unit per-class visits at every OI station");
744
745 std::vector<std::size_t> oiList, qList;
746 for (std::size_t i = 0; i < M; ++i) {
747 if (isOI[i]) oiList.push_back(i + 1);
748 if (isQ[i]) qList.push_back(i + 1);
749 }
750 std::vector<pfqn::OiRate<T>> rates;
751 for (std::size_t m = 0; m < oiList.size(); ++m) {
752 const std::function<T(const std::vector<std::size_t>&)> f =
753 sn.stations[oiList[m] - 1].svc_rate_fun;
754 rates.push_back(
755 [f](const std::vector<int>& n) { return f(detail::oi_microstate(n)); });
756 }
757
758 std::vector<std::size_t> shp, stride;
759 std::size_t total = 0;
760 detail::oi_lattice(N, shp, stride, total);
761
762 // The core table over the lattice: OI stations plus the aggregated delay.
763 std::vector<T> Gfull(total, zero);
764 for (std::size_t i = 0; i < total; ++i)
765 Gfull[i] = pfqn::pfqn_ncoi(Z, detail::oi_sub(i, shp), rates).G;
766
767 for (std::size_t i : qList) {
768 std::vector<T> Dq(K, zero);
769 for (std::size_t r = 0; r < K; ++r) Dq[r] = D(i - 1, r);
770 const std::vector<T> Wq =
771 detail::oi_ld_table(Dq, sn.stations[i - 1].nservers, shp, total);
772 Gfull = detail::oi_conv(Gfull, Wq, shp, stride, total);
773 }
774
775 const T G = Gfull[total - 1];
777
778 std::vector<T> X(K, zero);
779 for (std::size_t r = 0; r < K; ++r)
780 if (N[r] > 0) {
781 std::vector<int> Nr = N;
782 --Nr[r];
783 X[r] = T(Gfull[detail::oi_idx(Nr, stride)] / G);
784 }
785
786 Matrix<T> Q(M, K, zero), Tp(M, K, zero), R(M, K, zero), U(M, K, zero);
787 const T one = num_traits<T>::from_int(1);
788 for (std::size_t m = 0; m < oiList.size(); ++m) {
789 const std::size_t i = oiList[m];
790 const std::vector<T> Phi = detail::oi_phi<T>(rates[m], N);
791 for (std::size_t r = 0; r < K; ++r) {
792 if (N[r] == 0) continue;
794 Phi, N, [r](const std::vector<int>& n) {
795 return num_traits<T>::from_int(n[r]);
796 });
797 Q(i - 1, r) =
798 T(detail::oi_fnc_mean(fr.Psi, Gfull, shp, stride, total) / G - one);
799 }
800 }
801 for (std::size_t i : qList) {
802 std::vector<T> Dq(K, zero);
803 for (std::size_t r = 0; r < K; ++r) Dq[r] = D(i - 1, r);
804 const std::vector<T> Wq =
805 detail::oi_ld_table(Dq, sn.stations[i - 1].nservers, shp, total);
806 for (std::size_t r = 0; r < K; ++r) {
807 if (N[r] == 0) continue;
809 Wq, N, [r](const std::vector<int>& n) {
810 return num_traits<T>::from_int(n[r]);
811 });
812 Q(i - 1, r) =
813 T(detail::oi_fnc_mean(fr.Psi, Gfull, shp, stride, total) / G - one);
814 }
815 }
816 for (std::size_t i = 0; i < M; ++i)
817 if (isINF[i])
818 for (std::size_t r = 0; r < K; ++r) {
819 const double mu = num_traits<T>::to_double(sn.rates(i, r));
820 if (!std::isfinite(mu) || mu == 0.0) continue;
821 Q(i, r) = T(X[r] * V(i, r) / sn.rates(i, r));
822 }
823
824 for (std::size_t i = 0; i < M; ++i)
825 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(X[r] * V(i, r));
826 for (std::size_t i = 0; i < M; ++i)
827 if (isINF[i])
828 for (std::size_t r = 0; r < K; ++r) U(i, r) = Q(i, r); // INF convention
829 for (std::size_t i : qList) {
830 const double c_raw = sn.stations[i - 1].nservers;
831 const double c = (std::isfinite(c_raw) && c_raw > 0.0) ? c_raw : 1.0;
832 for (std::size_t r = 0; r < K; ++r)
833 U(i - 1, r) = T(X[r] * D(i - 1, r) / num_traits<T>::from_double(c));
834 }
835 for (std::size_t m = 0; m < oiList.size(); ++m) {
836 // IN-SERVICE utilization E[sir_r]/c, the exact CTMC / LDES
837 // convention: sir_r counts the class-r jobs receiving a strictly
838 // positive rank rate, which is a function of the count vector, so
839 // its mean is read off the same functional-server identity. It
840 // coincides with the offered-load form T/mu(e_r)/c only when a job
841 // engages a single server.
842 const std::size_t i = oiList[m];
843 const double s_raw = sn.stations[i - 1].nservers;
844 const double s = (std::isfinite(s_raw) && s_raw > 0.0) ? s_raw : 1.0;
845 const std::vector<T> Phi = detail::oi_phi<T>(rates[m], N);
846 const pfqn::OiInsvcResult<T> ins = pfqn::pfqn_oi_insvc<T>(rates[m], N);
847 for (std::size_t r = 0; r < K; ++r) {
848 if (N[r] == 0) continue;
850 Phi, N, [&ins, &stride, r](const std::vector<int>& n) {
851 return ins.g(detail::oi_idx(n, stride), r);
852 });
853 U(i - 1, r) =
854 T((detail::oi_fnc_mean(fr.Psi, Gfull, shp, stride, total) / G - one) /
856 }
857 }
858 for (std::size_t i = 0; i < M; ++i)
859 for (std::size_t r = 0; r < K; ++r)
860 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
861
862 std::vector<T> C(K, zero);
863 for (std::size_t r = 0; r < K; ++r)
864 if (X[r] > zero) C[r] = T(num_traits<T>::from_int(N[r]) / X[r]);
865
866 out.sol.Q = Q;
867 out.sol.U = U;
868 out.sol.R = R;
869 out.sol.Tp = Tp;
870 out.sol.X = X;
871 out.sol.C = C;
872 out.sol.iter = 1;
873 out.sol.method = "oi";
874 out.actualmethod = "oi";
875 return out;
876 }
877}
878
879/**
880 * Port of `solver_nc_pas_is_analyzer.m`.
881 *
882 * @param sn the refreshed struct
883 * @param opt solver controls; `samples` and `seed` reach `pfqn_pas_is`
884 */
885template <class T>
887 const NcSolverOptions& opt) {
888 using qn::SchedStrategy;
889 NcSolution<T> out;
890 if constexpr (!num_traits<T>::has_transcendental) {
891 (void)sn;
892 (void)opt;
893 throw UnsupportedError(ErrorKind{"Arithmetic"},
894 "solver_nc_pas_is_analyzer: the auto-normalized importance sampler draws from a "
895 "continuous proposal and reports lG = log(G); this backend has no transcendental "
896 "arithmetic");
897 } else {
898 const T zero = num_traits<T>::from_int(0);
899 const std::size_t M = sn.nstations, K = sn.nclasses;
900
901 for (std::size_t c = 0; c < sn.nchains; ++c)
902 if (sn.inchain[c].size() > 1)
903 throw UnsupportedError(ErrorKind{"ClassSwitch"},
904 "solver_nc_pas_is: requires one class per chain (no class switching)");
905 for (const qn::JobClass& c : sn.classes)
906 if (std::isinf(c.population))
907 throw UnsupportedError(ErrorKind{"OpenClass"}, "solver_nc_pas_is: requires a closed queueing network");
908 if (M != 2)
909 throw UnsupportedError(ErrorKind{"Topology"},
910 "solver_nc_pas_is: models a two-station pass-and-swap tandem");
911 std::vector<int> N(K, 0);
912 for (std::size_t r = 0; r < K; ++r)
913 N[r] = static_cast<int>(std::llround(sn.classes[r].population));
914
915 std::vector<std::function<T(const std::vector<std::size_t>&)>> svc(M);
916 std::vector<Matrix<T>> swapG(M);
917 for (std::size_t i = 0; i < M; ++i) {
918 const SchedStrategy s = sn.stations[i].sched;
919 if (s != SchedStrategy::PAS && s != SchedStrategy::OI)
920 throw UnsupportedError(ErrorKind{"SchedStrategy_PAS"},
921 "solver_nc_pas_is: requires both stations to be OI/PAS");
922 svc[i] = sn.stations[i].svc_rate_fun;
923 if (!svc[i])
924 throw UnsupportedError(ErrorKind{"Model"},
925 "solver_nc_pas_is: an OI/PAS station has no service rate function; set it via "
926 "setServiceRateFunction");
927 swapG[i] = qn::station_swap_graph(sn, i + 1);
928 }
929
930 std::vector<pfqn::OiRateFun<T>> mu(M);
931 for (std::size_t i = 0; i < M; ++i) mu[i] = detail::oi_rank_rate<T>(svc[i]);
932
933 // The stored graph is the raw class-compatibility graph; the estimator
934 // needs the global placement-order DAG that defines the recurrent
935 // communicating class, derived from the P&S dynamics on the one-job-per-
936 // class instance. Station 2 is the reversed suffix inside pfqn_pas_is,
937 // so a single global order suffices.
938 //
939 // pas_swap2order hands its rate functions an ORDERED microstate (a list
940 // of 1-based class indices), where pfqn_pas_is hands its own a support
941 // indicator; both reach the same svcRateFun, so only the adapter differs.
942 std::vector<pfqn::PasRateFun<T>> murates(M);
943 for (std::size_t i = 0; i < M; ++i) {
944 const std::function<T(const std::vector<std::size_t>&)> f = svc[i];
945 murates[i] = [f](const std::vector<int>& c) {
946 std::vector<std::size_t> mc(c.size());
947 for (std::size_t a = 0; a < c.size(); ++a)
948 mc[a] = static_cast<std::size_t>(c[a]);
949 return f(mc);
950 };
951 }
952 const Matrix<T> H = pfqn::pas_swap2order<T>(swapG, murates, std::vector<int>(K, 1));
953 Matrix<int> Hi(H.rows(), H.cols(), 0);
954 for (std::size_t a = 0; a < H.rows(); ++a)
955 for (std::size_t b = 0; b < H.cols(); ++b)
956 Hi(a, b) = static_cast<int>(std::llround(num_traits<T>::to_double(H(a, b))));
957
958 const Matrix<T> V = detail::oi_visits(sn);
959 for (std::size_t i = 0; i < M; ++i)
960 for (std::size_t r = 0; r < K; ++r)
961 if (N[r] > 0 && std::fabs(num_traits<T>::to_double(V(i, r)) - 1.0) > 1e-9)
962 throw UnsupportedError(ErrorKind{"Topology"},
963 "solver_nc_pas_is: requires unit per-class visits at both stations");
964
965 const std::size_t samples = opt.samples > 0 ? opt.samples : 10000;
966 const unsigned seed = opt.seed > 0 ? static_cast<unsigned>(opt.seed) : 23456u;
967
968 pfqn::McRng g0(seed);
969 const pfqn::PasIsResult<T> res = pfqn::pfqn_pas_is<T>(N, mu, Hi, samples, g0);
970 out.sol.lG = num_traits<T>::log_as_double(res.G);
971
972 Matrix<T> Q(M, K, zero), Tp(M, K, zero), R(M, K, zero), U(M, K, zero);
973 for (std::size_t i = 0; i < M; ++i)
974 for (std::size_t r = 0; r < K; ++r) Q(i, r) = res.Q(i, r);
975
976 // Common random numbers across the N and N-e_r runs: each call restarts
977 // the stream from the same seed, which is what makes the ratio far less
978 // noisy than two independent estimates would be.
979 std::vector<T> X(K, zero);
980 for (std::size_t r = 0; r < K; ++r)
981 if (N[r] > 0) {
982 std::vector<int> Nr = N;
983 --Nr[r];
984 pfqn::McRng gr_rng(seed);
985 // Only the constant is read here, so this run skips the
986 // prefix-count coefficients: same stream, same G, none of the
987 // O(ell R) per-sample bookkeeping behind the queue lengths.
988 const pfqn::PasIsResult<T> gr =
989 pfqn::pfqn_pas_is<T>(Nr, mu, Hi, samples, gr_rng, false);
990 if (res.G > zero) X[r] = T(gr.G / res.G);
991 }
992
993 for (std::size_t i = 0; i < M; ++i)
994 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(X[r] * V(i, r));
995 for (std::size_t i = 0; i < M; ++i) {
996 const double s_raw = sn.stations[i].nservers;
997 const double s = (std::isfinite(s_raw) && s_raw > 0.0) ? s_raw : 1.0;
998 for (std::size_t r = 0; r < K; ++r) {
999 if (N[r] == 0) continue;
1000 std::vector<int> er(K, 0);
1001 er[r] = 1;
1002 const T muR = mu[i](er); // rank rate with only class r present
1003 if (muR > zero)
1004 U(i, r) = T(Tp(i, r) / muR / num_traits<T>::from_double(s));
1005 }
1006 }
1007 for (std::size_t i = 0; i < M; ++i)
1008 for (std::size_t r = 0; r < K; ++r)
1009 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
1010
1011 std::vector<T> C(K, zero);
1012 for (std::size_t r = 0; r < K; ++r)
1013 if (X[r] > zero) C[r] = T(num_traits<T>::from_int(N[r]) / X[r]);
1014
1015 out.sol.Q = Q;
1016 out.sol.U = U;
1017 out.sol.R = R;
1018 out.sol.Tp = Tp;
1019 out.sol.X = X;
1020 out.sol.C = C;
1021 out.sol.iter = 1;
1022 out.sol.method = "is";
1023 out.actualmethod = "is";
1024 return out;
1025 }
1026}
1027
1028} // namespace nc
1029} // namespace line
1030
1031#endif // LINE_SOLVERS_NC_SOLVER_NC_OI_H
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
The exception types the port throws.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
double tot(const std::vector< double > &pops)
bool nc_is_oi_model(const qn::NetworkStruct< T > &sn)
Port of nc_is_oi_model.m: a closed, open or mixed network with at least one OI station and nothing bu...
NcSolution< T > solver_nc_pas_is_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_pas_is_analyzer.m.
NcSolution< T > solver_nc_oi_mixed(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_oi_mixed.m: exact normalizing-constant analysis of a MIXED (open and closed) networ...
mva::MvaSolution< T > solver_oi_open_analyzer(const qn::NetworkStruct< T > &sn, double tol)
Port of solver_oi_open_analyzer.m.
bool nc_is_pas_model(const qn::NetworkStruct< T > &sn)
Port of nc_is_pas_model.m: a closed two-station OI / P&S tandem.
NcSolution< T > solver_nc_oi_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_oi_analyzer.m.
std::string nc_oi_refusal(const qn::NetworkStruct< T > &sn, const std::string &route="oi")
Port of nc_oi_refusal.m: may the order-independent route ROUTE run on this model?
std::mt19937_64 McRng
The generator type every Monte Carlo entry point in this tree accepts.
OiMixedResult< T > pfqn_oi_mixed(const std::vector< T > &lambda, const std::vector< double > &N, const std::function< T(const std::vector< int > &)> &mu, const OiMixedOptions &opt=OiMixedOptions())
Closed-lattice station tables of an OI station with open classes summed out.
NcResult< T > pfqn_ncoi(const std::vector< T > &Z, const std::vector< int > &N, const std::vector< OiRate< T > > &mu, const Matrix< T > &visits)
Normalizing constant of a closed network of ORDER-INDEPENDENT (OI) / pass-and-swap stations with empt...
Definition pfqn_ncoi.h:153
PasIsResult< T > pfqn_pas_is(const std::vector< int > &N, const std::vector< OiRateFun< T > > &mu, const Matrix< int > &H, std::size_t samples, McRng &rng, bool want_qlen=true)
Importance-sampling estimate of the normalizing constant of a single communicating class of a cyclic ...
Matrix< T > pas_swap2order(const std::vector< Matrix< T > > &swap, const std::vector< PasRateFun< T > > &listRate, const std::vector< int > &N0=std::vector< int >())
Placement-order DAG of a two-station pass-and-swap tandem.
OiFncResult< T > pfqn_oi_fnc(const std::vector< T > &Phi, const std::vector< int > &N, const std::function< T(const std::vector< int > &)> &f)
Order-independent (OI) functional server: the balance function Psi and the rate mu_f of an auxiliary ...
Definition pfqn_oi_fnc.h:76
OiInsvcResult< T > pfqn_oi_insvc(const std::function< T(const std::vector< int > &)> &oirate, const std::vector< int > &N)
Conditional mean number of IN-SERVICE jobs per class at an order-independent station.
std::function< T(const std::vector< int > &)> OiRateFun
The OI rank rate of a station as a function of the per-class COUNT vector: the svcRateFun of an OI / ...
Definition pfqn_pas_is.h:79
Matrix< T > station_swap_graph(const NetworkStruct< T > &sn, std::size_t ist)
The swap graph of a PAS / OI station, with the defaults refreshLocalVars.m installs applied.
bool station_swap_graph_is_zero(const NetworkStruct< T > &sn, std::size_t ist)
True when the station's materialized swap graph is entirely zero.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
Global placement-order DAG of a closed two-station pass-and-swap tandem.
Normalizing constant of a closed network of ORDER-INDEPENDENT (OI) / pass-and-swap stations with empt...
Order-independent (OI) functional server: the balance function Psi and the rate mu_f of an auxiliary ...
Conditional mean number of IN-SERVICE jobs per class at an order-independent station.
Closed-lattice station tables of an order-independent (OI) station visited by CLOSED and OPEN classes...
Importance-sampling estimate of the normalizing constant of a single communicating class of a cyclic ...
Exact analysis of an OPEN queueing network mixing order-independent (OI) stations with BCMP product-f...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:134
mva::MvaSolution< T > sol
Definition nc_types.h:135
std::string actualmethod
Definition nc_types.h:136
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:35
Return value of pfqn_oi_fnc, mirroring [muf, Psi, mu] flattened.
Definition pfqn_oi_fnc.h:58
std::vector< T > Psi
column-major over the lattice
Definition pfqn_oi_fnc.h:59
Return value of pfqn_oi_insvc, mirroring [g, Xi, Phi].
Matrix< T > g
(prod(N+1) x R) E[sir_r | n]
The tuning fields of pfqn_oi_mixed / pfqn_oi_open (OPTIONS in the reference).
double tol
relative tolerance of the 'oi.trunc' branch
Return value of pfqn_oi_mixed, mirroring [W, H, S, stable, tau, method].
Matrix< T > S
(prod(Nc+1) x R) per-class in-service weights
std::vector< T > W
(prod(Nc+1)) column-major table over the closed lattice
std::string method
"oi" (exact) or "oi.trunc"
bool stable
false when some reachable macrostate has den(m) <= 0
Matrix< T > H
(prod(Nc+1) x R) per-class mean weights
Return value of pfqn_pas_is / pfqn_oi_is, mirroring [G, lG, Q].
Definition pfqn_pas_is.h:64
T G
estimate of the communicating-class normalizing constant
Definition pfqn_pas_is.h:65
Matrix< T > Q
(2 x R) mean per-class queue length, Q(1,:) = N - Q(0,:)
Definition pfqn_pas_is.h:67
One job class of the network.
double population
infinite for an open class
One station of the network.
SchedStrategy sched
double nservers
may be infinite (a Delay, or an inf-scheduled task)