LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mva_dispatch.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_MVA_MVA_DISPATCH_H
6#define LINE_SOLVERS_MVA_MVA_DISPATCH_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `@@SolverMVA/mvaDispatch.m`: one inner solve, choosing the analyzer
12 * that fits the model.
13 *
14 * THE ORDER IS THE CONTRACT. The branches are NOT disjoint -- a single-class
15 * open Source-Queue-Sink model with a size-based discipline satisfies two of
16 * them, a cache model with load dependence satisfies two more -- so the first
17 * match wins and reordering silently changes which algorithm a model gets.
18 * The sequence below is the reference's, top to bottom:
19 *
20 * 0 closed models with a shortest-job-next station <- ported
21 * 1 order-independent / pass-and-swap stations
22 * 2 delayed-hit retrieval caches, open then closed
23 * 3 size-based scheduling in an open Source-Queue-Sink model
24 * 4 single-class open Source-Queue-Sink <- ported
25 * 5 multiclass open polling
26 * 6 multiclass open HOL priority <- ported
27 * 7 multiclass open DPS, at most three classes <- ported
28 * 8 non-reentrant cache (Source-Cache-Sink)
29 * 9 integrated caching-queueing
30 * 10 bound methods (moved to SolverBA in the reference)
31 * 11 Marie's aggregation-decomposition
32 * 12 load- or class-dependent scaling <- ported
33 * 13 everything else <- solver_mva_analyzer,
34 * of whose method switch 'mvac' is dispatched here (solver_mvac.h)
35 *
36 * WHAT IS NOT PORTED IS REFUSED BY NAME, never allowed to fall through to the
37 * generic analyzer. A cache model solved as an ordinary queueing network
38 * returns numbers -- they are simply not the model's -- and the same holds for
39 * a polling system and for an OI station, whose rate function the AMVA cannot
40 * represent at all.
41 */
42
43#include <algorithm>
44#include <cmath>
45#include <limits>
46#include <memory>
47#include <string>
48#include <vector>
49
96#include "line/util/rootfind.h"
116
117namespace line {
118namespace mva {
119
120/**
121 * Why method 'erlanga' cannot answer this model's patience, or "". Erlang A is
122 * the M/M/s/r+M chain: it is defined for an EXPONENTIAL patience and reads only
123 * its rate, so an Erlang, HyperExp or PH law would be answered as an exponential
124 * of the same mean; 'mgisrgi' takes it. The gate, the method list and the
125 * analyzer ask this same predicate (MATLAB SolverMVA.supportsQueueingSystem).
126 */
127template <class T>
129 const std::string why = api::sn_patience_exp_refusal(L);
130 if (why.empty()) return why;
131 return why + " Use method 'mgisrgi', which takes any Markovian patience.";
132}
133
134/** What the dispatch returns: the metrics plus the algorithm that produced them. */
135template <class T>
138 /** The concrete algorithm, as the reference's `actualmethod`. */
139 std::string actualmethod;
140 /**
141 * Set only by the integrated cacheqn branch: the converged struct whose
142 * routing carries the actual hit/miss probabilities, from which the runner
143 * derives ArvR and ResidT. Empty for every other model.
144 */
145 std::shared_ptr<qn::NetworkStruct<T>> refreshed_struct;
146 /**
147 * What a cache branch measured, EMPTY on every model without a Cache.
148 *
149 * A cache's hit / miss / delayed-hit split is a SOLVER RESULT, not model
150 * state, and it is the only part of the answer the (station x class) tables
151 * cannot carry. Dropping it here is what left `-a cache` refusing under
152 * `-s mva` and, through CPPLINE, left MATLAB's Cache node holding whatever
153 * the PREVIOUS solver wrote -- retrieval_simple printed the LDES table under
154 * the MVA label. Assembled by `solvers::cache_metrics_of`, one rule for
155 * every branch of every solver.
156 */
158 /**
159 * Non-empty when the analyzer that ran would have raised a reference
160 * `line_warning` and still returned a usable answer, carrying its text.
161 * Set only by the SJN branch today (solver_mva_sjn.h).
162 *
163 * KNOWN DIVERGENCE, DELIBERATE. This port has no general warning channel --
164 * no line_warning equivalent exists under cpp/include/line/ -- so the text
165 * stops here, at the dispatch boundary. A caller of `mva_dispatch` sees it;
166 * a user going through SolverMVA does NOT, because solver_mva_runner.h does
167 * not read the field. Closing that last hop needs a runner change and a
168 * decision about where a solver-level warning should surface at all, which
169 * is wider than this analyzer.
170 */
171 std::string warning;
172};
173
174namespace detail {
175
176/** True when the model is exactly a Source, a Queue and a Sink. */
177template <class T>
178bool is_open_sqs(const qn::NetworkStruct<T>& L) {
179 if (L.nof_nodes() != 3) return false;
180 int src = 0, q = 0, snk = 0;
181 for (const qn::NodeDef& nd : L.nodes) {
182 if (nd.nodetype == qn::NodeType::Source) ++src;
183 else if (nd.nodetype == qn::NodeType::Queue) ++q;
184 else if (nd.nodetype == qn::NodeType::Sink) ++snk;
185 }
186 return src == 1 && q == 1 && snk == 1 && L.nclosedjobs() == 0.0;
187}
188
189/**
190 * The method names `solver_mva_qsys_analyzer` has an arm for.
191 *
192 * ONE PREDICATE FOR THE INTERCEPTION AND THE RUN. The Source-Queue-Sink shape is
193 * claimed by that analyzer, which answers this FIXED list of closed forms and
194 * refuses every other name -- so each general network method the report offers
195 * on an open model was advertised on the one open shape it could not run on and
196 * threw "not available for a model with one station and one class" the moment it
197 * was asked for: `mva`, `amva`, `sum`, `esum`, `lin`, `gflin`, `egflin`, `qli`,
198 * `fli`, `qd` and `qdlin`, eleven of them. They are NETWORK methods, and the
199 * general branch solves a one-queue network exactly as it solves a larger one,
200 * so the interception stands aside for them rather than claiming a model it
201 * cannot answer. `qna` was the first name found this way and used to be excluded
202 * by hand at the call site; it needs no special case now, having no arm here
203 * either.
204 *
205 * Judged on the ALIASED name, the same `amva_method_alias` the analyzer applies
206 * on the way in. Mirrors `matlab/src/solvers/MVA/@SolverMVA/mvaDispatch.m` and
207 * its JAR and native python twins.
208 *
209 * The list itself is `qn::mva_qsys_serves_method`, in lang/qn, so that
210 * `mva_feature_set` can read the same names when it withdraws the
211 * state-dependence features from the ones that are closed forms only.
212 */
213inline bool qsys_serves_method(const std::string& method) {
214 return qn::mva_qsys_serves_method(method);
215}
216
217/**
218 * A DECLARED STATE DEPENDENCE DISQUALIFIES EVERY SINGLE-STATION CLOSED FORM.
219 *
220 * `solver_mva_qsys_analyzer` reads `L.rates(queue, 0)`, ONE number, and a station
221 * carrying lldscaling, cdscaling or jdscaling has a lattice of them, so claiming
222 * such a model for mm1/mmk/mg1/gig1 answers the UNSCALED queue: a wrong number,
223 * not a coarse one, and silent. The model goes to the load-dependent branch
224 * instead, and `mva_feature_set` refuses the names that have no other arm. The
225 * same rule `sn_is_mm1k_loss` states for the loss shape.
226 */
227template <class T>
228bool has_state_dependent_rates(const qn::NetworkStruct<T>& L) {
229 for (const auto& st : L.stations)
230 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling) return true;
231 return false;
232}
233
234/** The same, with a Cache in place of the Queue. */
235template <class T>
236bool is_open_scs(const qn::NetworkStruct<T>& L) {
237 if (L.nof_nodes() != 3) return false;
238 int src = 0, ca = 0, snk = 0;
239 for (const qn::NodeDef& nd : L.nodes) {
240 if (nd.nodetype == qn::NodeType::Source) ++src;
241 else if (nd.nodetype == qn::NodeType::Cache) ++ca;
242 else if (nd.nodetype == qn::NodeType::Sink) ++snk;
243 }
244 return src == 1 && ca == 1 && snk == 1 && L.nclosedjobs() == 0.0;
245}
246
247/** The size-based disciplines the reference routes to its own analyzer. */
248inline bool is_size_based(qn::SchedStrategy s) {
249 return s == qn::SchedStrategy::SRPT || s == qn::SchedStrategy::PSJF ||
250 s == qn::SchedStrategy::FB || s == qn::SchedStrategy::LRPT ||
251 s == qn::SchedStrategy::SETF;
252}
253
254/** 1-based station index of the single node of this type, 0 when absent. */
255template <class T>
256std::size_t station_of_type(const qn::NetworkStruct<T>& L, qn::NodeType ty) {
257 for (std::size_t i = 0; i < L.nof_nodes(); ++i)
258 if (L.nodes[i].nodetype == ty) return L.nodes[i].station;
259 return 0;
260}
261
262/** True when every finite SCV of a station's row is 1, as the reference tests. */
263template <class T>
264bool row_is_exponential(const qn::NetworkStruct<T>& L, std::size_t ist) {
265 for (std::size_t r = 0; r < L.nclasses; ++r) {
266 if (L.disabled[ist - 1][r]) continue;
267 const double v = num_traits<T>::to_double(L.scv(ist - 1, r));
268 if (!std::isfinite(v)) continue;
269 if (std::fabs(v - 1.0) >= 1e-6) return false;
270 }
271 return true;
272}
273
274/** A process of order one: an exponential law, or a (D0,D1) pair of one phase. */
275template <class T>
276bool is_order_one_proc(const lang::Distrib<T>& d) {
277 return d.type == lang::ProcessType::EXP || (d.has_map() && d.D0.rows() == 1);
278}
279
280/**
281 * The plain-server half shared by the M^X/G/1 and breakdown predicates: one
282 * FCFS server, infinite buffer, no state dependence, no reneging. Empty when
283 * it holds, otherwise the missing property.
284 */
285template <class T>
286std::string qsys_plain_server_reason(const qn::NetworkStruct<T>& L, std::size_t q) {
287 const qn::Station<T>& st = L.stations[q - 1];
288 if (st.nservers != 1.0) return "a single server";
289 if (st.sched != qn::SchedStrategy::FCFS) return "FCFS scheduling";
290 if (std::isfinite(L.cap[q - 1])) return "an infinite buffer";
291 if (has_state_dependent_rates(L)) return "a load-independent server";
292 if (api::sn_patience_handles(L, q - 1, 0).present) return "no reneging";
293 return "";
294}
295
296} // namespace detail
297
298/**
299 * Port of `SolverMVA.finiteSourceVariant(sn, method)`: the finite-source closed
300 * form `solver_mva_finite_source_analyzer` answers under `method` on a closed
301 * single-class model of N jobs cycling between a Delay and one FCFS Queue (one
302 * visit each), or "" when there is none:
303 * "mg1kk" - exponential Delay, one server with a renewal service law (PH
304 * with rank-one D1, or a law with an LST); under default/exact only
305 * when the service is not exponential (product form covers that)
306 * "ddckk" - deterministic Delay and service, c servers
307 * "mmckk" - exponential Delay and service, c servers (by name)
308 */
309template <class T>
310std::string mva_finite_source_variant(const qn::NetworkStruct<T>& L, const std::string& method) {
311 using qn::SchedStrategy;
312 using lang::ProcessType;
313 if (!(method == "default" || method == "exact" || method == "mg1kk" || method == "ddckk" ||
314 method == "mmckk"))
315 return "";
316 if (!(L.nclasses == 1 && L.nstations == 2 && L.nclosedjobs() > 0 && L.nof_nodes() == 2)) return "";
317 {
318 int nd = 0, nq = 0;
319 for (const qn::NodeDef& n : L.nodes) {
320 if (n.nodetype == qn::NodeType::Delay) ++nd;
321 else if (n.nodetype == qn::NodeType::Queue) ++nq;
322 }
323 if (nd != 1 || nq != 1) return "";
324 }
325 std::size_t d = 0, q = 0; // 1-based
326 for (std::size_t i = 0; i < L.nstations; ++i) {
327 if (d == 0 && L.stations[i].sched == SchedStrategy::INF) d = i + 1;
328 if (q == 0 && L.stations[i].sched == SchedStrategy::FCFS) q = i + 1;
329 }
330 const double N = L.classes[0].population;
331 if (d == 0 || q == 0 || detail::has_state_dependent_rates(L) ||
332 !std::isfinite(L.stations[q - 1].nservers) || L.cap[q - 1] < N ||
333 api::sn_patience_handles(L, q - 1, 0).present)
334 return "";
335 if (L.visits.empty()) return "";
336 const double Vd = num_traits<T>::to_double(L.visits[0](L.stateful_of_station(d) - 1, 0));
337 const double Vq = num_traits<T>::to_double(L.visits[0](L.stateful_of_station(q) - 1, 0));
338 if (Vd <= 0.0 || Vq <= 0.0 || std::fabs(Vd - Vq) > 1e-10 * Vd) return "";
339 const bool dexp = L.procid(d, 1) == ProcessType::EXP;
340 const bool qexp = L.procid(q, 1) == ProcessType::EXP;
341 const bool ddet = L.procid(d, 1) == ProcessType::DET;
342 const bool qdet = L.procid(q, 1) == ProcessType::DET;
343 const bool single = L.stations[q - 1].nservers == 1.0 || N == 1.0;
344 const bool renewal = static_cast<bool>(api::sn_renewal_lst(L, q));
345 if (method == "default" || method == "exact") {
346 if (dexp && single && !qexp && renewal) return "mg1kk";
347 if (ddet && qdet) return "ddckk";
348 } else if (method == "mg1kk") {
349 if (dexp && single && renewal) return "mg1kk";
350 } else if (method == "ddckk") {
351 if (ddet && qdet) return "ddckk";
352 } else if (method == "mmckk") {
353 if (dexp && qexp) return "mmckk";
354 }
355 return "";
356}
357
358/**
359 * Port of `SolverMVA.qsysPrioVariant(sn)`: the exact priority closed form
360 * `solver_mva_qsys_prio_analyzer` answers on a multiclass open Source -> Queue
361 * -> Sink model with Poisson sources, or "" when there is none:
362 * "mg1.prio" - HOL, one server (Cobham; qsys_mg1_prio)
363 * "mg1.prio.pr" - FCFSPRPRIO, one server (qsys_mg1_prio_pr)
364 * "mmc.prio" - HOL, c > 1 servers, exponential service with a common rate
365 * for every class (qsys_mmc_prio)
366 */
367template <class T>
369 using qn::SchedStrategy;
370 if (!(L.nclasses > 1 && detail::is_open_sqs(L))) return "";
371 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
372 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
373 for (std::size_t r = 0; r < L.nclasses; ++r) {
374 const double v = num_traits<T>::to_double(L.scv(src - 1, r));
375 if (std::isfinite(v) && !(std::fabs(v - 1.0) < 1e-6)) return "";
376 }
377 if (detail::has_state_dependent_rates(L) || std::isfinite(L.cap[q - 1])) return "";
378 const double k = L.stations[q - 1].nservers;
379 const SchedStrategy sc = L.stations[q - 1].sched;
380 if (sc == SchedStrategy::HOL) {
381 if (k == 1.0) return "mg1.prio";
382 if (std::isfinite(k)) {
383 bool ok = true, first = true;
384 double mu1 = 0.0;
385 for (std::size_t r = 0; r < L.nclasses && ok; ++r) {
386 if (!(num_traits<T>::to_double(L.rates(src - 1, r)) > 0.0)) continue;
387 const double mu = num_traits<T>::to_double(L.rates(q - 1, r));
388 if (L.procid(q, r + 1) != lang::ProcessType::EXP) ok = false;
389 if (first) {
390 mu1 = mu;
391 first = false;
392 } else if (!(std::fabs(mu - mu1) <= 1e-12 * mu1)) {
393 ok = false;
394 }
395 }
396 if (ok) return "mmc.prio";
397 }
398 } else if (sc == SchedStrategy::FCFSPRPRIO) {
399 if (k == 1.0) return "mg1.prio.pr";
400 }
401 return "";
402}
403
404/**
405 * Port of `SolverMVA.isMxg1System`: the single-class Source -> Queue -> Sink
406 * shape whose source is a batch Poisson stream (a BMAP of order one) and whose
407 * queue is one FCFS server with a non-exponential service law, the M^X/G/1
408 * queue that `solver_mva_qsys_analyzer` answers with `qsys_mxg1` (Haverkort
409 * 1998, eq. 5.31).
410 */
411template <class T>
413 if (!(detail::is_open_sqs(L) && L.nclasses == 1)) return false;
414 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
415 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
416 if (src == 0 || q == 0) return false;
417 const lang::Distrib<T>& arv = L.service[src - 1][0];
418 if (arv.type != lang::ProcessType::BMAP || arv.D0.rows() != 1 || arv.Dmark.empty()) return false;
419 if (L.service[q - 1][0].type == lang::ProcessType::EXP) return false;
420 return detail::qsys_plain_server_reason(L, q).empty();
421}
422
423/**
424 * Port of `SolverMVA.supportsBreakdown`: a station with Queue.setBreakdown is
425 * served by one arm, the M/G/1 FCFS closed form `qsys_mg1_breakdown` (Gaver
426 * 1962; Avi-Itzhak and Naor 1963; Welch 1964), under 'default' or 'exact', on
427 * the single-class Source -> Queue -> Sink shape with a Poisson source, one
428 * FCFS server of infinite capacity, exponential failures that also strike an
429 * idle server, exponential repairs and no service while down. `mva_feature_set`
430 * grants Breakdown to those two names; this predicate keeps the shape half and
431 * the runner and the analyzer both call it. Empty when the model is served.
432 */
433template <class T>
434std::string mva_breakdown_reason(const qn::NetworkStruct<T>& L, const std::string& method) {
435 if (!L.has_breakdown()) return "";
436 const std::string base = qn::mva_base_method(method);
437 if (base != "default" && base != "exact")
438 return "a station with breakdowns is solved by the M/G/1 breakdown closed form under method "
439 "'default' or 'exact' only, not '" + method + "'; use SolverCTMC for any other model";
440 if (!(detail::is_open_sqs(L) && L.nclasses == 1))
441 return "SolverMVA solves breakdowns only on a single-class open Source -> Queue -> Sink model "
442 "(the M/G/1 breakdown closed form); use SolverCTMC";
443 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
444 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
445 std::string need;
446 if (L.service[src - 1][0].type != lang::ProcessType::EXP) need = "a Poisson source";
447 else need = detail::qsys_plain_server_reason(L, q);
448 if (need.empty() && L.breakdownparam.find(q) != L.breakdownparam.end()) {
449 const qn::BreakdownParam<T>& bp = L.breakdownparam.at(q);
450 for (const T& v : bp.down_service_rates)
451 if (v != num_traits<T>::from_int(0)) need = "no service while the server is down";
452 if (need.empty() && !(detail::is_order_one_proc(bp.failure) && detail::is_order_one_proc(bp.repair)))
453 need = "exponential failure and repair times";
454 }
455 if (need.empty()) return "";
456 return "the M/G/1 breakdown closed form needs " + need + " at the breakdown station; use SolverCTMC";
457}
458
459/**
460 * Port of `solver_mva_qsys_analyzer.m`: the closed forms for a single-class
461 * open Source-Queue-Sink model.
462 *
463 * `exact` resolves to M/M/1, M/M/k, M/G/1 or G/M/1 and REFUSES anything else,
464 * since no closed form covers it; `default` additionally falls back to the
465 * G/G/k approximation and to the KLB G/G/1 approximation.
466 */
467template <class T>
469 // The open-queue closed forms evaluate transcendentals (square roots, LSTs,
470 // Brent roots), so under exact/Rational arithmetic the whole body is
471 // discarded and the model is refused by name -- the field-arithmetic ladder
472 // branches stay exact. Guarding the body (not just a static_assert) is what
473 // lets mva_dispatch<Rational> compile at all.
474 if constexpr (!num_traits<T>::has_transcendental) {
475 throw UnsupportedError(ErrorKind{"Arithmetic"},
476 "solver_mva_qsys_analyzer: the open queueing-system closed forms need transcendental "
477 "arithmetic; rerun this model with --arith double or --arith real");
478 } else {
479 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
480 const std::size_t M = L.nstations;
481 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
482 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
483 if (src == 0 || q == 0) throw InputError("solver_mva_qsys_analyzer: no Source-Queue pair");
484
485 // The visit ratio of the queue, which for a feedback model exceeds one and
486 // separates the per-visit quantities from the per-job ones.
487 const std::size_t qstateful = L.stateful_of_station(q);
488 const T Vq = L.visits[0](qstateful - 1, 0);
489 const T srcRate = L.rates(src - 1, 0);
490 const T lambda = T(srcRate * Vq);
491 const T mu = L.rates(q - 1, 0);
492 const double k = L.stations[q - 1].nservers;
493 const unsigned ku = std::isfinite(k) ? static_cast<unsigned>(std::llround(k)) : 1u;
494 const T ca = num_traits<T>::from_double(std::sqrt(num_traits<T>::to_double(L.scv(src - 1, 0))));
495 T cs = num_traits<T>::from_double(std::sqrt(num_traits<T>::to_double(L.scv(q - 1, 0))));
496 const bool ca1 = std::fabs(num_traits<T>::to_double(ca) - 1.0) < 1e-12;
497 // The closed forms below are FCFS results. Under Poisson arrivals PS (and
498 // single-class DPS/GPS, which reduce to it) with any number of servers, and
499 // LCFS-PR with one server, are insensitive: the mean sojourn time depends on
500 // the service law only through its mean, so the M/M/1 or M/M/k value is exact.
501 const qn::SchedStrategy qsched = L.stations[q - 1].sched;
502 if (ca1 && (qsched == qn::SchedStrategy::PS || qsched == qn::SchedStrategy::DPS ||
503 qsched == qn::SchedStrategy::GPS || (qsched == qn::SchedStrategy::LCFSPR && k == 1)))
504 cs = T(1);
505 const bool cs1 = std::fabs(num_traits<T>::to_double(cs) - 1.0) < 1e-12;
506
507 // The common output layout of the closed-form arms below: per-visit R and Q
508 // at the queue, per-job cycle time and system throughput.
509 auto closed_form_out = [&](const T& Rv, const T& lam, const T& Uq, const T& Xsys,
510 const char* label) {
512 MvaSolution<T>& so = o.sol;
513 so.Q = Matrix<T>(M, 1, zero);
514 so.U = Matrix<T>(M, 1, zero);
515 so.R = Matrix<T>(M, 1, zero);
516 so.Tp = Matrix<T>(M, 1, zero);
517 so.X.assign(1, zero);
518 so.C.assign(1, zero);
519 so.method = opt.method;
520 so.iter = 1;
521 so.R(q - 1, 0) = Rv;
522 so.C[0] = T(Rv * Vq);
523 so.X[0] = Xsys;
524 so.U(q - 1, 0) = Uq;
525 so.Tp(src - 1, 0) = Xsys;
526 so.Tp(q - 1, 0) = lam;
527 so.Q(q - 1, 0) = T(lam * Rv);
528 o.actualmethod = label;
529 return o;
530 };
531 const std::string method0 = amva_method_alias(opt.method);
532
533 // Server breakdowns (Queue.setBreakdown): exponential failures that also
534 // strike an idle server, exponential repairs, preemptive resume and no
535 // service while down. mva_breakdown_reason admits the shape (Poisson source,
536 // one FCFS server, 'default' or 'exact'), so this is the M/G/1 breakdown
537 // closed form of qsys_mg1_breakdown, exact for any service law.
538 if (L.has_breakdown()) {
539 const std::string why = mva_breakdown_reason(L, opt.method);
540 if (!why.empty()) throw UnsupportedError(ErrorKind{"Structure"}, "solver_mva_qsys_analyzer: " + why);
541 const qn::BreakdownParam<T>& bp = L.breakdownparam.at(q);
542 const T alpha = bp.failure_rate; // failure rate of an up server
543 const T beta = bp.repair_rate; // repair rate
544 const T two = num_traits<T>::from_int(2);
545 const T W = qsys::qsys_mg1_breakdown(lambda, mu, cs, alpha, T(one / beta), T(two / (beta * beta)),
546 T(beta / (lambda + beta)))
547 .W;
548 // work utilization, as SolverCTMC reports it
549 return closed_form_out(W, lambda, T(lambda / mu), srcRate, "mg1.breakdown");
550 }
551
552 // BMAP source and one exponential server: the M^X/M/1 batch queue of
553 // qsys_mxm1, as solver_mva_qsys_analyzer.m's BMAP branch. The batch-size
554 // rates are weighted by the stationary vector of the BMAP's underlying CTMC
555 // (BMAP.getBatchRates), so a BMAP of any order is reduced to its batch law.
556 if (L.service[src - 1][0].type == lang::ProcessType::BMAP &&
557 L.service[q - 1][0].type == lang::ProcessType::EXP && ku == 1 && !L.service[src - 1][0].Dmark.empty()) {
558 const lang::Distrib<T>& arv = L.service[src - 1][0];
559 const std::size_t n = arv.D0.rows();
560 Matrix<T> gen = arv.D0;
561 for (const Matrix<T>& Dk : arv.Dmark)
562 for (std::size_t i = 0; i < n; ++i)
563 for (std::size_t j = 0; j < n; ++j) gen(i, j) += Dk(i, j);
564 const std::vector<T> pie = mc::ctmc_solve(gen);
565 T lambdaBatch = zero, m1 = zero, m2 = zero;
566 for (std::size_t b = 0; b < arv.Dmark.size(); ++b) {
567 T rb = zero;
568 for (std::size_t i = 0; i < n; ++i)
569 for (std::size_t j = 0; j < n; ++j) rb += T(pie[i] * arv.Dmark[b](i, j));
570 const T bs = num_traits<T>::from_int(static_cast<int>(b + 1));
571 lambdaBatch += rb;
572 m1 += T(bs * rb);
573 m2 += T(bs * bs * rb);
574 }
575 T EX = one, EX2 = one;
576 if (num_traits<T>::to_double(lambdaBatch) > 0.0) {
577 EX = T(m1 / lambdaBatch);
578 EX2 = T(m2 / lambdaBatch);
579 }
580 const qsys::MxM1Result<T> r = qsys::qsys_mxm1(lambdaBatch, mu, EX, EX2);
581 const T lamJobs = T(lambdaBatch * EX); // job arrival rate
582 return closed_form_out(T(r.W * Vq), lamJobs, r.U, lamJobs, "mxm1");
583 }
584
585 // Batch Poisson source (order-1 BMAP) and one FCFS server with a general
586 // service law: the M^X/G/1 queue (Haverkort 1998, eq. 5.31). The source scv
587 // describes the BATCH epochs, not the job stream, so the G/G/1 ladder below
588 // would answer a Poisson stream of single jobs at the batch rate.
589 if (lang::process_is_batch(L.service[src - 1][0].type) && L.service[q - 1][0].type != lang::ProcessType::EXP) {
590 if ((method0 == "default" || method0 == "exact") && mva_is_mxg1_system(L)) {
591 const lang::Distrib<T>& arv = L.service[src - 1][0];
592 T lambdaBatch = zero, m1 = zero, m2 = zero;
593 for (std::size_t b = 0; b < arv.Dmark.size(); ++b) {
594 const T rb = arv.Dmark[b](0, 0);
595 const T bs = num_traits<T>::from_int(static_cast<int>(b + 1));
596 lambdaBatch += rb;
597 m1 += T(bs * rb);
598 m2 += T(bs * bs * rb);
599 }
600 const T EX = T(m1 / lambdaBatch), EX2 = T(m2 / lambdaBatch);
601 const qsys::MeanValueResult<T> r = qsys::qsys_mxg1(lambdaBatch, mu, cs, EX, EX2);
602 const T lamJobs = T(lambdaBatch * EX); // job arrival rate
603 return closed_form_out(r.W, lamJobs, r.U, lamJobs, "mxg1"); // no feedback: Vq = 1
604 }
605 if (method0 == "exact")
606 throw UnsupportedError(ErrorKind{"Structure"},
607 "solver_mva_qsys_analyzer: MVA exact method unavailable for this model: the M^X/G/1 closed "
608 "form needs a batch Poisson source (an order-1 BMAP) feeding one FCFS server; use SolverCTMC");
609 }
610
611 // Finite-capacity loss branch (M/M/1/K with tail drop), the ONE finite
612 // buffer this solver honours: the moment-based MacGregor Smith loss
613 // probability, exact only at scv=1, with the queue length taken from the
614 // truncated M/M/1/K distribution. Being an approximation in general it is
615 // not offered under method='exact'; the capacity gate in the runner exempts
616 // exactly this shape for every other method, so the two must agree.
617 if (sn_is_mm1k_loss(L)) {
618 if (opt.method == "exact")
619 throw UnsupportedError(ErrorKind{"Method"},
620 "solver_mva_qsys_analyzer: M/M/1/K tail-drop is solved by the approximate "
621 "'mg1k.mgs' method (MacGregor Smith); it is not available under method='exact'. "
622 "Use the default method, or SolverCTMC/SolverNC for an exact result");
623 const double Kcap = L.cap[q - 1];
624 const T rho = T(lambda / mu);
625 const T Ploss =
626 qsys::qsys_mg1k_loss_mgs(lambda, mu, T(cs * cs), static_cast<unsigned>(std::llround(Kcap)))
627 .lossProbability;
628 const T Tq = T(lambda * (one - Ploss)); // carried throughput
629 const double rhod = num_traits<T>::to_double(rho);
630 T Lsys = zero;
631 if (std::fabs(rhod - 1.0) < 1e-10) {
632 Lsys = num_traits<T>::from_double(Kcap / 2.0); // L'Hopital limit at rho = 1
633 } else {
634 const T Kp1 = num_traits<T>::from_double(Kcap + 1.0);
635 const T rKp1 = qsys::detail::num_pow(rho, Kp1);
636 Lsys = T(rho / (one - rho) - Kp1 * rKp1 / (one - rKp1));
637 }
639 MvaSolution<T>& ls = lout.sol;
640 ls.Q = Matrix<T>(M, 1, zero);
641 ls.U = Matrix<T>(M, 1, zero);
642 ls.R = Matrix<T>(M, 1, zero);
643 ls.Tp = Matrix<T>(M, 1, zero);
644 ls.X.assign(1, zero);
645 ls.C.assign(1, zero);
646 ls.method = opt.method;
647 ls.iter = 1;
648 ls.R(q - 1, 0) = T(Lsys / Tq); // per-visit response time, by Little
649 ls.Q(q - 1, 0) = Lsys;
650 ls.U(q - 1, 0) = T(Tq / mu); // single-server utilization
651 ls.Tp(q - 1, 0) = Tq; // carried (effective) rate
652 ls.Tp(src - 1, 0) = lambda; // offered arrival rate
653 ls.X[0] = Tq; // system throughput = carried rate
654 ls.C[0] = T(ls.R(q - 1, 0) * Vq);
655 lout.actualmethod = "mg1k.mgs";
656 return lout;
657 }
658
659 // Empty unless the queue reneges.
660 const api::PatienceHandles<T> hpat = api::sn_patience_handles(L, q - 1, 0);
661 {
662 const std::string patWhy = api::sn_patience_refusal(L, q - 1, 0);
663 if (!patWhy.empty()) throw UnsupportedError(ErrorKind{"Structure"}, "solver_mva_qsys_analyzer: " + patWhy);
664 }
665
666 std::string method = amva_method_alias(opt.method);
667 if (method == "exact") {
668 if (ca1 && cs1 && ku == 1) method = "mm1";
669 else if (ca1 && cs1 && ku > 1) method = "mmk";
670 else if (ca1 && ku == 1) method = "mg1";
671 else if (cs1 && ku == 1) method = "gm1";
672 else if (cs1 && ku > 1 && api::sn_renewal_lst(L, src)) method = "gimc";
673 else
674 throw UnsupportedError(ErrorKind{"NonExponential"},
675 "solver_mva_qsys_analyzer: no exact closed form for this queueing system "
676 "(neither arrivals nor service are exponential, or it has several servers)");
677 } else if (method == "default") {
678 // A station customers walk away from is a different model, not a
679 // correction to one: nothing in the G/G/k family below carries an
680 // abandonment rate, so the choice is made here and not by ca/cs.
681 if (hpat.present) method = hpat.isExponential ? "erlanga" : "mgisrgi";
682 else if (ca1 && cs1 && ku == 1) method = "mm1";
683 else if (ca1 && cs1 && ku > 1) method = "mmk";
684 else if (ca1 && ku == 1) method = "mg1";
685 else if (cs1 && ku == 1) method = "gm1";
686 else if (cs1 && ku > 1 && api::sn_renewal_lst(L, src)) method = "gimc";
687 else if (ku > 1) method = "gigk";
688 else method = "gig1.klb";
689 }
690
691 // Whitt family, full metric set. These methods answer a station whose
692 // CARRIED throughput is below the offered rate -- customers abandon, or are
693 // blocked -- so Little's law on lambda would silently overstate the queue
694 // and the common tail below cannot be used.
695 if (method == "erlanga" || method == "mgisrgi" || method == "gigk.diffusion") {
696 const double cap = L.cap[q - 1];
697 // waiting spaces, servers excluded
698 const double room = std::isfinite(cap)
699 ? std::max(0.0, cap - static_cast<double>(ku))
700 : std::numeric_limits<double>::infinity();
701 T Lsys = zero, Tq = zero, Uq = zero;
702 if (method == "gigk.diffusion") {
703 const qsys::QsysGgnmResult<T> d = qsys::qsys_ggnm_diffusion(lambda, mu, ku, room, ca, cs);
704 Lsys = d.meanNumber;
705 Tq = d.throughput;
706 Uq = d.utilization;
707 } else {
708 if (!hpat.present)
709 throw UnsupportedError(ErrorKind{"Reneging"}, "solver_mva_qsys_analyzer: method '" + method +
710 "' needs a reneging patience law on the queue");
711 if (method == "erlanga") {
712 // Erlang A is defined for an exponential patience only, never its mean rate
713 const std::string why = mva_erlanga_patience_reason(L);
714 if (!why.empty()) throw UnsupportedError(ErrorKind{"Structure"}, "solver_mva_qsys_analyzer: " + why);
715 }
717 hpat.isExponential
718 // Exponential patience makes the state-dependent
719 // approximation exact, so take the exact chain either way.
720 ? qsys::qsys_erlanga(lambda, mu, hpat.rate, ku, room)
721 : qsys::qsys_mgisrgi_whitt(lambda, mu, ku, room, hpat.as_patience());
722 Lsys = ab.meanNumber;
723 Tq = ab.throughput;
724 Uq = ab.utilization;
725 }
727 MvaSolution<T>& as = aout.sol;
728 as.Q = Matrix<T>(M, 1, zero);
729 as.U = Matrix<T>(M, 1, zero);
730 as.R = Matrix<T>(M, 1, zero);
731 as.Tp = Matrix<T>(M, 1, zero);
732 as.X.assign(1, zero);
733 as.C.assign(1, zero);
734 as.method = opt.method;
735 as.iter = 1;
736 // Little's law on the CARRIED rate, as the loss branch above and
737 // SolverCTMC report it.
738 as.R(q - 1, 0) = Tq > zero ? T(Lsys / Tq) : zero;
739 as.Q(q - 1, 0) = Lsys;
740 as.U(q - 1, 0) = Uq;
741 as.Tp(q - 1, 0) = Tq; // carried rate
742 as.Tp(src - 1, 0) = srcRate; // offered arrival rate
743 as.X[0] = Tq;
744 as.C[0] = T(as.R(q - 1, 0) * Vq);
745 aout.actualmethod = method;
746 return aout;
747 }
748
749 T R = zero;
750 if (method == "mm1") R = qsys::qsys_mm1(lambda, mu).W;
751 else if (method == "mmk") R = qsys::qsys_mmk(lambda, mu, ku).W;
752 else if (method == "mg1" || method == "mgi1") R = qsys::qsys_mg1(lambda, mu, cs).W;
753 else if (method == "gigk") R = qsys::qsys_gigk_approx(lambda, mu, ca, cs, ku).W;
754 else if (method == "gigk.kingman_approx")
755 R = qsys::qsys_gigk_approx_kingman(lambda, mu, ca, cs, ku).W;
756 else if (method == "gig1.kingman") R = qsys::qsys_gig1_ubnd_kingman(lambda, mu, ca, cs).W;
757 else if (method == "gig1.heyman") R = qsys::qsys_gig1_approx_heyman(lambda, mu, ca, cs).W;
758 else if (method == "gig1" || method == "gig1.allen")
759 R = qsys::qsys_gig1_approx_allencunneen(lambda, mu, ca, cs).W;
760 else if (method == "gig1.kobayashi") R = qsys::qsys_gig1_approx_kobayashi(lambda, mu, ca, cs).W;
761 else if (method == "gig1.klb") R = qsys::qsys_gig1_approx_klb(lambda, mu, ca, cs).W;
762 else if (method == "gig1.marchal") R = qsys::qsys_gig1_approx_marchal(lambda, mu, ca, cs).W;
763 else if (method == "gig1.gelenbe") R = qsys::qsys_gig1_approx_gelenbe(lambda, mu, ca, cs).W;
764 else if (method == "gig1.kimura") R = qsys::qsys_gig1_approx_kimura(lambda, mu, ca, cs).W;
765 else if (method == "gigk.whitt") R = qsys::qsys_gigk_approx_whitt(lambda, mu, ca, cs, ku).W;
766 // RQNA and RQT reach the SINGLE-QUEUE robust formulas, not the network
767 // analyzers of solver_rqna.h / solver_rqt.h: this shape is one node, and
768 // the reference answers it here (solver_mva_qsys_analyzer.m cases rqna
769 // and rqt). Without these two arms the qsys interception below claimed the
770 // model and then refused the method, so `rqna` and `rqt` were advertised
771 // on every Source-Queue-Sink model and ran on none of them.
772 else if (method == "rqna") {
773 // The arrival flow enters through its index of dispersion for counts.
774 const mam::Map<T> arvMAP = lang::dist_to_map(L.service[src - 1][0]);
775 const T rho1 = lambda / mu;
776 auto IaFun = [&](const T& x) { return mam::map_count_idc(arvMAP, x); };
777 R = T(qsys::qsys_gig1_rq(rho1, mu, T(cs * cs), IaFun).W + one / mu);
778 } else if (method == "rqt") {
779 // Polyhedral uncertainty sets for the arrival and service flows.
780 const T rho1 = lambda / (num_traits<T>::from_int(static_cast<int>(ku)) * mu);
781 const T Gamma_a = ca / lambda;
782 const T two = num_traits<T>::from_int(2);
783 const T Gamma_s =
784 qsys::qsys_gigk_rqt_gamma(rho1, mu, Gamma_a, T(cs / mu), ku, two);
785 R = qsys::qsys_gigk_rqt(lambda, mu, Gamma_a, Gamma_s, ku, two, two).W;
786 }
787 else if (method == "qed") R = T(qsys::qsys_mmk_qed(lambda, mu, ku).meanWait + one / mu);
788 // The upper end, gig1.kingman already reporting a bound.
789 else if (method == "gig1.extremal")
790 R = T(qsys::qsys_gig1_bnds_extremal(lambda, mu, ca, cs).upperBound + one / mu);
791 else if (method == "gm1" || method == "gim1") {
792 // The PH path is exact only when sn.proc holds the arrival law ITSELF.
793 // For a non-Markovian arrival the refresh substitutes an Erlang-n SCV
794 // fit, so the PH sigma-root would answer a different model; those cases
795 // take the transform's sigma-root instead, as the reference does.
796 const lang::Distrib<T>& arv = L.service[src - 1][0];
797 const bool markovian = arv.has_map();
798 bool done = false;
799 if (markovian) {
800 const mam::Map<T> m = lang::dist_to_map(arv);
801 const std::vector<T> pie = mam::map_pie(m);
802 R = qsys::qsys_phm1(pie, m.D0, mu, num_traits<T>::from_double(1e-16)).meanSojournTime;
803 done = true;
804 }
805 if (!done) {
806 // sigma solves A*(mu - mu sigma) = sigma on (0,1)
807 //
808 // THE UPPER BRACKET CANNOT SIT AT 1. sigma = 1 is ALWAYS a root of
809 // this equation, and near it the transform is evaluated at s = mu(1-x)
810 // -> 0, where A*(s) is a difference of two exponentials that both
811 // tend to 1: at x = 1-1e-12 the cancellation leaves A* correct only to
812 // about 1e-4, so f came out POSITIVE at both ends and Brent refused
813 // the bracket outright ("the bracket endpoints do not straddle a
814 // root"), which killed SolverMVA on every G/M/1 with a non-Markovian
815 // arrival -- gallery_um1 (Uniform(1,2) -> Exp(2)) among them. f(0) is
816 // A*(mu) > 0 always, so only the upper end has to be found: walk it
817 // toward 1 until the sign turns, exactly as far as the sought root
818 // requires and no further. The reference sidesteps the same trap by
819 // seeding an UNBRACKETED fzero at 0.5 (solver_mva_qsys_analyzer.m).
820 auto f = [&](const T& x) { return T(lang::dist_lst(arv, T(mu - mu * x)) - x); };
821 double hi = 0.5;
822 bool straddles = false;
823 for (int i = 0; i < 8; ++i) {
825 straddles = true;
826 break;
827 }
828 hi = 1.0 - (1.0 - hi) / 10.0;
829 }
830 const RootResult<T> rr =
831 straddles ? root_brent(f, num_traits<T>::from_double(1e-12),
834 : RootResult<T>();
835 if (straddles && rr.converged) {
836 R = qsys::qsys_gm1(rr.root, mu);
837 } else {
838 R = qsys::qsys_gg1(lambda, mu, T(ca * ca), one).W;
839 }
840 }
841 } else if (method == "gimc") {
842 // GI/M/c with renewal arrivals: the transform of the interarrival law
843 // (a rank-one PH/MAP source, or a law with an LST), solved in double.
844 const api::RenewalLst LA = api::sn_renewal_lst(L, src);
845 // SolverMVA.supportsQueueingSystem's 'gimc' premise, which has no gate
846 // of its own in this port: exponential servers fed by a renewal stream
847 if (!cs1 && opt.method == "gimc")
848 throw UnsupportedError(ErrorKind{"Structure"},
849 "SolverMVA: the 'gimc' closed form needs exponential servers and renewal arrivals "
850 "(a PH source with rank-one D1, or a source with an LST); use 'gigk'");
851 if (!LA)
852 throw UnsupportedError(ErrorKind{"Method"},
853 "solver_mva_qsys_analyzer: the GI/M/c closed form needs renewal arrivals (a PH source, "
854 "or a source with an LST) and the arrival process is correlated");
855 const qsys::QsysRes resgimc =
857 R = num_traits<T>::from_double(resgimc.scalar("meanSojournTime"));
858 } else {
859 throw UnsupportedError(ErrorKind{"Topology"}, "solver_mva_qsys_analyzer: method '" + method +
860 "' is not available for a model with one station and one class");
861 }
862
864 MvaSolution<T>& s = out.sol;
865 s.Q = Matrix<T>(M, 1, zero);
866 s.U = Matrix<T>(M, 1, zero);
867 s.R = Matrix<T>(M, 1, zero);
868 s.Tp = Matrix<T>(M, 1, zero);
869 s.X.assign(1, zero);
870 s.C.assign(1, zero);
871 s.method = opt.method;
872 s.iter = 1;
873 // Per-visit response time and queue length at the queue; per-job cycle time
874 // and system throughput. For a feedback model (Vq > 1) the two differ.
875 s.R(q - 1, 0) = R;
876 s.C[0] = T(R * Vq);
877 s.X[0] = srcRate;
878 s.U(q - 1, 0) = T(lambda / mu / num_traits<T>::from_double(std::isfinite(k) ? k : 1.0));
879 s.Tp(src - 1, 0) = srcRate;
880 s.Tp(q - 1, 0) = lambda;
881 s.Q(q - 1, 0) = T(lambda * R);
882 out.actualmethod = method;
883 return out;
884 } // if constexpr has_transcendental
885}
886
887/**
888 * Port of `solver_mva_qsys_prio_analyzer.m`: the exact priority closed form for
889 * a single open queue with Poisson per-class arrivals, in the variant
890 * `mva_qsys_prio_variant` names: the Cobham formula for HOL M/G/1
891 * (qsys_mg1_prio), the preemptive-resume M/G/1 formula (qsys_mg1_prio_pr) and
892 * HOL M/M/c with a common service rate (qsys_mmc_prio).
893 *
894 * The classes are handed to `qsys_mg1_prio` in PRIORITY order (lowest value
895 * first), which is the order the formula's nested sums assume.
896 */
897template <class T>
899 const MvaOptions& opt) {
900 const std::string variant = mva_qsys_prio_variant(L);
901 if (variant.empty())
902 throw UnsupportedError(ErrorKind{"Structure"},
903 "solver_mva_qsys_prio_analyzer: no exact priority closed form for this model");
904 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
905 const std::size_t M = L.nstations, K = L.nclasses;
906 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
907 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
908 const double nsrv = L.stations[q - 1].nservers;
909
910 std::vector<std::size_t> order(K);
911 for (std::size_t r = 0; r < K; ++r) order[r] = r;
912 std::stable_sort(order.begin(), order.end(), [&](std::size_t a, std::size_t b) {
913 return L.classes[a].prio < L.classes[b].prio;
914 });
915
916 std::vector<T> lam(K, zero), mu(K, zero), cs(K, one);
917 for (std::size_t j = 0; j < K; ++j) {
918 const std::size_t r = order[j];
919 lam[j] = L.rates(src - 1, r);
920 mu[j] = L.rates(q - 1, r);
921 const double v = num_traits<T>::to_double(L.scv(q - 1, r));
922 cs[j] = (std::isfinite(v) && v > 0.0) ? num_traits<T>::from_double(std::sqrt(v)) : one;
923 }
924 // the active classes only, as `W(act) = ...` in the reference
925 std::vector<T> la, ma, ca;
926 for (std::size_t j = 0; j < K; ++j)
927 if (lam[j] > zero && std::isfinite(num_traits<T>::to_double(mu[j]))) {
928 la.push_back(lam[j]);
929 ma.push_back(mu[j]);
930 ca.push_back(cs[j]);
931 }
932 std::vector<T> Wa;
933 if (variant == "mg1.prio") Wa = qsys::qsys_mg1_prio(la, ma, ca).W;
934 else if (variant == "mg1.prio.pr") Wa = qsys::qsys_mg1_prio_pr(la, ma, ca).W;
935 else if (!ma.empty()) Wa = qsys::qsys_mmc_prio(la, ma[0], static_cast<unsigned>(nsrv)).W;
936 std::vector<T> W(K, zero);
937 for (std::size_t j = 0, a = 0; j < K; ++j)
938 if (lam[j] > zero && std::isfinite(num_traits<T>::to_double(mu[j]))) W[j] = Wa[a++];
939
941 MvaSolution<T>& s = out.sol;
942 s.Q = Matrix<T>(M, K, zero);
943 s.U = Matrix<T>(M, K, zero);
944 s.R = Matrix<T>(M, K, zero);
945 s.Tp = Matrix<T>(M, K, zero);
946 s.C.assign(K, zero);
947 s.X.assign(K, zero);
948 s.method = opt.method;
949 s.iter = 0;
950 for (std::size_t j = 0; j < K; ++j) {
951 const std::size_t r = order[j];
952 if (!(lam[j] > zero) || !std::isfinite(num_traits<T>::to_double(mu[j]))) continue;
953 s.R(q - 1, r) = W[j];
954 s.C[r] = W[j];
955 s.X[r] = lam[j];
956 s.U(q - 1, r) = T(lam[j] / mu[j] / num_traits<T>::from_double(nsrv));
957 s.Tp(q - 1, r) = lam[j];
958 s.Tp(src - 1, r) = lam[j];
959 s.Q(q - 1, r) = T(lam[j] * W[j]);
960 }
961 out.actualmethod = variant;
962 return out;
963}
964
965/**
966 * Port of `solver_mva_finite_source_analyzer.m`: the finite-source (machine
967 * repair) closed forms for the closed single-class model of N jobs cycling
968 * between a Delay (the operating time of the sources) and one FCFS Queue, in
969 * the variant `mva_finite_source_variant` names: "mg1kk" (exponential think
970 * time, one server with a renewal service law; Takacs 1962), "ddckk"
971 * (deterministic think and service times, c servers) and "mmckk" (exponential
972 * think and service times, c servers).
973 *
974 * qsys_ddckk is pure field arithmetic and keeps the exact type; qsys_mg1kk and
975 * qsys_mmckk are double-precision closed forms and are refused under exact
976 * arithmetic, as the other transcendental analyzers are.
977 */
978template <class T>
980 using qn::SchedStrategy;
981 const std::string variant = mva_finite_source_variant(L, amva_method_alias(opt.method));
982 if (variant.empty())
983 throw UnsupportedError(ErrorKind{"Structure"},
984 "solver_mva_finite_source_analyzer: no finite-source closed form for this model");
985 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
986 const std::size_t M = L.nstations;
987 std::size_t d = 0, q = 0; // 1-based
988 for (std::size_t i = 0; i < M; ++i) {
989 if (d == 0 && L.stations[i].sched == SchedStrategy::INF) d = i + 1;
990 if (q == 0 && L.stations[i].sched != SchedStrategy::INF) q = i + 1;
991 }
992 const double N = L.classes[0].population;
993 const double nsrv = L.stations[q - 1].nservers;
994 const unsigned c = static_cast<unsigned>(std::min(nsrv, N));
995 const unsigned K = static_cast<unsigned>(N);
996 const T EO = T(one / L.rates(d - 1, 0));
997 const T ES = T(one / L.rates(q - 1, 0));
998
999 T Xs = zero, Qq = zero, Rq = zero;
1000 if (variant == "ddckk") {
1001 const qsys::QsysResT<T> res = qsys::qsys_ddckk(EO, ES, c, K);
1002 Xs = res.scalar("throughput");
1003 Qq = res.scalar("meanQueueLength");
1004 Rq = res.scalar("meanSojournTime");
1005 } else {
1006 if constexpr (!num_traits<T>::has_transcendental) {
1007 throw UnsupportedError(ErrorKind{"Arithmetic"},
1008 "solver_mva_finite_source_analyzer: the " + variant + " closed form needs "
1009 "transcendental arithmetic; rerun this model with --arith double or --arith real");
1010 } else {
1011 const double EOd = num_traits<T>::to_double(EO), ESd = num_traits<T>::to_double(ES);
1012 qsys::QsysRes res;
1013 if (variant == "mg1kk") res = qsys::qsys_mg1kk(1.0 / EOd, K, api::sn_renewal_lst(L, q), ESd);
1014 else res = qsys::qsys_mmckk(1.0 / EOd, 1.0 / ESd, c, K);
1015 Xs = num_traits<T>::from_double(res.scalar("throughput"));
1016 Qq = num_traits<T>::from_double(res.scalar("meanQueueLength"));
1017 Rq = num_traits<T>::from_double(res.scalar("meanSojournTime"));
1018 }
1019 }
1020
1022 MvaSolution<T>& s = out.sol;
1023 s.Q = Matrix<T>(M, 1, zero);
1024 s.U = Matrix<T>(M, 1, zero);
1025 s.R = Matrix<T>(M, 1, zero);
1026 s.Tp = Matrix<T>(M, 1, zero);
1027 s.X.assign(1, zero);
1028 s.C.assign(1, zero);
1029 s.method = opt.method;
1030 s.iter = 0;
1031 const T Nt = num_traits<T>::from_double(N);
1032 s.Q(q - 1, 0) = Qq;
1033 s.R(q - 1, 0) = Rq;
1034 s.Tp(q - 1, 0) = Xs;
1035 s.U(q - 1, 0) = T(Xs * ES / num_traits<T>::from_double(nsrv));
1036 s.Q(d - 1, 0) = T(Nt - Qq);
1037 s.R(d - 1, 0) = EO;
1038 s.Tp(d - 1, 0) = Xs;
1039 s.U(d - 1, 0) = s.Q(d - 1, 0);
1040 // one visit to each station per cycle, the reference station being the Delay
1041 s.C[0] = T(Rq + EO);
1042 s.X[0] = Xs;
1043 out.actualmethod = variant;
1044 return out;
1045}
1046
1047/**
1048 * The exact multiclass M/M/1-DPS solve the reference inlines in mvaDispatch:
1049 * the truncated multiclass chain of `qsys_mm1_dps`, which the AMVA cross-term
1050 * correction cannot reproduce (it violates the equal-rate conservation law).
1051 */
1052template <class T>
1054 // The truncated-chain M/M/1-DPS closed form (qsys_mm1_dps) needs
1055 // transcendental arithmetic; refuse by name under exact/Rational.
1056 if constexpr (!num_traits<T>::has_transcendental) {
1057 throw UnsupportedError(ErrorKind{"Arithmetic"},
1058 "solver_mva_dps_exact: the exact DPS closed form needs transcendental arithmetic; "
1059 "rerun this model with --arith double or --arith real");
1060 } else {
1061 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
1062 const std::size_t M = L.nstations, K = L.nclasses;
1063 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
1064 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
1065
1066 std::vector<T> lam(K, zero), mu(K, zero), w(K, one);
1067 for (std::size_t r = 0; r < K; ++r) {
1068 lam[r] = L.rates(src - 1, r);
1069 mu[r] = L.rates(q - 1, r);
1070 const std::vector<T>& sp = L.stations[q - 1].schedparam;
1071 if (sp.size() > r && sp[r] > zero) w[r] = sp[r];
1072 }
1073 const std::vector<T> Wd = qsys::qsys_mm1_dps(lam, mu, w).T_;
1074
1076 MvaSolution<T>& s = out.sol;
1077 s.Q = Matrix<T>(M, K, zero);
1078 s.U = Matrix<T>(M, K, zero);
1079 s.R = Matrix<T>(M, K, zero);
1080 s.Tp = Matrix<T>(M, K, zero);
1081 s.C.assign(K, zero);
1082 s.X.assign(K, zero);
1083 s.method = opt.method;
1084 s.iter = 0;
1085 for (std::size_t r = 0; r < K; ++r) {
1086 s.R(q - 1, r) = Wd[r];
1087 s.C[r] = Wd[r];
1088 s.X[r] = lam[r];
1089 if (mu[r] > zero) s.U(q - 1, r) = T(lam[r] / mu[r]);
1090 s.Tp(q - 1, r) = lam[r];
1091 s.Tp(src - 1, r) = lam[r];
1092 s.Q(q - 1, r) = T(lam[r] * Wd[r]);
1093 }
1094 out.actualmethod = "mm1.dps";
1095 return out;
1096 } // if constexpr has_transcendental
1097}
1098
1099/**
1100 * Port of `solver_mvald_analyzer.m`: the load-dependent branch.
1101 *
1102 * `exact` and `mva` take the exact load-dependent recursion; `default` takes it
1103 * too on a small closed or an all-open product-form model, mirroring the default-to-exact
1104 * upgrade the non-LD analyzer applies; everything else goes to the AMVA, whose
1105 * lld and cd terms are now in place.
1106 */
1107template <class T>
1109 const Matrix<T>& init_sol) {
1110 const std::string method = amva_method_alias(opt.method);
1111 // BOTH dependences disqualify the exact recursion, and both disqualify the
1112 // default-to-exact upgrade below. The test read cdscaling alone until
1113 // 2026-09-13, so `exact` on a jdscaling station ran solver_mvald, which
1114 // reads only the lld lattice and returned the UNSCALED queue rather than
1115 // refusing; the reference names both (solver_mvald_analyzer.m:19,26).
1116 const bool has_cd_or_jd = [&] {
1117 for (const auto& st : L.stations)
1118 if (st.cdscaling || st.jdscaling) return true;
1119 return false;
1120 }();
1121
1122 if (method == "exact" || method == "mva") {
1123 if (has_cd_or_jd)
1124 throw UnsupportedError(ErrorKind{"ClassDependence"},
1125 "solver_mvald_analyzer: there is no exact class-/joint-dependent solver in MVA");
1127 out.sol = solver_mvald(L, opt);
1128 out.actualmethod = "exact";
1129 return out;
1130 }
1131 if (!(method == "default" || method == "amva" || method == "qd" || method == "lin" ||
1132 method == "qdlin"))
1133 throw UnsupportedError(ErrorKind{"Method"}, "solver_mvald_analyzer: the '" + method +
1134 "' method is not supported by the load-dependent MVA solver");
1135
1136 if (method == "default" && !has_cd_or_jd) {
1137 double Nsum = 0.0;
1138 bool integral = true, finite = true, all_open = !L.classes.empty();
1139 for (const qn::JobClass& c : L.classes) {
1140 if (std::isfinite(c.population)) all_open = false;
1141 if (!std::isfinite(c.population)) finite = false;
1142 else {
1143 Nsum += c.population;
1144 if (c.population != std::floor(c.population)) integral = false;
1145 }
1146 }
1147 // An all-open product-form LD network is a set of independent birth-death queues, solved exactly for
1148 // free; AMVA evaluates alpha at the mean queue length (M/M/3 as alpha=[1,2,3] gave 4.0, exact 4.989).
1149 if (((finite && integral && L.nchains <= 4 && Nsum <= 20.0) || all_open) && L.has_product_form()) {
1151 out.sol = solver_mvald(L, opt);
1152 out.actualmethod = "exact";
1153 return out;
1154 }
1155 }
1156 bool converged = true;
1158 MvaOptions o = opt;
1160 out.sol = solver_amva(L, d, o, init_sol, converged);
1161 // solver_amva computes the outer residual and reports it here; dropping the
1162 // flag on the floor left every caller with only `iter`, which on this route
1163 // aggregates the nested sweeps and cannot decide convergence.
1164 out.sol.converged = converged;
1165 out.actualmethod = out.sol.method;
1166 return out;
1167}
1168
1169/**
1170 * Port of `solver_mva_qsys_sizebased_analyzer.m`: the M/G/1 formulas for the
1171 * size-based disciplines (Wierman and Harchol-Balter, SIGMETRICS 2003).
1172 *
1173 * The arrival rate of each class is the source rate times the queue's VISIT
1174 * ratio, and the response time comes back per visit, so both are multiplied
1175 * out the same way the reference does.
1176 *
1177 * PER-VISIT VERSUS PER-JOB. `W` comes back per visit, so the response time is
1178 * `W * visits` while the queue length stays `lambda * W` with lambda already
1179 * carrying the visit ratio. That makes `Q != T * R` at the station whenever the
1180 * visit ratio differs from one: the reference inflates R by the visits but not
1181 * Q, so Little's law fails on a feedback routing. It is a defect of the
1182 * reference, reproduced here rather than silently corrected -- this branch is
1183 * only ever dispatched on a plain Source-Queue-Sink, where the visit ratio is
1184 * one and the discrepancy cannot arise.
1185 */
1186template <class T>
1188 const MvaOptions& opt) {
1189 // The M/G/1 size-based closed forms (SRPT/PSJF/FB/LRPT/SETF) evaluate
1190 // transcendentals; refuse by name under exact/Rational.
1191 if constexpr (!num_traits<T>::has_transcendental) {
1192 throw UnsupportedError(ErrorKind{"Arithmetic"},
1193 "solver_mva_qsys_sizebased_analyzer: the M/G/1 size-based closed forms need "
1194 "transcendental arithmetic; rerun this model with --arith double or --arith real");
1195 } else {
1196 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
1197 const std::size_t M = L.nstations, K = L.nclasses;
1198 const std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
1199 const std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
1200 const std::size_t qstateful = L.stateful_of_station(q);
1201
1202 // sn.visits is indexed by CHAIN. The reference wrote `sn.visits{source_ist}`
1203 // -- the chain whose number happens to equal the Source's STATION index --
1204 // so every class outside chain 1 read a visit of 0 and the analyzer rejected
1205 // its own multiclass model. Fixed in MATLAB in the same change; take the
1206 // chain each class belongs to.
1207 std::vector<std::size_t> chain_of(K, 0);
1208 for (std::size_t c = 0; c < L.nchains; ++c)
1209 for (std::size_t r : L.inchain[c]) chain_of[r - 1] = c;
1210
1211 std::vector<T> lambda(K, zero), mu(K, zero), cs(K, one), vis(K, one);
1212 for (std::size_t r = 0; r < K; ++r) {
1213 vis[r] = L.visits[chain_of[r]](qstateful - 1, r);
1214 lambda[r] = T(L.rates(src - 1, r) * vis[r]);
1215 mu[r] = L.rates(q - 1, r);
1216 const double v = num_traits<T>::to_double(L.scv(q - 1, r));
1217 cs[r] = (std::isfinite(v) && v > 0.0) ? num_traits<T>::from_double(std::sqrt(v)) : one;
1218 if (!(lambda[r] > zero) || !(mu[r] > zero))
1219 throw InputError(
1220 "solver_mva_qsys_sizebased_analyzer: the arrival and service rates must be "
1221 "positive");
1222 }
1223
1224 const qn::SchedStrategy sched = L.stations[q - 1].sched;
1225 std::vector<T> W;
1226 std::string actual;
1227 switch (sched) {
1228 case qn::SchedStrategy::SRPT:
1229 W = qsys::qsys_mg1_srpt(lambda, mu, cs).W;
1230 actual = "mg1.srpt";
1231 break;
1232 case qn::SchedStrategy::PSJF:
1233 W = qsys::qsys_mg1_psjf(lambda, mu, cs).W;
1234 actual = "mg1.psjf";
1235 break;
1236 case qn::SchedStrategy::FB:
1237 W = qsys::qsys_mg1_fb(lambda, mu, cs).W;
1238 actual = "mg1.fb";
1239 break;
1240 case qn::SchedStrategy::LRPT:
1241 W = qsys::qsys_mg1_lrpt(lambda, mu, cs).W;
1242 actual = "mg1.lrpt";
1243 break;
1244 case qn::SchedStrategy::SETF:
1245 W = qsys::qsys_mg1_setf(lambda, mu, cs).W;
1246 actual = "mg1.setf";
1247 break;
1248 case qn::SchedStrategy::SJF: {
1249 // non-preemptive shortest job first (Phipps 1956), a double-precision
1250 // closed form: its fitted size law is evaluated by quadrature
1251 std::vector<double> ld(K), md(K), cd(K);
1252 for (std::size_t r = 0; r < K; ++r) {
1253 ld[r] = num_traits<T>::to_double(lambda[r]);
1254 md[r] = num_traits<T>::to_double(mu[r]);
1255 cd[r] = num_traits<T>::to_double(cs[r]);
1256 }
1257 const std::vector<double> Wd = qsys::qsys_mg1_sjf(ld, md, cd).W;
1258 W.assign(K, zero);
1259 for (std::size_t r = 0; r < K; ++r) W[r] = num_traits<T>::from_double(Wd[r]);
1260 actual = "mg1.sjf";
1261 break;
1262 }
1263 default:
1264 throw UnsupportedError(ErrorKind{"SchedStrategy"}, std::string("solver_mva_qsys_sizebased_analyzer: ") +
1265 lang::sched_to_text(sched) + " is not a size-based discipline");
1266 }
1267
1269 MvaSolution<T>& s = out.sol;
1270 s.Q = Matrix<T>(M, K, zero);
1271 s.U = Matrix<T>(M, K, zero);
1272 s.R = Matrix<T>(M, K, zero);
1273 s.Tp = Matrix<T>(M, K, zero);
1274 s.C.assign(K, zero);
1275 s.X.assign(K, zero);
1276 s.method = opt.method;
1277 s.iter = 1;
1278 for (std::size_t r = 0; r < K; ++r) {
1279 s.R(q - 1, r) = T(W[r] * vis[r]);
1280 s.C[r] = s.R(q - 1, r);
1281 s.X[r] = lambda[r];
1282 s.U(q - 1, r) = T(lambda[r] / mu[r]);
1283 s.Tp(q - 1, r) = lambda[r];
1284 s.Tp(src - 1, r) = lambda[r];
1285 s.Q(q - 1, r) = T(lambda[r] * W[r]);
1286 }
1287 out.actualmethod = actual;
1288 return out;
1289 } // if constexpr has_transcendental
1290}
1291
1292/**
1293 * Port of `solver_mva_marie_analyzer.m`: Marie's iterative
1294 * aggregation-decomposition for a CLOSED network with non-exponential FCFS
1295 * service.
1296 *
1297 * Only FCFS is service-time sensitive; PS and LCFSPR are insensitive
1298 * (product form) and are handed an SCV of one, which is what makes the
1299 * decomposition exact for them. Delay stations fold into the per-chain think
1300 * time rather than entering the isolation, and multiserver isolation is
1301 * single-chain only -- all three restrictions are the reference's, and each is
1302 * refused by name rather than approximated.
1303 */
1304template <class T>
1306 // Marie's decomposition fits a Coxian per isolated station (square roots) and
1307 // stops on a tolerance; refuse by name under exact/Rational.
1308 if constexpr (!num_traits<T>::has_transcendental) {
1309 throw UnsupportedError(ErrorKind{"Arithmetic"},
1310 "solver_mva_marie_analyzer: Marie's aggregation-decomposition needs transcendental "
1311 "arithmetic; rerun this model with --arith double or --arith real");
1312 } else {
1313 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
1315 const std::size_t M = L.nstations, C = L.nchains;
1316
1317 for (std::size_t c = 0; c < C; ++c)
1318 if (!std::isfinite(d.Nchain[c]))
1319 throw UnsupportedError(ErrorKind{"OpenClass"},
1320 "solver_mva_marie_analyzer: the 'marie' method supports closed models only; this "
1321 "model has open classes");
1322 for (const auto& nd : L.nodes)
1323 if (nd.nodetype == qn::NodeType::Source)
1324 throw UnsupportedError(ErrorKind{"OpenClass"},
1325 "solver_mva_marie_analyzer: the 'marie' method supports closed models only; this "
1326 "model has a Source");
1327
1328 std::vector<std::size_t> qrows, drows;
1329 for (std::size_t i = 0; i < M; ++i) {
1330 const qn::SchedStrategy sc = L.stations[i].sched;
1331 const bool delay = std::isinf(L.stations[i].nservers) || sc == qn::SchedStrategy::INF;
1332 if (delay) {
1333 drows.push_back(i);
1334 continue;
1335 }
1336 if (!(sc == qn::SchedStrategy::FCFS || sc == qn::SchedStrategy::PS ||
1337 sc == qn::SchedStrategy::LCFSPR))
1338 throw UnsupportedError(ErrorKind{"SchedStrategy"}, std::string("solver_mva_marie_analyzer: the 'marie' method "
1339 "supports FCFS, PS, LCFSPR and Delay stations "
1340 "only; station '") +
1341 L.stations[i].name + "' is " + lang::sched_to_text(sc));
1342 qrows.push_back(i);
1343 }
1344
1345 std::vector<T> Z(C, zero);
1346 for (std::size_t c = 0; c < C; ++c)
1347 for (std::size_t i : drows) Z[c] += d.Lchain(i, c);
1348
1349 const std::size_t Mq = qrows.size();
1350 Matrix<T> Lq(Mq, C, zero), SCV(Mq, C, one);
1351 std::vector<int> ns(Mq, 1);
1352 bool multiserver = false;
1353 for (std::size_t a = 0; a < Mq; ++a) {
1354 const std::size_t i = qrows[a];
1355 const double srv = L.stations[i].nservers;
1356 ns[a] = std::isfinite(srv) ? static_cast<int>(std::llround(srv)) : 1;
1357 if (ns[a] > 1) multiserver = true;
1358 for (std::size_t c = 0; c < C; ++c) {
1359 Lq(a, c) = d.Lchain(i, c);
1360 if (L.stations[i].sched != qn::SchedStrategy::FCFS) continue;
1361 const double v = num_traits<T>::to_double(d.SCVchain(i, c));
1362 if (std::isfinite(v) && v > 0.0) SCV(a, c) = num_traits<T>::from_double(v);
1363 }
1364 }
1365 if (C > 1 && multiserver)
1366 throw UnsupportedError(ErrorKind{"MultiServer"},
1367 "solver_mva_marie_analyzer: the 'marie' method supports multiserver stations for "
1368 "single-chain models only");
1369
1370 std::vector<int> N(C, 0);
1371 for (std::size_t c = 0; c < C; ++c) N[c] = static_cast<int>(std::llround(d.Nchain[c]));
1373 if (Mq == 0) {
1374 // Nothing to isolate: with every station an infinite server the
1375 // aggregation-decomposition degenerates to the exact delay solution
1376 // X_c = N_c / Z_c, and pfqn_marie would be handed a zero-row demand matrix.
1377 mr.X.assign(C, zero);
1378 mr.Q = Matrix<T>(0, C, zero);
1379 mr.U = Matrix<T>(0, C, zero);
1380 mr.it = 1;
1381 for (std::size_t c = 0; c < C; ++c)
1382 if (Z[c] > zero) mr.X[c] = T(num_traits<T>::from_double(d.Nchain[c]) / Z[c]);
1383 } else {
1384 mr = C == 1 ? pfqn::pfqn_marie(Lq, N, Z, SCV, 1e-8, 1000, ns)
1385 : pfqn::pfqn_marie(Lq, N, Z, SCV, 1e-8, 1000, std::vector<int>());
1386 }
1387
1388 Matrix<T> Qchain(M, C, zero), Uchain(M, C, zero), Rchain(M, C, zero), Tchain(M, C, zero);
1389 for (std::size_t a = 0; a < Mq; ++a)
1390 for (std::size_t c = 0; c < C; ++c) {
1391 Qchain(qrows[a], c) = mr.Q(a, c);
1392 Uchain(qrows[a], c) = mr.U(a, c);
1393 }
1394 for (std::size_t i = 0; i < M; ++i)
1395 for (std::size_t c = 0; c < C; ++c) Tchain(i, c) = T(mr.X[c] * d.Vchain(i, c));
1396 for (std::size_t i = 0; i < M; ++i)
1397 for (std::size_t c = 0; c < C; ++c)
1398 if (Tchain(i, c) > zero) Rchain(i, c) = T(Qchain(i, c) / Tchain(i, c));
1399 // A delay station holds T S jobs, all of them in service.
1400 for (std::size_t i : drows)
1401 for (std::size_t c = 0; c < C; ++c) {
1402 Qchain(i, c) = T(Tchain(i, c) * d.STchain(i, c));
1403 Uchain(i, c) = Qchain(i, c);
1404 Rchain(i, c) = d.STchain(i, c);
1405 }
1406
1407 const ClassResults<T> cr =
1408 sn_deaggregate_chain_results(L, d, Qchain, Uchain, Rchain, Tchain, mr.X);
1410 out.sol.Q = cr.Q;
1411 out.sol.U = cr.U;
1412 out.sol.R = cr.R;
1413 out.sol.Tp = cr.Tp;
1414 out.sol.C = cr.C;
1415 out.sol.X = cr.X;
1416 out.sol.method = opt.method;
1417 out.sol.iter = mr.it;
1418 out.actualmethod = "marie";
1419 return out;
1420 } // if constexpr has_transcendental
1421}
1422
1423/**
1424 * The ladder itself. `init_sol` is the warm start the outer solver carries
1425 * across iterations; it reaches the AMVA paths only, as it does in the
1426 * reference.
1427 */
1428template <class T>
1430 const Matrix<T>& init_sol) {
1431 using qn::NodeType;
1432 using qn::SchedStrategy;
1433 const std::string method = amva_method_alias(opt.method);
1434
1435 // 0. closed models with a shortest-job-next station. This sits ABOVE every
1436 // other branch because the reference tests hasSJN first and the branches
1437 // are not disjoint: an SJF station in a closed model with a delay would
1438 // otherwise reach the generic AMVA path, which reads only the mean service
1439 // time and would report the station as if it scheduled size-blind. The
1440 // OPEN case has no population to recur over and is refused by name rather
1441 // than solved as though the discipline did nothing.
1442 if (sn_has_sjn(L)) {
1443 bool open = false;
1444 for (const auto& c : L.classes)
1445 if (std::isinf(c.population)) open = true;
1446 // An OPEN SJF station is the M/G/1 non-preemptive SJF queue (Phipps
1447 // 1956) on the Source -> Queue -> Sink shape with one server and Poisson
1448 // sources, which the size-based analyzer answers with qsys_mg1_sjf
1449 // (MATLAB SolverMVA.supportsSjn and mvaDispatch).
1450 if (open && detail::is_open_sqs(L)) {
1451 const std::size_t sq = detail::station_of_type(L, NodeType::Queue);
1452 const std::size_t ss = detail::station_of_type(L, NodeType::Source);
1453 bool poisson = true;
1454 for (std::size_t r = 0; r < L.nclasses; ++r) {
1455 const double v = num_traits<T>::to_double(L.scv(ss - 1, r));
1456 if (std::isfinite(v) && !(std::fabs(v - 1.0) < 1e-6)) poisson = false;
1457 }
1458 if (sq != 0 && L.stations[sq - 1].nservers == 1.0 && poisson)
1460 }
1461 if (open)
1462 throw UnsupportedError(ErrorKind{"OpenClass"},
1463 "SolverMVA supports shortest-job-next (SJF) scheduling in closed models (a population "
1464 "recursion) and in the open single-server M/G/1 system with Poisson sources "
1465 "(Source -> Queue -> Sink). Use SolverLDES for this model");
1467 DispatchResult<T> sout;
1468 sout.sol = sr.sol;
1469 sout.actualmethod = sr.actualmethod;
1470 sout.warning = sr.warning;
1471 return sout;
1472 }
1473
1474 // 1. order-independent / pass-and-swap stations. Detection is
1475 // `nc_is_oi_model`'s: PAS or OI scheduling, a rate function, and an
1476 // ALL-ZERO swap graph. A station with those disciplines that does not
1477 // qualify is a genuine pass-and-swap station, which is not product-form
1478 // and has no exact mean-value analyzer, so it is refused by name rather
1479 // than handed to an AMVA that cannot represent its rate function at all.
1480 // The gate is the reference's, and all three conjuncts matter: an OI
1481 // station must be present, the WHOLE model must be order-independent
1482 // (nc_is_oi_model: closed, and every other station product-form), and the
1483 // method must be `default` or `exact`. MVA reaches OI/PAS ONLY through the
1484 // exact analyzer; any other method would fall through to an AMVA that only
1485 // ever sees the single-job rates and would silently report a zero queue
1486 // length at the OI station.
1487 {
1488 const bool has_oi_station = std::any_of(
1489 L.stations.begin(), L.stations.end(), [](const qn::Station<T>& st) {
1490 return st.sched == SchedStrategy::OI || st.sched == SchedStrategy::PAS;
1491 });
1492 const bool exact_method = (opt.method == "default" || opt.method == "exact");
1493 // SolverMVA.supportsOrderIndependent, in its order: the method, then a
1494 // MIXED population (the mixed OI route is a normalizing-constant
1495 // construction, closed-lattice tables with the open classes summed out,
1496 // so it lives in SolverNC alone), then the shape, then one class per
1497 // chain, then the open route's own premises (nc_oi_refusal).
1498 bool anyOpen = false, allOpen = true;
1499 for (const auto& c : L.classes) {
1500 if (std::isinf(c.population)) anyOpen = true;
1501 else allOpen = false;
1502 }
1503 if (has_oi_station && exact_method && anyOpen && !allOpen)
1504 throw UnsupportedError(ErrorKind{"SchedStrategy_OI"},
1505 "the order-independent analyzer of SolverMVA serves closed and open networks; a "
1506 "mixed network with an OI station is solved exactly by SolverNC (method 'default' "
1507 "or 'exact').");
1508 if (!find_oi_stations(L).empty() && nc_is_oi_model(L) && exact_method) {
1509 for (std::size_t c = 0; c < L.nchains; ++c)
1510 if (L.inchain[c].size() > 1)
1511 throw UnsupportedError(ErrorKind{"ClassSwitch"},
1512 "the order-independent analyzer requires one class per chain (no class "
1513 "switching).");
1514 if (allOpen) {
1515 const std::string why = nc::nc_oi_refusal(L, "oi");
1516 if (!why.empty()) throw UnsupportedError(ErrorKind{"Structure"}, why);
1517 }
1518 DispatchResult<T> oout;
1519 oout.sol = solver_mva_oi_analyzer(L, opt);
1520 oout.actualmethod = oout.sol.method;
1521 return oout;
1522 }
1523 if (has_oi_station)
1524 throw UnsupportedError(ErrorKind{"SchedStrategy_OI"},
1525 "SolverMVA supports order-independent (OI) and pass-and-swap (PAS) stations only "
1526 "through its exact order-independent analyzer, which requires method 'default' or "
1527 "'exact' (got '" + opt.method +
1528 "'), an empty/zero swap graph at every OI/PAS station, a closed or fully open "
1529 "model, and every other station to be product-form (INF, PS, LCFS-PR, SIRO, or "
1530 "class-independent-rate FCFS). Use SolverCTMC or SolverLDES for this model");
1531 }
1532
1533 // 2. delayed-hit retrieval caches (Cache.setRetrievalSystem). The two
1534 // variants are DIFFERENT METHODS, not one method on two topologies, which
1535 // is why the Source test decides between them rather than parameterizing
1536 // one call. The OPEN model has no population to recur over, so the hit /
1537 // miss / delayed-hit split comes from the open fixed point
1538 // (`retrieval_fpi`) and all three are reported. The CLOSED model has no
1539 // exogenous arrival rate to run that fixed point on, so the split emerges
1540 // from a decomposition-aggregation sweep instead, and the delayed-hit
1541 // fraction folds into the miss (see solver_mva_cacheqn_retrieval.h).
1542 for (const auto& kv : L.nodeparam) {
1543 if (kv.second.retrieval_capacity <= 0) continue;
1544 DispatchResult<T> rout;
1545 if (detail::station_of_type(L, NodeType::Source) == 0) {
1547 rout.sol = cr.sol;
1549 cr.latency, cr.hitproblist, Matrix<T>(),
1550 std::vector<T>());
1551 } else {
1553 rout.sol = solver_mva_retrieval_analyzer(L, opt, &co);
1555 co.latency, co.hitproblist, co.itemprob,
1556 std::vector<T>());
1557 }
1558 rout.actualmethod = "fpi";
1559 return rout;
1560 }
1561
1562 const bool sqs = detail::is_open_sqs(L);
1563 const std::size_t qst = detail::station_of_type(L, NodeType::Queue);
1564 const SchedStrategy qsched = qst ? L.stations[qst - 1].sched : SchedStrategy::NONE;
1565 const std::size_t srcst = detail::station_of_type(L, NodeType::Source);
1566
1567 // 8. non-reentrant cache: a Source-Cache-Sink model
1568 if (detail::is_open_scs(L)) {
1569 DispatchResult<T> cout;
1571 cout.sol = cr.sol;
1572 cout.cache = solvers::cache_metrics_of(L, cr.hitprob, cr.missprob, std::vector<T>(),
1573 std::vector<T>(), cr.hitproblist, cr.itemprob,
1574 std::vector<T>());
1575 cout.actualmethod = cr.actualmethod;
1576 return cout;
1577 }
1578
1579 // 9. any OTHER cache -- one embedded in a queueing network -- is the
1580 // integrated caching-queueing analyzer (decomposition-aggregation).
1581 if (!L.nodeparam.empty()) {
1582 DispatchResult<T> qout;
1583 std::shared_ptr<qn::NetworkStruct<T>> refreshed(new qn::NetworkStruct<T>());
1585 qout.sol = solver_mva_cacheqn_analyzer(L, opt, refreshed.get(), &co);
1586 qout.refreshed_struct = refreshed;
1587 // The integrated branch reports the split per (cache, class) and no
1588 // delayed-hit fraction; the per-item law rides in separately because
1589 // only this branch has one per cache rather than one per model.
1591 for (std::size_t ci = 0; ci < qout.cache.caches.size() && ci < co.itemprob.size(); ++ci)
1592 qout.cache.caches[ci].itemprob = co.itemprob[ci];
1593 qout.actualmethod = (opt.method == "exact") ? "exact" : "default";
1594 return qout;
1595 }
1596
1597 // 3. size-based scheduling
1598 if (sqs && detail::is_size_based(qsched)) return solver_mva_qsys_sizebased_analyzer(L, opt);
1599
1600 // 4. single-class open Source-Queue-Sink.
1601 //
1602 // CLAIMED ONLY FOR THE NAMES THE ANALYZER ANSWERS, `detail::qsys_serves_method`.
1603 // Anything else -- 'qna', 'mva', 'amva', the linearizers, the qd family,
1604 // sum/esum -- falls through to the network branches below and is solved
1605 // there, as it is on every larger open network; this branch used to claim
1606 // the model for them and then refuse the method by name. 'rqna' and 'rqt'
1607 // are served here: the analyzer answers them with single-queue robust
1608 // formulas of their own.
1609 //
1610 // THE M/M/1/K LOSS SHAPE IS THE EXCEPTION and is claimed whatever the name.
1611 // Its branch is chosen by the SHAPE and not by the method, and the capacity
1612 // gate in the runner exempts exactly this shape for every method but
1613 // 'exact', so the two have to agree on which models come here.
1614 // AND ONLY FOR A STATION WHOSE RATE IS A CONSTANT, `detail::has_state_dependent_rates`:
1615 // a declared lld/cd/jd scaling sends the model on to branch 12, whose analyzer
1616 // carries the scaling terms, rather than to a closed form that cannot read them.
1617 if (sqs && L.nclasses == 1 &&
1618 ((detail::qsys_serves_method(method) && !detail::has_state_dependent_rates(L)) ||
1619 sn_is_mm1k_loss(L)))
1620 return solver_mva_qsys_analyzer(L, opt);
1621
1622 // 5. multiclass open polling
1623 if (sqs && L.nclasses > 1 && qsched == SchedStrategy::POLLING) {
1624 DispatchResult<T> pout;
1626 pout.actualmethod = "stationtime";
1627 if (opt.method == "default" || opt.method == "amva.default")
1629 return pout;
1630 }
1631
1632 // 5b. the closed Delay + FCFS Queue cycle: finite-source closed forms
1633 // (M/G/1/K/K, D/D/c/K/K, M/M/c/K/K) that hold outside product form too
1634 // (MATLAB mvaDispatch, isFiniteSource)
1635 if (!mva_finite_source_variant(L, method).empty()) return solver_mva_finite_source_analyzer(L, opt);
1636
1637 // 6. multiclass open priority queue with Poisson sources: HOL M/G/1
1638 // ('mg1.prio'), preemptive-resume M/G/1 ('mg1.prio.pr') and HOL M/M/c with
1639 // a common rate ('mmc.prio'), as SolverMVA.qsysPrioVariant names them
1640 if (!mva_qsys_prio_variant(L).empty()) return solver_mva_qsys_prio_analyzer(L, opt);
1641
1642 // 7. multiclass open DPS, at most three classes, exponential everywhere, and
1643 // a constant rate: qsys_mm1_dps reads one rate per class
1644 if (sqs && L.nclasses > 1 && L.nclasses <= 3 && qsched == SchedStrategy::DPS &&
1645 !detail::has_state_dependent_rates(L) &&
1646 L.stations[qst - 1].nservers == 1.0 && detail::row_is_exponential(L, srcst) &&
1647 detail::row_is_exponential(L, qst))
1648 return solver_mva_dps_exact(L, opt);
1649
1650 // 10. the bound family, which the reference moved to SolverBA
1651 static const char* kBounds[] = {"aba.upper", "aba.lower", "bjb.upper", "bjb.lower",
1652 "pb.upper", "pb.lower", "gb.upper", "gb.lower",
1653 "sb.upper", "sb.lower", "mw.upper", "mw.lower"};
1654 for (const char* b : kBounds)
1655 if (method == b)
1656 throw UnsupportedError(ErrorKind{"Method"}, "SolverMVA: bound methods have moved to SolverBA; use "
1657 "SolverBA with method '" +
1658 method + "'");
1659
1660 // 11. Marie's aggregation-decomposition
1661 if (method == "marie") return solver_mva_marie_analyzer(L, opt);
1662
1663 // 12. load-, class- or joint-dependent scaling. THE TEST MUST NAME ALL THREE:
1664 // it read lldscaling and cdscaling only until 2026-09-13, so a station whose
1665 // ONLY declared dependence was jdscaling fell through to branch 13 and was
1666 // solved at its unscaled rate, where the reference (mvaDispatch.m:240) sends
1667 // it to the load-dependent analyzer. Same predicate as branch 4's.
1668 if (detail::has_state_dependent_rates(L)) return solver_mvald_analyzer(L, opt, init_sol);
1669
1670 // 13. an ordinary queueing network. MVAC is a case of the analyzer's method
1671 // switch (solver_mva_analyzer.m:21-23) and so belongs BELOW branch 12: a
1672 // load-dependent model reaches solver_mvald_analyzer in the reference and
1673 // never sees the 'mvac' case, which is why this is not tested higher up.
1674 if (method == "mvac") {
1675 DispatchResult<T> mout;
1676 mout.sol = solver_mvac_analyzer(L, opt);
1677 mout.actualmethod = "mvac";
1678 return mout;
1679 }
1680 // QNA is dispatched here rather than in solver_mva_analyzer only because
1681 // solver_qna.h cannot include solver_mva.h without a cycle; the reference
1682 // reaches it from the analyzer's method table, and no branch above claims
1683 // 'qna', so the model it sees is the same.
1684 if (method == "qna") {
1685 DispatchResult<T> qout;
1686 qout.sol = solver_qna(L, opt);
1687 qout.actualmethod = "qna";
1688 return qout;
1689 }
1690 // RQNA (robust queueing-network analyzer) is likewise reached by method name,
1691 // and by the resolveMethod default->rqna upgrade for a bursty single-class
1692 // open network; dispatched here for the same include-cycle reason as qna.
1693 if (method == "rqna") {
1694 DispatchResult<T> rout;
1695 rout.sol = solver_rqna(L, opt);
1696 rout.actualmethod = "rqna";
1697 return rout;
1698 }
1699 // RQT (robust queueing theory) is reached by method name only; its
1700 // uncertainty-set decomposition has no default-dispatch upgrade.
1701 if (method == "rqt") {
1702 DispatchResult<T> tout;
1703 tout.sol = solver_rqt(L, opt);
1704 tout.actualmethod = "rqt";
1705 return tout;
1706 }
1707 // The horizontal-cut MVA for one exponential delay and one FCFS MAP queue
1708 // (mapqn_amva), reached by name; its shape gate is mva_mapqn_reason.
1709 if (method == "amva.mapqn" || method == "mapqn") {
1710 DispatchResult<T> mout;
1711 mout.sol = solver_mapqn(L, opt);
1712 mout.actualmethod = "amva.mapqn";
1713 return mout;
1714 }
1715 // bursty single-class open network: 'default' upgrades to RQNA, exactly as
1716 // the terminal branch of solver_mva_analyzer.m does. resolveMethod computes
1717 // this only for the feature gate and never writes it back to options, so the
1718 // substitution belongs HERE, after the structural special cases -- a 3-node
1719 // MAP/M/1 is a G/M/1 the qsys analyzer (branch 4) already solved and must
1720 // keep method='default'. A fork-transformed model is exempt: it is forced to
1721 // amva just below.
1722 if (method == "default" && !opt.base_has_fork && !L.has_fork() && L.nclasses == 1) {
1723 bool all_open = true;
1724 for (std::size_t r = 0; r < L.nclasses; ++r)
1725 if (std::isfinite(L.classes[r].population)) all_open = false;
1726 if (all_open && api::sn_has_bursty_arrival(L)) {
1727 DispatchResult<T> rout;
1728 rout.sol = solver_rqna(L, opt);
1729 rout.actualmethod = "rqna";
1730 return rout;
1731 }
1732 }
1733
1734 MvaOptions o = opt;
1735 if ((opt.base_has_fork || L.has_fork()) && method == "default") {
1736 // The fork transform yields a mixed model with auxiliary near-zero-rate
1737 // open classes. The default ladder would send it to exact mixed MVA,
1738 // which degenerates to zero there; the approximation needs the AMVA.
1739 //
1740 // The test is on the BASE model, as the reference writes it: by the
1741 // time this runs the transform has already removed the fork, so
1742 // `L.has_fork()` alone is false on exactly the models the rule is for.
1743 o.method = "amva";
1744 }
1746 out.sol = solver_mva_analyzer(L, o, init_sol);
1747 out.actualmethod = out.sol.method;
1748 return out;
1749}
1750
1751} // namespace mva
1752} // namespace line
1753
1754#endif // LINE_SOLVERS_MVA_MVA_DISPATCH_H
What a solver observed about the Cache nodes of a model.
InputError(const std::string &what)
Definition error.h:105
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
std::size_t stateful_of_station(std::size_t st) const
std::size_t nof_nodes() const
std::vector< std::vector< Distrib< T > > > service
service[i][r], 0-based station and class; a disabled entry marks a pair never visited.
std::map< std::size_t, BreakdownParam< T > > breakdownparam
Server breakdown / repair, keyed by 1-based STATION index.
bool has_breakdown() const
Any station at all, the guard every solver gate needs first.
std::map< std::size_t, CacheParam< T > > nodeparam
Cache parameters by 1-based NODE index; only Cache nodes have an entry.
Matrix< double > procid() const
sn.procid (M x K): the ProcessType id of each (station, class) pair, as refreshProcessTypes....
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< JobClass > classes
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< std::vector< std::size_t > > inchain
1-based class indices per chain
std::vector< NodeDef > nodes
every node, in creation order
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
double nclosedjobs() const
sn.nclosedjobs: the total population of the closed classes.
bool has_product_form() const
sn_has_product_form, conjunct for conjunct.
Steady-state distribution of a continuous-time Markov chain.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
Index of dispersion for counts (IDC) of a MAP at resolution t.
PatienceHandles< T > sn_patience_handles(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
Build the patience handles of station ist (0-based), class r.
bool sn_has_bursty_arrival(const qn::NetworkStruct< T > &sn)
std::string sn_patience_exp_refusal(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
Port of sn_patience_exp_refusal.m: the by-name refusal of a reneging patience that is not EXPONENTIAL...
std::string sn_patience_refusal(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
Port of sn_patience_refusal.m: the by-name refusal of a reneging patience that is not a Markovian law...
RenewalLst sn_renewal_lst(const qn::NetworkStruct< T > &sn, std::size_t ist)
Renewal inter-arrival LST of class 1 at station ist (1-based).
std::function< double(double)> RenewalLst
A real-argument Laplace-Stieltjes transform; empty when there is none.
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
bool process_is_batch(ProcessType p)
True when an EVENT of this process releases (or, as a service process, completes) a BATCH of jobs who...
Definition lang_types.h:771
T dist_lst(const Distrib< T > &d, const T &s)
sn.lst: the Laplace-Stieltjes transform E[exp(-sX)].
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
Definition lang_types.h:524
const char * sched_to_text(SchedStrategy s)
Definition lang_types.h:248
NodeType
Node kinds, with the values of MATLAB NodeType.
Definition lang_types.h:345
std::vector< T > map_count_idc(const Map< T > &m, const std::vector< T > &t)
Index of dispersion for counts (IDC) of a MAP at resolution t.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
Definition map_moment.h:89
std::vector< T > ctmc_solve(const Matrix< T > &Qin, const std::string &linsolver=std::string())
Steady-state distribution of a continuous-time Markov chain.
Definition ctmc_solve.h:133
std::string mva_qsys_prio_variant(const qn::NetworkStruct< T > &L)
Port of SolverMVA.qsysPrioVariant(sn): the exact priority closed form solver_mva_qsys_prio_analyzer a...
DispatchResult< T > solver_mva_qsys_prio_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_qsys_prio_analyzer.m: the exact priority closed form for a single open queue with ...
DispatchResult< T > solver_mva_qsys_sizebased_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_qsys_sizebased_analyzer.m: the M/G/1 formulas for the size-based disciplines (Wier...
MvaSolution< T > solver_mva_polling_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_polling_analyzer.m.
MvaSolution< T > solver_mva_cacheqn_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, qn::NetworkStruct< T > *refreshed_out=nullptr, MvaCacheqnCacheOutputs< T > *cache_out=nullptr)
bool sn_has_sjn(const qn::NetworkStruct< T > &L)
True when the layer has an SJF station, the reference's any(sn.sched == SchedStrategy....
bool mva_is_mxg1_system(const qn::NetworkStruct< T > &L)
Port of SolverMVA.isMxg1System: the single-class Source -> Queue -> Sink shape whose source is a batc...
std::vector< std::size_t > find_oi_stations(const qn::NetworkStruct< T > &L)
The OI stations of a model, 1-based station indices.
std::string mva_finite_source_variant(const qn::NetworkStruct< T > &L, const std::string &method)
Port of SolverMVA.finiteSourceVariant(sn, method): the finite-source closed form solver_mva_finite_so...
bool sn_is_mm1k_loss(const qn::NetworkStruct< T > &L)
Port of matlab/src/api/sn/sn_is_mm1k_loss.m: a single-class open Source-Queue-Sink system whose queue...
std::string polling_poisson_warning(const qn::NetworkStruct< T > &L)
The reference's line_warning for method 'default' when a polled class has a non-Poisson arrival proce...
MvaSolution< T > solver_rqna(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
SjnAnalyzerResult< T > solver_mva_sjn_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_sjn_analyzer.m.
std::string amva_method_alias(const std::string &m)
The amva.
std::string mva_erlanga_patience_reason(const qn::NetworkStruct< T > &L)
Why method 'erlanga' cannot answer this model's patience, or "".
DispatchResult< T > solver_mva_marie_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_marie_analyzer.m: Marie's iterative aggregation-decomposition for a CLOSED network...
CacheResult< T > solver_mva_cache_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_cache_analyzer.m for a Source-Cache-Sink model.
DispatchResult< T > solver_mva_finite_source_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_finite_source_analyzer.m: the finite-source (machine repair) closed forms for the ...
MvaSolution< T > solver_mvac_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mvac.m.
Definition solver_mvac.h:71
MvaSolution< T > solver_mapqn(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
MvaSolution< T > solver_qna(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_qna.m.
Definition solver_qna.h:86
DispatchResult< T > solver_mvald_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
Port of solver_mvald_analyzer.m: the load-dependent branch.
ClassResults< T > sn_deaggregate_chain_results(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, const Matrix< T > &Qchain, const Matrix< T > &Uchain, const Matrix< T > &Rchain, const Matrix< T > &Tchain, const std::vector< T > &Xchain)
Port of sn_deaggregate_chain_results.
Definition sn_chain.h:227
std::string mva_breakdown_reason(const qn::NetworkStruct< T > &L, const std::string &method)
Port of SolverMVA.supportsBreakdown: a station with Queue.setBreakdown is served by one arm,...
MvaSolution< T > solver_mvald(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mvald.m: exact MVA on a load-dependent model, through pfqn_mvaldmx.
MvaCacheqnRetrievalSolution< T > solver_mva_cacheqn_retrieval_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_cacheqn_retrieval_analyzer.m.
MvaSolution< T > solver_mva_oi_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_oi_analyzer.m.
MvaSolution< T > solver_rqt(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Definition solver_rqt.h:59
DispatchResult< T > solver_mva_qsys_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_qsys_analyzer.m: the closed forms for a single-class open Source-Queue-Sink model.
DispatchResult< T > solver_mva_dps_exact(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
The exact multiclass M/M/1-DPS solve the reference inlines in mvaDispatch: the truncated multiclass c...
MvaSolution< T > solver_amva(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, MvaOptions opt, const Matrix< T > &init_sol, bool &converged)
bool nc_is_oi_model(const qn::NetworkStruct< T > &L)
Port of nc_is_oi_model: whether the model as a WHOLE is order-independent, which is a strictly strong...
MvaSolution< T > solver_mva_retrieval_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, MvaRetrievalCacheOutputs< T > *cache_out=nullptr)
MvaSolution< T > solver_mva_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
Port of solver_mva_analyzer.m, default and the explicit method names.
DispatchResult< T > mva_dispatch(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
The ladder itself.
ChainDemands< T > sn_get_demands_chain(const qn::NetworkStruct< T > &L)
Port of sn_get_demands_chain.
Definition sn_chain.h:63
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?
MarieResult< T > pfqn_marie(const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z, const Matrix< T > &scv, double tol, int maxiter, const std::vector< int > &nservers)
Marie's method for a closed network with FCFS Coxian service.
Definition pfqn_marie.h:647
std::string mva_base_method(const std::string &method)
The method name with any leading "amva." alias stripped.
bool mva_qsys_serves_method(const std::string &method)
The method names solver_mva_qsys_analyzer has an arm for.
GigkRqtResult< T > qsys_gigk_rqt(const T &lambda, const T &mu, const T &Gamma_a, const T &Gamma_s, std::size_t k, const T &alpha_a, const T &alpha_s)
Robust Queueing Theory (RQT) worst-case system time of a G/G/k FCFS queue.
MeanValueResult< T > qsys_mg1_breakdown(const T &lambda, const T &mu, const T &cs, const T &alpha, const T &ER, const T &ER2, const T &RLST)
M/G/1 FCFS with exponential failures (busy or idle) and general repair.
QsysRes qsys_gimc(const std::function< double(double)> &lst, double lambda, double mu, unsigned c, const QsysResOptions &o=QsysResOptions())
Definition qsys_gimc.h:74
QsysQedResult< T > qsys_mmk_qed(const T &lambda, const T &mu, unsigned s)
Halfin-Whitt QED approximation for the M/M/s queue, and the square-root staffing rule that inverts it...
QsysResult< T > qsys_gigk_approx_kingman(const T &lambda, const T &mu, const T &ca, const T &cs, unsigned k)
Kingman (Lee-Longton) scaling of the exact M/M/k waiting time.
QsysResult< T > qsys_mm1(const T &lambda, const T &mu)
Exact mean response time of the M/M/1 queue.
Definition qsys_mm1.h:36
Gig1ExtremalResult< T > qsys_gig1_bnds_extremal(const T &lambda, const T &mu, const T &ca, const T &cs, std::size_t K=4000, std::size_t N=2000, bool skipTight=false)
Extremal two-moment bounds for the GI/GI/1 queue.
Mg1SjfResult qsys_mg1_sjf(const std::vector< double > &lambda, const std::vector< double > &mu, const std::vector< double > &cs)
M/G/1 non-preemptive SJF.
QsysResult< T > qsys_gigk_approx(const T &lambda, const T &mu, const T &ca, const T &cs, unsigned k)
Default G/I/G/k approximation of the mean response time.
QsysGgnmResult< T > qsys_ggnm_diffusion(const T &lambda, const T &mu, unsigned n, double m, const T &ca, const T &cs, const std::function< T(const T &)> &serviceCcdf=std::function< T(const T &)>(), double tol=1e-12, std::size_t panels=4000)
Diffusion approximation for the G/GI/n/m queue.
MxM1Result< T > qsys_mxm1(const T &lambda_batch, const T &mu, const T &E_X, const T &E_X2)
M^X/M/1: the batch-arrival queue with exponential service.
Definition qsys_mxm1.h:59
Mg1DisciplineResult< T > qsys_mg1_srpt(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under SRPT (shortest remaining processing time), by the Schrage-Miller formula.
QsysAbandonResult< T > qsys_erlanga(const T &lambda, const T &mu, const T &theta, unsigned s, double r=std::numeric_limits< double >::infinity(), const MgisrgiOptions &opts=MgisrgiOptions())
Exact analysis of the Erlang A model M/M/s/r+M.
T qsys_gm1(const T &sigma, const T &mu)
Exact mean response time of the G/M/1 queue.
Definition qsys_gm1.h:41
QsysResult< T > qsys_gig1_approx_gelenbe(const T &lambda, const T &mu, const T &ca, const T &cs)
Gelenbe diffusion approximation with instantaneous-return boundary.
QsysResult< T > qsys_gig1_approx_marchal(const T &lambda, const T &mu, const T &ca, const T &cs)
Marchal approximation of the mean response time of a G/I/G/1 queue.
Mg1DisciplineResult< T > qsys_mg1_fb(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under FB (feedback), also called LAS (least attained service).
Definition qsys_mg1_fb.h:84
MmcPrioResult< T > qsys_mmc_prio(const std::vector< T > &lambda, const T &mu, unsigned c)
M/M/c with head-of-line priorities.
QsysRes qsys_mmckk(double alpha, double mu, unsigned c, unsigned K, const QsysResOptions &o=QsysResOptions())
Exact M/M/c/K/K finite-source queue.
Definition qsys_mmckk.h:48
QsysAbandonResult< T > qsys_mgisrgi_whitt(const T &lambda, const T &mu, unsigned s, double r, const Patience< T > &patience, const MgisrgiOptions &opts=MgisrgiOptions())
Engineering solution of the call-center model M/GI/s/r+GI.
QsysResult< T > qsys_gigk_approx_whitt(const T &lambda, const T &mu, const T &ca, const T &cs, unsigned k)
Whitt (1993) approximation for the GI/G/k queue, eqs.
Mg1DisciplineResult< T > qsys_mg1_lrpt(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under LRPT (longest remaining processing time).
PhM1Result< T > qsys_phm1(const std::vector< T > &alpha, const Matrix< T > &Tm, const T &mu, const T &tol)
Exact PH/M/1, the GI/M/1 queue with phase-type interarrival times.
Definition qsys_phm1.h:92
QsysResT< T > qsys_ddckk(const T &EO, const T &ES, unsigned c, unsigned K)
Exact D/D/c/K/K finite-source queue.
Definition qsys_ddckk.h:48
Mm1DpsResult< T > qsys_mm1_dps(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &w, const T &tol, unsigned maxCutoff)
Multiclass M/M/1 under DPS (discriminatory processor sharing), solved numerically on the truncated po...
QsysRes qsys_mg1kk(double alpha, unsigned K, const std::function< double(double)> &lst, double ES)
Exact M/G/1/K/K finite-source queue, service given by its LST.
Definition qsys_mg1kk.h:60
QsysResult< T > qsys_mg1(const T &lambda, const T &mu, const T &cs)
Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
Definition qsys_mg1.h:40
MeanValueResult< T > qsys_mxg1(const T &lambda_batch, const T &mu, const T &cs, const T &E_X, const T &E_X2)
M^X/G/1 from the first two raw moments of the batch size.
Definition qsys_mxg1.h:56
QsysResT< double > QsysRes
Definition qsys_res.h:96
QsysResult< T > qsys_gig1_approx_kobayashi(const T &lambda, const T &mu, const T &ca, const T &cs)
Kobayashi diffusion approximation for the G/I/G/1 queue.
Mg1kLossMgsResult< T > qsys_mg1k_loss_mgs(const T &lambda, const T &mu, const T &mu_scv, unsigned K)
MacGregor Smith's closed-form approximation of the M/G/1/K loss probability.
T qsys_gigk_rqt_gamma(const T &rho, const T &mu, const T &Gamma_a, const T &sigma_s, std::size_t k, const T &alpha_a, const std::string &regime="independent")
Service variability parameter of the Robust Queueing Theory (RQT) framework.
QsysResult< T > qsys_gig1_approx_allencunneen(const T &lambda, const T &mu, const T &ca, const T &cs)
Allen-Cunneen approximation of the mean response time of a G/I/G/1 queue.
QsysResult< T > qsys_mmk(const T &lambda, const T &mu, unsigned k)
Exact mean response time of the M/M/k queue (Erlang-C).
Definition qsys_mmk.h:67
QsysResult< T > qsys_gig1_approx_heyman(const T &lambda, const T &mu, const T &ca, const T &cs)
Heyman approximation of the mean response time of a G/I/G/1 queue.
QsysResult< T > qsys_gg1(const T &lambda, const T &mu, const T &ca2, const T &cs2)
G/G/1 dispatcher: exact where a two-moment description determines the answer, Allen-Cunneen otherwise...
Definition qsys_gg1.h:118
QsysResult< T > qsys_gig1_approx_klb(const T &lambda, const T &mu, const T &ca, const T &cs)
Kraemer and Langenbach-Belz approximation for the G/I/G/1 queue.
Mg1PrioResult< T > qsys_mg1_prio(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 with non-preemptive head-of-line priorities: per-class mean response times from the Cobham/Klei...
Mg1PrioPrResult< T > qsys_mg1_prio_pr(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs, const std::vector< T > &ES3=std::vector< T >())
M/G/1 with preemptive-resume priorities.
Mg1DisciplineResult< T > qsys_mg1_psjf(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under PSJF (preemptive shortest job first).
QsysResult< T > qsys_gig1_ubnd_kingman(const T &lambda, const T &mu, const T &ca, const T &cs)
Kingman upper bound on the mean waiting time of a G/G/1 queue.
Mg1DisciplineResult< T > qsys_mg1_setf(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under SETF (shortest elapsed time first), the non-preemptive counterpart of FB/LAS.
Gig1RqResult< T > qsys_gig1_rq(const T &rho, const T &mu, const T &cs2, IaFun &&IaFun_)
Robust Queueing (RQ) approximation of a G/GI/1 queue characterized by its arrival index of dispersion...
QsysResult< T > qsys_gig1_approx_kimura(const T &lambda, const T &mu, const T &ca, const T &cs)
Kimura diffusion-interpolation approximation for the G/I/G/1 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
RootResult< T > root_brent(F f, const T &a0, const T &b0, const T &tol, unsigned maxiter=200)
Brent's method on a bracket with a sign change.
Definition rootfind.h:130
A queueing network and its refreshed NetworkStruct.
Marie's iterative aggregation-decomposition for closed networks with FCFS general (Coxian) service.
Exact analysis of the finite-source D/D/c/K/K machine-repair model.
G/G/1 dispatcher: exact where a two-moment description determines the answer, Allen-Cunneen otherwise...
Diffusion approximation for the G/GI/n/m queue.
Allen-Cunneen approximation of the mean response time of a G/I/G/1 queue.
Gelenbe diffusion approximation with instantaneous-return boundary.
Heyman approximation of the mean response time of a G/I/G/1 queue.
Kimura diffusion-interpolation approximation for the G/I/G/1 queue.
Kraemer and Langenbach-Belz approximation for the G/I/G/1 queue.
Kobayashi diffusion approximation for the G/I/G/1 queue.
Marchal approximation of the mean response time of a G/I/G/1 queue.
Extremal two-moment bounds for the GI/GI/1 queue.
Robust Queueing (RQ) approximation of a G/GI/1 queue characterized by its arrival index of dispersion...
Kingman upper bound on the mean waiting time of a G/G/1 queue.
Default G/I/G/k approximation of the mean response time.
Kingman (Lee-Longton) scaling of the exact M/M/k waiting time.
Whitt (1993) approximation for the GI/G/k queue, eqs.
Robust Queueing Theory (RQT) worst-case system time of a G/G/k FCFS queue.
Service variability parameter of the Robust Queueing Theory (RQT) framework.
Exact analysis of the GI/M/c queue (Takacs, 1962).
Exact mean response time of the G/M/1 queue.
Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
M/G/1 FCFS with server breakdowns: Queue.setBreakdown with no down service.
M/G/1 under FB (feedback), also called LAS (least attained service).
M/G/1 under LRPT (longest remaining processing time).
M/G/1 with non-preemptive head-of-line priorities: per-class mean response times from the Cobham/Klei...
M/G/1 with preemptive-resume priorities: per-class mean (and optionally variance of the) response tim...
M/G/1 under PSJF (preemptive shortest job first).
M/G/1 under SETF (shortest elapsed time first), the non-preemptive counterpart of FB/LAS.
M/G/1 with non-preemptive shortest-job-first scheduling: per-class mean response times.
M/G/1 under SRPT (shortest remaining processing time), by the Schrage-Miller formula.
MacGregor Smith's closed-form approximation of the M/G/1/K loss probability.
Exact analysis of the finite-source M/G/1/K/K (machine-repair) queue.
Engineering solution of the call-center model M/GI/s/r+GI.
Exact mean response time of the M/M/1 queue.
Multiclass M/M/1 under DPS (discriminatory processor sharing), solved numerically on the truncated po...
M/M/c with non-preemptive (head-of-line) priorities and a common exponential service rate (Cobham,...
Exact analysis of the finite-source M/M/c/K/K (machine-repair) queue.
Exact mean response time of the M/M/k queue (Erlang-C).
Halfin-Whitt QED approximation for the M/M/s queue, and the square-root staffing rule that inverts it...
M^X/G/1: the FCFS batch-Poisson queue with general service.
M^X/M/1: the batch-arrival queue with exponential service.
Exact PH/M/1, the GI/M/1 queue with phase-type interarrival times.
Deterministic scalar root finding.
Port of matlab/src/api/sn/sn_has_bursty_arrival.m.
Port of matlab/src/api/sn/sn_patience_handles.m.
Port of matlab/src/api/sn/sn_renewal_lst.m.
The DECLARED side of the gate: one feature set per solver.
SolverMVA method 'amva.mapqn': the horizontal-cut mean value analysis (mapqn_amva) of a closed multic...
SolverMVA over a SolverLN layer.
The non-reentrant cache analyzer: a Source-Cache-Sink model.
Integrated caching-queueing analyzer, a port of matlab/src/solvers/MVA/solver_mva_cacheqn_analyzer....
Port of solver_mva_cacheqn_retrieval_analyzer.m: a CLOSED integrated cache-queueing model whose Cache...
Exact mean-value analysis for networks with order-independent stations.
The multiclass open polling analyzer (ladder branch 5).
Delayed-hit (retrieval-system) cache analyzer, a port of matlab/src/solvers/MVA/solver_mva_retrieval_...
Closed networks with shortest-job-next (SJF) stations, ladder branch 0.
MVAC, exact mean value analysis BY CHAIN (Conway, de Souza e Silva and Lavenberg, IEEE Trans.
QNA, the two-moment open-network decomposition analyzer.
Robust Queueing Network Analyzer (RQNA), a port of matlab/src/solvers/MVA/solver_rqna....
Robust Queueing Network Analyzer (RQNA) of Robust Queueing Theory, a port of matlab/src/solvers/MVA/s...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
Outcome of a scalar solve.
Definition rootfind.h:52
bool converged
tolerance was met before the iteration cap
Definition rootfind.h:57
T root
best estimate of the root
Definition rootfind.h:53
The patience law of one station-class pair, in the forms the solvers consume.
qsys::Patience< T > as_patience() const
This law as the Patience argument of the abandonment solvers.
bool present
Whether the pair declares reneging at all; everything below is unset when false.
bool isExponential
Whether the law is exponential, in which case the analysis is exact.
T rate
The abandonment rate 1/mean.
bool has_map() const
True when the type carries a (D0,D1) pair of its own.
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
Definition lang_types.h:921
std::vector< Matrix< T > > Dmark
MMAP per-class D1 blocks / BMAP per-batch-size blocks; empty otherwise.
Definition lang_types.h:931
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Matrix< T > D0
Definition map_moment.h:54
What the cache analyzer reports beyond the [Q,U,R,T] block.
std::vector< T > hitprob
per class, NaN where the class does not read
std::vector< T > missprob
Matrix< T > itemprob
(n x h+1) per-item occupancy, column 0 = miss.
Matrix< T > hitproblist
(R x h) per-list hit fractions, access-weighted over items.
The chain-level view of a layer, as sn_get_demands_chain returns it.
Definition sn_chain.h:46
std::vector< double > Nchain
(C) population, infinite for an open chain
Definition sn_chain.h:51
Matrix< T > STchain
(M x C) mean service time
Definition sn_chain.h:48
Matrix< T > Lchain
(M x C) demand
Definition sn_chain.h:47
Matrix< T > Vchain
(M x C) visits
Definition sn_chain.h:49
Matrix< T > SCVchain
(M x C)
Definition sn_chain.h:52
Class-level results, as sn_deaggregate_chain_results returns them.
Definition sn_chain.h:204
std::vector< T > C
Definition sn_chain.h:206
std::vector< T > X
Definition sn_chain.h:206
What the dispatch returns: the metrics plus the algorithm that produced them.
std::string actualmethod
The concrete algorithm, as the reference's actualmethod.
std::string warning
Non-empty when the analyzer that ran would have raised a reference line_warning and still returned a ...
solvers::CacheMetrics< T > cache
What a cache branch measured, EMPTY on every model without a Cache.
std::shared_ptr< qn::NetworkStruct< T > > refreshed_struct
Set only by the integrated cacheqn branch: the converged struct whose routing carries the actual hit/...
The cache half of the reference's return list: the (ncaches x nclasses) hit and miss split,...
Matrix< T > missprob
(ncaches x nclasses)
Matrix< T > hitprob
(ncaches x nclasses)
std::vector< Matrix< T > > itemprob
per cache, (n x h+1); EMPTY = not computed
What the closed delayed-hit analyzer returns.
std::vector< T > delayedprob
(K) zero on this path, by the reference's convention
Matrix< T > hitproblist
(K x h) NaN: not computed on this path
std::vector< T > missprob
(K) the delayed fraction is folded in here
std::vector< T > latency
(K) NaN: not computed on this path
std::vector< T > hitprob
(K) P(item cached), read class only
The options SolverMVA reads.
Definition mva_types.h:32
std::string method
Definition mva_types.h:33
The cache half of the reference's return list: hitprob, missprob, delayedprob, latency,...
Matrix< T > itemprob
(n x h+1), column 0 = miss
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
std::vector< T > C
Definition mva_types.h:99
What the analyzer returns, the reference's metrics plus its actualmethod.
Result of pfqn_marie, mirroring the six MATLAB outputs.
Definition pfqn_marie.h:342
int it
iterations performed
Definition pfqn_marie.h:353
Matrix< T > Q
(M x R) mean queue length
Definition pfqn_marie.h:344
std::vector< T > X
(R) per-class throughput
Definition pfqn_marie.h:343
Matrix< T > U
(M x R) utilization
Definition pfqn_marie.h:345
Server breakdown and repair of a station whose server fails and is repaired.
lang::Distrib< T > repair
time to repair of a down server
lang::Distrib< T > failure
time to failure of an up server
std::vector< T > down_service_rates
sn.downServiceRates(ist, :): per class, 0 = no service while down.
One job class of the network.
double population
infinite for an open class
A node of the network.
One station of the network.
The four outputs [W, Wq, U, Q] of qsys_mxg1, qsys_mg1_vacation and qsys_mg1_breakdown.
Definition qsys_mxg1.h:39
T W
mean response (sojourn) time of an arbitrary job
Definition qsys_mxg1.h:40
T U
server utilization (fraction of time doing work)
Definition qsys_mxg1.h:42
std::vector< double > W
per-class mean response time
T W
mean time in system
Definition qsys_mxm1.h:44
T U
server utilization rho
Definition qsys_mxm1.h:46
Steady-state measures of a multiserver queue with customer abandonment.
Steady-state measures of the G/GI/n/m diffusion approximation.
T meanNumber
mean number in system
MATLAB's res struct: named measures in insertion order, plus res.analyzer.
Definition qsys_res.h:57
T scalar(const std::string &name) const
The scalar field name; throws when absent.
Definition qsys_res.h:67
Every Cache node of the model, in node order; empty on a model with none.