LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_nc_runner.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_RUNNER_H
6#define LINE_SOLVERS_NC_SOLVER_NC_RUNNER_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * The SolverNC class surface: `@@SolverNC/runAnalyzer.m` and the gates around it.
12 *
13 * What sits here rather than in the dispatch is everything that happens BEFORE
14 * and AFTER one inner solve: the method whitelist, the structural gates, the
15 * MULTISERVER-TO-LOAD-DEPENDENCE conversion, the conversions from response time
16 * to residence time and from throughput to arrival rate, and the metric filter.
17 *
18 * THE MULTISERVER CONVERSION IS THE INTERESTING PART, and it belongs here and
19 * not in an analyzer. A c-server station is rewritten as the rate lattice
20 * mu(n) = min(n, c), which routes the model to `solver_ncld` and is EXACT,
21 * whereas leaving it alone routes it to `solver_nc` and Seidmann's
22 * approximation. The reference does the rewrite on 'exact' and 'is' always, and
23 * on 'default' only for the two-station Delay-plus-multiserver shape (which is
24 * every SolverLN layer submodel), and only when the model is product-form --
25 * a non-product-form model has no exact load-dependent solution, so it is sent
26 * to 'comom' instead. The server count is deliberately KEPT: utilization is the
27 * fraction of the c servers busy, and c is not recoverable from min(1:Nt, c)
28 * once the population is below it.
29 *
30 * The metric filter is shared with SolverMVA verbatim (`filter_metric`,
31 * `sn_get_residt_from_respt`, `sn_get_arvr_from_tput` in `solver_mva_runner.h`)
32 * because `@@NetworkSolver/getAvg` is solver-independent: it is the same code
33 * path for both solvers in the reference.
34 */
35
37#include <algorithm>
38#include <cctype>
39#include <cmath>
40#include <limits>
41#include <string>
42#include <vector>
43
68#include "line/util/error.h"
70
71namespace line {
72namespace nc {
73
74/**
75 * Port of `SolverNC.listValidMethods`.
76 *
77 * A LISTED NAME MUST ACTUALLY RUN, or be refused with a message that names the
78 * missing analyzer. `erlangfp` and `mci` (the loss-network Erlang fixed point
79 * and its Monte Carlo counterpart) DO run: a Finite Capacity Region is now
80 * representable -- `sn.regions` and `Network::add_region` -- and
81 * `solver_nc_lossn_analyzer` claims the model above the product-form and
82 * multiserver gates. A model that is not a loss network still reaches the
83 * refusal further down, which is the honest outcome and different from silently
84 * solving a model with its region ignored. `comomld` is not in the reference's
85 * list; it is accepted because the reference selects it internally from
86 * 'default'. `ms` names the same lossn_manjunath transform as `exact` on a loss
87 * network (solver_nc_lossn.h's own method name alias) and was missing here, which
88 * blocked it before it ever reached the analyzer that already accepts it.
89 */
90inline std::vector<std::string> list_valid_methods() {
91 // the names and their order are this solver's row of the method registry (doc/line-methods.json)
92 return ::line::method_registry::methods("NC");
93}
94
95/**
96 * Port of `SolverNC.isStochasticMethod`.
97 *
98 * NC is deterministic except for the Monte Carlo integrators, the logistic
99 * sampler, the importance-sampling estimators and the Chen-O'Cinneide Markov
100 * chain Monte Carlo method, whose answer depends on the seed. The name is TOKENIZED on `.` and `/` so that a runtime-resolved name
101 * such as `default/imci` and a prefixed one such as `nc.ls` classify alike.
102 */
103inline bool is_stochastic_method(const std::string& method) {
104 std::string tok;
105 std::vector<std::string> toks;
106 for (char ch : method) {
107 if (ch == '.' || ch == '/') {
108 toks.push_back(tok);
109 tok.clear();
110 } else {
111 tok += static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
112 }
113 }
114 toks.push_back(tok);
115 for (const std::string& t : toks)
116 if (t == "mci" || t == "imci" || t == "ls" || t == "sampling" || t == "is" ||
117 t == "mcmc")
118 return true;
119 return false;
120}
121
122/**
123 * Port of `SolverNC.resolveMethod`: `default` is NOT resolved ahead of the run.
124 *
125 * Every route the default dispatch takes (Morrison, the OI convolution, the
126 * cache and loss-network families, comom, the cubature) is gated as `default`
127 * itself, which is what `nc_method_refusal` and the feature set answer. Until
128 * MATLAB's 2026-09-05 change this resolved an open non-Markovian model to `mem`,
129 * mirroring a dispatch the run had stopped taking (mem on explicit request
130 * only), so the gate asked mem's questions about a run that took the
131 * product-form path. The identity is kept as a function so findSolver's
132 * resolution step names every family's rule in one place.
133 */
134template <class T>
135std::string resolve_method(const qn::NetworkStruct<T>& /*L*/, const std::string& method) {
136 return method;
137}
138
139/** Port of `runAnalyzerChecks`' method gate: an unlisted method is refused. */
140inline void check_method(const std::string& method) {
141 const std::vector<std::string> valid = list_valid_methods();
142 if (std::find(valid.begin(), valid.end(), method) != valid.end()) return;
143 throw UnsupportedError(ErrorKind{"Method"}, "SolverNC: the '" + method + "' method is unsupported by this solver");
144}
145
146namespace detail {
147
148/** Is there a node of this type? */
149template <class T>
150bool has_node_type(const qn::NetworkStruct<T>& sn, qn::NodeType ty) {
151 for (const qn::NodeDef& nd : sn.nodes)
152 if (nd.nodetype == ty) return true;
153 return false;
154}
155
156/**
157 * The cache-metric assemblers now live in `line/solvers/cache_metrics.h`, beside
158 * the struct they build, because SolverMVA's cache branches need the identical
159 * rule. Re-exported into this namespace so the call sites below read unchanged.
160 */
163
164/**
165 * Rewrite every finite multiserver station as the rate lattice mu(n)=min(n,c).
166 * Port of `nc_lld_from_nservers.m`.
167 *
168 * On an open or mixed model the row only has to reach the largest finite
169 * server count c (and the closed population), because min(n,c) is constant
170 * beyond c and `solver_ncld` holds the last column; its mixed route
171 * (`pfqn_ncldmx`) is then exact. That conversion is made only for an
172 * UNBUDGETED caller, the 'exact' arm: the budgeted 'default' arms keep
173 * Seidmann's approximation on an open or mixed model, as they always have.
174 *
175 * @param unbudgeted true on the 'exact' arm, which converts open and mixed
176 * models too
177 * @return false when the conversion does not apply (an open or mixed model
178 * for a budgeted caller, or a closed model with no population), in
179 * which case the reference leaves the model alone
180 */
181template <class T>
182bool multiserver_to_lld(qn::NetworkStruct<T>& sn, bool unbudgeted = false) {
183 double Nt = 0.0;
184 bool hasOpen = false;
185 for (const qn::JobClass& c : sn.classes) {
186 if (std::isinf(c.population))
187 hasOpen = true;
188 else
189 Nt += c.population;
190 }
191 if (hasOpen && !unbudgeted) return false;
192 std::size_t n = static_cast<std::size_t>(std::llround(Nt));
193 if (hasOpen) {
194 // width = max(1, closed population, largest finite c)
195 n = std::max<std::size_t>(1, n);
196 for (std::size_t i = 0; i < sn.nstations; ++i) {
197 const double c = sn.stations[i].nservers;
198 if (std::isfinite(c))
199 n = std::max(n, static_cast<std::size_t>(std::llround(c)));
200 }
201 }
202 if (n < 1) return false;
203 for (std::size_t i = 0; i < sn.nstations; ++i) {
204 std::vector<T> lld(n, num_traits<T>::from_int(1));
205 const double c = sn.stations[i].nservers;
206 if (std::isfinite(c) && c > 1.0)
207 for (std::size_t k = 1; k <= n; ++k)
208 lld[k - 1] =
209 num_traits<T>::from_double(std::min<double>(static_cast<double>(k), c));
210 sn.stations[i].lldscaling = lld;
211 }
212 return true;
213}
214
215/**
216 * Resolves `NcSolverOptions::multiserver` into the handling this solver
217 * implements: `default`, `seidmann` or `lld`.
218 *
219 * Unknown values -- the SolverMVA approximations NC has no counterpart for
220 * (`softmin`, `conway`, `krzesinski`, `suri`, `erlang`) -- resolve to `default`
221 * rather than throwing, because one options object is commonly reused across
222 * solvers. They are NOT honoured silently: `warning`, when given, receives the
223 * text the other three codebases pass to `line_warning`. The port has no
224 * `line_warning` channel, so a warning travels on `NcSolution::warning`, which
225 * `line-cli` prints to stderr; see `NcSolution::warning`.
226 */
227inline std::string nc_multiserver_policy(const std::string& requested,
228 std::string* warning = nullptr) {
229 if (requested.empty() || requested == "default") return "default";
230 if (requested == "seidmann") return "seidmann";
231 if (requested == "lld" || requested == "exact" || requested == "loaddep" ||
232 requested == "load-dependent")
233 return "lld";
234 if (warning != nullptr)
235 *warning = "SolverNC does not implement config.multiserver='" + requested +
236 "' (it is a SolverMVA approximation); using 'default'. SolverNC accepts "
237 "'default', 'seidmann' and 'lld'.";
238 return "default";
239}
240
241/**
242 * The per-chain population lattice `prod(1+Nchain)`, which prices the exact
243 * enumeration `solver_ncld` performs.
244 */
245template <class T>
246double nc_population_lattice(const qn::NetworkStruct<T>& sn) {
247 double lattice = 1.0;
248 if (!sn.chains.empty()) {
249 // sn.chains is (nchains x nclasses) as vector<vector<bool>>, not a Matrix
250 for (std::size_t c = 0; c < sn.chains.size(); ++c) {
251 double popc = 0.0;
252 for (std::size_t r = 0; r < sn.nclasses && r < sn.chains[c].size(); ++r)
253 if (sn.chains[c][r]) {
254 const double v = sn.classes[r].population;
255 if (std::isfinite(v)) popc += v;
256 }
257 lattice *= (1.0 + popc);
258 }
259 } else {
260 for (const qn::JobClass& c : sn.classes)
261 if (std::isfinite(c.population)) lattice *= (1.0 + c.population);
262 }
263 return lattice;
264}
265
266} // namespace detail
267
268/**
269 * Is the closed model in NORMAL USAGE, the domain of the Mitra-McKenna PANACEA
270 * asymptotic expansion (J. ACM 33(3), 1986)?
271 *
272 * Normal usage asks that every queueing centre absorb the load the think
273 * stations offer it: with rho_j0 = Ztot(j) the aggregate think demand of chain
274 * j, r_ij = L_ij / rho_j0 and mu_i(Ntot) the saturation rate,
275 *
276 * alpha_i = 1 - (sum_j N_j r_ij) / mu_i(Ntot) > 0 at every centre i.
277 *
278 * Outside it the {phi(n)} series DIVERGES, which is why `pfqn_panaceald` returns
279 * NaN there and `pfqn_ncld` turns that NaN into a refusal rather than a warning.
280 * It is a property of the DEMANDS and not of a declared construct, so it has no
281 * feature-registry name and cannot live in `nc_feature_set`.
282 *
283 * The rates are the ones `solver_ncld` would build: one for an ordinary single
284 * server, min(n, c) for a finite multiserver (the conversion the runner performs
285 * on the 'panald' arm), and the declared lldscaling row when the model sets
286 * one. An infinite server is a think station and feeds Ztot.
287 *
288 * `seidmann` selects which of the two shapes the demands take on the way to the
289 * expansion. false (default) is the load-dependent lattice form above, what
290 * `pfqn_panaceald` receives. true is the load-INDEPENDENT form of the 'pana' arm
291 * of `pfqn_nc`, which `solver_nc` reaches through Seidmann's approximation: a
292 * c-server centre enters as demand L/c with mu_i(n) = 1 and its remainder
293 * L(c-1)/c is added to the think demand, so a multiserver model may be in normal
294 * usage in one form and not in the other.
295 */
296template <class T>
297bool nc_is_normal_usage(const qn::NetworkStruct<T>& sn, bool seidmann = false) {
298 if (sn.has_open_classes()) return true; // no rho_j0 to expand around
299 const std::size_t M = sn.nstations, C = sn.nchains;
300 const std::vector<double> Nchain = detail::chain_population(sn);
301 double NtD = 0.0;
302 for (std::size_t c = 0; c < C; ++c)
303 if (std::isfinite(Nchain[c])) NtD += Nchain[c];
304 const std::size_t Nt = static_cast<std::size_t>(std::llround(NtD));
305 if (Nt < 1) return true; // the empty network: G = 1, nothing to expand
306
308
309 std::vector<double> Ztot(C, 0.0);
310 for (std::size_t i = 0; i < M; ++i) {
311 const double nserv = sn.stations[i].nservers;
312 for (std::size_t c = 0; c < C; ++c) {
313 const double L = num_traits<T>::to_double(d.Lchain(i, c));
314 if (std::isinf(nserv))
315 Ztot[c] += L;
316 else if (seidmann && nserv > 1.0)
317 Ztot[c] += L * (nserv - 1.0) / nserv; // Seidmann's surrogate delay
318 }
319 }
320 for (std::size_t c = 0; c < C; ++c)
321 if (Nchain[c] > 0.0 && !(Ztot[c] > 0.0))
322 return false; // no think station on a populated chain's route
323
324 for (std::size_t i = 0; i < M; ++i) {
325 const double nserv = sn.stations[i].nservers;
326 if (std::isinf(nserv)) continue;
327 const std::vector<T>& lld = sn.stations[i].lldscaling;
328 double muK;
329 // Seidmann's split: demand L/c at a unit-rate centre
330 const double lscale = (seidmann && nserv > 1.0) ? 1.0 / nserv : 1.0;
331 if (seidmann)
332 muK = 1.0;
333 else if (!lld.empty())
334 muK = num_traits<T>::to_double(lld[std::min(Nt, lld.size()) - 1]);
335 else if (nserv > 1.0)
336 muK = std::min(static_cast<double>(Nt), nserv);
337 else
338 muK = 1.0;
339 if (!(muK > 0.0) || !std::isfinite(muK)) return false;
340 double lambda = 0.0;
341 for (std::size_t c = 0; c < C; ++c)
342 if (Ztot[c] > 0.0)
343 lambda += num_traits<T>::to_double(d.Lchain(i, c)) * lscale / Ztot[c] * Nchain[c];
344 if (!(1.0 - lambda / muK > 0.0)) return false;
345 }
346 // Every centre cleared the test; a model with no queueing centre at all
347 // reaches here too, and there the delay-only constant is exact.
348 if (seidmann) return true;
349 // Normal usage is necessary, not sufficient: pfqn_panaceald also declines
350 // when the retained terms of its asymptotic series do not decrease, which
351 // happens at small populations close to saturation. The run evaluates the
352 // constant at N and at every N-e_r, so the report asks the kernel itself at
353 // those populations instead of restating its rule.
354 std::vector<std::size_t> qrows;
355 for (std::size_t i = 0; i < M; ++i)
356 if (!std::isinf(sn.stations[i].nservers)) qrows.push_back(i);
357 if (qrows.empty()) return true;
358 Matrix<double> Lq(qrows.size(), C, 0.0), muq(qrows.size(), Nt, 1.0);
359 for (std::size_t a = 0; a < qrows.size(); ++a) {
360 const std::size_t i = qrows[a];
361 const double nserv = sn.stations[i].nservers;
362 const std::vector<T>& lld = sn.stations[i].lldscaling;
363 for (std::size_t c = 0; c < C; ++c) Lq(a, c) = num_traits<T>::to_double(d.Lchain(i, c));
364 for (std::size_t k = 0; k < Nt; ++k) {
365 if (!lld.empty())
366 muq(a, k) = num_traits<T>::to_double(lld[std::min(k, lld.size() - 1)]);
367 else if (nserv > 1.0)
368 muq(a, k) = std::min(static_cast<double>(k + 1), nserv);
369 }
370 }
371 std::vector<int> Nint(C, 0);
372 for (std::size_t c = 0; c < C; ++c)
373 Nint[c] = std::isfinite(Nchain[c]) ? static_cast<int>(std::llround(Nchain[c])) : 0;
374 if (!pfqn::pfqn_panaceald(Lq, Nint, Ztot, muq).normalUsage) return false;
375 for (std::size_t c = 0; c < C; ++c) {
376 if (Nint[c] <= 0) continue;
377 std::vector<int> Nr = Nint;
378 --Nr[c];
379 if (!pfqn::pfqn_panaceald(Lq, Nr, Ztot, muq).normalUsage) return false;
380 }
381 return true;
382}
383
384/**
385 * Is Birman-Kogan load concealment ('lc'/'lc.ue') degenerate on this model?
386 * True when a populated closed chain with no think demand has its whole demand
387 * at one queueing station that another populated chain also visits: that
388 * station is always busy and the concealment's residual capacity for the other
389 * chains is zero. Mirrors the MATLAB nc_method_refusal block.
390 */
391template <class T>
393 const std::size_t M = sn.nstations, C = sn.nchains;
394 const std::vector<double> Nchain = detail::chain_population(sn);
395 std::vector<bool> popd(C, false);
396 bool any = false;
397 for (std::size_t c = 0; c < C; ++c) {
398 popd[c] = std::isfinite(Nchain[c]) && Nchain[c] > 0.0;
399 any = any || popd[c];
400 }
401 if (!any) return false;
403 for (std::size_t c = 0; c < C; ++c) {
404 if (!popd[c]) continue;
405 double Lz = 0.0;
406 std::size_t at = 0, count = 0;
407 for (std::size_t i = 0; i < M; ++i) {
408 const double L = num_traits<T>::to_double(d.Lchain(i, c));
409 if (std::isinf(sn.stations[i].nservers)) {
410 Lz += L;
411 } else if (L > 0.0) {
412 at = i;
413 ++count;
414 }
415 }
416 if (Lz > 0.0 || count != 1) continue;
417 for (std::size_t s2 = 0; s2 < C; ++s2)
418 if (s2 != c && popd[s2] && num_traits<T>::to_double(d.Lchain(at, s2)) > 0.0)
419 return true;
420 }
421 return false;
422}
423
424/**
425 * How many queueing (non-infinite-server) stations carry demand from a CLOSED
426 * chain?
427 *
428 * That is the row count L reaches `pfqn_nc` and `pfqn_comomrm_ld` with, once the
429 * delay rows have been folded into Z and the zero-demand rows dropped. Zero when
430 * the model has no closed population at all.
431 */
432template <class T>
434 const std::size_t M = sn.nstations, C = sn.nchains;
435 const std::vector<double> Nchain = detail::chain_population(sn);
436 bool any_closed = false;
437 std::vector<bool> closed(C, false);
438 for (std::size_t c = 0; c < C; ++c) {
439 closed[c] = std::isfinite(Nchain[c]) && Nchain[c] > 0.0;
440 if (closed[c]) any_closed = true;
441 }
442 if (!any_closed) return 0;
443
445 std::size_t nq = 0;
446 for (std::size_t i = 0; i < M; ++i) {
447 if (std::isinf(sn.stations[i].nservers)) continue;
448 for (std::size_t c = 0; c < C; ++c)
449 if (closed[c] &&
451 ++nq;
452 break;
453 }
454 }
455 return nq;
456}
457
458/**
459 * May `method` run on this model? "" when it may, otherwise the reason it may
460 * not, in the words the runner refuses with.
461 *
462 * ONE PREDICATE, TWO CALLERS. `solver_nc_solve` asks it once, ahead of the
463 * dispatch, and throws on a non-empty answer; `auto_family_refusal` asks it so
464 * that `auto_find_solver` never offers a (family, method) pair that would throw,
465 * and so that the ranking never delegates to one. Two copies of these rules is
466 * precisely how the report and the run drift apart, which is the failure this
467 * function exists to prevent, so a new rule goes here and not at a call site.
468 *
469 * ONLY WHAT THE FEATURE REGISTRY CANNOT NAME LIVES HERE. A feature set declares
470 * what the method ACCEPTS, so it can refuse a model for HAVING a construct and
471 * never for lacking one: "closed population only" and "no think time" are said
472 * in `qn::nc_feature_set` by dropping OpenClass and SchedStrategy_INF, while
473 * "requires a cache", "requires state-dependent routing", "requires a loss
474 * network", "requires exactly two stations" and "requires normal usage" have no
475 * such form and are decided here.
476 *
477 * `for_report` says WHICH QUESTION IS BEING ASKED, and for two method names the
478 * two questions have different answers:
479 *
480 * true -- "should `auto_find_solver` offer this pair?" A pair that comes back
481 * as a table of zeros must not be offered, so the answer is no.
482 * false -- "what does the reference DO when asked for it by name?" For 'mmint2'
483 * and 'gleint' outside their shape the reference deliberately WARNS AND
484 * RETURNS A ZERO TABLE (pfqn_nc.m, case {'mmint2','gleint'}: lG = [] and
485 * return, unconditionally), and a caller who names the method keeps that
486 * answer -- which is what `test_nc.cpp` pins.
487 *
488 * THE ASYMMETRY IS A RULING, NOT AN OVERSIGHT (2026-07-25, reaffirmed when this
489 * gate was added): the report answers "should this be offered" and the run answers
490 * "what does the reference do". 'comomld' is NOT in that bucket --
491 * `pfqn_comomrm_ld` refuses "The solver accepts at most a single queueing station."
492 * natively -- so it is refused on both paths.
493 *
494 * @param sn the refreshed struct
495 * @param method the concrete method name
496 * @param slotted true on the discrete-time route, which answers for itself
497 * @param for_report true when the caller is the report, false when it is the run
498 * @param multiserver the caller's config.multiserver; empty when the caller
499 * passes no options (the report), which reads as 'default'
500 */
501template <class T>
502std::string nc_method_refusal(const qn::NetworkStruct<T>& sn, const std::string& method,
503 bool slotted = false, bool for_report = true,
504 const std::string& multiserver = std::string()) {
505 const std::string m = method.empty() ? std::string("default") : method;
506
507 // The discrete-time route answers for itself: `solver_nc_dt` decides
508 // admissibility on the slot lattice, and every gate below is written about a
509 // continuous-time queueing network.
510 if (slotted) return "";
511
512 // -- perfect sampling --------------------------------------------------
513 // The sampler's structural predicate is the whole of its envelope: a
514 // closed single-class Gordon-Newell network, which excludes every shape the
515 // rules below route (DPS, SDR, Petri nets, OI, caches, regions).
516 if (m == "cftp" || m == "cftp.approx") return solver_nc_cftp_supports(sn);
517
518 // -- discriminatory processor sharing ---------------------------------
519 // Morrison's heavy-usage expansion is the ONLY NC route that can see the DPS
520 // weights; every other method builds a product-form normalizing constant
521 // that silently drops them and answers with the egalitarian-PS network,
522 // which is a wrong number rather than a coarse one.
523 if (nc_is_dps_model(sn)) {
524 if (m != "default" && m != "morrison")
525 return "SolverNC: method '" + m +
526 "' cannot represent the DPS weights of a discriminatory processor-sharing "
527 "station; it would return the egalitarian-PS network. Use method 'default' or "
528 "'morrison' (npfqn_dps_morrison), SolverMVA, SolverFLD or SolverCTMC.";
529 return "";
530 }
531 if (sn_has_dps(sn))
532 // A DPS station outside Morrison's shape. SchedStrategy_DPS is declared
533 // in the feature set because a boolean feature cannot express "this shape
534 // only"; this is that imperative half.
535 return "SolverNC analyzes a discriminatory processor-sharing station only in the shape "
536 "Morrison's expansion is derived for: a CLOSED network of exactly two stations, one "
537 "infinite-server (think) station and one single-server DPS station, exponential "
538 "service, each class visiting the two equally often. Use SolverMVA, SolverFLD or "
539 "SolverCTMC for any other DPS model.";
540 if (m == "morrison")
541 // The method named on a model that is not the shape at all -- not even a
542 // DPS station in it. Left ungated it reaches no route of its own and
543 // falls through to the ordinary normalizing-constant path, which would
544 // answer the product-form model UNDER THE CALLER'S LABEL.
545 return "SolverNC: method 'morrison' is the heavy-usage expansion of a CLOSED network of "
546 "exactly two stations, one infinite-server (think) station and one single-server DPS "
547 "station with exponential service, which this model is not. Remove the method option "
548 "to let SolverNC choose, or use SolverMVA, SolverFLD or SolverCTMC.";
549
550 // -- Krzesinski state-dependent routing -------------------------------
551 // An SDR model is intercepted by `solver_nc_sdr` whatever the method says,
552 // so reaching the second test means the model declares none.
553 if (!sn.sdr.branch.empty()) return "";
554 if (m == "sdr" || m == "sdr.mva")
555 return "SolverNC: method '" + m +
556 "' requires state-dependent routing, which this model does not declare.";
557
558 // -- stochastic Petri net ---------------------------------------------
559 // A net is served only by the MDD-rec route, and none of the gates below --
560 // written about stations, capacities and the queueing-network product form --
561 // says anything about a net. `spn_pf` decides its product-form class, by name.
562 for (std::size_t ind = 0; ind < sn.nodes.size(); ++ind)
563 if (sn.nodes[ind].nodetype == lang::NodeType::Place) {
564 if (m != "default" && m != "rec")
565 return "solver_nc: a stochastic Petri net is solved by the MDD-rec route; method '" +
566 m + "' is a normalizing-constant algorithm for queueing networks. Use 'rec' "
567 "or 'default'";
568 return "";
569 }
570
571 // -- order-independent stations ---------------------------------------
572 // Every method other than the four listed reads the single-job rate mu([r])
573 // of an OI station: the rank rate mu(n) is silently dropped and the answer is
574 // that of an ordinary queue.
575 // What each OI route then refuses on its own shape is `nc_oi_refusal`
576 // (nc_oi_refusal.m), asked here as the reference asks it, so the report
577 // never offers a pair the run refuses: the sampler needs a closed network,
578 // a finite buffer at an open OI station is a loss queue that only the
579 // isolated Source -> OI -> Sink shape answers, a Fork or a declared
580 // load/class/joint dependence has no OI route.
581 if (nc_is_oi_model(sn)) {
582 if (m != "default" && m != "exact" && m != "is" && m != "sampling")
583 return "SolverNC: method '" + m +
584 "' cannot represent the rank rate mu(n) of an order-independent station; use "
585 "method 'default' or 'exact' (pfqn_ncoi), 'is', SolverMVA, or SolverCTMC.";
586 return (m == "is" || m == "sampling") ? nc_oi_refusal(sn, "pas") : nc_oi_refusal(sn, "oi");
587 }
588
589 // -- caches -------------------------------------------------------------
590 // 'rayint' and 'spm' both name the SPM saddle point of a cache (and, on a
591 // retrieval model, the ray/WKB delayed-hit expansion), so they are admissible
592 // here and nowhere else. Three cache routes, three name sets
593 // (nc_method_refusal.m):
594 // Source-Cache-Sink solver_nc_cache_analyzer switches on exact / sampling
595 // and sends EVERY other name to the SPM saddle point;
596 // open retrieval cache solver_nc_retrieval_analyzer reads 'rayint' and
597 // answers every other name with the exact recurrences;
598 // cache-queueing the cache takes exact or SPM and the name is handed to
599 // the network solve, where pfqn_nc has no arm for
600 // 'rayint'/'spm' on a closed chain.
601 // cache_prob_erec, which 'exact' uses on the first and the third, is exact for
602 // the exchangeable (RR/FIFO) family only.
603 for (std::size_t ind = 0; ind < sn.nodes.size(); ++ind)
604 if (sn.nodes[ind].nodetype == qn::NodeType::Cache) {
605 const auto itp = sn.nodeparam.find(ind + 1);
606 const bool has_retrieval =
607 itp != sn.nodeparam.end() && itp->second.retrieval_capacity > 0;
608 bool has_source = false;
609 for (std::size_t j = 0; j < sn.nodes.size(); ++j)
610 if (sn.nodes[j].nodetype == qn::NodeType::Source) has_source = true;
612 if (m != "default" && m != "exact" && m != "sampling" && m != "rayint" && m != "spm")
613 return "Method '" + m + "' has no route on a Source-Cache-Sink model: "
614 "solver_nc_cache_analyzer would answer it with the SPM saddle point under "
615 "that name. Use 'default' (or 'spm'/'rayint'), 'exact' or 'sampling'.";
616 } else if (has_retrieval && has_source) {
617 if (m != "default" && m != "exact" && m != "rayint")
618 return "Method '" + m + "' has no route on a delayed-hit retrieval cache: "
619 "solver_nc_retrieval_analyzer would answer it with the exact recurrences "
620 "under that name. Use 'default', 'exact' or 'rayint'.";
621 } else if ((m == "rayint" || m == "spm") && sn.nclosedjobs() > 0) {
622 return "Method '" + m + "' names the SPM saddle point of an isolated cache; on an "
623 "integrated cache-queueing model the name is handed to the network solve, "
624 "where pfqn_nc has no arm for it. Use 'default' (SPM cache, default network) "
625 "or 'exact'.";
626 }
627 if (m == "exact" && !has_retrieval && itp != sn.nodeparam.end() &&
628 itp->second.replacestrat != lang::ReplacementStrategy::RR &&
629 itp->second.replacestrat != lang::ReplacementStrategy::FIFO)
630 return "NC does not support exact solution of the specified cache replacement "
631 "policy; use the default (approximate) method or SolverCTMC.";
632 return "";
633 }
634 if (m == "rayint" || m == "spm")
635 return "SolverNC: method " + m +
636 " names the SPM saddle point of a cache and, on a retrieval model, the ray/WKB "
637 "delayed-hit expansion; this model declares no Cache node.";
638
639 // -- loss networks and finite capacity regions --------------------------
640 if (nc_is_lossn_model(sn)) {
641 // solver_nc_lossn_analyzer switches on its seven method names and would answer any
642 // other name with the residue transform ('exact') under that name.
643 std::string ml = m;
644 for (char& ch : ml) ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
645 if (ml != "default" && ml != "exact" && ml != "ms" && ml != "erlangfp" && ml != "asy" &&
646 ml != "rec" && ml != "mci")
647 return "Method '" + m + "' has no route on a loss network, which "
648 "solver_nc_lossn_analyzer would answer with the residue transform under that "
649 "name. Use 'default', 'exact' (or 'ms'), 'rec', 'erlangfp', 'asy' or 'mci'.";
650 return "";
651 }
653 return "SolverNC: the Finite Capacity Region holds a single infinite server but does not "
654 "apply DROP to every class; holding an arrival back (WAITQ) or blocking the server "
655 "(BAS/BBS/RSRD) keeps the job in the region while it waits, which the Erlang loss "
656 "model has no state for -- use DROP, or SolverCTMC/SolverJMT";
657 if (m == "erlangfp")
658 return "SolverNC: the 'erlangfp' Erlang fixed point applies only to a loss network, which "
659 "is an open model whose single Delay sits inside a Finite Capacity Region under a "
660 "DROP rule; this model declares no such region (see nc_is_lossn_model)";
661 if (m == "ms")
662 return "SolverNC: method 'ms' is admissible only on a loss network (open model, one DROP "
663 "region holding a single Delay).";
664 if (m == "asy")
665 return "SolverNC: method 'asy' is admissible only on a loss network (open model, one DROP "
666 "region holding a single Delay).";
667 if (m == "rec")
668 return "SolverNC: method rec is the MDD-rec route, admissible on a stochastic Petri net or "
669 "on a loss network (open model, one DROP region holding a single Delay); this model "
670 "is neither.";
671 if (!sn.regions.empty())
672 return "SolverNC: this model applies a Finite Capacity Region to queueing stations, whose "
673 "aggregate population limit no normalizing-constant algorithm here enforces; only "
674 "the loss network -- one region over a single infinite server, DROP on every "
675 "class -- is solvable. Use SolverCTMC or SolverJMT, or setCapacity for a "
676 "single-station limit";
677
678 // -- the maximum-entropy route reads ONE service law ----------------------
679 // `solver_nc_mem` builds Kouvatsos's GE/GE/1/N from the first two moments of a
680 // SINGLE service law -- neither it nor `solver_nc_mem_supports` mentions
681 // lldscaling, cdscaling or jdscaling -- so a station declaring one is answered
682 // with the UNSCALED queue. That is worse than it looks: 'mem' is also the one
683 // name exempt from the binding-capacity gate, so on a finite buffer it is the
684 // last route standing and the silent answer is the one the caller gets. A
685 // method that cannot read a declared field has no feature name for it.
686 if (m == "mem") {
687 for (std::size_t i = 0; i < sn.nstations; ++i)
688 if (!sn.stations[i].lldscaling.empty() ||
689 static_cast<bool>(sn.stations[i].cdscaling) ||
690 static_cast<bool>(sn.stations[i].jdscaling))
691 return "SolverNC: method 'mem' is the maximum-entropy GE/GE/1/N of "
692 "solver_nc_mem, which reads the first two moments of ONE service law and "
693 "cannot apply a declared load-, class- or joint-dependent rate. Use "
694 "SolverMVA, SolverCTMC or SolverLDES";
695 }
696
697 // -- class-dependent rates: closed only -----------------------------------
698 // A cdscaling station diverts the whole model, on every route and whatever
699 // the method, to `solver_nc_conv`, Sauer's multichain convolution. That
700 // recursion is defined on the CLOSED population lattice and holds no position
701 // for an open chain, so the analyzer throws there. The rule is a CONJUNCTION
702 // -- class dependence AND an open chain -- which a boolean feature set cannot
703 // express, so it lives here; said here as well as at the run so the report
704 // and the run agree. BOTH dependences, since 2026-09-13: `solver_ncld` now
705 // diverts on `jdscaling` as well, `solver_nc_conv` folding eta into the same
706 // handle, so the joint-dependent model lands on the same closed lattice.
707 if (sn.has_open_classes()) {
708 for (std::size_t i = 0; i < sn.nstations; ++i)
709 if (static_cast<bool>(sn.stations[i].cdscaling) ||
710 static_cast<bool>(sn.stations[i].jdscaling))
711 return "SolverNC: class- or joint-dependent rates are solved by the convolution "
712 "of solver_nc_conv, Sauer's multichain recursion on the CLOSED population "
713 "lattice, which holds no position for an open chain; this model is open "
714 "or mixed. Use SolverMVA, SolverCTMC or SolverLDES";
715 }
716 // The convolution reads `nservers` only to tell a delay from a queue and
717 // never reads `lldscaling`: a c-server or load-dependent station beside a
718 // class-dependent one would be solved as a single fixed-rate server.
719 // Refused rather than answered wrongly, the same pattern as the residual FCR
720 // above. A COUNT and a CONJUNCTION, so no feature set can say it
721 // (nc_method_refusal.m:347).
722 {
723 bool any_cd = false, any_multi = false, any_lld = false;
724 for (std::size_t i = 0; i < sn.nstations; ++i) {
725 if (static_cast<bool>(sn.stations[i].cdscaling) ||
726 static_cast<bool>(sn.stations[i].jdscaling))
727 any_cd = true;
728 const double c = sn.stations[i].nservers;
729 if (std::isfinite(c) && c > 1.0) any_multi = true;
730 if (!sn.stations[i].lldscaling.empty()) any_lld = true;
731 }
732 if (any_cd && (any_multi || any_lld))
733 return "SolverNC: class- or joint-dependent rates are solved by the convolution of "
734 "solver_nc_conv, which reads no server count above one and no load-dependent "
735 "rate lattice; fold the multiserver capacity into the class-dependent handle, "
736 "or use SolverMVA or SolverCTMC";
737 }
738
739 // -- PANACEA's domain ----------------------------------------------------
740 // Normal usage is a property of the demands rather than of a declared
741 // construct, so it has no feature name; an open chain is refused earlier by
742 // the closed-population feature set of the load-dependent evaluators.
743 //
744 // BOTH TOKENS ARE GATED, because `pfqn_ncld` evaluates 'pana' and
745 // 'panald' with the SAME `pfqn_panaceald` -- its case label covers both --
746 // so on a model carrying a rate lattice the load-INDEPENDENT name reaches the
747 // load-dependent expansion and throws with it. Off that lattice 'pana'
748 // takes its own `pfqn_nc` arm, which warns and returns an empty constant
749 // rather than throwing, so it is left alone there. CLASS-dependent scaling
750 // diverts the whole model to `solver_nc_conv`, which never reads the method
751 // at all -- and only class-dependent, because that is the one `solver_ncld`
752 // diverts on in this port; a joint-dependent model still reaches the kernel.
753 if ((m == "pana" || m == "panald") && !sn.has_open_classes()) {
754 bool diverted_to_conv = false, any_lld = false;
755 for (std::size_t i = 0; i < sn.nstations; ++i) {
756 if (static_cast<bool>(sn.stations[i].cdscaling) ||
757 static_cast<bool>(sn.stations[i].jdscaling))
758 diverted_to_conv = true;
759 if (!sn.stations[i].lldscaling.empty()) any_lld = true;
760 }
761 const bool reaches_ld_kernel = (m == "panald") || any_lld;
762 if (!diverted_to_conv && reaches_ld_kernel && !nc_is_normal_usage(sn)) {
763 const std::string why =
764 "the model is not in normal usage, or the retained terms of the 'panald' "
765 "asymptotic series do not decrease at this population, so the expansion does "
766 "not apply. Use 'exact', 'clw' or an approximate load-dependent method instead.";
767 if (m == "pana")
768 return "SolverNC: method 'pana' reaches the load-dependent kernel on this "
769 "model, where pfqn_ncld evaluates it as 'panald', and " + why;
770 return "SolverNC: " + why;
771 }
772 // Off the lattice 'pana' is gated for the REPORT ONLY, like 'mmint2':
773 // `pfqn_panacea` returns NaN outside normal usage and `pfqn_nc` answers with
774 // an empty constant, so the run renders an empty table under that name.
775 // The question is asked in the Seidmann form `solver_nc` hands `pfqn_nc`.
776 if (for_report && !diverted_to_conv && !reaches_ld_kernel &&
777 !nc_is_normal_usage(sn, /*seidmann=*/true))
778 return "SolverNC: the model is not in normal usage, so the 'pana' asymptotic "
779 "expansion does not apply (pfqn_panacea returns NaN and the analyzer an "
780 "empty table). Use 'exact', 'clw' or 'default' instead.";
781 }
782
783 // -- Birman-Kogan load concealment -----------------------------------------
784 // `pfqn_bklc` solves each chain as a single-chain network on the RESIDUAL
785 // capacity 1 - (sum of the other chains' utilizations) of every station. A
786 // closed chain whose whole demand sits at ONE queueing station with no think
787 // demand (a SelfLoopingClass, or a chain routed only there) keeps that
788 // station busy all the time, so its single-chain MVA takes X = A/L and the
789 // residual left to every other chain sharing the station is zero. Those
790 // chains then collapse to X ~ FineTol and R ~ 1e7 (R = 6.7e7 against an exact
791 // 2.0 on a repairman model with a two-job SelfLoopingClass at its queue): a
792 // structural limit of the approximation, refused on both paths.
793 if ((m == "lc" || m == "lc.ue") && nc_lc_concealment_degenerate(sn))
794 return "SolverNC: method '" + m + "' (Birman-Kogan load concealment) does not apply: "
795 "a closed chain with no think time is confined to a single queueing station "
796 "shared with other chains, so that station is always busy and the residual "
797 "capacity the concealment hands the other chains is zero. Use 'exact', "
798 "'default' or another approximate method instead.";
799
800 // -- the single-queueing-station recursions --------------------------------
801 // Two families are stated for a model with a delay and ONE queueing station,
802 // and neither can say so with a feature name: it is a COUNT, and a feature
803 // set has no arithmetic. `pfqn_nc` states it for 'mmint2'/'gleint' in those
804 // words and `pfqn_comomrm_ld` refuses with "The solver accepts at most a
805 // single queueing station." 'comom' is the same recursion at fixed rates:
806 // `pfqn_nc` refuses it on a multiclass model with more than one queue, and on
807 // a single-class one the queue-length step augments the model with an
808 // auxiliary class and refuses there, so the rule is the station count alone.
809 //
810 // The count is taken over the CLOSED chains only, and the rule is inactive
811 // without a closed population, because `pfqn_nc` answers an open network with
812 // the exact open formulas BEFORE its method switch -- the method name is never read
813 // there, so a purely open model with three queues runs these names correctly
814 // today and must go on doing so.
815 // 'mmint2' and 'gleint' are gated for the REPORT ONLY: `pfqn_nc` answers them
816 // with an empty constant and the caller renders a table of zeros, which is a
817 // pair the report must not offer and a run the reference nonetheless performs.
818 // See `for_report` above.
819 if (m == "comom" || m == "comomld" || (for_report && (m == "mmint2" || m == "gleint"))) {
820 const std::size_t nq = nc_closed_queueing_stations(sn);
821 if (nq > 1) {
822 if (m == "comomld")
823 return "SolverNC: method 'comomld' is the load-dependent CoMoM recursion, and "
824 "pfqn_comomrm_ld accepts at most a single queueing station; this model has " +
825 std::to_string(nq) + ".";
826 if (m == "comom")
827 return "SolverNC: method 'comom' is the CoMoM recursion of pfqn_comomrm, which "
828 "accepts at most a single queueing station; this model has " +
829 std::to_string(nq) + ". Use 'default' or 'ca' for an exact normalizing "
830 "constant, or SolverJMT with method 'jmva.recal'.";
831 return "SolverNC: the '" + m +
832 "' method requires a model with a delay and a single queueing station; this "
833 "model has " + std::to_string(nq) + ".";
834 }
835 }
836
837 // -- 'exact' outside its domain ------------------------------------------
838 if (m == "exact") {
839 bool multi = false;
840 for (std::size_t i = 0; i < sn.nstations; ++i)
841 if (std::isfinite(sn.stations[i].nservers) && sn.stations[i].nservers > 1.0) multi = true;
842 // An open or mixed multiserver model IS served exactly: the 'exact' arm
843 // represents each c-server station as mu(n)=min(n,c) (multiserver_to_lld,
844 // unbudgeted) and solver_ncld's mixed route solves it. Only
845 // config.multiserver='seidmann' keeps the surrogate on this arm, and the
846 // surrogate is not exact (nc_method_refusal.m).
847 if (multi && sn.has_open_classes() &&
848 detail::nc_multiserver_policy(multiserver) == "seidmann")
849 return "solver_nc_analyzer: the NC solver cannot provide exact solutions for open "
850 "or mixed multiserver queueing networks under config.multiserver='seidmann'. "
851 "Remove the 'exact' option or the config.multiserver setting";
852 // The fork-join fixed point hands nc_dispatch the MMT image, whose parallelism rides on
853 // OPEN auxiliary classes, so the inner model is mixed (nc_method_refusal.m:462).
854 if (multi && detail::has_node_type(sn, qn::NodeType::Fork))
855 return "SolverNC: NC solver cannot provide exact solutions for a fork-join model with a "
856 "multiserver station: the fork-join transformation carries the parallelism as "
857 "open auxiliary classes, so the inner model is mixed. Remove the 'exact' option.";
858 }
859 if (m == "exact") {
860 // nc_method_refusal.m: the load-dependent analyzer (reached by a scaling row
861 // or, after multiserver_to_lld, by a c-server station) interpolates a
862 // fractional population between its integer neighbours, which is an
863 // approximation, so it refuses the exactness the caller asked for by name.
864 bool scaling = false, multiserver = false, fractional = false;
865 for (std::size_t i = 0; i < sn.nstations; ++i) {
866 const auto& st = sn.stations[i];
867 if (!st.lldscaling.empty() || static_cast<bool>(st.cdscaling) ||
868 static_cast<bool>(st.jdscaling))
869 scaling = true;
870 if (std::isfinite(st.nservers) && st.nservers > 1.0) multiserver = true;
871 }
872 for (const qn::JobClass& c : sn.classes)
873 if (std::isfinite(c.population) &&
874 std::fabs(c.population - std::floor(c.population)) > GlobalConstants::FineTol)
875 fractional = true;
876 if ((scaling || multiserver) && fractional)
877 return "SolverNC: NC load-dependent solver cannot provide exact solutions for "
878 "fractional populations.";
879 }
880 return "";
881}
882
883
884/**
885 * The gates, the multiserver conversion and the dispatch of
886 * `@@SolverNC/runAnalyzer.m`, without the metric filter.
887 *
888 * Kept separate so that the reported log normalizing constant comes from the
889 * SAME model the metrics do: reaching the dispatch without the conversion above
890 * would evaluate the constant of the Seidmann-approximated network while the
891 * table reported the load-dependent one.
892 *
893 * A model with a Fork is solved through the shared fork-join fixed point
894 * (`fj_driver.h`), which drives `nc_dispatch` as its inner solve on the
895 * transformed model; a model without one runs the dispatch exactly once.
896 */
897template <class T>
899 check_method(opt_in.method);
900 // a closed chain whose (station,class) routing has several closed sets would be
901 // normalized over all of them at once; see sn_reducible_chain.h
902 {
903 const std::string redWhy = api::sn_reducible_chain_refusal(L_in);
904 if (!redWhy.empty()) throw UnsupportedError(ErrorKind{"Structure"}, "SolverNC: " + redWhy);
905 }
906 // THE PERFECT SAMPLER, intercepted ahead of every other gate and route, as
907 // `@SolverNC/runAnalyzer.m` does right after getStruct. Its own structural
908 // predicate is asked FIRST, so a caller reads "the cftp method supports
909 // closed models only" rather than a bare "(feature: OpenClass)", and it is
910 // asked here in the run as well as in the report, so skipping the report
911 // cannot bypass it. The routes below (DPS, OI, cache, loss network,
912 // multiserver rewrite) have nothing to say about a balance-function draw.
913 if (opt_in.method == "cftp" || opt_in.method == "cftp.approx") {
914 const std::string why = solver_nc_cftp_supports(L_in);
915 if (!why.empty()) throw UnsupportedError(ErrorKind{"Model"}, why);
916 qn::feature_gate("SolverNC", qn::nc_feature_set(opt_in.method), L_in);
917 if constexpr (num_traits<T>::has_transcendental) {
918 return solver_nc_cftp_solution(solver_nc_cftp(L_in, opt_in));
919 } else {
920 throw UnsupportedError(ErrorKind{"Arithmetic"},
921 "SolverNC(cftp): the cftp methods draw random states and form the station "
922 "balance functions in the log domain, neither of which exists in exact rational "
923 "arithmetic");
924 }
925 }
926 // runAnalyzerChecks' universal feature gate, AFTER the method gate. Gated on
927 // `L_in`, before multiserver_to_lld rewrites lldscaling. NC DECLARES Region,
928 // so a loss network passes straight through to the imperative split below.
929 qn::feature_gate("SolverNC", qn::nc_feature_set(opt_in.method), L_in);
930
931 // SolverNC.supportsModelMethod's product-form rule, which runAnalyzer asks on the USER model: a fork-join
932 // has no product form, so 'exact'/'is'/'panald' are refused before the transform below hides the fork.
933 // Asked BEFORE nc_method_refusal, since NetworkSolver's support check runs ahead of runAnalyzer.
934 // OI/PAS stations are exempt, as in the reference.
935 if (L_in.has_fork() && (opt_in.method == "exact" || opt_in.method == "is" || opt_in.method == "panald") &&
936 !L_in.has_product_form()) {
937 bool oi = false;
938 for (const qn::Station<T>& st : L_in.stations)
939 if (st.sched == qn::SchedStrategy::OI || st.sched == qn::SchedStrategy::PAS) oi = true;
940 if (!oi)
941 throw UnsupportedError(ErrorKind{"Structure"},
942 "SolverNC: method '" + opt_in.method + "' requires a product-form solution; use "
943 "SolverCTMC for an exact answer, or 'comom', which applies Seidmann's "
944 "approximation, for an approximate one");
945 }
946
947 // THE STRUCTURAL METHOD GATE, asked once and in one place.
948 //
949 // `nc_method_refusal` holds every rule of the form "this method has no route
950 // on this model": the DPS shape, state-dependent routing, the Petri net, the
951 // order-independent rank rate, the cache and loss-network tokens, PANACEA's
952 // normal usage. `auto_family_refusal` asks the SAME function, which is what
953 // keeps `auto_find_solver` from offering a pair that would throw here.
954 {
955 // for_report=false: this is the RUN, and it asks what the reference DOES
956 // rather than what the report should offer. The two answers differ for
957 // 'mmint2'/'gleint', which `pfqn_nc` answers with an empty constant and a
958 // zero table; see `nc_method_refusal`.
959 const std::string refusal =
960 nc_method_refusal(L_in, opt_in.method, nc_is_slotted(opt_in), /*for_report=*/false,
961 opt_in.multiserver);
962 if (!refusal.empty()) throw UnsupportedError(ErrorKind{"Structure"}, refusal);
963 }
964
965 NcSolverOptions opt = opt_in;
966 qn::NetworkStruct<T> L = L_in;
967 NcSolution<T> res;
968
969 // Discrete time before every other gate: the slot lattice is a property of
970 // the MODEL, not of a method, and the imperative gates below (finite
971 // capacity, the multiserver-to-lldscaling rewrite, the load-dependence
972 // routing) all assume a continuous time scale. `solver_nc_dt` refuses a
973 // model outside the discrete-time product form rather than falling through.
974 if (nc_is_slotted(opt)) return solver_nc_dt(L, opt);
975
976 // THE STRUCTURAL FINITE-CAPACITY GATE, port of `@@SolverNC/SolverNC.m:180-188`.
977 //
978 // It was missing here, and its absence was not a missing message: a closed
979 // two-queue model with setCapacity(1) on the second station SOLVED, and
980 // reported the UNCONSTRAINED product-form answer (QLen 0.852459/1.147541,
981 // the values of the same model with no buffer at all) where MATLAB, the JAR
982 // and python all refuse by name. A wrong number, silently, is the failure
983 // mode `check_binding_capacity` exists to stop -- SolverMVA has called it
984 // since the port (`mva_check_finite_capacity`) and NC never did.
985 //
986 // AFTER THE SLOTTED RETURN, as in the reference: a finite buffer on a
987 // Bernoulli server is the loss system of Daduna's corollary 2.8, which
988 // `solver_nc_dt` solves exactly, so this gate must not see it.
989 //
990 // TWO EXEMPTIONS. mem.blocking represents the buffer as a censored
991 // GE/GE/c/0;N queue and therefore DOES honour it. The single-station
992 // M/M/1/K with tail drop is answered exactly by the `qsys_mm1k_loss` branch
993 // in `nc_dispatch`, ported 2026-09-13; before that this port had no such
994 // branch and the shape was refused here, while `nc_feature_set` advertised
995 // FiniteCapacity for 'default'/'exact' on a route that did not exist.
996 //
997 // IT READS `opt.method`, NOT `resolve_method`, and the difference is not
998 // cosmetic. `nc_dispatch` reaches the MEM algorithm on the literal name --
999 // `if (opt.method == "mem")` -- and nothing on the solve path resolves
1000 // `default` into it, so exempting a `default` run because `resolve_method`
1001 // would have called it `mem` skips the gate and then dispatches somewhere
1002 // that does NOT honour the buffer. That is the very failure this gate
1003 // exists to stop. (The reference gates on its resolved method and its
1004 // analyzer reads `options.method` directly, so MATLAB has the same seam;
1005 // do not copy it.)
1006 {
1007 bool mem_blocking = false;
1008 if (opt.method == "mem") {
1009 const MemSupport ms = solver_nc_mem_supports(L);
1010 mem_blocking = ms.supported && ms.blocking;
1011 }
1012 const bool mm1k_closed_form =
1013 (opt.method == "default" || opt.method == "exact") && api::sn_is_mm1k_loss(L);
1014 // The isolated order-independent loss queue likewise (qsys_oi_loss,
1015 // sn_is_oi_loss), reached through the OI route (SolverNC.m).
1016 const bool oi_loss =
1017 (opt.method == "default" || opt.method == "exact") && api::sn_is_oi_loss(L);
1018 if (!mem_blocking && !mm1k_closed_form && !oi_loss) qn::check_binding_capacity("SolverNC", L);
1019 }
1020
1021 if (L.has_fork()) {
1022 // The transform turns the fork into a router, the join into a delay and
1023 // the branches into auxiliary open classes. `nc_dispatch` then sees a
1024 // plain mixed network, which is why none of the specialised NC routes
1025 // has to know about forks.
1027 std::vector<T> lam(tr.V.classes.size() + 1,
1029 mva::MvaOptions mopt;
1030 mopt.method = opt.method;
1031 mopt.tol = opt.tol;
1032 mopt.iter_tol = opt.iter_tol;
1033 mopt.iter_max = opt.iter_max;
1034 mopt.fork_join = opt.fork_join;
1035 mopt.base_has_fork = true;
1036 NcSolverOptions inner = opt;
1037 inner.base_has_fork = true;
1038 std::string am, wn;
1039 res.sol = mva::fj_fixed_point(L, tr, lam, mopt, [&inner, &am, &wn](qn::NetworkStruct<T>& V) {
1040 const NcSolution<T> d = nc_dispatch(V, inner);
1041 am = d.actualmethod;
1042 wn = d.warning;
1043 return d.sol;
1044 }, &res.warning);
1045 res.actualmethod = am;
1046 // the last inner solve's own warning, ahead of the fixed point's
1047 if (!wn.empty()) res.warning = res.warning.empty() ? wn : wn + " " + res.warning;
1048 return res;
1049 } else {
1050 // Closed think+DPS network -> Morrison's heavy-usage generating-function
1051 // expansion, the DEFAULT for that shape. Intercepted FIRST, ahead of every
1052 // other branch: "SchedStrategy_DPS" is now inside the solver's reach, and
1053 // each of the branches below would silently drop the weights and answer
1054 // with the egalitarian-PS network. Not a product-form route: lG is NaN.
1055 if (nc_is_dps_model(L)) return solver_nc_dps_analyzer(L, opt);
1056 // The four refusal arms that used to follow -- another method on a DPS
1057 // model, a DPS station outside Morrison's shape, "morrison" on a model with
1058 // no DPS station at all, and "sdr"/"sdr.mva" on a model declaring no
1059 // state-dependent routing -- moved into `nc_method_refusal` above, with
1060 // their wording unchanged.
1061
1062 // Single-station M/M/1/K with tail drop: exact probability-based loss
1063 // analysis off the M/M/1/K stationary distribution (runAnalyzer.m:397).
1064 // Intercepted here for the same reason the loss network is: the buffer
1065 // makes `has_product_form` say no, so the 'exact' gate below would
1066 // refuse the one truncated shape that does keep a product form over its
1067 // single station. 'mem' asked by name never reaches this (it is claimed
1068 // above); every other name is refused by `nc_method_refusal`, since the
1069 // closed form reads none.
1070 // Order-independent networks (closed, open, mixed, and the isolated OI
1071 // loss queue) are intercepted AHEAD of the M/M/1/K closed form, as
1072 // `@SolverNC/runAnalyzer.m` orders them: a single-class OI loss queue is
1073 // also an M/M/1/K shape, and the closed form would read only mu([1]).
1074 // They also precede the multiserver-to-lldscaling rewrite below: an OI
1075 // station is multiserver but is not a plain min(n,c) load-dependent
1076 // station, so the rewrite would send it down a path that cannot
1077 // represent its rate function.
1078 if (nc_is_oi_model(L) && (opt.method == "default" || opt.method == "exact"))
1079 return solver_nc_oi_analyzer(L, opt);
1080
1081 if ((opt.method == "default" || opt.method == "exact") && api::sn_is_mm1k_loss(L)) {
1082 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
1083 const std::size_t M = L.nstations;
1084 const std::size_t src = mva::detail::station_of_type(L, qn::NodeType::Source);
1085 const std::size_t q = mva::detail::station_of_type(L, qn::NodeType::Queue);
1086 const std::size_t qstateful = L.stateful_of_station(q);
1087 const T Vq = L.visits[0](qstateful - 1, 0);
1088 const T lambda = T(L.rates(src - 1, 0) * Vq);
1089 const T mu = L.rates(q - 1, 0);
1090 const T rho = T(lambda / mu);
1091 const double Kcap = L.cap[q - 1];
1092 const unsigned Kint = static_cast<unsigned>(std::llround(Kcap));
1093 const T Ploss = qsys::qsys_mm1k_loss(lambda, mu, Kint).lossProbability;
1094 const T Tq = T(lambda * (one - Ploss)); // carried throughput
1095 T Lsys = zero;
1096 if (std::fabs(num_traits<T>::to_double(rho) - 1.0) < 1e-10) {
1097 Lsys = num_traits<T>::from_double(Kcap / 2.0); // L'Hopital limit at rho = 1
1098 } else {
1099 // K is a capacity, so the exponent is an INTEGER: num_pow_int stays exact
1100 // at T = Rational, where pow(rational, rational) does not exist at all.
1101 const T Kp1 = num_traits<T>::from_int(static_cast<int>(Kint) + 1);
1102 const T rKp1 = num_pow_int(rho, Kint + 1);
1103 Lsys = T(rho / (one - rho) - Kp1 * rKp1 / (one - rKp1));
1104 }
1105 NcSolution<T> lout;
1106 mva::MvaSolution<T>& ls = lout.sol;
1107 ls.Q = Matrix<T>(M, 1, zero);
1108 ls.U = Matrix<T>(M, 1, zero);
1109 ls.R = Matrix<T>(M, 1, zero);
1110 ls.Tp = Matrix<T>(M, 1, zero);
1111 ls.X.assign(1, zero);
1112 ls.C.assign(1, zero);
1113 ls.method = "mm1k.loss";
1114 ls.iter = 1;
1115 ls.lG = 0.0; // a closed form, not a convolution: no normalizing constant is formed
1116 ls.R(q - 1, 0) = T(Lsys / Tq); // per-visit response time, by Little
1117 ls.Q(q - 1, 0) = Lsys;
1118 ls.U(q - 1, 0) = T(Tq / mu); // single-server utilization
1119 ls.Tp(q - 1, 0) = Tq; // carried (effective) rate
1120 ls.Tp(src - 1, 0) = lambda; // offered arrival rate
1121 ls.X[0] = Tq; // system throughput = carried rate
1122 ls.C[0] = T(ls.R(q - 1, 0) * Vq);
1123 lout.actualmethod = "mm1k.loss";
1124 return lout;
1125 }
1126
1127 // A loss network is intercepted above the gates below: it is judged by
1128 // has_product_form on the 'exact' path and its infinite server would be
1129 // run through the multiserver-to-lldscaling rewrite, neither of which
1130 // applies to a model whose only dynamics are the region's admission rule.
1131 if (nc_is_lossn_model(L)) return solver_nc_lossn_analyzer(L, opt).sol;
1132
1133 // A stochastic Petri net takes the MDD-rec route: the reachable set
1134 // lives in a decision diagram and the product form supplies the rates,
1135 // so none of the queueing-network gates below say anything about it.
1136 // `spn_pf` is where a net's product-form class is decided, by name.
1137 for (std::size_t ind = 0; ind < L.nodes.size(); ++ind)
1138 if (L.nodes[ind].nodetype == lang::NodeType::Place)
1139 return solver_nc_spn_analyzer(L, opt).sol;
1140
1141 bool multiserver = false;
1142 for (const qn::Station<T>& st : L.stations)
1143 if (std::isfinite(st.nservers) && st.nservers > 1.0) multiserver = true;
1144 bool anyLld = false;
1145 for (const qn::Station<T>& st : L.stations)
1146 if (!st.lldscaling.empty()) anyLld = true;
1147
1148 // How this model's finite multiserver stations are represented. The
1149 // shipped "default" reproduces the historical dispatch exactly, so no
1150 // result moves unless config.multiserver is set.
1151 std::string ms_warning;
1152 const std::string ms_policy =
1153 detail::nc_multiserver_policy(opt.multiserver, &ms_warning);
1154
1155 if (opt.method == "default") {
1156 // The two-station Delay-plus-multiserver shape: every SolverLN layer
1157 // submodel. Exact through load-dependent CoMoM when product-form,
1158 // Seidmann through 'comom' when not.
1159 if (L.nstations == 2 && !detail::has_node_type(L, qn::NodeType::Cache) &&
1160 detail::has_node_type(L, qn::NodeType::Delay) && multiserver) {
1161 if (L.has_product_form() && !anyLld) {
1162 if (detail::multiserver_to_lld(L)) anyLld = true;
1163 } else {
1164 opt.method = "comom";
1165 }
1166 } else if (ms_policy == "lld" && multiserver && !anyLld && L.has_product_form() &&
1167 detail::nc_population_lattice(L) <= 6000.0) {
1168 // config.multiserver="lld" generalizes the exact load-dependent
1169 // lattice of the branch above to any closed product-form model,
1170 // under the same 6000-state enumeration budget. Off unless asked
1171 // for: with the shipped "default" policy this branch never runs
1172 // and the model keeps Seidmann's approximation, as it always has.
1173 if (detail::multiserver_to_lld(L)) anyLld = true;
1174 }
1175 } else if (opt.method == "exact" || opt.method == "is" || opt.method == "panald") {
1176 // 'is' and 'panald' need the same model as 'exact', i.e. the same
1177 // multiserver conversion.
1178 //
1179 // 'is' on an OI / P&S model is the specialised sampler, not the
1180 // generic one: an OI station is multiserver but not min(n,c), and a
1181 // P&S tandem has only per-communicating-class product form, so
1182 // has_product_form is false and the gate below would reject it.
1183 // nc_is_oi_model too, not only nc_is_pas_model: the latter demands
1184 // that BOTH stations be OI/PAS, so a Delay + OI cycle -- the canonical
1185 // topology pfqn_oi_is exists to sample -- fell to the guard below.
1186 if (opt.method == "is" && (nc_is_pas_model(L) || nc_is_oi_model(L))) {
1187 // handled by solver_nc_analyzer (pfqn_pas_is / pfqn_oi_is)
1188 } else if (nc_is_lossn_model(L)) {
1189 // A LOSS NETWORK (open, one DROP region holding a single Delay)
1190 // IS product form -- the truncated Poisson law the residue
1191 // transform of solver_nc_lossn evaluates exactly under 'exact'
1192 // -- but any region reads as blocking, so has_product_form says
1193 // no. Exempted here as `nc_method_refusal` already exempts it.
1194 } else if (!L.has_product_form())
1195 throw UnsupportedError(ErrorKind{"ProductForm"},
1196 "SolverNC: the '" + opt.method +
1197 "' method requires the model to have a product-form solution, and this model "
1198 "does not");
1199 // Only a GENUINE multiserver is converted: filling lldscaling with
1200 // ones on an all-single-server model is a semantic no-op that forces
1201 // the load-dependent path, whose recovery mishandles a
1202 // single-station-confined closed chain.
1203 // config.multiserver="seidmann" asks for Seidmann's approximation on
1204 // this arm too, so the conversion is skipped. Off by default.
1205 // Unbudgeted, so an open or mixed model is converted too
1206 // (nc_lld_from_nservers.m): solver_ncld's mixed route is exact on it.
1207 if (!anyLld && multiserver && ms_policy != "seidmann") {
1208 if (detail::multiserver_to_lld(L, /*unbudgeted=*/true)) anyLld = true;
1209 }
1210 }
1211
1212 // Caches, in the reference's order: a delayed-hit retrieval system
1213 // first (open or closed), then the non-reentrant Source-Cache-Sink
1214 // model, then any other cache as an integrated caching-queueing network.
1215 // The order is the contract -- a retrieval cache is ALSO a cache, and a
1216 // Source-Cache-Sink model is also "a model with a cache node".
1217 if (nc_has_retrieval(L)) {
1218 if (detail::has_node_type(L, qn::NodeType::Source)) {
1220 rr.sol.cache = detail::cache_metrics_of(L, rr.hitprob, rr.missprob, rr.delayedprob,
1221 rr.latency, rr.hitproblist, rr.itemprob,
1222 std::vector<T>());
1223 return rr.sol;
1224 }
1226 cr.sol.cache = detail::cache_metrics_of(L, cr.hitprob, cr.missprob, cr.delayedprob,
1227 cr.latency, cr.hitproblist, Matrix<T>(),
1228 std::vector<T>());
1229 return cr.sol;
1230 }
1231 if (nc_is_noreentrant_cache(L)) {
1233 // The non-reentrant model reports the per-list hit fractions and the
1234 // per-item law but no scalar hit probability of its own: the hit and
1235 // miss columns are the row sums of `hitproblist` and its complement,
1236 // and `cache_metrics_of` derives them rather than leaving the total
1237 // row of getAvgCacheTable empty on the one branch that knows most.
1238 cr.sol.cache = detail::cache_metrics_of(L, cr.hitprob, cr.missprob,
1239 std::vector<T>(), std::vector<T>(),
1240 cr.hitproblist, cr.itemprob, cr.listcost);
1241 return cr.sol;
1242 }
1243 if (nc_is_cacheqn(L)) {
1245 res = cr.sol;
1247 // hitprob/missprob are (ncaches x nclasses) here, one row per cache,
1248 // against the (K) vectors the retrieval branches return.
1249 res.cache = detail::cache_metrics_of_matrix(L, cr.hitprob, cr.missprob);
1250 // the per-item law rides in separately: this branch has one per cache
1251 // rather than one per model
1252 for (std::size_t ci = 0; ci < res.cache.caches.size() && ci < cr.itemprob.size(); ++ci)
1253 res.cache.caches[ci].itemprob = cr.itemprob[ci];
1254 for (std::size_t ci = 0; ci < res.cache.caches.size() && ci < cr.listcost.size(); ++ci)
1255 res.cache.caches[ci].listcost = cr.listcost[ci];
1256 return res;
1257 }
1258
1259 // A region this solver cannot enforce must STOP the solve, not be
1260 // dropped from it. Everything below computes an unconstrained answer,
1261 // so a model that reaches it with a live region would be reported as
1262 // though the region were absent -- numbers that are not wrong for any
1263 // model the user described. The reference raises at the same two points
1264 // (`runAnalyzer.m:326,334-336`) for the same reason.
1265 //
1266 // The loss-network SHAPE with a rule other than all-DROP is named
1267 // separately from a region on ordinary queueing stations, because the
1268 // two have different remedies: the first is asking for blocking, where
1269 // switching the rule to DROP makes the model solvable here, while the
1270 // second needs a solver that carries the region as state.
1271 // The token gates that used to stand here -- the loss-network shape under
1272 // a rule other than all-DROP, a Finite Capacity Region on queueing
1273 // stations, "erlangfp"/"ms"/"rec" off a loss network and "rayint"/"spm"
1274 // with no Cache node -- moved into `nc_method_refusal`, which decides them
1275 // from the same struct before the dispatch begins and which
1276 // `auto_family_refusal` asks too; their wording is unchanged. The six
1277 // load-dependent evaluators on an OPEN chain are now refused by the
1278 // feature set instead (`nc_feature_set` drops OpenClass from them):
1279 // "closed population only" is a rule the registry CAN name, and naming it
1280 // there is what makes `auto_find_solver` drop the row rather than report
1281 // it runnable.
1282
1283 if (anyLld || nc::detail::has_scaling(L)) {
1284 res = solver_ncld_analyzer(L, opt);
1285 } else if (opt.method == "rd" || opt.method == "nrp" || opt.method == "nrl" ||
1286 opt.method == "nre" || opt.method == "comomld" || opt.method == "panald") {
1287 res = solver_ncld_analyzer(L, opt);
1288 } else {
1289 res = solver_nc_analyzer(L, opt);
1290 }
1291 // A config.multiserver value this solver does not implement was silently
1292 // ignored before; it now says so. Joined rather than overwriting, as the
1293 // analyzer warnings are.
1294 if (!ms_warning.empty())
1295 res.warning = res.warning.empty() ? ms_warning : res.warning + " " + ms_warning;
1296 return res;
1297 }
1298}
1299
1300/**
1301 * Port of `@@SolverNC/runAnalyzer.m` for the `lang='matlab'` path: solve, then
1302 * apply the metric filter `@@NetworkSolver/getAvg` puts between the analyzer and
1303 * the caller.
1304 */
1305template <class T>
1306mva::AvgResult<T> solver_nc_avg_table(const qn::NetworkStruct<T>& L_in, const NcSolution<T>& d,
1307 const std::string& origmethod);
1308
1309template <class T>
1311 return solver_nc_avg_table(L_in, solver_nc_solve(L_in, opt_in), opt_in.method);
1312}
1313
1314/**
1315 * The metric filter half of `solver_nc_run_analyzer`, for a caller that already
1316 * holds the `NcSolution` and needs more of it than the table (the CLI's cftp
1317 * banner reads the sampled states and horizons off the same solve).
1318 */
1319template <class T>
1321 const std::string& origmethod) {
1322 const mva::MvaSolution<T>& s = d.sol;
1323 const std::string& actualmethod = d.actualmethod;
1324 const qn::NetworkStruct<T>& L = L_in;
1325
1326 const std::size_t M = L.nstations, K = L.nclasses;
1327 std::vector<std::vector<bool>> mask(M, std::vector<bool>(K, false));
1328 for (std::size_t i = 0; i < M; ++i)
1329 for (std::size_t k = 0; k < K; ++k)
1330 mask[i][k] = num_traits<T>::to_double(s.R(i, k)) < 10.0 * GlobalConstants::FineTol;
1331 std::vector<std::vector<bool>> srcmask(M, std::vector<bool>(K, false));
1332 for (std::size_t i = 0; i < M; ++i)
1333 if (L.stations[i].nodetype == qn::NodeType::Source)
1334 for (std::size_t k = 0; k < K; ++k) srcmask[i][k] = true;
1335
1337 out.QN = mva::filter_metric(L, s.Q, mva::MetricKind::QLen, &mask);
1338 out.UN = mva::filter_metric(L, s.U, mva::MetricKind::Util, &mask);
1339 out.RN = mva::filter_metric(L, s.R, mva::MetricKind::RespT, nullptr);
1340 out.TN = mva::filter_metric(L, s.Tp, mva::MetricKind::Tput, nullptr);
1341 // Both ArvR and ResidT come from the refreshed struct when the cacheqn
1342 // analyzer supplied one: its cache self-switch is normalized at the ACTUAL
1343 // hit/miss split, so the visits back the carried rate without the over-route
1344 // inflation. filter_metric still keys on the base L for its topology masking.
1347 mva::MetricKind::ResidT, nullptr);
1349 &srcmask);
1351 // The saturated open-station rule of getAvg.m, applied AFTER out.WN so the
1352 // residence times keep their pre-saturation value. Without it SolverNC
1353 // reported the mixed formula's raw `QLen 3.05, Util 61.8` for a station
1354 // MATLAB and SolverMVA both call saturated (chaos seed 215).
1355 std::string satwarn;
1356 if (mva::cap_unstable_open_stations(L, out.QN, out.UN, out.RN, out.TN))
1357 satwarn = mva::unstable_open_warning();
1358 out.CN = s.C;
1359 out.XN = s.X;
1360 out.method = origmethod;
1361 // `runAnalyzer` reports 'default/<algorithm>' when the caller asked for the
1362 // default and something more specific ran, so the algorithm that produced
1363 // the numbers is never lost.
1364 out.actualmethod = (origmethod == "default" && !actualmethod.empty() &&
1365 actualmethod != "default")
1366 ? "default/" + actualmethod
1367 : actualmethod;
1368 // Approximated, not refused, for the reason SolverMVA gives: a normalizing
1369 // constant counts a fed-back visit as an ordinary re-entry, having no way
1370 // to express a job that keeps its server. `@@SolverNC/runAnalyzer.m` warns
1371 // and solves, and this text is that warning verbatim.
1372 if (L.has_immediate_feedback())
1373 out.warning =
1374 "SolverNC does not handle immediate feedback (immfeed); the solver will treat "
1375 "self-loops as class-switching with re-queueing.";
1376 // A warning raised by an analyzer (the cache branch's cost-cap conditions)
1377 // must survive the runner; both can fire, so they are joined rather than
1378 // one overwriting the other.
1379 if (!d.warning.empty())
1380 out.warning = out.warning.empty() ? d.warning : out.warning + " " + d.warning;
1381 if (!satwarn.empty())
1382 out.warning = out.warning.empty() ? satwarn : out.warning + " " + satwarn;
1383 out.listcost = d.listcost;
1384 // What the cache branch measured, carried to `getAvgCacheTable` and
1385 // `getAvgItemTable`; empty on every model without a Cache node.
1386 out.cache = d.cache;
1387 // `runAnalyzer.m`'s last line: the log normalizing constant is stored beside
1388 // the average table rather than recomputed, so `getProbNormConstAggr` costs
1389 // the caller nothing once `getAvg` has run.
1390 out.lognormconst = s.lG;
1391 out.iter = s.iter;
1392 out.fj = s.fj; // fork-join section metrics, see getAvgFJ
1393 out.lossn = d.lossn; // loss-network inputs, see getAvgLinkTable
1394 {
1395 const double lg = num_traits<T>::to_double(s.lG);
1396 if (std::isfinite(lg))
1397 line::util::LineConsole::step("normalizing constant obtained: log G = %.6g", lg);
1398 }
1399 return out;
1400}
1401
1402/** Port of `@@SolverNC/getProbNormConstAggr.m`: the log normalizing constant. */
1403template <class T>
1405 return solver_nc_solve(L, opt).sol.lG;
1406}
1407
1408} // namespace nc
1409} // namespace line
1410
1411#endif // LINE_SOLVERS_NC_SOLVER_NC_RUNNER_H
What a solver observed about the Cache nodes of a model.
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
bool has_immediate_feedback() const
Whether immediate feedback is EFFECTIVE anywhere in the model.
std::size_t stateful_of_station(std::size_t st) const
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< NodeDef > nodes
every node, in creation order
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
bool has_product_form() const
sn_has_product_form, conjunct for conjunct.
static void step(const char *fmt,...)
Write one progress line.
The exception types the port throws.
The fork-join fixed point that drives one inner MVA solve.
The Heidelberger-Trivedi fork-join transform, options.config.fork_join='ht'.
The fork-join transform SolverMVA applies before solving a layer that contains a Fork.
Running progress log of a LINE solver run (the "solver console").
The method names of each solver, in listing order.
bool sn_is_oi_loss(const qn::NetworkStruct< T > &sn, std::size_t *qist=nullptr)
Port of sn_is_oi_loss.m: the isolated order-independent loss queue (Source -> OI -> Sink with a finit...
bool sn_is_mm1k_loss(const qn::NetworkStruct< T > &sn)
sn_is_mm1k_loss: the three-node Source/Queue/Sink model of an M/M/1/K with loss, the shape MVA answer...
std::string sn_reducible_chain_refusal(const qn::NetworkStruct< T > &sn)
The by-name refusal of the first closed chain whose (station,class) routing has more than one closed ...
NodeType
Node kinds, with the values of MATLAB NodeType.
Definition lang_types.h:345
@ FIFO
first in, first out
Definition lang_types.h:421
Matrix< T > sn_get_residt_from_respt(const qn::NetworkStruct< T > &L, const Matrix< T > &RN)
Port of sn_get_residt_from_respt: the per-JOB residence time.
Matrix< T > filter_metric(const qn::NetworkStruct< T > &L, const Matrix< T > &metric, MetricKind kind, const std::vector< std::vector< bool > > *zero_mask)
Port of filterMetric: what @@NetworkSolver/getAvg does between the analyzer and the caller.
bool cap_unstable_open_stations(const qn::NetworkStruct< T > &L, Matrix< T > &QN, Matrix< T > &UN, Matrix< T > &RN, const Matrix< T > &TN)
The saturated open-station rule of @@NetworkSolver/getAvg.m:221-308.
void apply_analyzer_arvr(Matrix< T > &AN, const Matrix< T > &supplied)
Overwrite the routing-derived arrival rates with those an analyzer supplied (MvaSolution::AN,...
const char * unstable_open_warning()
The warning getAvg.m raises when cap_unstable_open_stations() fires.
FjMmt< T > fj_fork_join_transform(const qn::NetworkStruct< T > &L, const std::string &method)
options.config.fork_join -> the transform it names.
Definition fj_ht.h:389
MvaSolution< T > fj_fixed_point(const qn::NetworkStruct< T > &L, FjMmt< T > &tr, std::vector< T > &lam, const MvaOptions &opt, InnerSolve inner, std::string *warning=nullptr)
Drive the fork-join fixed point of a transformed model to convergence.
Definition fj_driver.h:512
Matrix< T > sn_get_arvr_from_tput(const qn::NetworkStruct< T > &L, const Matrix< T > &TN)
Port of sn_get_arvr_from_tput: the arrival rate each station sees, from the throughputs and the class...
ChainDemands< T > sn_get_demands_chain(const qn::NetworkStruct< T > &L)
Port of sn_get_demands_chain.
Definition sn_chain.h:63
NcCftpSolution< T > solver_nc_cftp(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt, const NcCftpOptions &cftpopt)
Solve with the cftp / cftp.approx method.
mva::AvgResult< T > solver_nc_run_analyzer(const qn::NetworkStruct< T > &L_in, const NcSolverOptions &opt_in)
bool nc_is_cacheqn(const qn::NetworkStruct< T > &sn)
True when the model has a Cache node and is not the Source-Cache-Sink shape.
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_dt(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Exact discrete-time analysis of sn.
NcSpnSolution< T > solver_nc_spn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Analyse a product-form stochastic Petri net.
NcSolution< T > solver_nc_dps_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Analyzes the closed think+DPS network.
bool nc_is_slotted(const NcSolverOptions &opt)
True when the caller asked for the discrete-time route (slotted or timescale "discrete").
Definition nc_types.h:128
MemSupport solver_nc_mem_supports(const qn::NetworkStruct< T > &sn)
Port of solver_nc_mem_supports.m.
NcCacheSolution< T > solver_nc_cache_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_cache_analyzer.m.
bool nc_is_normal_usage(const qn::NetworkStruct< T > &sn, bool seidmann=false)
Is the closed model in NORMAL USAGE, the domain of the Mitra-McKenna PANACEA asymptotic expansion (J.
NcSolution< T > solver_nc_cftp_solution(const NcCftpSolution< T > &s)
A cftp solve in the shape every other SolverNC analyzer returns, so the runner's metric filter applie...
bool nc_is_lossn_model(const qn::NetworkStruct< T > &sn)
True when the model is a loss network: the shape above, with EVERY class dropped at the region.
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.
bool nc_lc_concealment_degenerate(const qn::NetworkStruct< T > &sn)
Is Birman-Kogan load concealment ('lc'/'lc.ue') degenerate on this model?
double solver_nc_lognormconst(const qn::NetworkStruct< T > &L, const NcSolverOptions &opt)
Port of @@SolverNC/getProbNormConstAggr.m: the log normalizing constant.
std::string resolve_method(const qn::NetworkStruct< T > &, const std::string &method)
Port of SolverNC.resolveMethod: default is NOT resolved ahead of the run.
NcCacheqnRetrievalSolution< T > solver_nc_cacheqn_retrieval_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_cacheqn_retrieval_analyzer.m.
void check_method(const std::string &method)
Port of runAnalyzerChecks' method gate: an unlisted method is refused.
std::vector< std::string > list_valid_methods()
Port of SolverNC.listValidMethods.
std::size_t nc_closed_queueing_stations(const qn::NetworkStruct< T > &sn)
How many queueing (non-infinite-server) stations carry demand from a CLOSED chain?
NcRetrievalSolution< T > solver_nc_retrieval_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_retrieval_analyzer.m.
NcSolution< T > solver_nc_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_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?
bool is_stochastic_method(const std::string &method)
Port of SolverNC.isStochasticMethod.
std::string nc_method_refusal(const qn::NetworkStruct< T > &sn, const std::string &method, bool slotted=false, bool for_report=true, const std::string &multiserver=std::string())
May method run on this model?
NcSolution< T > solver_nc_solve(const qn::NetworkStruct< T > &L_in, const NcSolverOptions &opt_in)
The gates, the multiserver conversion and the dispatch of @@SolverNC/runAnalyzer.m,...
bool nc_has_lossn_shape(const qn::NetworkStruct< T > &sn)
True when the model has the SHAPE of a loss network – open, one region, one member station,...
NcCacheqnSolution< T > solver_nc_cacheqn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_cacheqn_analyzer.m.
NcSolution< T > solver_ncld_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_ncld_analyzer.m: the load-dependent analyzer, which is solver_ncld plus the same fract...
bool sn_has_dps(const qn::NetworkStruct< T > &sn)
True when any station of the network is scheduled DPS.
bool nc_has_retrieval(const qn::NetworkStruct< T > &sn)
True when the model's Cache carries a delayed-hit retrieval system.
NcLossnSolution< T > solver_nc_lossn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_lossn_analyzer.m.
bool nc_is_noreentrant_cache(const qn::NetworkStruct< T > &sn)
True when the model is exactly a Source, a Cache and a Sink.
mva::AvgResult< T > solver_nc_avg_table(const qn::NetworkStruct< T > &L_in, const NcSolution< T > &d, const std::string &origmethod)
Port of @@SolverNC/runAnalyzer.m for the lang='matlab' path: solve, then apply the metric filter @@Ne...
std::string solver_nc_cftp_supports(const qn::NetworkStruct< T > &sn)
The cftp model-class gate as a public predicate.
bool nc_is_dps_model(const qn::NetworkStruct< T > &sn)
True when the model is the closed two-station network Morrison's expansion is derived for: one infini...
NcSolution< T > nc_dispatch(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of @@SolverNC/ncDispatch.m: the inner solve of the fork-join fixed point, which is the load-depe...
PanaceaLdResult< T > pfqn_panaceald(const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z, const Matrix< T > &mu, int terms)
PANACEA normal-usage asymptotic expansion for LOAD-DEPENDENT closed networks (Mitra and McKenna,...
FeatureSet nc_feature_set(const std::string &method)
SolverNC.getFeatureSet, 48 names, transcribed unchanged.
void check_binding_capacity(const std::string &solver, const NetworkStruct< T > &sn)
NetworkSolver.checkBindingCapacity (NetworkSolver.m:1172-1228): the shared structural gate for finite...
void feature_gate(const std::string &solver, const FeatureSet &declared, const NetworkStruct< T > &sn, const std::string &requested_method="", const std::string &resolved_method="")
runAnalyzerChecks: refuse a model the solver does not declare, by name.
Mm1kLossResult< T > qsys_mm1k_loss(const T &lambda, const T &mu, unsigned K)
Blocking probability of the M/M/1/K queue.
CacheMetrics< T > cache_metrics_of(const qn::NetworkStruct< T > &sn, const std::vector< T > &hitprob, const std::vector< T > &missprob, const std::vector< T > &delayedprob, const std::vector< T > &latency, const Matrix< T > &hitproblist, const Matrix< T > &itemprob, const std::vector< T > &listcost)
Assemble CacheMetrics from what a cache analyzer returned.
CacheMetrics< T > cache_metrics_of_matrix(const qn::NetworkStruct< T > &sn, const Matrix< T > &hitprob, const Matrix< T > &missprob)
The same, for the integrated caching-queueing branch, whose hit and miss probabilities are (ncaches x...
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition number.h:204
Port of solver_nc_analyzer.m, solver_ncld_analyzer.m and @@SolverNC/ncDispatch.m: one inner solve,...
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
PANACEA normal-usage asymptotic expansion for LOAD-DEPENDENT closed networks (Mitra and McKenna,...
Blocking probability of the M/M/1/K queue.
Chain aggregation and de-aggregation.
Ports of the sn_has_* / sn_is_* predicate family of matlab/src/api/sn.
Port of sn_reducible_chain_refusal.m: refusal of a closed chain whose (station,class) routing is redu...
The DECLARED side of the gate: one feature set per solver.
The SolverMVA class surface: @@SolverMVA/runAnalyzer.m and the gates around it.
Port of solver_nc_cache_analyzer.m: the NON-REENTRANT cache, a model that is exactly a Source,...
Port of solver_nc_cacheqn_analyzer.m: the INTEGRATED caching-queueing network, where a Cache sits ins...
Port of solver_nc_cacheqn_retrieval_analyzer.m: a CLOSED integrated cache-queueing model whose Cache ...
The cftp and cftp.approx methods of SolverNC: stationary analysis of a closed single-class product-fo...
Heavy-usage asymptotic analysis of the closed two-station network with one think (infinite-server) st...
Port of solver_nc_lossn_analyzer.m: the open LOSS NETWORK, which is a Source, ONE multiclass Delay si...
Port of solver_nc_mem.m and solver_nc_mem_supports.m: the Maximum Entropy Method of Kouvatsos (1994).
Order-independent (OI) and pass-and-swap (P&S) normalizing-constant analysis.
Port of solver_nc_retrieval_analyzer.m: the OPEN delayed-hit (retrieval-system) cache.
Stationary analysis of a PRODUCT-FORM stochastic Petri net by MDD-rec.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
The metrics getAvg returns, after filtering.
Matrix< T > TN
throughput
solvers::LossnInfo lossn
self.result.LossN: the loss-network inputs SolverNC keeps for getAvgLinkTable, EMPTY for every other ...
Matrix< T > RN
response time, per visit
std::string warning
The reference's own warning text, verbatim, empty when it did not warn.
Matrix< T > UN
utilization
solvers::FjMetrics< T > fj
self.result.FJ: the fork-join section metrics FJQLen, FJRespT and FJTput, filled by the solvers the f...
std::vector< T > listcost
(h) mean storage cost held by each cache list, K_j = sum_i sigma_i pi_ij, filled only by the NC cache...
std::optional< double > lognormconst
@@SolverNC/getProbNormConstAggr, i.e.
Matrix< T > WN
residence time, per job
std::string method
the method asked for
std::string actualmethod
the algorithm that ran
Matrix< T > QN
queue length
std::vector< T > CN
system response time per class
std::vector< T > XN
system throughput per class
solvers::CacheMetrics< T > cache
What the cache branches observed, EMPTY on a model with no Cache node and on every solver that does n...
Matrix< T > AN
arrival rate
The chain-level view of a layer, as sn_get_demands_chain returns it.
Definition sn_chain.h:46
Matrix< T > Lchain
(M x C) demand
Definition sn_chain.h:47
The transformed layer and the bookkeeping the fixed point needs to drive it and to merge its results ...
Definition fj_mmt.h:113
The options SolverMVA reads.
Definition mva_types.h:32
bool base_has_fork
Whether the model this solve came from has a Fork, which the model handed to the analyzer no longer d...
Definition mva_types.h:66
std::string method
Definition mva_types.h:33
std::string fork_join
options.config.fork_join: which fork-join arm the fixed point takes.
Definition mva_types.h:52
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:97
std::vector< T > X
Definition mva_types.h:99
double lG
log of the normalizing constant, the reference's lG.
Definition mva_types.h:119
Matrix< T > AN
Analyzer-supplied station arrival rates (M x K), NaN where the runner derives them from the routing; ...
Definition mva_types.h:127
std::vector< T > C
Definition mva_types.h:99
solvers::FjMetrics< T > fj
Fork-join section metrics set by the fork-join fixed point (fj_driver.h); empty otherwise.
Definition mva_types.h:121
static constexpr double FineTol
Definition lang_types.h:823
The verdict of solver_nc_mem_supports.
bool blocking
the model carries a binding finite station buffer
What the cache analyzer returns beyond the usual metric table.
Matrix< T > hitproblist
(u x h) access-weighted per-list hit probability, NaN if not exact
std::vector< T > missprob
(u) per-class miss and hit PROBABILITIES, missrate divided by the read class's arrival rate and its c...
Matrix< T > itemprob
(n x h+1) the same from the EXACT recursion, NaN above 10 items
std::vector< T > listcost
(h) mean storage cost held by each list, EMPTY without item sizes
What the closed delayed-hit analyzer returns.
std::vector< T > delayedprob
(K) zero on this path, by the reference's convention
std::vector< T > missprob
(K) the delayed fraction is folded in here
std::vector< T > hitprob
(K) P(item cached)
std::vector< T > latency
(K) NaN: not computed on this path
Matrix< T > hitproblist
(K x h) NaN: not computed on this path
What the integrated analyzer returns: the metrics plus the converged split.
Matrix< T > hitprob
(ncaches x nclasses) converged hit probability
Matrix< T > missprob
(ncaches x nclasses)
qn::NetworkStruct< T > refreshed
The struct whose cache self-switch carries the CONVERGED split rather than the offered one,...
std::vector< std::vector< T > > listcost
per cache, (h) mean storage cost per list; EMPTY without item sizes
std::vector< Matrix< T > > itemprob
per cache, (n x h+1); EMPTY = not computed
What the delayed-hit analyzer returns beyond the metric table.
Matrix< T > itemprob
(n x h+1) column 0 = miss, 1.. = per list
std::vector< T > hitprob
(K) TRUE hit fraction, NaN off the read class
Matrix< T > hitproblist
(K x h) per-list hit fraction
std::vector< T > delayedprob
(K) delayed-hit fraction
std::vector< T > latency
(K) NaN: the latency belongs to SolverMVA
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:134
solvers::LossnInfo lossn
Set only by the loss-network analyzer (solver_nc_lossn.h), EMPTY for every other model: the inputs ge...
Definition nc_types.h:186
std::vector< T > listcost
(h) mean storage cost held by each cache list, K_j = sum_i sigma_i pi_ij.
Definition nc_types.h:160
mva::MvaSolution< T > sol
Definition nc_types.h:135
std::string warning
The reference's warning text, verbatim, empty when it did not warn.
Definition nc_types.h:154
std::shared_ptr< qn::NetworkStruct< T > > refreshed_struct
Set only by the integrated cacheqn branch: the converged struct whose routing carries the ACTUAL hit/...
Definition nc_types.h:144
solvers::CacheMetrics< T > cache
What the cache branches observed, EMPTY on a model with no Cache node.
Definition nc_types.h:169
std::string actualmethod
Definition nc_types.h:136
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:35
std::string multiserver
options.config.multiserver: how a finite multiserver station is represented.
Definition nc_types.h:65
bool base_has_fork
Whether the model this solve came from has a Fork, which the model handed to the analyzer no longer d...
Definition nc_types.h:100
One job class of the network.
double population
infinite for an open class
A node of the network.
One station of the network.
SchedStrategy sched
double nservers
may be infinite (a Delay, or an inf-scheduled task)
std::vector< T > lldscaling
sn.lldscaling for this station: the multiplier at population 1, 2, ... Empty when the station is not ...