LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
api_dispatch.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 *
5 * The --api dispatch table.
6 *
7 * One entry per exposed function, hand written: it pulls its named arguments
8 * out of the parsed JSON and calls the templated function at the arithmetic
9 * the caller selected. Registry-generated dispatch is the eventual goal, but a
10 * generated table cannot know that pfqn_conv takes callables it must refuse or
11 * that pfqn_comom's Z is a vector where pfqn_comomrm's is a matrix, so the
12 * table is explicit while the argument shapes are being pinned down.
13 *
14 * Compiled once into a static library rather than instantiated per translation
15 * unit: three arithmetics times a dozen algorithms is a lot of template
16 * instantiation to repeat in the CLI, the tests and a future binding.
17 */
18
20#include "api_dispatch_detail.h"
21
22#include <algorithm>
23#include <cctype>
24#include <cmath>
25#include <functional>
26#include <map>
27#include <sstream>
28#include <stdexcept>
29
61#include "line/api/fj/fj_rmax.h"
101#include "line/api/mc/ctmc_kms.h"
191
192namespace line {
193namespace reg {
194
195// Arithmetic selection
196
197std::string ArithSpec::str() const {
198 switch (mode) {
199 case Arith::Double: return "double";
200 case Arith::Exact: return "exact";
201 case Arith::Real: return "real:" + std::to_string(digits);
202 }
203 return "?";
204}
205
206ArithSpec parse_arith(const std::string& text) {
207 ArithSpec s;
208 if (text == "double") {
210 return s;
211 }
212 if (text == "exact") {
213 s.mode = Arith::Exact;
214 return s;
215 }
216 if (text.compare(0, 5, "real:") == 0 || text == "real") {
217 unsigned want = 50;
218 if (text != "real") {
219 const std::string d = text.substr(5);
220 if (d.empty() || d.find_first_not_of("0123456789") != std::string::npos)
221 throw InputError("--arith real:<digits> needs a decimal digit count, got '" + d +
222 "'");
223 want = static_cast<unsigned>(std::strtoul(d.c_str(), nullptr, 10));
224 if (want == 0) throw InputError("--arith real:<digits> needs at least one digit");
225 }
226 s.mode = Arith::Real;
227 // Round UP to an instantiated tier: never give less precision than asked.
228 if (want <= 50)
229 s.digits = 50;
230 else if (want <= 100)
231 s.digits = 100;
232 else if (want <= 200)
233 s.digits = 200;
234 else
235 throw UnsupportedError(ErrorKind{"Arithmetic"},
236 "--arith real:" + std::to_string(want) +
237 " exceeds the precision tiers this build instantiates (50, 100, 200 digits); "
238 "a wider tier has to be compiled in, it cannot be selected at run time.");
239 return s;
240 }
241 throw InputError("unknown --arith '" + text +
242 "'; accepted forms are: double, exact, real:<digits> "
243 "(digits rounded up to 50, 100 or 200)");
244}
245
246// ---------------------------------------------------------------------------
247// The table
248// ---------------------------------------------------------------------------
249
250namespace {
251
252/** G and lG, the shape most of the normalizing-constant family returns. */
253template <class T>
254Json nc_results(const pfqn::NcResult<T>& r) {
255 Json out;
256 out["G"] = encode_scalar(r.G);
257 out["lG"] = r.lG;
258 return out;
259}
260
261struct OpPfqnCa {
262 template <class T>
263 static Json run(Args& a) {
264 const Matrix<T> L = a.matrix<T>("L");
265 const std::vector<int> N = a.ints("N");
266 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
267 a.done();
268 return nc_results(pfqn::pfqn_ca(L, N, Z));
269 }
270};
271
272struct OpPfqnConv {
273 template <class T>
274 static Json run(Args& a) {
275 const Matrix<T> L = a.matrix<T>("L");
276 const std::vector<int> N = a.ints("N");
277 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
278 a.unsupported("cdscaling",
279 "the class-dependence scaling argument is a vector of callables, which has "
280 "no JSON representation; call pfqn_conv from the library for that case");
281 a.unsupported("options", "solver options are not carried over the --api boundary");
282 a.done();
283 return nc_results(pfqn::pfqn_conv(L, N, Z));
284 }
285};
286
287struct OpPfqnRecal {
288 template <class T>
289 static Json run(Args& a) {
290 const Matrix<T> L = a.matrix<T>("L");
291 const std::vector<int> N = a.ints("N");
292 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
293 const std::vector<int> m0 = a.ints_or_empty("m0");
294 a.done();
295 return nc_results(pfqn::pfqn_recal(L, N, Z, m0));
296 }
297};
298
299struct OpPfqnGld {
300 template <class T>
301 static Json run(Args& a) {
302 const Matrix<T> L = a.matrix<T>("L");
303 const std::vector<int> N = a.ints("N");
304 const Matrix<T> mu = a.matrix<T>("mu");
305 a.unsupported("options", "solver options are not carried over the --api boundary");
306 a.done();
307 return nc_results(pfqn::pfqn_gld(L, N, mu));
308 }
309};
310
311struct OpPfqnMva {
312 template <class T>
313 static Json run(Args& a) {
314 const Matrix<T> L = a.matrix<T>("L");
315 const std::vector<int> N = a.ints("N");
316 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
317 const std::vector<int> mi = a.ints_or_empty("mi");
318 a.done();
319 const pfqn::MvaResult<T> r = pfqn::pfqn_mva(L, N, Z, mi);
320 Json out;
321 out["XN"] = encode_vector(r.XN);
322 out["QN"] = encode_matrix(r.QN);
323 out["UN"] = encode_matrix(r.UN);
324 out["CN"] = encode_matrix(r.CN);
325 out["G"] = encode_scalar(r.G);
326 out["lG"] = r.lG;
327 return out;
328 }
329};
330
331/** G, lG and the CoMoM basis. */
332template <class T>
333Json comom_results(const pfqn::ComomResult<T>& r) {
334 Json out;
335 out["G"] = encode_scalar(r.G);
336 out["lG"] = r.lG;
337 out["basis"] = encode_vector(r.basis);
338 return out;
339}
340
341struct OpPfqnComom {
342 template <class T>
343 static Json run(Args& a) {
344 const Matrix<T> L = a.matrix<T>("L");
345 const std::vector<int> N = a.ints("N");
346 const std::vector<T> Z = a.vector_or_empty<T>("Z");
347 const T atol = a.scalar<T>("atol", num_traits<T>::from_int(0));
348 a.done();
349 return comom_results(pfqn::pfqn_comom(L, N, Z, atol));
350 }
351};
352
353struct OpPfqnComomrm {
354 template <class T>
355 static Json run(Args& a) {
356 const Matrix<T> L = a.matrix<T>("L");
357 const std::vector<int> N = a.ints("N");
358 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
359 const int m = a.integer("m", 1);
360 a.done();
361 return comom_results(pfqn::pfqn_comomrm(L, N, Z, m));
362 }
363};
364
365struct OpPfqnComomrmOrig {
366 template <class T>
367 static Json run(Args& a) {
368 const Matrix<T> L = a.matrix<T>("L");
369 const std::vector<int> N = a.ints("N");
370 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
371 const T atol = a.scalar<T>("atol", num_traits<T>::from_int(0));
372 a.done();
373 return comom_results(pfqn::pfqn_comomrm_orig(L, N, Z, atol));
374 }
375};
376
377struct OpPfqnComomrmMs {
378 template <class T>
379 static Json run(Args& a) {
380 const Matrix<T> L = a.matrix<T>("L");
381 const std::vector<int> N = a.ints("N");
382 const Matrix<T> Z = a.matrix_or_empty<T>("Z");
383 const int m = a.integer("m", 1);
384 const int S = a.integer("S", 1);
385 a.done();
386 const pfqn::ComomRmResult<T> r = pfqn::pfqn_comomrm_ms(L, N, Z, m, S);
387 Json out;
388 out["G"] = encode_scalar(r.G);
389 out["lG"] = r.lG;
390 out["prob"] = encode_vector(r.prob);
391 return out;
392 }
393};
394
395struct OpPfqnProcomom {
396 template <class T>
397 static Json run(Args& a) {
398 const Matrix<T> L = a.matrix<T>("L");
399 const std::vector<int> N = a.ints("N");
400 const std::vector<T> Z = a.vector_or_empty<T>("Z");
401 const T atol = a.scalar<T>("atol", num_traits<T>::from_int(0));
402 a.done();
403 const pfqn::ProcomomResult<T> r = pfqn::pfqn_procomom(L, N, Z, atol);
404 Json out;
405 out["Pr"] = encode_matrix(r.Pr);
406 out["Q"] = encode_vector(r.Q);
407 out["rankdef"] = r.rankdef;
408 return out;
409 }
410};
411
412struct OpCtmcSolve {
413 template <class T>
414 static Json run(Args& a) {
415 const Matrix<T> Q = a.matrix<T>("Q");
416 a.unsupported("options", "solver options are not carried over the --api boundary");
417 a.done();
418 Json out;
419 out["p"] = encode_vector(mc::ctmc_solve(Q));
420 return out;
421 }
422};
423
424struct OpDtmcSolve {
425 template <class T>
426 static Json run(Args& a) {
427 const Matrix<T> P = a.matrix<T>("P");
428 a.unsupported("options", "solver options are not carried over the --api boundary");
429 a.done();
430 Json out;
431 out["PROB"] = encode_vector(mc::dtmc_solve(P));
432 return out;
433 }
434};
435
436struct OpCtmcMakeinfgen {
437 template <class T>
438 static Json run(Args& a) {
439 const Matrix<T> Q = a.matrix<T>("Q");
440 a.done();
441 Json out;
442 out["Q"] = encode_matrix(mc::ctmc_makeinfgen(Q));
443 return out;
444 }
445};
446
447// ---------------------------------------------------------------------------
448// api/sim, the simulation output analysis family
449// ---------------------------------------------------------------------------
450
451/*
452 * EXACT ARITHMETIC IS REFUSED BY EVERY ENTRY BELOW, and the refusal has to be a
453 * runtime branch even though the registry already gates it: `run_at` names all
454 * three arithmetics in one switch, so the Rational instantiation is COMPILED
455 * whether or not it can be reached, and the family's `static_assert` would fire
456 * at build time. The `if constexpr` guard is what keeps the translation unit
457 * compilable, exactly as the mdd path in the CLI does.
458 *
459 * There is no `--api sym_*` counterpart. `api/sym` is a backend, not a family of
460 * numeric functions: it has no MATLAB `sym_*` entry points to mirror, and what
461 * it serves reaches the user through the solvers that call it (`--symbolic` on
462 * fluid, the CTMC symbolic getters). Exposing a REST client as an `--api`
463 * function would invent a signature that exists in no other codebase.
464 */
465
466/** Option overrides and whether the caller gave any, which FIRQUEST reads. */
467struct QuestOptionsRead {
468 sim::QuestOptions opt;
469 bool supplied = false;
470};
471
472/** The QUEST option overrides, read from the same keys MATLAB's struct uses. */
473QuestOptionsRead read_quest_options(Args& a) {
474 QuestOptionsRead out;
475 const char* keys[] = {"b0", "m0", "s", "beta", "eta", "theta", "weight", "force"};
476 for (std::size_t k = 0; k < sizeof(keys) / sizeof(keys[0]); ++k)
477 if (a.has(keys[k])) out.supplied = true;
478 out.opt.b0 = static_cast<long>(a.integer("b0", static_cast<int>(out.opt.b0)));
479 out.opt.m0 = static_cast<long>(a.integer("m0", static_cast<int>(out.opt.m0)));
480 const std::vector<int> s = a.ints_or_empty("s");
481 if (!s.empty()) {
482 out.opt.s.clear();
483 for (std::size_t i = 0; i < s.size(); ++i) out.opt.s.push_back(static_cast<long>(s[i]));
484 }
485 out.opt.beta = a.scalar<double>("beta", out.opt.beta);
486 out.opt.eta = a.scalar<double>("eta", out.opt.eta);
487 out.opt.theta = a.scalar<double>("theta", out.opt.theta);
488 out.opt.weight = a.scalar<double>("weight", out.opt.weight);
489 out.opt.force = a.integer("force", out.opt.force ? 1 : 0) != 0;
490 return out;
491}
492
493/** The shared shape of `sim_fquest` and `sim_firquest`. */
494template <class T>
495Json quest_results(const sim::QuestResult<T>& r) {
496 Json out;
497 out["estimate"] = encode_scalar(r.estimate);
498 out["lower"] = encode_scalar(r.lower);
499 out["upper"] = encode_scalar(r.upper);
500 out["halfwidth"] = encode_scalar(r.halfwidth);
501 out["b"] = static_cast<long long>(r.b);
502 out["m"] = static_cast<long long>(r.m);
503 out["n"] = static_cast<long long>(r.n);
504 out["R"] = static_cast<long long>(r.R);
505 out["truncated"] = static_cast<long long>(r.truncated);
506 out["Ap"] = encode_scalar(r.Ap);
507 out["Np"] = encode_scalar(r.Np);
508 out["Vp"] = encode_scalar(r.Vp);
509 out["heuristic"] = r.heuristic;
510 out["warnings"] = r.warnings;
511 return out;
512}
513
514/** The message every exact-arithmetic refusal in this family shares. */
515std::string sim_exact_refusal(const char* fn, const char* why) {
516 return std::string(fn) + ": " + why +
517 ", so exact rational arithmetic has nothing to preserve and is refused; rerun with "
518 "--arith double or --arith real";
519}
520
521struct OpSimVonneumann {
522 template <class T>
523 static Json run(Args& a) {
524 if constexpr (!num_traits<T>::has_transcendental) {
525 throw UnsupportedError(ErrorKind{"Arithmetic"},
526 sim_exact_refusal("sim_vonneumann", "the p-value is a normal tail"));
527 } else {
528 const std::vector<T> x = vector_from_json<T>(a.get("x"), "sim_vonneumann: x");
529 const double alpha = a.scalar<double>("alpha", 0.05);
530 a.done();
531 const sim::VonNeumannResult<T> r = sim::sim_vonneumann(x, alpha);
532 Json out;
533 out["ratio"] = encode_scalar(r.ratio);
534 out["zscore"] = r.zscore;
535 out["pvalue"] = r.pvalue;
536 out["reject"] = r.reject;
537 out["nobs"] = static_cast<long long>(r.nobs);
538 return out;
539 }
540 }
541};
542
543struct OpSimShapirowilk {
544 template <class T>
545 static Json run(Args& a) {
546 if constexpr (!num_traits<T>::has_transcendental) {
547 throw UnsupportedError(ErrorKind{"Arithmetic"}, sim_exact_refusal(
548 "sim_shapirowilk", "the weights and the p-value are normal-order statistics"));
549 } else {
550 const std::vector<T> x = vector_from_json<T>(a.get("x"), "sim_shapirowilk: x");
551 const double alpha = a.scalar<double>("alpha", 0.05);
552 a.done();
553 const sim::ShapiroWilkResult<T> r = sim::sim_shapirowilk(x, alpha);
554 Json out;
555 out["W"] = encode_scalar(r.W);
556 out["pvalue"] = r.pvalue;
557 out["zscore"] = r.zscore;
558 out["reject"] = r.reject;
559 out["nobs"] = static_cast<long long>(r.nobs);
560 return out;
561 }
562 }
563};
564
565struct OpSimStsQuantileAreas {
566 template <class T>
567 static Json run(Args& a) {
568 if constexpr (!num_traits<T>::has_transcendental) {
569 throw UnsupportedError(ErrorKind{"Arithmetic"}, sim_exact_refusal(
570 "sim_sts_quantile_areas", "the areas carry the irrational weight sqrt(12)"));
571 } else {
572 const std::vector<T> Y =
573 vector_from_json<T>(a.get("Y"), "sim_sts_quantile_areas: Y");
574 const int b = a.integer("b", 0);
575 const int m = a.integer("m", 0);
576 const double p = a.scalar<double>("p", 0.5);
577 const double weight = a.scalar<double>("weight", std::sqrt(12.0));
578 a.done();
579 if (b <= 0 || m <= 0)
580 throw InputError(
581 "sim_sts_quantile_areas: the batch count b and batch size m are required and "
582 "must be positive integers");
583 const sim::StsQuantileStats<T> r = sim::sim_sts_quantile_areas(
584 Y, static_cast<std::size_t>(b), static_cast<std::size_t>(m), p, weight);
585 Json out;
586 out["areas"] = encode_vector(r.areas);
587 out["bqe"] = encode_vector(r.bqe);
588 out["quantile"] = encode_scalar(r.quantile);
589 out["Ap"] = encode_scalar(r.Ap);
590 out["Np"] = encode_scalar(r.Np);
591 out["Vp"] = encode_scalar(r.Vp);
592 out["b"] = static_cast<long long>(r.b);
593 out["m"] = static_cast<long long>(r.m);
594 out["n"] = static_cast<long long>(r.n);
595 return out;
596 }
597 }
598};
599
600struct OpSimFquest {
601 template <class T>
602 static Json run(Args& a) {
603 if constexpr (!num_traits<T>::has_transcendental) {
604 throw UnsupportedError(ErrorKind{"Arithmetic"}, sim_exact_refusal(
605 "sim_fquest", "the interval is a t quantile times a square root"));
606 } else {
607 const std::vector<T> Y = vector_from_json<T>(a.get("Y"), "sim_fquest: Y");
608 const double p = a.scalar<double>("p", 0.5);
609 const double alpha = a.scalar<double>("alpha", 0.05);
610 const QuestOptionsRead o = read_quest_options(a);
611 a.done();
612 return quest_results(sim::sim_fquest(Y, p, alpha, o.opt));
613 }
614 }
615};
616
617struct OpSimFirquest {
618 template <class T>
619 static Json run(Args& a) {
620 if constexpr (!num_traits<T>::has_transcendental) {
621 throw UnsupportedError(ErrorKind{"Arithmetic"}, sim_exact_refusal(
622 "sim_firquest", "the interval is a t quantile times a square root"));
623 } else {
624 // MATLAB passes an (n x R) matrix, one column per replication; the
625 // C++ signature is replication-major, so the columns are transposed
626 // here rather than reinterpreted -- pooling order is what the
627 // procedure's stage tests act on.
628 const Matrix<T> Ym = a.matrix<T>("Y");
629 const double p = a.scalar<double>("p", 0.5);
630 const double alpha = a.scalar<double>("alpha", 0.05);
631 const QuestOptionsRead o = read_quest_options(a);
632 a.done();
633 std::vector<std::vector<T> > Y(Ym.cols(), std::vector<T>(Ym.rows()));
634 for (std::size_t i = 0; i < Ym.rows(); ++i)
635 for (std::size_t r = 0; r < Ym.cols(); ++r) Y[r][i] = Ym(i, r);
636 // A missing option set is not the same as the FQUEST defaults here:
637 // FIRQUEST's own defaults depend on R, and nullptr is how they are
638 // asked for.
639 return quest_results(
640 sim::sim_firquest(Y, p, alpha, o.supplied ? &o.opt : nullptr));
641 }
642 }
643};
644
645// ---------------------------------------------------------------------------
646// qsys: the closed-form queueing systems
647// ---------------------------------------------------------------------------
648//
649// The most mechanical part of the surface -- scalar rates and coefficients of
650// variation in, a named result struct out -- so it is exposed wholesale rather
651// than one function at a time. What is NOT exposed is exactly the set whose
652// MATLAB signature takes a FUNCTION: qsys_gig1_rq takes the interarrival law as
653// a handle, qsys_mg1k_loss a density, qsys_mapg1k / qsys_mapg1k_perflow /
654// qsys_mmapg1k a service law and qsys_ldps_workload a workload law. A callable
655// has no JSON representation, so those six report that from api_invoke's
656// not-exposed arm rather than being given an argument shape that silently
657// stands in for the caller's function.
658//
659// AN ABSENT OPTIONAL ARGUMENT CALLS THE PORT'S OWN SHORT OVERLOAD, never a
660// default written out here. Several of these functions carry a tuned default
661// (qsys_mapd1's 4096 arrival truncation, qsys_phmc's 50000 iterations,
662// qsys_phm1's 1e-16) and a plausible-looking value restated at this boundary
663// would answer a different question from the library and the reference.
664//
665// The KEYS ARE THE MATLAB PARAMETER NAMES, which is why qsys_mapmap1 reads its
666// ARRIVAL process from (C0, C1) and its SERVICE process from (D0, D1): that is
667// the order matlab/src/api/qsys/qsys_mapmap1.m declares, and the opposite
668// reading silently swaps the two processes of a stable queue for an unstable
669// one. The returned keys are the port's struct field names.
670
671/** [W, rhohat], what most of the family returns. */
672template <class T>
673Json qsys_results(const qsys::QsysResult<T>& r) {
674 Json out;
675 out["W"] = encode_scalar(r.W);
676 // MATLAB spells this `rho` in qsys_mm1/qsys_mmk and `rhohat` everywhere
677 // else; it is one quantity, the modified utilization, and it is reported
678 // under the port's single name so a host does not key on the file it came
679 // from.
680 out["rhohat"] = encode_scalar(r.rhohat);
681 return out;
682}
683
684/**
685 * The trailing `res` output of the exact closed forms (qsys_mm1, qsys_mmk,
686 * qsys_mg1, qsys_gm1, qsys_mg1_prio). MATLAB computes it when a further output
687 * is requested; JSON has no nargout, so it is asked for by name ("res": true)
688 * or implied by any option that only shapes it. Its measures are incomplete
689 * gamma tails, exponentials and bisection percentiles, evaluated in double as
690 * in the reference, so the exact arm refuses it.
691 */
692template <class T>
693bool want_qsys_res(Args& a, std::initializer_list<const char*> shaping) {
694 bool want = a.has("res") ? a.boolean("res", false) : false;
695 for (const char* k : shaping) want = want || a.has(k);
696 if (want && !num_traits<T>::has_transcendental)
697 throw UnsupportedError(ErrorKind{"Arithmetic"},
698 "the res measures (distributions, CDFs, percentiles) are transcendental and evaluated "
699 "in double precision; rerun with --arith double or --arith real");
700 return want;
701}
702
703template <class T>
704double qd(const T& v) { return num_traits<T>::to_double(v); }
705
706template <class T>
707std::vector<double> qd(const std::vector<T>& v) {
708 std::vector<double> o;
709 for (const T& x : v) o.push_back(num_traits<T>::to_double(x));
710 return o;
711}
712
713#define LINE_QSYS_GIG1(OpName, fn) \
714 struct OpName { \
715 template <class T> \
716 static Json run(Args& a) { \
717 const T lambda = a.number<T>("lambda"); \
718 const T mu = a.number<T>("mu"); \
719 const T ca = a.number<T>("ca"); \
720 const T cs = a.number<T>("cs"); \
721 a.done(); \
722 return qsys_results(qsys::fn(lambda, mu, ca, cs)); \
723 } \
724 }
725
726LINE_QSYS_GIG1(OpQsysGig1AllenCunneen, qsys_gig1_approx_allencunneen);
727LINE_QSYS_GIG1(OpQsysGig1Gelenbe, qsys_gig1_approx_gelenbe);
728LINE_QSYS_GIG1(OpQsysGig1Heyman, qsys_gig1_approx_heyman);
729LINE_QSYS_GIG1(OpQsysGig1Kimura, qsys_gig1_approx_kimura);
730LINE_QSYS_GIG1(OpQsysGig1Klb, qsys_gig1_approx_klb);
731LINE_QSYS_GIG1(OpQsysGig1Kobayashi, qsys_gig1_approx_kobayashi);
732LINE_QSYS_GIG1(OpQsysGig1Marchal, qsys_gig1_approx_marchal);
733LINE_QSYS_GIG1(OpQsysGig1Lbnd, qsys_gig1_lbnd);
734LINE_QSYS_GIG1(OpQsysGig1UbndKingman, qsys_gig1_ubnd_kingman);
735#undef LINE_QSYS_GIG1
736
737#define LINE_QSYS_GIGK(OpName, fn) \
738 struct OpName { \
739 template <class T> \
740 static Json run(Args& a) { \
741 const T lambda = a.number<T>("lambda"); \
742 const T mu = a.number<T>("mu"); \
743 const T ca = a.number<T>("ca"); \
744 const T cs = a.number<T>("cs"); \
745 const unsigned k = a.uinteger("k"); \
746 a.done(); \
747 return qsys_results(qsys::fn(lambda, mu, ca, cs, k)); \
748 } \
749 }
750
751LINE_QSYS_GIGK(OpQsysGigkApprox, qsys_gigk_approx);
752LINE_QSYS_GIGK(OpQsysGigkCosmetatos, qsys_gigk_approx_cosmetatos);
753LINE_QSYS_GIGK(OpQsysGigkKingman, qsys_gigk_approx_kingman);
754LINE_QSYS_GIGK(OpQsysGigkWhitt, qsys_gigk_approx_whitt);
755#undef LINE_QSYS_GIGK
756
757// The abandonment and QED families. Only the entry points whose arguments are
758// JSON-expressible are exposed here: qsys_mgisrgi_whitt with a general patience
759// law, qsys_ggisgi_fluid and qsys_mtginf all take CALLABLES (a hazard, a ccdf,
760// an arrival rate), which no argument object can carry, so they stay
761// library-only. qsys_erlanga is the exponential-patience case of the first, and
762// its whole model is five numbers.
763struct OpQsysErlangA {
764 template <class T>
765 static Json run(Args& a) {
766 const T lambda = a.number<T>("lambda");
767 const T mu = a.number<T>("mu");
768 const T theta = a.number<T>("theta");
769 const unsigned s = a.uinteger("s");
770 // JSON has no infinity, so an absent r is the unbounded waiting room.
771 const double r = a.has("r") ? num_traits<double>::to_double(a.number<double>("r"))
772 : std::numeric_limits<double>::infinity();
773 qsys::MgisrgiOptions opts;
774 opts.wPoints = a.vector_or_empty<double>("wPoints");
775 opts.maxQueue = a.count("maxQueue", qsys::MgisrgiOptions().maxQueue);
776 a.done();
777 const qsys::QsysAbandonResult<T> res = qsys::qsys_erlanga(lambda, mu, theta, s, r, opts);
778 Json out;
779 out["queueLengthDist"] = encode_vector(res.queueLengthDist);
780 out["probLoss"] = encode_scalar(res.probLoss);
781 out["probNoWait"] = encode_scalar(res.probNoWait);
782 out["probServed"] = encode_scalar(res.probServed);
783 out["probAbandon"] = encode_scalar(res.probAbandon);
784 out["meanNumber"] = encode_scalar(res.meanNumber);
785 out["varNumber"] = encode_scalar(res.varNumber);
786 out["meanQueueLength"] = encode_scalar(res.meanQueueLength);
787 out["varQueueLength"] = encode_scalar(res.varQueueLength);
788 out["utilization"] = encode_scalar(res.utilization);
789 out["throughput"] = encode_scalar(res.throughput);
790 out["abandonRate"] = encode_scalar(res.abandonRate);
791 out["meanWaitServed"] = encode_scalar(res.meanWaitServed);
792 out["varWaitServed"] = encode_scalar(res.varWaitServed);
793 out["meanWaitAbandon"] = encode_scalar(res.meanWaitAbandon);
794 out["varWaitAbandon"] = encode_scalar(res.varWaitAbandon);
795 out["meanWait"] = encode_scalar(res.meanWait);
796 out["secondMomentWait"] = encode_scalar(res.secondMomentWait);
797 out["numWaitingSpaces"] = static_cast<double>(res.numWaitingSpaces);
798 if (!res.waitPoints.empty()) {
799 out["waitPoints"] = encode_vector(res.waitPoints);
800 out["cdfWaitServed"] = encode_vector(res.cdfWaitServed);
801 out["cdfWaitAbandon"] = encode_vector(res.cdfWaitAbandon);
802 out["cdfWait"] = encode_vector(res.cdfWait);
803 }
804 return out;
805 }
806};
807
808struct OpQsysGgnmDiffusion {
809 template <class T>
810 static Json run(Args& a) {
811 const T lambda = a.number<T>("lambda");
812 const T mu = a.number<T>("mu");
813 const unsigned n = a.uinteger("n");
814 // JSON has no infinity, so an absent m is the unbounded waiting room.
815 const double m = a.has("m") ? a.number<double>("m")
816 : std::numeric_limits<double>::infinity();
817 const T ca = a.number<T>("ca");
818 const T cs = a.number<T>("cs");
819 a.done();
820 // The service ccdf is a callable, so the CLI can only offer the
821 // exponential default; the library entry point takes the general law.
822 const qsys::QsysGgnmResult<T> r = qsys::qsys_ggnm_diffusion<T>(lambda, mu, n, m, ca, cs);
823 Json out;
824 out["beta"] = encode_scalar(r.beta);
825 out["peakedness"] = encode_scalar(r.peakedness);
826 out["variability"] = encode_scalar(r.variability);
827 out["probDelay"] = encode_scalar(r.probDelay);
828 out["probBlock"] = encode_scalar(r.probBlock);
829 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
830 out["meanNumber"] = encode_scalar(r.meanNumber);
831 out["meanWait"] = encode_scalar(r.meanWait);
832 out["utilization"] = encode_scalar(r.utilization);
833 out["throughput"] = encode_scalar(r.throughput);
834 return out;
835 }
836};
837
838struct OpQsysGig1BndsExtremal {
839 template <class T>
840 static Json run(Args& a) {
841 const T lambda = a.number<T>("lambda");
842 const T mu = a.number<T>("mu");
843 const T ca = a.number<T>("ca");
844 const T cs = a.number<T>("cs");
845 const std::size_t K = a.count("K", 4000);
846 const std::size_t N = a.count("N", 2000);
847 const bool skipTight = a.boolean("skipTight", false);
848 a.done();
849 const qsys::Gig1ExtremalResult<T> r =
850 qsys::qsys_gig1_bnds_extremal(lambda, mu, ca, cs, K, N, skipTight);
851 Json out;
852 out["trafficIntensity"] = encode_scalar(r.trafficIntensity);
853 out["lowerBound"] = encode_scalar(r.lowerBound);
854 out["upperBound"] = encode_scalar(r.upperBound);
855 out["upperBoundClosed"] = encode_scalar(r.upperBoundClosed);
856 out["upperBoundDaley"] = encode_scalar(r.upperBoundDaley);
857 out["upperBoundKingman"] = encode_scalar(r.upperBoundKingman);
858 out["heavyTraffic"] = encode_scalar(r.heavyTraffic);
859 out["delta"] = encode_scalar(r.delta);
860 out["relativeWidth"] = encode_scalar(r.relativeWidth);
861 out["tightComputed"] = r.tightComputed;
862 return out;
863 }
864};
865
866struct OpQsysMmkQed {
867 template <class T>
868 static Json run(Args& a) {
869 const T lambda = a.number<T>("lambda");
870 const T mu = a.number<T>("mu");
871 const unsigned s = a.uinteger("s");
872 a.done();
873 const qsys::QsysQedResult<T> r = qsys::qsys_mmk_qed(lambda, mu, s);
874 Json out;
875 out["offeredLoad"] = encode_scalar(r.offeredLoad);
876 out["trafficIntensity"] = encode_scalar(r.trafficIntensity);
877 out["beta"] = encode_scalar(r.beta);
878 out["probDelay"] = encode_scalar(r.probDelay);
879 out["meanWaitDelayed"] = encode_scalar(r.meanWaitDelayed);
880 out["meanWait"] = encode_scalar(r.meanWait);
881 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
882 out["meanNumber"] = encode_scalar(r.meanNumber);
883 out["utilization"] = encode_scalar(r.utilization);
884 return out;
885 }
886};
887
888struct OpQsysMmkQedAlpha {
889 template <class T>
890 static Json run(Args& a) {
891 const T beta = a.number<T>("beta");
892 a.done();
893 Json out;
894 out["alpha"] = encode_scalar(qsys::qsys_mmk_qed_alpha(beta));
895 return out;
896 }
897};
898
899struct OpQsysMmkQedStaffing {
900 template <class T>
901 static Json run(Args& a) {
902 const T lambda = a.number<T>("lambda");
903 const T mu = a.number<T>("mu");
904 const std::string crit = a.text("criterion", "delay");
905 const T target = a.has("target") ? a.number<T>("target") : num_traits<T>::from_int(0);
906 const T deadline = a.has("deadline") ? a.number<T>("deadline") : num_traits<T>::from_int(0);
907 const T level = a.has("level") ? a.number<T>("level") : num_traits<T>::from_int(0);
908 const bool exact = a.boolean("exact", false);
909 a.done();
911 if (crit == "meanwait") {
913 } else if (crit == "servicelevel") {
915 } else if (crit != "delay") {
916 throw InputError("qsys_mmk_qed_staffing: unknown criterion '" + crit + "'");
917 }
918 const qsys::QsysQedStaffingResult<T> r =
919 qsys::qsys_mmk_qed_staffing(lambda, mu, target, c, deadline, level, exact);
920 Json out;
921 out["numServers"] = static_cast<double>(r.numServers);
922 out["beta"] = encode_scalar(r.beta);
923 out["betaTarget"] = encode_scalar(r.betaTarget);
924 out["offeredLoad"] = encode_scalar(r.offeredLoad);
925 out["probDelay"] = encode_scalar(r.probDelay);
926 out["meanWait"] = encode_scalar(r.meanWait);
928 out["serviceLevel"] = encode_scalar(r.serviceLevel);
929 return out;
930 }
931};
932
933// The RQT family takes uncertainty-set variability parameters rather than
934// coefficients of variation, and returns the worst case alongside the bound.
935struct OpQsysGigkRqt {
936 template <class T>
937 static Json run(Args& a) {
938 const T lambda = a.number<T>("lambda");
939 const T mu = a.number<T>("mu");
940 const T Gamma_a = a.number<T>("Gamma_a");
941 const T Gamma_s = a.number<T>("Gamma_s");
942 const unsigned k = a.uinteger("k");
943 const T alpha_a = a.number<T>("alpha_a");
944 const T alpha_s = a.number<T>("alpha_s");
945 a.done();
946 const qsys::GigkRqtResult<T> r =
947 qsys::qsys_gigk_rqt(lambda, mu, Gamma_a, Gamma_s, k, alpha_a, alpha_s);
948 Json out;
949 out["W"] = encode_scalar(r.W);
950 out["rhohat"] = encode_scalar(r.rhohat);
951 out["Sworst"] = encode_scalar(r.Sworst);
952 return out;
953 }
954};
955
956struct OpQsysGig1Rqt {
957 template <class T>
958 static Json run(Args& a) {
959 const T lambda = a.number<T>("lambda");
960 const T mu = a.number<T>("mu");
961 const T Gamma_a = a.number<T>("Gamma_a");
962 const T Gamma_s = a.number<T>("Gamma_s");
963 const T alpha_a = a.number<T>("alpha_a");
964 const T alpha_s = a.number<T>("alpha_s");
965 a.done();
966 const qsys::GigkRqtResult<T> r =
967 qsys::qsys_gig1_rqt(lambda, mu, Gamma_a, Gamma_s, alpha_a, alpha_s);
968 Json out;
969 out["W"] = encode_scalar(r.W);
970 out["rhohat"] = encode_scalar(r.rhohat);
971 out["Sworst"] = encode_scalar(r.Sworst);
972 return out;
973 }
974};
975
976struct OpQsysGigkRqtGamma {
977 template <class T>
978 static Json run(Args& a) {
979 const T rho = a.number<T>("rho");
980 const T mu = a.number<T>("mu");
981 const T Gamma_a = a.number<T>("Gamma_a");
982 const T sigma_s = a.number<T>("sigma_s");
983 const unsigned k = a.uinteger("k");
984 const T alpha_a = a.number<T>("alpha_a");
985 const std::string regime = a.text("regime", "independent");
986 a.done();
987 Json out;
988 out["Gamma_s"] =
989 encode_scalar(qsys::qsys_gigk_rqt_gamma(rho, mu, Gamma_a, sigma_s, k, alpha_a, regime));
990 return out;
991 }
992};
993
994#define LINE_QSYS_MYSKJA(OpName, fn) \
995 struct OpName { \
996 template <class T> \
997 static Json run(Args& a) { \
998 const T lambda = a.number<T>("lambda"); \
999 const T mu = a.number<T>("mu"); \
1000 const T ca = a.number<T>("ca"); \
1001 const T cs = a.number<T>("cs"); \
1002 const T q0 = a.number<T>("q0"); \
1003 const T qa = a.number<T>("qa"); \
1004 a.done(); \
1005 return qsys_results(qsys::fn(lambda, mu, ca, cs, q0, qa)); \
1006 } \
1007 }
1008
1009LINE_QSYS_MYSKJA(OpQsysGig1Myskja, qsys_gig1_approx_myskja);
1010LINE_QSYS_MYSKJA(OpQsysGig1Myskja2, qsys_gig1_approx_myskja2);
1011#undef LINE_QSYS_MYSKJA
1012
1013struct OpQsysMm1 {
1014 template <class T>
1015 static Json run(Args& a) {
1016 const T lambda = a.number<T>("lambda");
1017 const T mu = a.number<T>("mu");
1018 const bool want = want_qsys_res<T>(a, {"tPoints", "percentiles", "nmax"});
1019 const qsys::QsysResOptions o = read_qsys_res_options(a);
1020 a.done();
1021 Json out = qsys_results(qsys::qsys_mm1(lambda, mu));
1022 if (want) out["res"] = encode_qsys_res(qsys::qsys_mm1_res(qd(lambda), qd(mu), o));
1023 return out;
1024 }
1025};
1026
1027struct OpQsysMmk {
1028 template <class T>
1029 static Json run(Args& a) {
1030 const T lambda = a.number<T>("lambda");
1031 const T mu = a.number<T>("mu");
1032 const unsigned k = a.uinteger("k");
1033 const bool want = want_qsys_res<T>(a, {"tPoints", "percentiles", "nmax"});
1034 const qsys::QsysResOptions o = read_qsys_res_options(a);
1035 a.done();
1036 Json out = qsys_results(qsys::qsys_mmk(lambda, mu, k));
1037 if (want) out["res"] = encode_qsys_res(qsys::qsys_mmk_res(qd(lambda), qd(mu), k, o));
1038 return out;
1039 }
1040};
1041
1042struct OpQsysMg1 {
1043 template <class T>
1044 static Json run(Args& a) {
1045 const T lambda = a.number<T>("lambda");
1046 const T mu = a.number<T>("mu");
1047 const T cs = a.number<T>("cs");
1048 const bool want = want_qsys_res<T>(a, {"ES3"});
1049 const double ES3 = a.has("ES3") ? a.number<double>("ES3") : -1.0;
1050 a.done();
1051 Json out = qsys_results(qsys::qsys_mg1(lambda, mu, cs));
1052 if (want) out["res"] = encode_qsys_res(qsys::qsys_mg1_res(qd(lambda), qd(mu), qd(cs), ES3));
1053 return out;
1054 }
1055};
1056
1057struct OpQsysGg1 {
1058 template <class T>
1059 static Json run(Args& a) {
1060 const T lambda = a.number<T>("lambda");
1061 const T mu = a.number<T>("mu");
1062 const T ca2 = a.number<T>("ca2");
1063 const T cs2 = a.number<T>("cs2");
1064 a.done();
1065 return qsys_results(qsys::qsys_gg1(lambda, mu, ca2, cs2));
1066 }
1067};
1068
1069/** The one member of the family returning a bare scalar, MATLAB's `W`. */
1070struct OpQsysGm1 {
1071 template <class T>
1072 static Json run(Args& a) {
1073 const T sigma = a.number<T>("sigma");
1074 const T mu = a.number<T>("mu");
1075 const bool want = want_qsys_res<T>(a, {"lambda", "tPoints", "percentiles"});
1076 const double lambda = a.has("lambda") ? a.number<double>("lambda") : -1.0;
1077 const qsys::QsysResOptions o = read_qsys_res_options(a, false);
1078 a.done();
1079 Json out;
1080 out["W"] = encode_scalar(qsys::qsys_gm1(sigma, mu));
1081 if (want) out["res"] = encode_qsys_res(qsys::qsys_gm1_res(qd(sigma), qd(mu), lambda, o));
1082 return out;
1083 }
1084};
1085
1086struct OpQsysMginf {
1087 template <class T>
1088 static Json run(Args& a) {
1089 const T lambda = a.number<T>("lambda");
1090 const T mu = a.number<T>("mu");
1091 const bool has_k = a.has("k");
1092 const unsigned k = has_k ? a.uinteger("k") : 0u;
1093 a.done();
1094 const qsys::MginfResult<T> r =
1095 has_k ? qsys::qsys_mginf(lambda, mu, k) : qsys::qsys_mginf(lambda, mu);
1096 Json out;
1097 out["L"] = encode_scalar(r.L);
1098 out["Lq"] = encode_scalar(r.Lq);
1099 out["W"] = encode_scalar(r.W);
1100 out["Wq"] = encode_scalar(r.Wq);
1101 out["p0"] = encode_scalar(r.p0);
1102 // pk IS REPORTED ONLY WHEN IT EXISTS: the reference returns it for the
1103 // k the caller named and leaves it undefined otherwise, and a zero
1104 // there would read as a probability rather than as the absence of one.
1105 if (r.has_pk) out["pk"] = encode_scalar(r.pk);
1106 return out;
1107 }
1108};
1109
1110/**
1111 * qsys_mgck_sync. Unlike qsys_mapg1k its service law is read from a JSON
1112 * object, the MATLAB svc struct: {"type":"det","d":..}, {"type":"gamma",
1113 * "alpha":..,"theta":..} or {"type":"ph","alpha":[..],"T":[[..]]}. The
1114 * 'density' type takes a function handle and has no JSON form. 'tol' and
1115 * 'nmax' tune one truncation together, so naming either requires both.
1116 */
1117struct OpQsysMgckSync {
1118 template <class T>
1119 static Json run(Args& a) {
1120 const T lambda = a.number<T>("lambda");
1121 const std::size_t c = a.count("c");
1122 const std::size_t K = a.count("K");
1123 Args sv(a.get("svc"), "qsys_mgck_sync: svc");
1124 const std::string type = sv.text("type", "");
1125 qsys::ServiceLaw<T> svc;
1126 if (type == "det") {
1127 svc = qsys::ServiceLaw<T>::deterministic(sv.number<T>("d"));
1128 } else if (type == "gamma") {
1129 const T al = sv.number<T>("alpha");
1130 svc = qsys::ServiceLaw<T>::gamma(al, sv.number<T>("theta"));
1131 } else if (type == "ph") {
1132 const std::vector<T> al = sv.vector<T>("alpha");
1133 svc = qsys::ServiceLaw<T>::phase_type(al, sv.matrix<T>("T"));
1134 } else if (type == "density") {
1135 throw UnsupportedError(ErrorKind{"Api"},
1136 "qsys_mgck_sync: a 'density' service law is a function handle and has no "
1137 "named-JSON form; use 'det', 'gamma' or 'ph', or call it from the library");
1138 } else {
1139 throw UnsupportedError(ErrorKind{"Distribution"},
1140 "qsys_mgck_sync: svc.type must be 'det', 'gamma' or 'ph', got '" + type + "'");
1141 }
1142 sv.done();
1143 const std::string variant = a.text("variant", "");
1144 if (variant.empty()) throw InputError("qsys_mgck_sync: missing required argument 'variant'");
1145 const std::size_t nphases = a.count("nphases", 0);
1146 const bool any = a.has("tol") || a.has("nmax");
1147 if (any && !(a.has("tol") && a.has("nmax")))
1148 throw InputError("qsys_mgck_sync: 'tol' and 'nmax' tune one truncation together; "
1149 "give both or neither");
1150 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1151 const std::size_t nmax = a.count("nmax", 0);
1152 a.done();
1153 const qsys::MgckSyncResult<T> r =
1154 any ? qsys::qsys_mgck_sync(lambda, c, K, svc, variant, nphases, tol, nmax)
1155 : qsys::qsys_mgck_sync(lambda, c, K, svc, variant, nphases);
1156 Json out;
1157 out["queueLengthDist"] = encode_vector(r.queueLengthDist);
1158 out["p0"] = encode_scalar(r.p0);
1159 out["pK"] = encode_scalar(r.pK);
1160 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1161 out["meanQueueLengthQ"] = encode_scalar(r.meanQueueLengthQ);
1162 out["throughput"] = encode_scalar(r.throughput);
1163 out["lossProbability"] = encode_scalar(r.lossProbability);
1164 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1165 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1166 out["utilization"] = encode_scalar(r.utilization);
1167 out["variant"] = r.variant;
1168 out["nphases"] = r.nphases;
1169 out["stateSpaceSize"] = r.stateSpaceSize;
1170 out["analyzer"] = r.analyzer;
1171 return out;
1172 }
1173};
1174
1175struct OpQsysMmck {
1176 template <class T>
1177 static Json run(Args& a) {
1178 const T lambda = a.number<T>("lambda");
1179 const T mu = a.number<T>("mu");
1180 const unsigned c = a.uinteger("c");
1181 const unsigned K = a.uinteger("K");
1182 const qsys::QsysResOptions o = read_qsys_res_options(a, false);
1183 const bool dist = !o.tPoints.empty() || !o.percentiles.empty();
1184 if (dist && !num_traits<T>::has_transcendental)
1185 throw UnsupportedError(ErrorKind{"Arithmetic"},
1186 "qsys_mmck: the waiting and sojourn CDFs and percentiles are transcendental; rerun "
1187 "with --arith double or --arith real");
1188 a.done();
1189 const qsys::MmckResult<T> r = qsys::qsys_mmck(lambda, mu, c, K);
1190 Json out;
1191 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1192 out["meanQueueLengthQ"] = encode_scalar(r.meanQueueLengthQ);
1193 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1194 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1195 out["utilization"] = encode_scalar(r.utilization);
1196 out["throughput"] = encode_scalar(r.throughput);
1197 out["lossProbability"] = encode_scalar(r.lossProbability);
1198 out["queueLengthDist"] = encode_vector(r.queueLengthDist);
1199 out["varQueueLength"] = encode_scalar(r.varQueueLength);
1200 out["arrivalDist"] = encode_vector(r.arrivalDist);
1201 out["probWait"] = encode_scalar(r.probWait);
1202 out["condMeanWaitingTime"] = encode_scalar(r.condMeanWaitingTime);
1203 out["varWaitingTime"] = encode_scalar(r.varWaitingTime);
1204 out["varSojournTime"] = encode_scalar(r.varSojournTime);
1205 std::string analyzer = "exact:M/M/" + std::to_string(c) + "/" + std::to_string(K);
1206 if (dist) {
1207 const qsys::QsysRes d = qsys::qsys_mmck_dist(qd(lambda), qd(mu), c, K, o);
1208 const Json dj = encode_qsys_res(d);
1209 for (auto it = dj.begin(); it != dj.end(); ++it)
1210 if (it.key() != "analyzer") out[it.key()] = it.value();
1211 analyzer = d.analyzer;
1212 }
1213 out["analyzer"] = analyzer;
1214 return out;
1215 }
1216};
1217
1218struct OpQsysMm1kLoss {
1219 template <class T>
1220 static Json run(Args& a) {
1221 const T lambda = a.number<T>("lambda");
1222 const T mu = a.number<T>("mu");
1223 const unsigned K = a.uinteger("K");
1224 a.done();
1225 const qsys::Mm1kLossResult<T> r = qsys::qsys_mm1k_loss(lambda, mu, K);
1226 Json out;
1227 out["lossProbability"] = encode_scalar(r.lossProbability);
1228 out["utilization"] = encode_scalar(r.utilization);
1229 return out;
1230 }
1231};
1232
1233struct OpQsysMg1kLossMgs {
1234 template <class T>
1235 static Json run(Args& a) {
1236 const T lambda = a.number<T>("lambda");
1237 const T mu = a.number<T>("mu");
1238 const T mu_scv = a.number<T>("mu_scv");
1239 const unsigned K = a.uinteger("K");
1240 a.done();
1241 const qsys::Mg1kLossMgsResult<T> r = qsys::qsys_mg1k_loss_mgs(lambda, mu, mu_scv, K);
1242 Json out;
1243 out["lossProbability"] = encode_scalar(r.lossProbability);
1244 out["utilization"] = encode_scalar(r.utilization);
1245 return out;
1246 }
1247};
1248
1249/**
1250 * The batch-arrival M[X]/M/1. MATLAB's fourth argument is
1251 * `E_X2_or_Var_X`, whose reading depends on a trailing 'variance' flag; the two
1252 * readings are separate C++ overloads, so the boundary takes the two names
1253 * apart and refuses both at once rather than guessing which was meant.
1254 */
1255struct OpQsysMxm1 {
1256 template <class T>
1257 static Json run(Args& a) {
1258 const T lambda_batch = a.number<T>("lambda_batch");
1259 const T mu = a.number<T>("mu");
1260 const T E_X = a.number<T>("E_X");
1261 const bool has_m2 = a.has("E_X2"), has_var = a.has("Var_X");
1262 if (has_m2 == has_var)
1263 throw InputError(
1264 "qsys_mxm1: give exactly one of 'E_X2' (the second moment of the batch size) "
1265 "and 'Var_X' (its variance); MATLAB selects between them with a trailing "
1266 "'variance' flag, which has no place in a named-argument object");
1267 const T m2 = has_m2 ? a.number<T>("E_X2")
1268 : T(a.number<T>("Var_X") + E_X * E_X);
1269 a.done();
1270 const qsys::MxM1Result<T> r = qsys::qsys_mxm1(lambda_batch, mu, E_X, m2);
1271 Json out;
1272 out["W"] = encode_scalar(r.W);
1273 out["Wq"] = encode_scalar(r.Wq);
1274 out["U"] = encode_scalar(r.U);
1275 out["Q"] = encode_scalar(r.Q);
1276 return out;
1277 }
1278};
1279
1280template <class T>
1281Json mean_value_results(const qsys::MeanValueResult<T>& r) {
1282 Json out;
1283 out["W"] = encode_scalar(r.W);
1284 out["Wq"] = encode_scalar(r.Wq);
1285 out["U"] = encode_scalar(r.U);
1286 out["Q"] = encode_scalar(r.Q);
1287 return out;
1288}
1289
1290/** The batch law of qsys_mxg1 and qsys_mg1_vacation: exactly one of E_X2 and Var_X. */
1291template <class T>
1292T batch_second_moment(Args& a, const T& E_X, const char* fn) {
1293 const bool has_m2 = a.has("E_X2"), has_var = a.has("Var_X");
1294 if (has_m2 && has_var)
1295 throw InputError(ErrorKind("Argument"),
1296 std::string(fn) + ": give at most one of 'E_X2' (the second moment of the batch "
1297 "size) and 'Var_X' (its variance)");
1298 if (has_var) return T(a.number<T>("Var_X") + E_X * E_X);
1299 return a.number<T>("E_X2");
1300}
1301
1302struct OpQsysMxg1 {
1303 template <class T>
1304 static Json run(Args& a) {
1305 const T lambda_batch = a.number<T>("lambda_batch");
1306 const T mu = a.number<T>("mu");
1307 const T cs = a.number<T>("cs");
1308 const T E_X = a.number<T>("E_X");
1309 if (!a.has("E_X2") && !a.has("Var_X"))
1310 throw InputError(ErrorKind("Argument"),
1311 "qsys_mxg1: give one of 'E_X2' (the second moment of the batch size) and "
1312 "'Var_X' (its variance)");
1313 const T m2 = batch_second_moment<T>(a, E_X, "qsys_mxg1");
1314 a.done();
1315 return mean_value_results(qsys::qsys_mxg1(lambda_batch, mu, cs, E_X, m2));
1316 }
1317};
1318
1319struct OpQsysMg1Vacation {
1320 template <class T>
1321 static Json run(Args& a) {
1322 const T lambda = a.number<T>("lambda");
1323 const T mu = a.number<T>("mu");
1324 const T cs = a.number<T>("cs");
1325 const T EV = a.number<T>("EV");
1326 const T EV2 = a.number<T>("EV2");
1327 qsys::Mg1VacationOptions<T> opt;
1328 const std::string policy = a.text("policy", "multiple");
1329 if (policy == "multiple") {
1330 opt.policy = qsys::VacationPolicy::Multiple;
1331 } else if (policy == "single") {
1332 opt.policy = qsys::VacationPolicy::Single;
1333 } else {
1334 throw InputError(ErrorKind("Argument"), "qsys_mg1_vacation: unknown vacation policy '" + policy +
1335 "'; use 'multiple' or 'single'");
1336 }
1337 if (a.has("lst")) {
1338 opt.lst = a.number<T>("lst");
1339 opt.has_lst = true;
1340 }
1341 if (a.has("E_X")) {
1342 opt.E_X = a.number<T>("E_X");
1343 if (!a.has("E_X2") && !a.has("Var_X"))
1344 throw InputError(ErrorKind("Argument"),
1345 "qsys_mg1_vacation: a batch mean 'E_X' needs 'E_X2' or 'Var_X'");
1346 opt.E_X2 = batch_second_moment<T>(a, opt.E_X, "qsys_mg1_vacation");
1347 } else if (a.has("E_X2") || a.has("Var_X")) {
1348 throw InputError(ErrorKind("Argument"), "qsys_mg1_vacation: a batch second moment needs 'E_X'");
1349 }
1350 a.done();
1351 return mean_value_results(qsys::qsys_mg1_vacation(lambda, mu, cs, EV, EV2, opt));
1352 }
1353};
1354
1355struct OpQsysMg1Breakdown {
1356 template <class T>
1357 static Json run(Args& a) {
1358 const T lambda = a.number<T>("lambda");
1359 const T mu = a.number<T>("mu");
1360 const T cs = a.number<T>("cs");
1361 const T alpha = a.number<T>("alpha");
1362 const T ER = a.number<T>("ER");
1363 const T ER2 = a.number<T>("ER2");
1364 const T RLST = a.number<T>("RLST");
1365 a.done();
1366 return mean_value_results(qsys::qsys_mg1_breakdown(lambda, mu, cs, alpha, ER, ER2, RLST));
1367 }
1368};
1369
1370struct OpQsysDmc {
1371 template <class T>
1372 static Json run(Args& a) {
1373 const T lambda = a.number<T>("lambda_arr");
1374 const T mu = a.number<T>("mu");
1375 const unsigned c = a.uinteger("c");
1376 const bool tuned = a.has("truncation") || a.has("quadSteps");
1377 const unsigned truncation = a.uinteger("truncation", 0u);
1378 const unsigned quadSteps = a.uinteger("quadSteps", 200u);
1379 a.done();
1380 const qsys::DmcResult<T> r = tuned ? qsys::qsys_dmc(lambda, mu, c, truncation, quadSteps)
1381 : qsys::qsys_dmc(lambda, mu, c);
1382 Json out;
1383 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1384 out["meanWaitingQueue"] = encode_scalar(r.meanWaitingQueue);
1385 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1386 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1387 out["utilization"] = encode_scalar(r.utilization);
1388 return out;
1389 }
1390};
1391
1392struct OpQsysMmccRetrialFp {
1393 template <class T>
1394 static Json run(Args& a) {
1395 const T lambda = a.number<T>("lambda");
1396 const T mu = a.number<T>("mu");
1397 const unsigned c = a.uinteger("c");
1398 const bool tuned = a.has("tol") || a.has("maxiter") || a.has("p") || a.has("q");
1399 // An absent tol / maxiter keeps the MATLAB default (1e-10, 10000) when
1400 // only p or q is given.
1401 const T tol = a.scalar<T>("tol", a.has("p") || a.has("q") ? num_traits<T>::from_double(1e-10)
1402 : num_traits<T>::from_int(0));
1403 const std::size_t maxiter = a.count("maxiter", a.has("p") || a.has("q") ? 10000 : 0);
1404 const T p = a.scalar<T>("p", num_traits<T>::from_int(1));
1405 const T q = a.scalar<T>("q", num_traits<T>::from_int(1));
1406 a.done();
1407 const qsys::MmccRetrialFpResult<T> r =
1408 tuned ? qsys::qsys_mmcc_retrial_fp(lambda, mu, c, tol, maxiter, p, q)
1409 : qsys::qsys_mmcc_retrial_fp(lambda, mu, c);
1410 Json out;
1411 out["blockingProbability"] = encode_scalar(r.blockingProbability);
1412 out["retrialRate"] = encode_scalar(r.retrialRate);
1413 out["iterations"] = encode_count(r.iterations);
1414 out["converged"] = r.converged;
1415 out["lossProbability"] = encode_scalar(r.lossProbability);
1416 return out;
1417 }
1418};
1419
1420/** The "policy" argument of the M/G/1/1 and M/M/c/c retrial functions. */
1421inline qsys::RetrialPolicy retrial_policy_arg(Args& a, const char* fn) {
1422 const std::string pol = a.text("policy", "LINEAR");
1423 if (pol == "LINEAR") return qsys::RetrialPolicy::LINEAR;
1424 if (pol == "CONSTANT") return qsys::RetrialPolicy::CONSTANT;
1425 throw InputError(std::string(fn) + ": policy must be LINEAR or CONSTANT");
1426}
1427
1428struct OpQsysRetrialIsstable {
1429 template <class T>
1430 static Json run(Args& a) {
1431 const std::vector<T> lambda = a.vector<T>("lambda");
1432 const std::vector<T> mu = a.vector<T>("mu");
1433 const unsigned c = a.uinteger("c");
1434 const std::vector<T> alpha = a.vector_or_empty<T>("alpha");
1435 const qsys::RetrialPolicy policy = retrial_policy_arg(a, "qsys_retrial_isstable");
1436 const std::vector<T> p = a.vector_or_empty<T>("p");
1437 const std::vector<T> q = a.vector_or_empty<T>("q");
1438 const std::vector<T> gamma = a.vector_or_empty<T>("gamma");
1439 const double maxOrbit = a.has("maxOrbit") ? a.number<double>("maxOrbit") : -1.0;
1440 a.done();
1441 const qsys::RetrialStabilityResult<T> r =
1442 qsys::qsys_retrial_isstable(lambda, mu, c, alpha, policy, p, q, gamma, maxOrbit);
1443 Json out;
1444 out["isStable"] = r.isStable;
1445 // JSON has no infinity: an unbounded margin (q < 1 or a finite orbit,
1446 // stable whatever the load) is the string "Inf", as MATLAB's Inf.
1447 out["margin"] = std::isinf(num_traits<T>::to_double(r.margin)) ? Json("Inf")
1448 : encode_scalar(r.margin);
1449 out["reason"] = r.reason;
1450 return out;
1451 }
1452};
1453
1454struct OpQsysMg11Retrial {
1455 template <class T>
1456 static Json run(Args& a) {
1457 const T lambda = a.number<T>("lambda");
1458 const T mu = a.number<T>("mu");
1459 const T cs = a.number<T>("cs");
1460 const T nu = a.number<T>("nu");
1461 const qsys::RetrialPolicy policy = retrial_policy_arg(a, "qsys_mg11_retrial");
1462 a.done();
1463 const qsys::Mg11RetrialResult<T> r = qsys::qsys_mg11_retrial(lambda, mu, cs, nu, policy);
1464 Json out;
1465 out["N"] = encode_scalar(r.N);
1466 out["Norb"] = encode_scalar(r.Norb);
1467 out["R"] = encode_scalar(r.R);
1468 out["U"] = encode_scalar(r.U);
1469 Json res;
1470 res["meanQueueLength"] = encode_scalar(r.res.meanQueueLength);
1471 res["meanOrbitLength"] = encode_scalar(r.res.meanOrbitLength);
1472 res["meanResponseTime"] = encode_scalar(r.res.meanResponseTime);
1473 res["meanOrbitTime"] = encode_scalar(r.res.meanOrbitTime);
1474 res["utilization"] = encode_scalar(r.res.utilization);
1475 res["probIdle"] = encode_scalar(r.res.probIdle);
1476 res["probBlock"] = encode_scalar(r.res.probBlock);
1477 res["meanRetrials"] = r.res.hasMeanRetrials ? encode_scalar(r.res.meanRetrials) : Json(nullptr);
1478 res["probEmpty"] = r.res.hasProbEmpty ? encode_scalar(r.res.probEmpty) : Json(nullptr);
1479 res["throughput"] = encode_scalar(r.res.throughput);
1480 res["policy"] = policy == qsys::RetrialPolicy::LINEAR ? "LINEAR" : "CONSTANT";
1481 out["res"] = res;
1482 return out;
1483 }
1484};
1485
1486struct OpQsysMm11Retrial {
1487 template <class T>
1488 static Json run(Args& a) {
1489 const T lambda = a.number<T>("lambda");
1490 const T mu = a.number<T>("mu");
1491 const T nu = a.number<T>("nu");
1492 const qsys::RetrialPolicy policy = retrial_policy_arg(a, "qsys_mm11_retrial");
1493 const long nmax = a.has("nmax") ? static_cast<long>(a.count("nmax")) : -1L;
1494 a.done();
1495 const qsys::Mm11RetrialResult<T> r = qsys::qsys_mm11_retrial(lambda, mu, nu, policy, nmax);
1496 Json out;
1497 out["P0"] = encode_vector(r.P0);
1498 out["P1"] = encode_vector(r.P1);
1499 out["N"] = encode_scalar(r.N);
1500 out["Norb"] = encode_scalar(r.Norb);
1501 return out;
1502 }
1503};
1504
1505struct OpQsysMg11RetrialHt {
1506 template <class T>
1507 static Json run(Args& a) {
1508 const T lambda = a.number<T>("lambda");
1509 const T mu = a.number<T>("mu");
1510 const T cs = a.number<T>("cs");
1511 const T nu = a.number<T>("nu");
1512 const qsys::RetrialPolicy policy = retrial_policy_arg(a, "qsys_mg11_retrial_ht");
1513 a.done();
1514 const qsys::Mg11RetrialHtResult<T> r = qsys::qsys_mg11_retrial_ht(lambda, mu, cs, nu, policy);
1515 Json out;
1516 out["shape"] = encode_scalar(r.shape);
1517 out["scale"] = encode_scalar(r.scale);
1518 out["meanOrb"] = encode_scalar(r.meanOrb);
1519 out["varOrb"] = encode_scalar(r.varOrb);
1520 return out;
1521 }
1522};
1523
1524struct OpQsysMm1Dps {
1525 template <class T>
1526 static Json run(Args& a) {
1527 const std::vector<T> lambda = a.vector<T>("lambda");
1528 const std::vector<T> mu = a.vector<T>("mu");
1529 const std::vector<T> w = a.vector<T>("w");
1530 const bool tuned = a.has("tol") || a.has("maxCutoff");
1531 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1532 const unsigned maxCutoff = a.uinteger("maxCutoff", 0u);
1533 a.done();
1534 const qsys::Mm1DpsResult<T> r = tuned
1535 ? qsys::qsys_mm1_dps(lambda, mu, w, tol, maxCutoff)
1536 : qsys::qsys_mm1_dps(lambda, mu, w);
1537 Json out;
1538 // The port names the per-class response times `T_` because `T` is the
1539 // arithmetic parameter; MATLAB's output is `T`, which is the name a
1540 // caller reading the reference will look for, so that is the wire key.
1541 out["T"] = encode_vector(r.T_);
1542 out["rho"] = encode_scalar(r.rho);
1543 return out;
1544 }
1545};
1546
1547/** The six M/G/1 disciplines, all {W per class, rhohat}. */
1548#define LINE_QSYS_MG1_DISC(OpName, fn, ResultT) \
1549 struct OpName { \
1550 template <class T> \
1551 static Json run(Args& a) { \
1552 const std::vector<T> lambda = a.vector<T>("lambda"); \
1553 const std::vector<T> mu = a.vector<T>("mu"); \
1554 const std::vector<T> cs = a.vector<T>("cs"); \
1555 a.done(); \
1556 const qsys::ResultT<T> r = qsys::fn(lambda, mu, cs); \
1557 Json out; \
1558 out["W"] = encode_vector(r.W); \
1559 out["rhohat"] = encode_scalar(r.rhohat); \
1560 return out; \
1561 } \
1562 }
1563
1564LINE_QSYS_MG1_DISC(OpQsysMg1Fb, qsys_mg1_fb, Mg1DisciplineResult);
1565LINE_QSYS_MG1_DISC(OpQsysMg1Lrpt, qsys_mg1_lrpt, Mg1DisciplineResult);
1566LINE_QSYS_MG1_DISC(OpQsysMg1Psjf, qsys_mg1_psjf, Mg1DisciplineResult);
1567LINE_QSYS_MG1_DISC(OpQsysMg1Setf, qsys_mg1_setf, Mg1DisciplineResult);
1568LINE_QSYS_MG1_DISC(OpQsysMg1Srpt, qsys_mg1_srpt, Mg1DisciplineResult);
1569#undef LINE_QSYS_MG1_DISC
1570
1571/** qsys_mg1_prio, Cobham's HOL M/G/1: {W, rhohat} plus the `res` output on request. */
1572struct OpQsysMg1Prio {
1573 template <class T>
1574 static Json run(Args& a) {
1575 const std::vector<T> lambda = a.vector<T>("lambda");
1576 const std::vector<T> mu = a.vector<T>("mu");
1577 const std::vector<T> cs = a.vector<T>("cs");
1578 const bool want = want_qsys_res<T>(a, {"ES3"});
1579 const std::vector<double> ES3 = a.has("ES3") ? a.vector<double>("ES3") : std::vector<double>();
1580 a.done();
1581 const qsys::Mg1PrioResult<T> r = qsys::qsys_mg1_prio(lambda, mu, cs);
1582 Json out;
1583 out["W"] = encode_vector(r.W);
1584 out["rhohat"] = encode_scalar(r.rhohat);
1585 if (want) out["res"] = encode_qsys_res(qsys::qsys_mg1_prio_res(qd(lambda), qd(mu), qd(cs), ES3));
1586 return out;
1587 }
1588};
1589
1590/**
1591 * The two slotted systems. `convention` selects LAS-DA (late arrival, delayed
1592 * access; the reference's default) or EAS (early arrival). They are DIFFERENT
1593 * queues, not two readings of one, so an unknown name is refused rather than
1594 * falling back to the default.
1595 */
1596inline dqsys::GeoConvention read_geo_convention(Args& a) {
1597 const std::string c = a.text("convention", "LAS_DA");
1598 if (c == "LAS_DA" || c == "las_da" || c == "LASDA") return dqsys::GeoConvention::LAS_DA;
1599 if (c == "EAS" || c == "eas") return dqsys::GeoConvention::EAS;
1600 throw InputError("'convention' must be LAS_DA or EAS, got '" + c + "'");
1601}
1602
1603inline const char* geo_convention_name(dqsys::GeoConvention c) {
1604 return c == dqsys::GeoConvention::EAS ? "EAS" : "LAS_DA";
1605}
1606
1607struct OpQsysGeoGeo1 {
1608 template <class T>
1609 static Json run(Args& a) {
1610 const T arrival = a.number<T>("a");
1611 const T service = a.number<T>("s");
1612 const dqsys::GeoConvention conv = read_geo_convention(a);
1613 a.done();
1614 const dqsys::GeoGeo1Result<T> r = dqsys::dqsys_geogeo1(arrival, service, conv);
1615 Json out;
1616 out["convention"] = geo_convention_name(r.convention);
1617 out["arrivalProb"] = encode_scalar(r.arrivalProb);
1618 out["serviceProb"] = encode_scalar(r.serviceProb);
1619 out["utilization"] = encode_scalar(r.utilization);
1620 out["throughput"] = encode_scalar(r.throughput);
1621 out["emptyProb"] = encode_scalar(r.emptyProb);
1622 out["ratio"] = encode_scalar(r.ratio);
1623 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1624 out["meanWaitingQueue"] = encode_scalar(r.meanWaitingQueue);
1625 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1626 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1627 out["meanServiceTime"] = encode_scalar(r.meanServiceTime);
1628 return out;
1629 }
1630};
1631
1632struct OpQsysGeoxGeo1 {
1633 template <class T>
1634 static Json run(Args& a) {
1635 const T arrival = a.number<T>("a");
1636 const T beta = a.number<T>("beta");
1637 const T service = a.number<T>("s");
1638 const dqsys::GeoConvention conv = read_geo_convention(a);
1639 a.done();
1640 const dqsys::GeoXGeo1Result<T> r = dqsys::dqsys_geoxgeo1(arrival, beta, service, conv);
1641 Json out;
1642 out["convention"] = geo_convention_name(r.convention);
1643 out["batchArrivalProb"] = encode_scalar(r.batchArrivalProb);
1644 out["batchMean"] = encode_scalar(r.batchMean);
1645 out["batchSecondFactorialMoment"] = encode_scalar(r.batchSecondFactorialMoment);
1646 out["serviceProb"] = encode_scalar(r.serviceProb);
1647 out["arrivalRate"] = encode_scalar(r.arrivalRate);
1648 out["throughput"] = encode_scalar(r.throughput);
1649 out["utilization"] = encode_scalar(r.utilization);
1650 out["boundaryEmptyProb"] = encode_scalar(r.boundaryEmptyProb);
1651 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1652 out["meanWaitingQueue"] = encode_scalar(r.meanWaitingQueue);
1653 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1654 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1655 out["meanServiceTime"] = encode_scalar(r.meanServiceTime);
1656 return out;
1657 }
1658};
1659
1660/** The four means plus the level distribution, shared by the MAP-driven queues. */
1661template <class R>
1662Json qsys_map_results(const R& r) {
1663 Json out;
1664 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1665 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1666 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1667 out["utilization"] = encode_scalar(r.utilization);
1668 out["queueLengthDist"] = encode_vector(r.queueLengthDist);
1669 return out;
1670}
1671
1672/** qsys_map_results plus the reference's queueLengthMoments / sojournTimeMoments. */
1673template <class R>
1674Json qsys_map_results_moments(const R& r) {
1675 Json out = qsys_map_results(r);
1676 out["queueLengthMoments"] = encode_vector(r.queueLengthMoments);
1677 out["sojournTimeMoments"] = encode_vector(r.sojournTimeMoments);
1678 return out;
1679}
1680
1681/** A MAP as the (D0, D1) pair the reference passes around, under any two keys. */
1682template <class T>
1683mam::Map<T> read_map(Args& a, const char* d0, const char* d1) {
1684 mam::Map<T> m;
1685 m.D0 = a.matrix<T>(d0);
1686 m.D1 = a.matrix<T>(d1);
1687 return m;
1688}
1689
1690struct OpQsysMapm1 {
1691 template <class T>
1692 static Json run(Args& a) {
1693 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1694 const T mu = a.number<T>("mu");
1695 const bool sized = a.has("dist_size");
1696 const std::size_t dist_size = a.count("dist_size", 0);
1697 a.done();
1698 return qsys_map_results(sized ? qsys::qsys_mapm1(arrival, mu, dist_size)
1699 : qsys::qsys_mapm1(arrival, mu));
1700 }
1701};
1702
1703struct OpQsysMapmc {
1704 template <class T>
1705 static Json run(Args& a) {
1706 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1707 const T mu = a.number<T>("mu");
1708 const unsigned c = a.uinteger("c");
1709 const bool sized = a.has("dist_size");
1710 const std::size_t dist_size = a.count("dist_size", 0);
1711 a.done();
1712 return qsys_map_results(sized ? qsys::qsys_mapmc(arrival, mu, c, dist_size)
1713 : qsys::qsys_mapmc(arrival, mu, c));
1714 }
1715};
1716
1717struct OpQsysMapmap1 {
1718 template <class T>
1719 static Json run(Args& a) {
1720 const mam::Map<T> arrival = read_map<T>(a, "C0", "C1");
1721 const mam::Map<T> service = read_map<T>(a, "D0", "D1");
1722 const std::size_t dist_size = a.count("dist_size", 100);
1723 const std::size_t numQLMoms = a.count("numQLMoms", 3);
1724 const std::size_t numSTMoms = a.count("numSTMoms", 3);
1725 a.done();
1726 return qsys_map_results_moments(
1727 qsys::qsys_mapmap1(arrival, service, dist_size, numQLMoms, numSTMoms));
1728 }
1729};
1730
1731struct OpQsysMapph1 {
1732 template <class T>
1733 static Json run(Args& a) {
1734 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1735 const std::vector<T> sigma = a.vector<T>("sigma");
1736 const Matrix<T> S = a.matrix<T>("S");
1737 const bool sized = a.has("dist_size");
1738 const std::size_t dist_size = a.count("dist_size", 0);
1739 a.done();
1740 return qsys_map_results(sized ? qsys::qsys_mapph1(arrival, sigma, S, dist_size)
1741 : qsys::qsys_mapph1(arrival, sigma, S));
1742 }
1743};
1744
1745/**
1746 * MAP/PH/c. The port offers exactly two overloads, the defaulted one and the
1747 * one taking all three tuning arguments, so naming ANY of them requires naming
1748 * ALL of them rather than mixing a caller value with defaults restated here.
1749 */
1750struct OpQsysMapphc {
1751 template <class T>
1752 static Json run(Args& a) {
1753 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1754 const std::vector<T> alpha = a.vector<T>("alpha");
1755 const Matrix<T> S = a.matrix<T>("S");
1756 const unsigned c = a.uinteger("c");
1757 const bool any =
1758 a.has("dist_size") || a.has("num_w_moms") || a.has("w_points");
1759 const bool all =
1760 a.has("dist_size") && a.has("num_w_moms") && a.has("w_points");
1761 if (any && !all)
1762 throw InputError(
1763 "qsys_mapphc: 'dist_size', 'num_w_moms' and 'w_points' select one tuned "
1764 "overload together; give all three or none");
1765 const std::size_t dist_size = a.count("dist_size", 0);
1766 const std::size_t num_w_moms = a.count("num_w_moms", 0);
1767 const std::vector<T> w_points = a.vector_or_empty<T>("w_points");
1768 a.done();
1769 const qsys::MapPhcResult<T> r =
1770 all ? qsys::qsys_mapphc(arrival, alpha, S, c, dist_size, num_w_moms, w_points)
1771 : qsys::qsys_mapphc(arrival, alpha, S, c);
1772 Json out = qsys_map_results(r);
1773 out["waitingTimeMoments"] = encode_vector(r.waitingTimeMoments);
1774 out["waitingTimeCCDF"] = encode_vector(r.waitingTimeCCDF);
1775 out["waitingTimePoints"] = encode_vector(r.waitingTimePoints);
1776 out["probWait"] = encode_scalar(r.probWait);
1777 // The repeating configuration count, binomial(ms+c-1,c): it is what
1778 // sizes the solve, so a caller comparing runtimes needs it reported
1779 // rather than recomputed from ms and c.
1780 out["phaseCount"] = encode_count(r.phaseCount);
1781 return out;
1782 }
1783};
1784
1785struct OpQsysPhph1 {
1786 template <class T>
1787 static Json run(Args& a) {
1788 const std::vector<T> alpha = a.vector<T>("alpha");
1789 const Matrix<T> Tm = a.matrix<T>("T");
1790 const std::vector<T> beta = a.vector<T>("beta");
1791 const Matrix<T> S = a.matrix<T>("S");
1792 const bool sized = a.has("dist_size");
1793 const std::size_t dist_size = a.count("dist_size", 0);
1794 a.done();
1795 return qsys_map_results(sized ? qsys::qsys_phph1(alpha, Tm, beta, S, dist_size)
1796 : qsys::qsys_phph1(alpha, Tm, beta, S));
1797 }
1798};
1799
1800/**
1801 * The two deterministic-service MAP queues. Their four tuning arguments move
1802 * together -- the arrival truncation bounds a sum the level iteration then
1803 * inverts -- so naming ANY of them requires naming ALL of them, rather than
1804 * mixing one caller value with three library defaults from a different regime.
1805 */
1806inline bool qsys_map_d_tuned(Args& a, const char* who) {
1807 const bool any = a.has("dist_size") || a.has("max_arrivals") || a.has("max_levels") ||
1808 a.has("tol");
1809 const bool all = a.has("dist_size") && a.has("max_arrivals") && a.has("max_levels") &&
1810 a.has("tol");
1811 if (any && !all)
1812 throw InputError(std::string(who) +
1813 ": 'dist_size', 'max_arrivals', 'max_levels' and 'tol' tune one "
1814 "truncation together; give all four or none");
1815 return all;
1816}
1817
1818struct OpQsysMapd1 {
1819 template <class T>
1820 static Json run(Args& a) {
1821 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1822 const T s = a.number<T>("s");
1823 const bool tuned = qsys_map_d_tuned(a, "qsys_mapd1");
1824 const std::size_t dist_size = a.count("dist_size", 0);
1825 const unsigned max_arrivals = a.uinteger("max_arrivals", 0u);
1826 const std::size_t max_levels = a.count("max_levels", 0);
1827 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1828 a.done();
1829 return qsys_map_results(
1830 tuned ? qsys::qsys_mapd1(arrival, s, dist_size, max_arrivals, max_levels, tol)
1831 : qsys::qsys_mapd1(arrival, s));
1832 }
1833};
1834
1835struct OpQsysMapdc {
1836 template <class T>
1837 static Json run(Args& a) {
1838 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1839 const T s = a.number<T>("s");
1840 const unsigned c = a.uinteger("c");
1841 const bool tuned = qsys_map_d_tuned(a, "qsys_mapdc");
1842 const std::size_t dist_size = a.count("dist_size", 0);
1843 const unsigned max_arrivals = a.uinteger("max_arrivals", 0u);
1844 const std::size_t max_levels = a.count("max_levels", 0);
1845 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1846 a.done();
1847 return qsys_map_results(
1848 tuned ? qsys::qsys_mapdc(arrival, s, c, dist_size, max_arrivals, max_levels, tol)
1849 : qsys::qsys_mapdc(arrival, s, c));
1850 }
1851};
1852
1853struct OpQsysMapg1 {
1854 template <class T>
1855 static Json run(Args& a) {
1856 const mam::Map<T> arrival = read_map<T>(a, "D0", "D1");
1857 const std::vector<T> moments = a.vector<T>("serviceMoments");
1858 const std::size_t dist_size = a.count("dist_size", 100);
1859 const std::size_t numQLMoms = a.count("numQLMoms", 3);
1860 const std::size_t numSTMoms = a.count("numSTMoms", 3);
1861 a.done();
1862 const qsys::MapG1Result<T> r =
1863 qsys::qsys_mapg1(arrival, moments, dist_size, numQLMoms, numSTMoms);
1864 Json out = qsys_map_results_moments(r);
1865 out["analyzer"] = r.analyzer;
1866 // WHICH LAW WAS FITTED IS PART OF THE ANSWER: the moments select an
1867 // exponential, an Erlang, a hyperexponential or an acyclic PH, and a
1868 // caller comparing against MATLAB has to know which branch produced the
1869 // number before it can call a difference a discrepancy.
1870 const char* kind = "Acyclic";
1871 switch (r.fitKind) {
1872 case qsys::MapG1ServiceFit::Exponential: kind = "Exponential"; break;
1873 case qsys::MapG1ServiceFit::Erlang: kind = "Erlang"; break;
1874 case qsys::MapG1ServiceFit::ErlangMixture: kind = "ErlangMixture"; break;
1875 case qsys::MapG1ServiceFit::Hyperexponential: kind = "Hyperexponential"; break;
1876 case qsys::MapG1ServiceFit::Acyclic: kind = "Acyclic"; break;
1877 }
1878 out["fitKind"] = kind;
1879 out["servicePhases"] = encode_count(r.servicePhases);
1880 out["serviceFitD0"] = encode_matrix(r.serviceFit.D0);
1881 out["serviceFitD1"] = encode_matrix(r.serviceFit.D1);
1882 return out;
1883 }
1884};
1885
1886struct OpQsysPhm1 {
1887 template <class T>
1888 static Json run(Args& a) {
1889 const std::vector<T> alpha = a.vector<T>("alpha");
1890 const Matrix<T> Tm = a.matrix<T>("T");
1891 const T mu = a.number<T>("mu");
1892 const bool tuned = a.has("tol");
1893 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1894 a.done();
1895 const qsys::PhM1Result<T> r = tuned ? qsys::qsys_phm1(alpha, Tm, mu, tol)
1896 : qsys::qsys_phm1(alpha, Tm, mu);
1897 Json out;
1898 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1899 out["meanWaitingQueue"] = encode_scalar(r.meanWaitingQueue);
1900 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1901 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1902 out["utilization"] = encode_scalar(r.utilization);
1903 out["sigma"] = encode_scalar(r.sigma);
1904 return out;
1905 }
1906};
1907
1908struct OpQsysPhmc {
1909 template <class T>
1910 static Json run(Args& a) {
1911 const std::vector<T> alpha = a.vector<T>("alpha");
1912 const Matrix<T> Tm = a.matrix<T>("T");
1913 const T mu = a.number<T>("mu");
1914 const unsigned c = a.uinteger("c");
1915 const bool any = a.has("maxIter") || a.has("tol");
1916 const bool all = a.has("maxIter") && a.has("tol");
1917 if (any && !all)
1918 throw InputError(
1919 "qsys_phmc: 'maxIter' and 'tol' bound one fixed-point iteration together; give "
1920 "both or neither");
1921 const unsigned maxIter = a.uinteger("maxIter", 0u);
1922 const T tol = a.scalar<T>("tol", num_traits<T>::from_int(0));
1923 a.done();
1924 const qsys::PhMcResult<T> r = all ? qsys::qsys_phmc(alpha, Tm, mu, c, maxIter, tol)
1925 : qsys::qsys_phmc(alpha, Tm, mu, c);
1926 Json out;
1927 out["meanQueueLength"] = encode_scalar(r.meanQueueLength);
1928 out["meanWaitingQueue"] = encode_scalar(r.meanWaitingQueue);
1929 out["meanWaitingTime"] = encode_scalar(r.meanWaitingTime);
1930 out["meanSojournTime"] = encode_scalar(r.meanSojournTime);
1931 out["utilization"] = encode_scalar(r.utilization);
1932 return out;
1933 }
1934};
1935
1936struct OpQsysBmapphnnRetrial {
1937 template <class T>
1938 static Json run(Args& a) {
1939 const std::vector<Matrix<T> > D = a.matrices<T>("D");
1940 const std::vector<T> beta = a.vector<T>("beta");
1941 const Matrix<T> S = a.matrix<T>("S");
1942 const int N = a.required_integer("N");
1943 const T alpha = a.number<T>("alpha");
1944 const T gamma = a.number<T>("gamma");
1945 const T p = a.number<T>("p");
1946 const std::vector<int> Ri = a.ints("R");
1947 qsys::BmapPhNnRetrialOptions opt;
1948 opt.maxLevel = a.count("maxLevel", 0);
1949 if (a.has("retrialPolicy")) {
1950 const std::string pol = a.text("retrialPolicy", "LINEAR");
1951 if (pol == "CONSTANT") opt.retrialPolicy = qsys::RetrialPolicy::CONSTANT;
1952 else if (pol == "LINEAR") opt.retrialPolicy = qsys::RetrialPolicy::LINEAR;
1953 else throw InputError("qsys_bmapphnn_retrial: retrialPolicy must be LINEAR or CONSTANT");
1954 }
1955 if (a.has("tolerance")) opt.tolerance = a.number<double>("tolerance");
1956 if (a.has("tailTolerance")) opt.tailTolerance = a.number<double>("tailTolerance");
1957 if (a.has("maxDim")) opt.maxDim = a.number<double>("maxDim");
1958 if (a.has("maxBlockSize")) opt.maxBlockSize = a.number<double>("maxBlockSize");
1959 a.done();
1960 std::vector<long> R(Ri.size());
1961 for (std::size_t i = 0; i < Ri.size(); ++i) R[i] = static_cast<long>(Ri[i]);
1962 const qsys::BmapPhNnRetrialResult<T> r =
1963 qsys::qsys_bmapphnn_retrial(D, beta, S, N, alpha, gamma, p, R, opt);
1964 Json out;
1965 out["L_orbit"] = encode_scalar(r.L_orbit);
1966 out["N_server"] = encode_scalar(r.N_server);
1967 out["L_system"] = encode_scalar(r.L_system);
1968 out["utilization"] = encode_scalar(r.utilization);
1969 out["throughput"] = encode_scalar(r.throughput);
1970 out["P_idle"] = encode_scalar(r.P_idle);
1971 out["P_empty_orbit"] = encode_scalar(r.P_empty_orbit);
1972 out["P_empty_system"] = encode_scalar(r.P_empty_system);
1973 out["pi"] = encode_matrix(r.pi);
1974 out["truncLevel"] = encode_count(r.truncLevel);
1975 out["truncError"] = encode_scalar(r.truncError);
1976 out["topLevelMass"] = encode_scalar(r.topLevelMass);
1977 out["converged"] = r.converged;
1978 // WHETHER THE LEVEL WAS CLIPPED is part of the answer: a clipped
1979 // truncation makes every reported mass a lower bound on the true one.
1980 out["clipped"] = r.clipped;
1981 return out;
1982 }
1983};
1984
1985// ---------------------------------------------------------------------------
1986// moment: the moment-basis changes
1987// ---------------------------------------------------------------------------
1988//
1989// Every member is a pure change of basis on a moment sequence -- raw, central,
1990// factorial, up-factorial, binomial, negative-binomial -- so each takes one
1991// vector and returns one vector under the reference's own argument and output
1992// names. They are field operations throughout, which is why the registry lists
1993// all three arithmetics and none of them needs the transcendental guard.
1994
1995#define LINE_MOMENT_VEC(OpName, fn, in_key, out_key) \
1996 struct OpName { \
1997 template <class T> \
1998 static Json run(Args& a) { \
1999 const std::vector<T> v = a.vector<T>(in_key); \
2000 a.done(); \
2001 Json out; \
2002 out[out_key] = encode_vector(moment::fn(v)); \
2003 return out; \
2004 } \
2005 }
2006
2007LINE_MOMENT_VEC(OpMomentBinomialFromFactorial, moment_binomial_from_factorial, "f", "b");
2008LINE_MOMENT_VEC(OpMomentBinomialFromNegbinomial, moment_binomial_from_negbinomial, "bm", "b");
2009LINE_MOMENT_VEC(OpMomentBinotrans, moment_binotrans, "x", "y");
2010LINE_MOMENT_VEC(OpMomentBinotransinv, moment_binotransinv, "y", "x");
2011LINE_MOMENT_VEC(OpMomentCentralFromRaw, moment_central_from_raw, "m", "mc");
2012LINE_MOMENT_VEC(OpMomentFactorialFromBinomial, moment_factorial_from_binomial, "b", "f");
2013LINE_MOMENT_VEC(OpMomentFactorialFromRaw, moment_factorial_from_raw, "m", "f");
2014LINE_MOMENT_VEC(OpMomentFactorialFromUpfactorial, moment_factorial_from_upfactorial, "fp", "f");
2015LINE_MOMENT_VEC(OpMomentNegbinomialFromBinomial, moment_negbinomial_from_binomial, "b", "bm");
2016LINE_MOMENT_VEC(OpMomentNegbinomialFromUpfactorial, moment_negbinomial_from_upfactorial, "fp",
2017 "bm");
2018LINE_MOMENT_VEC(OpMomentRawFromFactorial, moment_raw_from_factorial, "f", "m");
2019LINE_MOMENT_VEC(OpMomentRawFromUpfactorial, moment_raw_from_upfactorial, "fp", "m");
2020LINE_MOMENT_VEC(OpMomentUpfactorialFromFactorial, moment_upfactorial_from_factorial, "f", "fp");
2021LINE_MOMENT_VEC(OpMomentUpfactorialFromNegbinomial, moment_upfactorial_from_negbinomial, "bm",
2022 "fp");
2023LINE_MOMENT_VEC(OpMomentUpfactorialFromRaw, moment_upfactorial_from_raw, "m", "fp");
2024#undef LINE_MOMENT_VEC
2025
2026/**
2027 * The inverse of moment_central_from_raw needs the MEAN as well: a central
2028 * sequence has lost it (mc(1) is 0 by construction), so it cannot be recovered
2029 * from the sequence alone and is a second argument rather than an option.
2030 */
2031struct OpMomentRawFromCentral {
2032 template <class T>
2033 static Json run(Args& a) {
2034 const std::vector<T> mc = a.vector<T>("mc");
2035 const T m1 = a.number<T>("m1");
2036 a.done();
2037 Json out;
2039 return out;
2040 }
2041};
2042
2043/** The four triangular coefficient matrices, each a function of the order n. */
2044#define LINE_MOMENT_TRI(OpName, fn, out_key) \
2045 struct OpName { \
2046 template <class T> \
2047 static Json run(Args& a) { \
2048 const int n = a.required_integer("n"); \
2049 a.done(); \
2050 Json out; \
2051 out[out_key] = encode_matrix(moment::fn<T>(n)); \
2052 return out; \
2053 } \
2054 }
2055
2056LINE_MOMENT_TRI(OpMomentLah, moment_lah, "L");
2057LINE_MOMENT_TRI(OpMomentStirling1, moment_stirling1, "s");
2058LINE_MOMENT_TRI(OpMomentStirling2, moment_stirling2, "S");
2059LINE_MOMENT_TRI(OpMomentStirlingcycle, moment_stirlingcycle, "sigma");
2060#undef LINE_MOMENT_TRI
2061
2062// ---------------------------------------------------------------------------
2063// mc: the Markov-chain solvers beyond ctmc_solve / dtmc_solve
2064// ---------------------------------------------------------------------------
2065//
2066// `ctmc_rand` is NOT exposed: it takes a random generator by reference, so its
2067// answer depends on a stream this boundary cannot carry, and a generator seeded
2068// here would return a matrix the caller cannot reproduce.
2069//
2070// AN ITERATIVE SOLVER REPORTS WHETHER IT CONVERGED, and that flag rides beside
2071// the vector rather than being folded into it. A caller that reads only the
2072// numbers from a run that hit its iteration cap would be reading a partial
2073// sweep as a stationary law.
2074
2075/** The block partition MS/MSS: a list of state-index lists, 0-based. */
2076inline std::vector<std::vector<std::size_t> > read_partition(Args& a, const char* key) {
2077 const Json& j = a.get(key);
2078 const std::string where = std::string("partition '") + key + "'";
2079 if (!j.is_array()) throw InputError(where + " must be an array of index arrays");
2080 std::vector<std::vector<std::size_t> > out;
2081 for (std::size_t b = 0; b < j.size(); ++b) {
2082 if (!j[b].is_array())
2083 throw InputError(where + ": block " + std::to_string(b) + " must be an array");
2084 std::vector<std::size_t> blk;
2085 for (std::size_t i = 0; i < j[b].size(); ++i) {
2086 const std::string text = decimal_text(j[b][i], where);
2087 const long long v = std::strtoll(text.c_str(), nullptr, 10);
2088 if (v < 0)
2089 throw InputError(where + ": a state index cannot be negative, got " + text);
2090 blk.push_back(static_cast<std::size_t>(v));
2091 }
2092 out.push_back(blk);
2093 }
2094 return out;
2095}
2096
2097/** A list of state indices, reported unchanged: an index is not a measurement. */
2098inline Json encode_indices(const std::vector<std::size_t>& v) {
2099 Json a = Json::array();
2100 for (std::size_t i = 0; i < v.size(); ++i) a.push_back(static_cast<std::uint64_t>(v[i]));
2101 return a;
2102}
2103
2104/**
2105 * The reducible solvers' five outputs. `pis` is the per-component stationary
2106 * law and `pi0` the absorption probabilities into each component, so the two
2107 * together say WHERE the mass went as well as how it is spread once there;
2108 * reporting only `pi` would lose the decomposition the function exists for.
2109 */
2110template <class T>
2111Json reducible_results(const mc::ReducibleResult<T>& r) {
2112 Json out;
2113 out["pi"] = encode_vector(r.pi);
2114 out["pis"] = encode_matrix(r.pis);
2115 out["pi0"] = encode_matrix(r.pi0);
2116 out["scc"] = encode_indices(r.scc);
2117 Json isrec = Json::array();
2118 for (std::size_t i = 0; i < r.isrec.size(); ++i) isrec.push_back(bool(r.isrec[i]));
2119 out["isrec"] = isrec;
2120 out["Pl"] = encode_matrix(r.Pl);
2121 out["pil"] = encode_matrix(r.pil);
2122 return out;
2123}
2124
2125/** The block-decomposition variant, which has no lumped chain to report. */
2126template <class T>
2127Json blkdecomp_results(const mc::BlkDecompResult<T>& r) {
2128 Json out;
2129 out["pi"] = encode_vector(r.pi);
2130 out["pis"] = encode_matrix(r.pis);
2131 out["pi0"] = encode_matrix(r.pi0);
2132 out["scc"] = encode_indices(r.scc);
2133 Json isrec = Json::array();
2134 for (std::size_t i = 0; i < r.isrec.size(); ++i) isrec.push_back(bool(r.isrec[i]));
2135 out["isrec"] = isrec;
2136 return out;
2137}
2138
2139struct OpCtmcSolveReducible {
2140 template <class T>
2141 static Json run(Args& a) {
2142 const Matrix<T> Q = a.matrix<T>("Q");
2143 const std::vector<T> pi0 = a.vector<T>("pi0");
2144 const double zeroColTol = a.scalar<double>("zeroColTol", 1e-12);
2145 a.done();
2146 const mc::ReducibleResult<T> r = mc::ctmc_solve_reducible(Q, pi0, zeroColTol);
2147 return reducible_results(r);
2148 }
2149};
2150
2151struct OpCtmcSolveReducibleBlkdecomp {
2152 template <class T>
2153 static Json run(Args& a) {
2154 const Matrix<T> Q = a.matrix<T>("Q");
2155 const std::vector<T> pin = a.vector<T>("pin");
2156 const double reachTol = a.scalar<double>("reachTol", 1e-15);
2157 const double zeroColTol = a.scalar<double>("zeroColTol", 1e-12);
2158 a.done();
2159 const mc::BlkDecompResult<T> r =
2160 mc::ctmc_solve_reducible_blkdecomp(Q, pin, reachTol, zeroColTol);
2161 return blkdecomp_results(r);
2162 }
2163};
2164
2165struct OpDtmcSolveReducible {
2166 template <class T>
2167 static Json run(Args& a) {
2168 const Matrix<T> P = a.matrix<T>("P");
2169 const std::vector<T> pin = a.vector<T>("pin");
2170 const double zeroColTol = a.scalar<double>("zeroColTol", 1e-12);
2171 a.done();
2172 const mc::ReducibleResult<T> r = mc::dtmc_solve_reducible(P, pin, zeroColTol);
2173 return reducible_results(r);
2174 }
2175};
2176
2177struct OpDtmcMakestochastic {
2178 template <class T>
2179 static Json run(Args& a) {
2180 const Matrix<T> P = a.matrix<T>("Pin");
2181 a.done();
2182 Json out;
2184 return out;
2185 }
2186};
2187
2188struct OpCtmcSens {
2189 template <class T>
2190 static Json run(Args& a) {
2191 const Matrix<T> Q = a.matrix<T>("Q");
2192 const Matrix<T> dQ = a.matrix<T>("dQ");
2193 const std::vector<T> pi = a.vector<T>("pi");
2194 a.done();
2195 Json out;
2196 out["dpi"] = encode_vector(mc::ctmc_sens(Q, dQ, pi));
2197 return out;
2198 }
2199};
2200
2201struct OpStronglyConnComp {
2202 template <class T>
2203 static Json run(Args& a) {
2204 const Matrix<T> A = a.matrix<T>("A");
2205 a.done();
2206 const mc::SccResult r = mc::stronglyconncomp(A);
2207 Json out;
2208 out["scc"] = encode_indices(r.scc);
2209 Json rec = Json::array();
2210 for (std::size_t i = 0; i < r.recurrent.size(); ++i) rec.push_back(bool(r.recurrent[i]));
2211 out["recurrent"] = rec;
2212 Json mem = Json::array();
2213 for (std::size_t i = 0; i < r.members.size(); ++i)
2214 mem.push_back(encode_indices(r.members[i]));
2215 out["members"] = mem;
2216 return out;
2217 }
2218};
2219
2220struct OpCtmcRandomization {
2221 template <class T>
2222 static Json run(Args& a) {
2223 const Matrix<T> Q = a.matrix<T>("Q");
2224 const bool given = a.has("q");
2225 const T q = a.scalar<T>("q", num_traits<T>::from_int(0));
2226 a.done();
2227 if (!given)
2228 throw InputError(
2229 "ctmc_randomization: 'q' is the uniformization rate and has no default here; "
2230 "MATLAB requires it too");
2231 const mc::RandomizationResult<T> r = mc::ctmc_randomization(Q, q);
2232 Json out;
2233 out["P"] = encode_matrix(r.P);
2234 out["q"] = encode_scalar(r.q);
2235 return out;
2236 }
2237};
2238
2239/**
2240 * The three nearly-completely-decomposable solvers. `q` is the uniformization
2241 * rate and is OPTIONAL for courtois and multi, because the port carries the
2242 * reference's own derived default (courtois_default_rate) and restating it here
2243 * would fix a value the library computes from Q and MS.
2244 */
2245struct OpCtmcCourtois {
2246 template <class T>
2247 static Json run(Args& a) {
2248 const Matrix<T> Q = a.matrix<T>("Q");
2249 const std::vector<std::vector<std::size_t> > MS = read_partition(a, "MS");
2250 const bool given = a.has("q");
2251 const T q = a.scalar<T>("q", num_traits<T>::from_int(0));
2252 a.done();
2253 const mc::CourtoisResult<T> r =
2254 given ? mc::ctmc_courtois(Q, MS, q) : mc::ctmc_courtois(Q, MS);
2255 Json out;
2256 out["p"] = encode_vector(r.p);
2257 out["v"] = encode_indices(r.v);
2258 out["Qperm"] = encode_matrix(r.Qperm);
2259 out["Qdec"] = encode_matrix(r.Qdec);
2260 out["P"] = encode_matrix(r.P);
2261 out["B"] = encode_matrix(r.B);
2262 out["C"] = encode_scalar(r.C);
2263 out["eps"] = encode_scalar(r.eps);
2264 out["epsRowMax"] = encode_scalar(r.epsRowMax);
2265 out["epsMAX"] = encode_scalar(r.epsMAX);
2266 out["q"] = encode_scalar(r.q);
2267 return out;
2268 }
2269};
2270
2271/** KMS and Takahashi return the same six outputs, under the same names. */
2272template <class R>
2273Json kms_results(const R& r) {
2274 Json out;
2275 out["p"] = encode_vector(r.p);
2276 out["p_1"] = encode_vector(r.p_1);
2277 out["pcourt"] = encode_vector(r.pcourt);
2278 out["Qperm"] = encode_matrix(r.Qperm);
2279 out["eps"] = encode_scalar(r.eps);
2280 out["epsMAX"] = encode_scalar(r.epsMAX);
2281 return out;
2282}
2283
2284struct OpCtmcKms {
2285 template <class T>
2286 static Json run(Args& a) {
2287 const Matrix<T> Q = a.matrix<T>("Q");
2288 const std::vector<std::vector<std::size_t> > MS = read_partition(a, "MS");
2289 const std::size_t numSteps = a.count("numSteps");
2290 a.done();
2291 return kms_results(mc::ctmc_kms(Q, MS, numSteps));
2292 }
2293};
2294
2295struct OpCtmcTakahashi {
2296 template <class T>
2297 static Json run(Args& a) {
2298 const Matrix<T> Q = a.matrix<T>("Q");
2299 const std::vector<std::vector<std::size_t> > MS = read_partition(a, "MS");
2300 const std::size_t numSteps = a.count("numSteps");
2301 const double massTol = a.scalar<double>("massTol", 1e-14);
2302 a.done();
2303 return kms_results(mc::ctmc_takahashi(Q, MS, numSteps, massTol));
2304 }
2305};
2306
2307struct OpCtmcMulti {
2308 template <class T>
2309 static Json run(Args& a) {
2310 const Matrix<T> Q = a.matrix<T>("Q");
2311 const std::vector<std::vector<std::size_t> > MS = read_partition(a, "MS");
2312 const std::vector<std::vector<std::size_t> > MSS = read_partition(a, "MSS");
2313 const bool given = a.has("q");
2314 const T q = a.scalar<T>("q", num_traits<T>::from_int(0));
2315 a.done();
2316 const mc::MultiResult<T> r =
2317 given ? mc::ctmc_multi(Q, MS, MSS, q) : mc::ctmc_multi(Q, MS, MSS);
2318 Json out;
2319 out["p"] = encode_vector(r.p);
2320 out["pcourt"] = encode_vector(r.pcourt);
2321 out["Qperm"] = encode_matrix(r.Qperm);
2322 out["eps"] = encode_scalar(r.eps);
2323 out["epsMAX"] = encode_scalar(r.epsMAX);
2324 return out;
2325 }
2326};
2327
2328/**
2329 * GMRES reports MATLAB's `flag` rather than a boolean: 0 is convergence and the
2330 * nonzero values distinguish an iteration cap from a stagnation, which are
2331 * different failures and are what a caller checks before using `x`.
2332 */
2333struct OpCtmcGmres {
2334 template <class T>
2335 static Json run(Args& a) {
2336 const Matrix<T> A = a.matrix<T>("A");
2337 const std::vector<T> b = a.vector<T>("b");
2338 const double tol = a.scalar<double>("tol", 1e-12);
2339 const int restart = a.integer("restart", 0);
2340 const int maxit = a.integer("maxit", 0);
2341 const std::vector<T> x0 = a.vector_or_empty<T>("x0");
2342 a.done();
2343 const mc::GmresResult<T> r = mc::ctmc_gmres(A, b, tol, restart, maxit, x0);
2344 Json out;
2345 out["x"] = encode_vector(r.x);
2346 out["flag"] = r.flag;
2347 out["relres"] = encode_scalar(r.relres);
2348 out["iter"] = static_cast<std::int64_t>(r.iter);
2349 return out;
2350 }
2351};
2352
2353struct OpCtmcGmresMulti {
2354 template <class T>
2355 static Json run(Args& a) {
2356 const Matrix<T> A = a.matrix<T>("A");
2357 const Matrix<T> B = a.matrix<T>("B");
2358 const double tol = a.scalar<double>("tol", 1e-12);
2359 const int restart = a.integer("restart", 0);
2360 const int maxit = a.integer("maxit", 0);
2361 a.done();
2362 const mc::GmresMultiResult<T> r = mc::ctmc_gmres_multi(A, B, tol, restart, maxit);
2363 Json out;
2364 out["X"] = encode_matrix(r.X);
2365 out["flag"] = r.flag;
2366 return out;
2367 }
2368};
2369
2370/**
2371 * BiCGSTAB reports MATLAB's `flag` on the same convention as GMRES, with the
2372 * addition of 4 for a scalar breakdown of the underlying Lanczos process, which
2373 * is a different failure from an iteration cap and is what a caller checks
2374 * before using `x`. `iter` counts matrix-vector products with A, so it is
2375 * directly comparable with the `iter` GMRES reports.
2376 */
2377struct OpCtmcBicgstab {
2378 template <class T>
2379 static Json run(Args& a) {
2380 const Matrix<T> A = a.matrix<T>("A");
2381 const std::vector<T> b = a.vector<T>("b");
2382 const double tol = a.scalar<double>("tol", 1e-12);
2383 const int maxit = a.integer("maxit", 0);
2384 const std::vector<T> x0 = a.vector_or_empty<T>("x0");
2385 a.done();
2386 const mc::BicgstabResult<T> r = mc::ctmc_bicgstab(A, b, tol, maxit, x0);
2387 Json out;
2388 out["x"] = encode_vector(r.x);
2389 out["flag"] = r.flag;
2390 out["relres"] = encode_scalar(r.relres);
2391 out["iter"] = static_cast<std::int64_t>(r.iter);
2392 return out;
2393 }
2394};
2395
2396struct OpCtmcBicgstabMulti {
2397 template <class T>
2398 static Json run(Args& a) {
2399 const Matrix<T> A = a.matrix<T>("A");
2400 const Matrix<T> B = a.matrix<T>("B");
2401 const double tol = a.scalar<double>("tol", 1e-12);
2402 const int maxit = a.integer("maxit", 0);
2403 a.done();
2404 const mc::BicgstabMultiResult<T> r = mc::ctmc_bicgstab_multi(A, B, tol, maxit);
2405 Json out;
2406 out["X"] = encode_matrix(r.X);
2407 out["flag"] = r.flag;
2408 return out;
2409 }
2410};
2411
2412struct OpCtmcFoxglynn {
2413 template <class T>
2414 static Json run(Args& a) {
2415 const std::vector<T> pi0 = a.vector<T>("pi0");
2416 const Matrix<T> Q = a.matrix<T>("Q");
2417 const T t = a.number<T>("t");
2418 const double tol = a.scalar<double>("tol", 1e-12);
2419 const int maxiter = a.integer("maxiter", -1);
2420 a.done();
2421 const mc::FoxGlynnResult<T> r = mc::ctmc_foxglynn(pi0, Q, t, tol, maxiter);
2422 Json out;
2423 out["pi"] = encode_vector(r.pi);
2424 // The Poisson weight window: `left` and `right` are the truncation
2425 // points the algorithm chose, and `w` the weights between them, so a
2426 // caller can see how much mass the truncation kept.
2427 out["left"] = static_cast<std::int64_t>(r.left);
2428 out["right"] = static_cast<std::int64_t>(r.right);
2429 out["w"] = encode_vector(r.w);
2430 return out;
2431 }
2432};
2433
2434struct OpCtmcSaddlepoint {
2435 template <class T>
2436 static Json run(Args& a) {
2437 const Matrix<T> D0 = a.matrix<T>("D0");
2438 const Matrix<T> D1 = a.matrix<T>("D1");
2439 const std::vector<T> t = a.vector<T>("t");
2440 const std::vector<int> ki = a.ints("k");
2441 const std::string method = a.text("method", "daniels2");
2442 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
2443 a.done();
2445 if (method == "daniels" || method == "sp1")
2447 else if (method == "plain" || method == "bare")
2449 else if (!(method == "daniels2" || method == "sp2"))
2450 throw InputError("ctmc_saddlepoint: unknown method '" + method +
2451 "', expected daniels2, daniels or plain");
2452 std::vector<long> k(ki.size());
2453 for (std::size_t i = 0; i < ki.size(); ++i) k[i] = static_cast<long>(ki[i]);
2454 const mc::SaddlepointResult<T> r = mc::ctmc_saddlepoint(D0, D1, t, k, m, pi0);
2455 Json out;
2456 out["p"] = encode_vector(r.p);
2457 out["logp"] = encode_vector(r.logp);
2458 out["theta"] = encode_vector(r.theta);
2459 out["k2"] = encode_vector(r.k2);
2460 out["lambda"] = encode_scalar(r.lambda);
2461 // K2 = t*eta''(theta*) is the expansion parameter, so a caller that
2462 // ignores out_of_regime is reading a number outside its own validity
2463 out["outOfRegime"] = r.out_of_regime;
2464 return out;
2465 }
2466};
2467
2468struct OpCtmcFau {
2469 template <class T>
2470 static Json run(Args& a) {
2471 const std::vector<T> pi0 = a.vector<T>("pi0");
2472 const Matrix<T> Q = a.matrix<T>("Q");
2473 const T t = a.number<T>("t");
2474 const double epsilon = a.scalar<double>("epsilon", 1e-6);
2475 const double delta = a.scalar<double>("delta", 1e-12);
2476 const int maxsteps = a.integer("maxsteps", -1);
2477 a.done();
2478 const mc::FauResult<T> r = mc::ctmc_fau(pi0, Q, t, epsilon, delta, maxsteps);
2479 Json out;
2480 out["pi"] = encode_vector(r.pit);
2481 // The whole error budget, since the method removes mass and never puts
2482 // any back: errorBound is the L1 distance to the exact distribution,
2483 // and the three components say where it went.
2484 out["steps"] = static_cast<std::int64_t>(r.steps);
2485 out["lambdaMin"] = r.lambdaMin;
2486 out["lambdaMax"] = r.lambdaMax;
2487 out["uniformRate"] = r.uniformRate;
2488 out["weightTail"] = num_traits<T>::to_double(r.weightTail);
2489 out["weightWindow"] = num_traits<T>::to_double(r.weightWindow);
2490 out["droppedMass"] = num_traits<T>::to_double(r.droppedMass);
2491 out["errorBound"] = num_traits<T>::to_double(r.errorBound);
2492 out["supportMax"] = static_cast<std::int64_t>(r.supportMax);
2493 out["supportFinal"] = static_cast<std::int64_t>(r.supportFinal);
2494 out["truncated"] = r.truncated;
2495 out["absorbed"] = r.absorbed;
2496 return out;
2497 }
2498};
2499
2500struct OpCtmcTransient {
2501 template <class T>
2502 static Json run(Args& a) {
2503 const Matrix<T> Q = a.matrix<T>("Q");
2504 const std::vector<T> pi0 = a.vector<T>("pi0");
2505 const T t0 = a.number<T>("t0");
2506 const T t1 = a.number<T>("t1");
2507 const double rtol = a.scalar<double>("rtol", 1e-3);
2508 const double atol = a.scalar<double>("atol", 1e-6);
2509 a.done();
2510 const mc::TransientResult<T> r = mc::ctmc_transient(Q, pi0, t0, t1, rtol, atol);
2511 Json out;
2512 out["t"] = encode_vector(r.t);
2513 out["pi"] = encode_matrix(r.pi);
2514 return out;
2515 }
2516};
2517
2518struct OpCtmcTransientSens {
2519 template <class T>
2520 static Json run(Args& a) {
2521 const Matrix<T> Q = a.matrix<T>("Q");
2522 const Matrix<T> dQ = a.matrix<T>("dQ");
2523 const std::vector<T> pi0 = a.vector<T>("pi0");
2524 const T t0 = a.number<T>("t0");
2525 const T t1 = a.number<T>("t1");
2526 const double rtol = a.scalar<double>("rtol", 1e-3);
2527 const double atol = a.scalar<double>("atol", 1e-6);
2528 a.done();
2529 const mc::TransientSensResult<T> r =
2530 mc::ctmc_transient_sens(Q, dQ, pi0, t0, t1, rtol, atol);
2531 Json out;
2532 out["t"] = encode_vector(r.t);
2533 out["pi"] = encode_matrix(r.pi);
2534 out["dpi"] = encode_matrix(r.dpi);
2535 return out;
2536 }
2537};
2538
2539// ---------------------------------------------------------------------------
2540// aoi: the age-of-information laws
2541// ---------------------------------------------------------------------------
2542//
2543// The MATLAB signatures take the service law as a LAPLACE-STIELTJES TRANSFORM,
2544// which in C++ is a std::function and has no JSON representation. Rather than
2545// leave nine of the fifteen laws unreachable, the boundary takes a NAMED law
2546// and builds the transform with the port's own aoi_lst_* constructors -- the
2547// same four the reference offers -- so the caller states which law it means and
2548// nothing about the transform is invented here.
2549//
2550// `lstAoI` IS NOT REPORTED, because it is a transform and not a number; the
2551// header states that nothing in the family inverts one. `has_lst` says whether
2552// the law returned one at all, which is the part a caller can act on.
2553
2554/** The service law of the G/M/1 and M/G/1 age formulas, by name. */
2555template <class T>
2556aoi::Lst<T> read_aoi_lst(Args& a, T& E1, T& E2, bool& has_E2) {
2557 const std::string kind = a.text("lst", "");
2558 if (kind.empty())
2559 throw InputError(
2560 "'lst' names the service law whose Laplace-Stieltjes transform this age formula "
2561 "needs: exp, erlang, det or ph. A transform itself cannot cross a JSON boundary");
2562 has_E2 = true;
2563 if (kind == "exp") {
2564 const T mu = a.number<T>("lst_mu");
2565 E1 = T(num_traits<T>::from_int(1) / mu);
2566 E2 = T(num_traits<T>::from_int(2) / (mu * mu));
2567 return aoi::aoi_lst_exp(mu);
2568 }
2569 if (kind == "erlang") {
2570 const unsigned k = a.uinteger("lst_k");
2571 const T mu = a.number<T>("lst_mu");
2572 const T kk = num_traits<T>::from_int(static_cast<int>(k));
2573 E1 = T(kk / mu);
2574 E2 = T(kk * (kk + num_traits<T>::from_int(1)) / (mu * mu));
2575 return aoi::aoi_lst_erlang(k, mu);
2576 }
2577 if (kind == "det") {
2578 const T d = a.number<T>("lst_d");
2579 E1 = d;
2580 E2 = T(d * d);
2581 return aoi::aoi_lst_det(d);
2582 }
2583 if (kind == "ph") {
2584 const std::vector<T> alpha = a.vector<T>("lst_alpha");
2585 const Matrix<T> Tmat = a.matrix<T>("lst_T");
2586 // The two moments of a PH law are -alpha inv(T) 1 and 2 alpha inv(T)^2 1;
2587 // the caller states them rather than having this boundary invert T, so
2588 // the number the formula uses is the caller's own and not a second
2589 // inversion that could disagree with the transform beside it.
2590 E1 = a.number<T>("E_1");
2591 E2 = a.number<T>("E_2");
2592 return aoi::aoi_lst_ph(alpha, Tmat);
2593 }
2594 throw InputError("'lst' must be one of exp, erlang, det, ph; got '" + kind + "'");
2595}
2596
2597/** [meanAoI, varAoI, peakAoI], the closed-form arm of the family. */
2598template <class T>
2599Json aoi_results(const aoi::AoiResult<T>& r) {
2600 Json out;
2601 out["meanAoI"] = encode_scalar(r.meanAoI);
2602 out["varAoI"] = encode_scalar(r.varAoI);
2603 out["peakAoI"] = encode_scalar(r.peakAoI);
2604 return out;
2605}
2606
2607/** The transform arm: the two means, and whether an LST came back with them. */
2608template <class T>
2609Json aoi_lst_results(const aoi::AoiLstResult<T>& r) {
2610 Json out;
2611 out["meanAoI"] = encode_scalar(r.meanAoI);
2612 out["peakAoI"] = encode_scalar(r.peakAoI);
2613 out["has_lst"] = r.has_lst;
2614 return out;
2615}
2616
2617#define LINE_AOI_TWO(OpName, fn, k1, k2) \
2618 struct OpName { \
2619 template <class T> \
2620 static Json run(Args& a) { \
2621 const T x = a.number<T>(k1); \
2622 const T y = a.number<T>(k2); \
2623 a.done(); \
2624 return aoi_results(aoi::fn(x, y)); \
2625 } \
2626 }
2627
2628LINE_AOI_TWO(OpAoiFcfsDm1, aoi_fcfs_dm1, "tau", "mu");
2629LINE_AOI_TWO(OpAoiFcfsMd1, aoi_fcfs_md1, "lambda", "d");
2630LINE_AOI_TWO(OpAoiFcfsMm1, aoi_fcfs_mm1, "lambda", "mu");
2631LINE_AOI_TWO(OpAoiLcfsprDm1, aoi_lcfspr_dm1, "tau", "mu");
2632LINE_AOI_TWO(OpAoiLcfsprMd1, aoi_lcfspr_md1, "lambda", "d");
2633LINE_AOI_TWO(OpAoiLcfsprMm1, aoi_lcfspr_mm1, "lambda", "mu");
2634#undef LINE_AOI_TWO
2635
2636/** The two non-preemptive LCFS M/GI/1 laws: transform at lambda plus both moments. */
2637#define LINE_AOI_MGI1_TWO(OpName, fn) \
2638 struct OpName { \
2639 template <class T> \
2640 static Json run(Args& a) { \
2641 const T lambda = a.number<T>("lambda"); \
2642 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0); \
2643 bool has_E2 = false; \
2644 const aoi::Lst<T> H = read_aoi_lst<T>(a, E1, E2, has_E2); \
2645 a.done(); \
2646 return aoi_lst_results(aoi::fn(lambda, H, E1, E2)); \
2647 } \
2648 }
2649
2650LINE_AOI_MGI1_TWO(OpAoiLcfsdMgi1, aoi_lcfsd_mgi1);
2651LINE_AOI_MGI1_TWO(OpAoiLcfssMgi1, aoi_lcfss_mgi1);
2652#undef LINE_AOI_MGI1_TWO
2653
2654struct OpAoiFcfsMgi1 {
2655 template <class T>
2656 static Json run(Args& a) {
2657 const T lambda = a.number<T>("lambda");
2658 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0);
2659 bool has_E2 = false;
2660 const aoi::Lst<T> H = read_aoi_lst<T>(a, E1, E2, has_E2);
2661 a.done();
2662 return aoi_lst_results(aoi::aoi_fcfs_mgi1(lambda, H, E1, E2));
2663 }
2664};
2665
2666struct OpAoiLcfsprMgi1 {
2667 template <class T>
2668 static Json run(Args& a) {
2669 const T lambda = a.number<T>("lambda");
2670 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0);
2671 bool has_E2 = false;
2672 const aoi::Lst<T> H = read_aoi_lst<T>(a, E1, E2, has_E2);
2673 a.done();
2674 return aoi_lst_results(aoi::aoi_lcfspr_mgi1(lambda, H, E1));
2675 }
2676};
2677
2678struct OpAoiFcfsGim1 {
2679 template <class T>
2680 static Json run(Args& a) {
2681 const T mu = a.number<T>("mu");
2682 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0);
2683 bool has_E2 = false;
2684 const aoi::Lst<T> Y = read_aoi_lst<T>(a, E1, E2, has_E2);
2685 a.done();
2686 return aoi_lst_results(aoi::aoi_fcfs_gim1(Y, mu, E1, E2));
2687 }
2688};
2689
2690#define LINE_AOI_GIM1_TWO(OpName, fn) \
2691 struct OpName { \
2692 template <class T> \
2693 static Json run(Args& a) { \
2694 const T mu = a.number<T>("mu"); \
2695 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0); \
2696 bool has_E2 = false; \
2697 const aoi::Lst<T> Y = read_aoi_lst<T>(a, E1, E2, has_E2); \
2698 a.done(); \
2699 return aoi_lst_results(aoi::fn(Y, mu, E1, E2)); \
2700 } \
2701 }
2702
2703LINE_AOI_GIM1_TWO(OpAoiLcfsdGim1, aoi_lcfsd_gim1);
2704LINE_AOI_GIM1_TWO(OpAoiLcfssGim1, aoi_lcfss_gim1);
2705#undef LINE_AOI_GIM1_TWO
2706
2707struct OpAoiLcfsprGim1 {
2708 template <class T>
2709 static Json run(Args& a) {
2710 const T mu = a.number<T>("mu");
2711 T E1 = num_traits<T>::from_int(0), E2 = num_traits<T>::from_int(0);
2712 bool has_E2 = false;
2713 const aoi::Lst<T> Y = read_aoi_lst<T>(a, E1, E2, has_E2);
2714 a.done();
2715 return aoi_lst_results(aoi::aoi_lcfspr_gim1(Y, mu, E1, E2));
2716 }
2717};
2718
2719// ---------------------------------------------------------------------------
2720// fj: the fork-join order-statistic bounds and approximations
2721// ---------------------------------------------------------------------------
2722//
2723// `fj_order_stat` is NOT exposed: its last argument is the CDF of the branch
2724// service law as a callable, and unlike the age family there is no set of named
2725// laws the reference offers in its place, so a substitute would be this file's
2726// choice rather than the caller's.
2727
2728/** The many members returning one bare number, under the reference's name. */
2729#define LINE_FJ_K_LAMBDA_MU(OpName, fn, out_key) \
2730 struct OpName { \
2731 template <class T> \
2732 static Json run(Args& a) { \
2733 const unsigned K = a.uinteger("K"); \
2734 const T lambda = a.number<T>("lambda"); \
2735 const T mu = a.number<T>("mu"); \
2736 a.done(); \
2737 Json out; \
2738 out[out_key] = encode_scalar(fj::fn(K, lambda, mu)); \
2739 return out; \
2740 } \
2741 }
2742
2743LINE_FJ_K_LAMBDA_MU(OpFjResptNt, fj_respt_nt, "R");
2744LINE_FJ_K_LAMBDA_MU(OpFjResptVarki, fj_respt_varki, "R");
2745LINE_FJ_K_LAMBDA_MU(OpFjResptVm, fj_respt_vm, "R");
2746LINE_FJ_K_LAMBDA_MU(OpFjRmax, fj_rmax, "Rmax");
2747#undef LINE_FJ_K_LAMBDA_MU
2748
2749#define LINE_FJ_K_MU(OpName, fn, out_key) \
2750 struct OpName { \
2751 template <class T> \
2752 static Json run(Args& a) { \
2753 const unsigned K = a.uinteger("K"); \
2754 const T mu = a.number<T>("mu"); \
2755 a.done(); \
2756 Json out; \
2757 out[out_key] = encode_scalar(fj::fn(K, mu)); \
2758 return out; \
2759 } \
2760 }
2761
2762LINE_FJ_K_MU(OpFjSmTput, fj_sm_tput, "X");
2763LINE_FJ_K_MU(OpFjXmaxEmma, fj_xmax_emma, "Xmax");
2764LINE_FJ_K_MU(OpFjXmaxExp, fj_xmax_exp, "Xmax");
2765#undef LINE_FJ_K_MU
2766
2767struct OpFjHarmonic {
2768 template <class T>
2769 static Json run(Args& a) {
2770 const unsigned K = a.uinteger("K");
2771 a.done();
2772 Json out;
2773 out["HK"] = encode_scalar(fj::fj_harmonic<T>(K));
2774 return out;
2775 }
2776};
2777
2778struct OpFjQuantile {
2779 template <class T>
2780 static Json run(Args& a) {
2781 const unsigned K = a.uinteger("K");
2782 const T q = a.number<T>("q");
2783 a.done();
2784 Json out;
2785 out["x"] = encode_scalar(fj::fj_quantile(K, q));
2786 return out;
2787 }
2788};
2789
2790struct OpFjResptTwoway {
2791 template <class T>
2792 static Json run(Args& a) {
2793 const T lambda = a.number<T>("lambda");
2794 const T mu = a.number<T>("mu");
2795 a.done();
2796 Json out;
2797 out["R"] = encode_scalar(fj::fj_respt_2way(lambda, mu));
2798 return out;
2799 }
2800};
2801
2802struct OpFjSynchDelay {
2803 template <class T>
2804 static Json run(Args& a) {
2805 const T lambda = a.number<T>("lambda");
2806 const T mu = a.number<T>("mu");
2807 a.done();
2808 Json out;
2809 out["D"] = encode_scalar(fj::fj_synch_delay(lambda, mu));
2810 return out;
2811 }
2812};
2813
2814struct OpFjXmax2 {
2815 template <class T>
2816 static Json run(Args& a) {
2817 const T lambda1 = a.number<T>("lambda1");
2818 const T lambda2 = a.number<T>("lambda2");
2819 a.done();
2820 Json out;
2821 out["Xmax"] = encode_scalar(fj::fj_xmax_2(lambda1, lambda2));
2822 return out;
2823 }
2824};
2825
2826struct OpFjXmaxErlang {
2827 template <class T>
2828 static Json run(Args& a) {
2829 const unsigned K = a.uinteger("K");
2830 const unsigned k = a.uinteger("k");
2831 const T mu = a.number<T>("mu");
2832 a.done();
2833 Json out;
2834 out["Xmax"] = encode_scalar(fj::fj_xmax_erlang(K, k, mu));
2835 return out;
2836 }
2837};
2838
2839struct OpFjRmaxErlang {
2840 template <class T>
2841 static Json run(Args& a) {
2842 const unsigned K = a.uinteger("K");
2843 const unsigned k = a.uinteger("k");
2844 const T lambda = a.number<T>("lambda");
2845 const T mu = a.number<T>("mu");
2846 a.done();
2847 Json out;
2848 out["Rmax"] = encode_scalar(fj::fj_rmax_erlang(K, k, lambda, mu));
2849 return out;
2850 }
2851};
2852
2853struct OpFjXmaxHyperexp {
2854 template <class T>
2855 static Json run(Args& a) {
2856 const unsigned K = a.uinteger("K");
2857 const T p1 = a.number<T>("p1");
2858 const T mu1 = a.number<T>("mu1");
2859 const T mu2 = a.number<T>("mu2");
2860 a.done();
2861 Json out;
2862 out["Xmax"] = encode_scalar(fj::fj_xmax_hyperexp(K, p1, mu1, mu2));
2863 return out;
2864 }
2865};
2866
2867/**
2868 * The EVD response-time fit. `calibrated` selects the version whose constants
2869 * were refitted, which is a DIFFERENT approximation and not a refinement of the
2870 * same one, so it defaults to the reference's own false rather than to the
2871 * one that happens to be more accurate on any given model.
2872 */
2873struct OpFjRmaxEvd {
2874 template <class T>
2875 static Json run(Args& a) {
2876 const unsigned K = a.uinteger("K");
2877 const T R = a.number<T>("R");
2878 const T sigma_R = a.number<T>("sigma_R");
2879 const bool calibrated = a.boolean("calibrated", false);
2880 a.done();
2881 Json out;
2882 out["Rmax"] = encode_scalar(fj::fj_rmax_evd(K, R, sigma_R, calibrated));
2883 return out;
2884 }
2885};
2886
2887struct OpFjBounds {
2888 template <class T>
2889 static Json run(Args& a) {
2890 const unsigned K = a.uinteger("K");
2891 const T lambda = a.number<T>("lambda");
2892 const T mu = a.number<T>("mu");
2893 a.done();
2894 const fj::FJBoundsResult<T> r = fj::fj_bounds(K, lambda, mu);
2895 Json out;
2896 out["Rmax"] = encode_scalar(r.Rmax);
2897 out["Rmin"] = encode_scalar(r.Rmin);
2898 return out;
2899 }
2900};
2901
2902struct OpFjCharMax {
2903 template <class T>
2904 static Json run(Args& a) {
2905 const unsigned K = a.uinteger("K");
2906 const T mu = a.number<T>("mu");
2907 a.done();
2908 const fj::FJCharMaxResult<T> r = fj::fj_char_max(K, mu);
2909 Json out;
2910 out["MK"] = encode_scalar(r.MK);
2911 out["mK"] = encode_scalar(r.mK);
2912 return out;
2913 }
2914};
2915
2916struct OpFjGkBound {
2917 template <class T>
2918 static Json run(Args& a) {
2919 const unsigned K = a.uinteger("K");
2920 a.done();
2921 const fj::FJGKBoundResult<T> r = fj::fj_gk_bound<T>(K);
2922 Json out;
2923 out["K"] = encode_count(r.K);
2924 out["exponential"] = encode_scalar(r.exponential);
2925 out["uniform"] = encode_scalar(r.uniform);
2926 out["evd"] = encode_scalar(r.evd);
2927 out["upper_bound"] = encode_scalar(r.upper_bound);
2928 return out;
2929 }
2930};
2931
2932struct OpFjOrdstatExp {
2933 template <class T>
2934 static Json run(Args& a) {
2935 const std::vector<T> ri = a.vector<T>("ri");
2936 const std::size_t k = a.count("k");
2937 a.done();
2938 Json out;
2939 out["m"] = encode_scalar(fj::fj_ordstat_exp<T>(ri, k));
2940 return out;
2941 }
2942};
2943
2944struct OpFjQuorumMoments {
2945 template <class T>
2946 static Json run(Args& a) {
2947 const std::vector<T> branchMeans = a.vector<T>("branchMeans");
2948 const std::vector<T> branchVars = a.vector<T>("branchVars");
2949 const std::size_t k = a.count("k");
2950 a.done();
2951 const fj::FJQuorumMomentsResult<T> r =
2952 fj::fj_quorum_moments(branchMeans, branchVars, k);
2953 Json out;
2954 out["m"] = encode_scalar(r.m);
2955 out["v"] = encode_scalar(r.v);
2956 return out;
2957 }
2958};
2959
2960struct OpFjXmaxApprox {
2961 template <class T>
2962 static Json run(Args& a) {
2963 const unsigned K = a.uinteger("K");
2964 const T mu_X = a.number<T>("mu_X");
2965 const T sigma_X = a.number<T>("sigma_X");
2966 const std::string t = a.text("type", "Exp");
2968 if (t == "Exp") type = fj::FJDistType::Exp;
2969 else if (t == "Uniform") type = fj::FJDistType::Uniform;
2970 else if (t == "Evd") type = fj::FJDistType::Evd;
2971 else if (t == "Bound") type = fj::FJDistType::Bound;
2972 else throw InputError("'type' must be Exp, Uniform, Evd or Bound; got '" + t + "'");
2973 a.done();
2974 const fj::FJXmaxApproxResult<T> r = fj::fj_xmax_approx(K, mu_X, sigma_X, type);
2975 Json out;
2976 out["Xmax"] = encode_scalar(r.Xmax);
2977 out["GK"] = encode_scalar(r.GK);
2978 return out;
2979 }
2980};
2981
2982struct OpFjXmaxNormal {
2983 template <class T>
2984 static Json run(Args& a) {
2985 const unsigned K = a.uinteger("K");
2986 const T mu = a.number<T>("mu");
2987 const T sigma = a.number<T>("sigma");
2988 const std::string m = a.text("method", "Johnson");
2990 if (m == "Johnson") method = fj::FJNormalMethod::Johnson;
2991 else if (m == "Arnold") method = fj::FJNormalMethod::Arnold;
2992 else if (m == "Corrected") method = fj::FJNormalMethod::Corrected;
2993 else throw InputError("'method' must be Johnson, Arnold or Corrected; got '" + m + "'");
2994 a.done();
2995 const fj::FJXmaxNormalResult<T> r = fj::fj_xmax_normal(K, mu, sigma, method);
2996 Json out;
2997 out["Xmax"] = encode_scalar(r.Xmax);
2998 out["Vmax"] = encode_scalar(r.Vmax);
2999 return out;
3000 }
3001};
3002
3003struct OpFjXmaxPareto {
3004 template <class T>
3005 static Json run(Args& a) {
3006 const unsigned K = a.uinteger("K");
3007 const T beta = a.number<T>("beta");
3008 const T k = a.number<T>("k");
3009 a.done();
3010 const fj::FJXmaxParetoResult<T> r = fj::fj_xmax_pareto(K, beta, k);
3011 Json out;
3012 out["Xmax"] = encode_scalar(r.Xmax);
3013 out["MK"] = encode_scalar(r.MK);
3014 return out;
3015 }
3016};
3017
3018
3019
3020DispatchTable build_dispatch_table() {
3022 {"pfqn_ca", make<OpPfqnCa>()},
3023 {"pfqn_conv", make<OpPfqnConv>()},
3024 {"pfqn_recal", make<OpPfqnRecal>()},
3025 {"pfqn_gld", make<OpPfqnGld>()},
3026 {"pfqn_mva", make<OpPfqnMva>()},
3027 {"pfqn_comom", make<OpPfqnComom>()},
3028 {"pfqn_comomrm", make<OpPfqnComomrm>()},
3029 {"pfqn_comomrm_orig", make<OpPfqnComomrmOrig>()},
3030 {"pfqn_comomrm_ms", make<OpPfqnComomrmMs>()},
3031 {"pfqn_procomom", make<OpPfqnProcomom>()},
3032 {"ctmc_solve", make<OpCtmcSolve>()},
3033 {"dtmc_solve", make<OpDtmcSolve>()},
3034 {"ctmc_makeinfgen", make<OpCtmcMakeinfgen>()},
3035 {"sim_vonneumann", make<OpSimVonneumann>()},
3036 {"sim_shapirowilk", make<OpSimShapirowilk>()},
3037 {"sim_sts_quantile_areas", make<OpSimStsQuantileAreas>()},
3038 {"sim_fquest", make<OpSimFquest>()},
3039 {"sim_firquest", make<OpSimFirquest>()},
3040 {"qsys_bmapphnn_retrial", make<OpQsysBmapphnnRetrial>()},
3041 {"aoi_fcfs_dm1", make<NeedsTranscendental<OpAoiFcfsDm1>>()},
3042 {"aoi_fcfs_gim1", make<NeedsTranscendental<OpAoiFcfsGim1>>()},
3043 {"aoi_fcfs_md1", make<NeedsTranscendental<OpAoiFcfsMd1>>()},
3044 {"aoi_fcfs_mgi1", make<NeedsTranscendental<OpAoiFcfsMgi1>>()},
3045 {"aoi_fcfs_mm1", make<OpAoiFcfsMm1>()},
3046 {"aoi_lcfsd_gim1", make<NeedsTranscendental<OpAoiLcfsdGim1>>()},
3047 {"aoi_lcfsd_mgi1", make<NeedsTranscendental<OpAoiLcfsdMgi1>>()},
3048 {"aoi_lcfspr_dm1", make<NeedsTranscendental<OpAoiLcfsprDm1>>()},
3049 {"aoi_lcfspr_gim1", make<NeedsTranscendental<OpAoiLcfsprGim1>>()},
3050 {"aoi_lcfspr_md1", make<NeedsTranscendental<OpAoiLcfsprMd1>>()},
3051 {"aoi_lcfspr_mgi1", make<NeedsTranscendental<OpAoiLcfsprMgi1>>()},
3052 {"aoi_lcfspr_mm1", make<OpAoiLcfsprMm1>()},
3053 {"aoi_lcfss_gim1", make<NeedsTranscendental<OpAoiLcfssGim1>>()},
3054 {"aoi_lcfss_mgi1", make<NeedsTranscendental<OpAoiLcfssMgi1>>()},
3055 {"fj_bounds", make<OpFjBounds>()},
3056 {"fj_char_max", make<NeedsTranscendental<OpFjCharMax>>()},
3057 {"fj_gk_bound", make<NeedsTranscendental<OpFjGkBound>>()},
3058 {"fj_harmonic", make<OpFjHarmonic>()},
3059 {"fj_quantile", make<NeedsTranscendental<OpFjQuantile>>()},
3060 {"fj_ordstat_exp", make<OpFjOrdstatExp>()},
3061 {"fj_quorum_moments", make<NeedsTranscendental<OpFjQuorumMoments>>()},
3062 {"fj_respt_2way", make<OpFjResptTwoway>()},
3063 {"fj_respt_nt", make<OpFjResptNt>()},
3064 {"fj_respt_varki", make<OpFjResptVarki>()},
3065 {"fj_respt_vm", make<OpFjResptVm>()},
3066 {"fj_rmax", make<OpFjRmax>()},
3067 {"fj_rmax_erlang", make<NeedsTranscendental<OpFjRmaxErlang>>()},
3068 {"fj_rmax_evd", make<NeedsTranscendental<OpFjRmaxEvd>>()},
3069 {"fj_sm_tput", make<OpFjSmTput>()},
3070 {"fj_synch_delay", make<OpFjSynchDelay>()},
3071 {"fj_xmax_2", make<OpFjXmax2>()},
3072 {"fj_xmax_approx", make<NeedsTranscendental<OpFjXmaxApprox>>()},
3073 {"fj_xmax_emma", make<NeedsTranscendental<OpFjXmaxEmma>>()},
3074 {"fj_xmax_erlang", make<NeedsTranscendental<OpFjXmaxErlang>>()},
3075 {"fj_xmax_exp", make<OpFjXmaxExp>()},
3076 {"fj_xmax_hyperexp", make<OpFjXmaxHyperexp>()},
3077 {"fj_xmax_normal", make<NeedsTranscendental<OpFjXmaxNormal>>()},
3078 {"fj_xmax_pareto", make<NeedsTranscendental<OpFjXmaxPareto>>()},
3079 {"ctmc_courtois", make<NeedsTranscendental<OpCtmcCourtois>>()},
3080 {"ctmc_fau", make<NeedsTranscendental<OpCtmcFau>>()},
3081 {"ctmc_foxglynn", make<NeedsTranscendental<OpCtmcFoxglynn>>()},
3082 {"ctmc_saddlepoint", make<NeedsTranscendental<OpCtmcSaddlepoint>>()},
3083 {"ctmc_bicgstab", make<NeedsTranscendental<OpCtmcBicgstab>>()},
3084 {"ctmc_bicgstab_multi", make<NeedsTranscendental<OpCtmcBicgstabMulti>>()},
3085 {"ctmc_gmres", make<NeedsTranscendental<OpCtmcGmres>>()},
3086 {"ctmc_gmres_multi", make<NeedsTranscendental<OpCtmcGmresMulti>>()},
3087 {"ctmc_kms", make<NeedsTranscendental<OpCtmcKms>>()},
3088 {"ctmc_multi", make<NeedsTranscendental<OpCtmcMulti>>()},
3089 {"ctmc_randomization", make<OpCtmcRandomization>()},
3090 {"ctmc_sens", make<OpCtmcSens>()},
3091 {"ctmc_solve_reducible", make<OpCtmcSolveReducible>()},
3092 {"ctmc_solve_reducible_blkdecomp", make<OpCtmcSolveReducibleBlkdecomp>()},
3093 {"ctmc_takahashi", make<NeedsTranscendental<OpCtmcTakahashi>>()},
3094 {"ctmc_transient", make<NeedsTranscendental<OpCtmcTransient>>()},
3095 {"ctmc_transient_sens", make<NeedsTranscendental<OpCtmcTransientSens>>()},
3096 {"dtmc_makestochastic", make<OpDtmcMakestochastic>()},
3097 {"dtmc_solve_reducible", make<OpDtmcSolveReducible>()},
3098 {"moment_binomial_from_factorial", make<OpMomentBinomialFromFactorial>()},
3099 {"moment_binomial_from_negbinomial", make<OpMomentBinomialFromNegbinomial>()},
3100 {"moment_binotrans", make<OpMomentBinotrans>()},
3101 {"moment_binotransinv", make<OpMomentBinotransinv>()},
3102 {"moment_central_from_raw", make<OpMomentCentralFromRaw>()},
3103 {"moment_factorial_from_binomial", make<OpMomentFactorialFromBinomial>()},
3104 {"moment_factorial_from_raw", make<OpMomentFactorialFromRaw>()},
3105 {"moment_factorial_from_upfactorial", make<OpMomentFactorialFromUpfactorial>()},
3106 {"moment_lah", make<OpMomentLah>()},
3107 {"moment_negbinomial_from_binomial", make<OpMomentNegbinomialFromBinomial>()},
3108 {"moment_negbinomial_from_upfactorial", make<OpMomentNegbinomialFromUpfactorial>()},
3109 {"moment_raw_from_central", make<OpMomentRawFromCentral>()},
3110 {"moment_raw_from_factorial", make<OpMomentRawFromFactorial>()},
3111 {"moment_raw_from_upfactorial", make<OpMomentRawFromUpfactorial>()},
3112 {"moment_stirling1", make<OpMomentStirling1>()},
3113 {"moment_stirling2", make<OpMomentStirling2>()},
3114 {"moment_stirlingcycle", make<OpMomentStirlingcycle>()},
3115 {"moment_upfactorial_from_factorial", make<OpMomentUpfactorialFromFactorial>()},
3116 {"moment_upfactorial_from_negbinomial", make<OpMomentUpfactorialFromNegbinomial>()},
3117 {"moment_upfactorial_from_raw", make<OpMomentUpfactorialFromRaw>()},
3118 {"stronglyconncomp", make<OpStronglyConnComp>()},
3119 {"qsys_dmc", make<NeedsTranscendental<OpQsysDmc>>()},
3120 {"dqsys_geogeo1", make<OpQsysGeoGeo1>()},
3121 {"dqsys_geoxgeo1", make<OpQsysGeoxGeo1>()},
3122 {"qsys_gg1", make<NeedsTranscendental<OpQsysGg1>>()},
3123 {"qsys_gig1_approx_allencunneen", make<OpQsysGig1AllenCunneen>()},
3124 {"qsys_gig1_approx_gelenbe", make<NeedsTranscendental<OpQsysGig1Gelenbe>>()},
3125 {"qsys_gig1_approx_heyman", make<OpQsysGig1Heyman>()},
3126 {"qsys_gig1_approx_kimura", make<OpQsysGig1Kimura>()},
3127 {"qsys_gig1_approx_klb", make<NeedsTranscendental<OpQsysGig1Klb>>()},
3128 {"qsys_gig1_approx_kobayashi", make<NeedsTranscendental<OpQsysGig1Kobayashi>>()},
3129 {"qsys_gig1_approx_marchal", make<OpQsysGig1Marchal>()},
3130 {"qsys_gig1_approx_myskja", make<NeedsTranscendental<OpQsysGig1Myskja>>()},
3131 {"qsys_gig1_approx_myskja2", make<NeedsTranscendental<OpQsysGig1Myskja2>>()},
3132 {"qsys_gig1_lbnd", make<OpQsysGig1Lbnd>()},
3133 {"qsys_gig1_ubnd_kingman", make<OpQsysGig1UbndKingman>()},
3134 {"qsys_gigk_approx", make<NeedsTranscendental<OpQsysGigkApprox>>()},
3135 {"qsys_gigk_approx_cosmetatos", make<NeedsTranscendental<OpQsysGigkCosmetatos>>()},
3136 {"qsys_gigk_approx_kingman", make<OpQsysGigkKingman>()},
3137 {"qsys_gigk_approx_whitt", make<NeedsTranscendental<OpQsysGigkWhitt>>()},
3138 {"qsys_erlanga", make<NeedsTranscendental<OpQsysErlangA>>()},
3139 {"qsys_ggnm_diffusion", make<NeedsTranscendental<OpQsysGgnmDiffusion>>()},
3140 {"qsys_gig1_bnds_extremal", make<NeedsTranscendental<OpQsysGig1BndsExtremal>>()},
3141 {"qsys_mmk_qed", make<NeedsTranscendental<OpQsysMmkQed>>()},
3142 {"qsys_mmk_qed_alpha", make<NeedsTranscendental<OpQsysMmkQedAlpha>>()},
3143 {"qsys_mmk_qed_staffing", make<NeedsTranscendental<OpQsysMmkQedStaffing>>()},
3144 {"qsys_gigk_rqt", make<NeedsTranscendental<OpQsysGigkRqt>>()},
3145 {"qsys_gig1_rqt", make<NeedsTranscendental<OpQsysGig1Rqt>>()},
3146 {"qsys_gigk_rqt_gamma", make<NeedsTranscendental<OpQsysGigkRqtGamma>>()},
3147 {"qsys_gm1", make<OpQsysGm1>()},
3148 {"qsys_mapd1", make<NeedsTranscendental<OpQsysMapd1>>()},
3149 {"qsys_mapdc", make<NeedsTranscendental<OpQsysMapdc>>()},
3150 {"qsys_mapg1", make<NeedsTranscendental<OpQsysMapg1>>()},
3151 {"qsys_mapm1", make<NeedsTranscendental<OpQsysMapm1>>()},
3152 {"qsys_mapmap1", make<NeedsTranscendental<OpQsysMapmap1>>()},
3153 {"qsys_mapmc", make<NeedsTranscendental<OpQsysMapmc>>()},
3154 {"qsys_mapph1", make<NeedsTranscendental<OpQsysMapph1>>()},
3155 {"qsys_mapphc", make<NeedsTranscendental<OpQsysMapphc>>()},
3156 {"qsys_mg1", make<OpQsysMg1>()},
3157 {"qsys_mg1_fb", make<NeedsTranscendental<OpQsysMg1Fb>>()},
3158 {"qsys_mg1_lrpt", make<NeedsTranscendental<OpQsysMg1Lrpt>>()},
3159 {"qsys_mg1_prio", make<OpQsysMg1Prio>()},
3160 {"qsys_mg1_psjf", make<NeedsTranscendental<OpQsysMg1Psjf>>()},
3161 {"qsys_mg1_setf", make<NeedsTranscendental<OpQsysMg1Setf>>()},
3162 {"qsys_mg1_srpt", make<NeedsTranscendental<OpQsysMg1Srpt>>()},
3163 {"qsys_mg1k_loss_mgs", make<NeedsTranscendental<OpQsysMg1kLossMgs>>()},
3164 {"qsys_mginf", make<NeedsTranscendental<OpQsysMginf>>()},
3165 {"qsys_mm1", make<OpQsysMm1>()},
3166 {"qsys_mm1_dps", make<NeedsTranscendental<OpQsysMm1Dps>>()},
3167 {"qsys_mm1k_loss", make<OpQsysMm1kLoss>()},
3168 {"qsys_mmcc_retrial_fp", make<NeedsTranscendental<OpQsysMmccRetrialFp>>()},
3169 {"qsys_retrial_isstable", make<NeedsTranscendental<OpQsysRetrialIsstable>>()},
3170 {"qsys_mg11_retrial", make<OpQsysMg11Retrial>()},
3171 {"qsys_mm11_retrial", make<NeedsTranscendental<OpQsysMm11Retrial>>()},
3172 {"qsys_mg11_retrial_ht", make<OpQsysMg11RetrialHt>()},
3173 {"qsys_mgck_sync", make<NeedsTranscendental<OpQsysMgckSync>>()},
3174 {"qsys_mmck", make<OpQsysMmck>()},
3175 {"qsys_mmk", make<OpQsysMmk>()},
3176 {"qsys_mxm1", make<OpQsysMxm1>()},
3177 {"qsys_mxg1", make<OpQsysMxg1>()},
3178 {"qsys_mg1_vacation", make<OpQsysMg1Vacation>()},
3179 {"qsys_mg1_breakdown", make<OpQsysMg1Breakdown>()},
3180 {"qsys_phm1", make<NeedsTranscendental<OpQsysPhm1>>()},
3181 {"qsys_phmc", make<NeedsTranscendental<OpQsysPhmc>>()},
3182 {"qsys_phph1", make<NeedsTranscendental<OpQsysPhph1>>()},
3183 };
3184 // The per-domain translation units add their own entries. A name entered
3185 // twice is a wiring error, refused at first use rather than letting the
3186 // later entry silently shadow the earlier one.
3187 for (const auto& reg : api_dispatch_registrars()) {
3188 DispatchTable part;
3189 reg(part);
3190 for (auto& kv : part) {
3191 if (!table.emplace(kv.first, std::move(kv.second)).second)
3192 throw std::logic_error("--api dispatch: '" + kv.first + "' is registered twice");
3193 }
3194 }
3195 return table;
3196}
3197
3198const DispatchTable& dispatch_table() {
3199 static const DispatchTable table = build_dispatch_table();
3200 return table;
3201}
3202
3203const std::map<std::string, std::string>& library_only_table() {
3204 static const std::map<std::string, std::string> table = [] {
3205 std::map<std::string, std::string> t;
3206 for (const auto& reg : api_library_only_registrars()) reg(t);
3207 return t;
3208 }();
3209 return table;
3210}
3211
3212std::string join(const std::vector<std::string>& v, const char* sep) {
3213 std::string s;
3214 for (std::size_t i = 0; i < v.size(); ++i) {
3215 if (i) s += sep;
3216 s += v[i];
3217 }
3218 return s;
3219}
3220
3221} // namespace
3222
3223std::vector<std::string> api_exposed_functions() {
3224 std::vector<std::string> names;
3225 for (const auto& kv : dispatch_table()) names.push_back(kv.first);
3226 return names; // std::map already orders them
3227}
3228
3229std::map<std::string, std::string> api_library_only_functions() {
3230 return library_only_table();
3231}
3232
3233bool api_is_exposed(const std::string& name) {
3234 return dispatch_table().find(name) != dispatch_table().end();
3235}
3236
3237Json api_invoke(const std::string& name, const std::string& arith, const Json& args) {
3238 const ApiEntry* entry = find_api(name);
3239 if (entry == nullptr)
3240 throw UnsupportedError(ErrorKind{"Api"}, "API function '" + name +
3241 "' is not ported to C++ yet (--list-api shows what is).");
3242
3243 const ArithSpec spec = parse_arith(arith);
3244
3245 // arithmetic-gate-before-exposure-gate rationale: see _kb/14-cpp-multiprecision.md
3246 if (!api_supports(*entry, spec.mode)) {
3247 std::vector<std::string> modes;
3248 for (Arith m : entry->arith) modes.push_back(arith_name(m));
3249 throw UnsupportedError(ErrorKind{"Arithmetic"}, "API function '" + name + "' does not support --arith " +
3250 spec.str() + "; it supports: " + join(modes, ", ") + ".");
3251 }
3252
3253 auto it = dispatch_table().find(name);
3254 if (it == dispatch_table().end()) {
3255 // The two api domains that take a MODEL, not matrices, can never be
3256 // reached from here whatever the port does next, and telling a caller
3257 // to wait for an exposure that will never come is worse than telling it
3258 // nothing: it names a route that exists instead of the one that does.
3259 if (entry->domain == "sn" || entry->domain == "lqn")
3260 throw UnsupportedError(ErrorKind{"Api"},
3261 "API function '" + name +
3262 "' takes a NetworkStruct or a LayeredNetworkStruct, not matrices, so it has no "
3263 "named-JSON-argument form and --api cannot carry it in any future version. Reach "
3264 "the model-level answer with -s <solver> -a <analysis>, or call it from the "
3265 "library.");
3266 auto lo = library_only_table().find(name);
3267 if (lo != library_only_table().end())
3268 throw UnsupportedError(ErrorKind{"Api"},
3269 "API function '" + name + "' has no named-JSON-argument form: " + lo->second +
3270 " It is reachable from the C++ library only.");
3271 throw UnsupportedError(ErrorKind{"Api"},
3272 "API function '" + name +
3273 "' is ported to C++ but not yet exposed over --api; it is reachable from the library "
3274 "and its tests only. Exposed over --api so far: " +
3275 join(api_exposed_functions(), ", ") + ".");
3276 }
3277
3278 Args reader(args, name);
3279 Json out;
3280 out["function"] = name;
3281 out["arith"] = spec.str();
3282 out["results"] = it->second(spec, reader);
3283 return out;
3284}
3285
3286// ---------------------------------------------------------------------------
3287// Readable rendering
3288// ---------------------------------------------------------------------------
3289
3290namespace {
3291
3292void render_value(std::ostringstream& os, const Json& v, const std::string& indent) {
3293 // readable-vs-JSON rendering consistency: see _kb/14-cpp-multiprecision.md
3294 if (v.is_object() && v.contains("double")) {
3295 os << v["double"].dump();
3296 if (v.contains("num"))
3297 os << " = " << v["num"].get<std::string>() << " / " << v["den"].get<std::string>();
3298 else if (v.contains("dec"))
3299 os << " = " << v["dec"].get<std::string>();
3300 os << "\n";
3301 return;
3302 }
3303 if (v.is_array()) {
3304 if (!v.empty() && v[0].is_array()) {
3305 os << "\n";
3306 for (const Json& row : v) {
3307 os << indent << " ";
3308 for (std::size_t k = 0; k < row.size(); ++k) {
3309 if (k) os << " ";
3310 if (row[k].is_object() && row[k].contains("double"))
3311 os << row[k]["double"].dump();
3312 else
3313 os << row[k].dump();
3314 }
3315 os << "\n";
3316 }
3317 return;
3318 }
3319 os << "[";
3320 for (std::size_t k = 0; k < v.size(); ++k) {
3321 if (k) os << ", ";
3322 if (v[k].is_object() && v[k].contains("double"))
3323 os << v[k]["double"].dump();
3324 else
3325 os << v[k].dump();
3326 }
3327 os << "]\n";
3328 return;
3329 }
3330 os << v.dump() << "\n";
3331}
3332
3333} // namespace
3334
3335std::string api_render_readable(const Json& result) {
3336 std::ostringstream os;
3337 os << result["function"].get<std::string>() << " (arith: "
3338 << result["arith"].get<std::string>() << ")\n";
3339 const Json& res = result["results"];
3340 for (auto it = res.begin(); it != res.end(); ++it) {
3341 os << " " << it.key() << " = ";
3342 render_value(os, it.value(), " ");
3343 }
3344 return os.str();
3345}
3346
3347} // namespace reg
3348} // namespace line
Mean, variance and peak Age of Information of a D/M/1 FCFS queue.
Mean Age of Information, its transform and the peak age of a GI/M/1 FCFS queue.
Mean, variance and peak Age of Information of an M/D/1 FCFS queue.
Mean Age of Information, its transform and the peak age of an M/GI/1 FCFS queue.
Mean, variance and peak Age of Information of an M/M/1 FCFS queue.
Mean Age of Information, its transform and the peak age of a GI/M/1 non-preemptive LCFS queue with di...
Mean Age of Information, its transform and the peak age of an M/GI/1 non-preemptive LCFS queue with d...
Mean, variance and peak Age of Information of a D/M/1 preemptive LCFS queue.
Mean Age of Information, its transform and the peak age of a GI/M/1 preemptive LCFS queue.
Mean, variance and peak Age of Information of an M/D/1 preemptive LCFS queue.
Mean Age of Information, its transform and the peak age of an M/GI/1 preemptive LCFS queue.
Mean, variance and peak Age of Information of an M/M/1 preemptive LCFS queue.
Mean Age of Information, its transform and the peak age of a GI/M/1 non-preemptive LCFS queue with se...
Mean Age of Information, its transform and the peak age of an M/GI/1 non-preemptive LCFS queue with s...
Laplace-Stieltjes transform of a deterministic (constant) distribution.
Laplace-Stieltjes transform of an Erlang-k distribution.
Laplace-Stieltjes transform of an exponential distribution.
Laplace-Stieltjes transform of a phase-type distribution PH(alpha, T).
#define LINE_MOMENT_VEC(OpName, fn, in_key, out_key)
#define LINE_AOI_GIM1_TWO(OpName, fn)
#define LINE_QSYS_MG1_DISC(OpName, fn, ResultT)
The six M/G/1 disciplines, all {W per class, rhohat}.
#define LINE_FJ_K_LAMBDA_MU(OpName, fn, out_key)
The many members returning one bare number, under the reference's name.
#define LINE_QSYS_MYSKJA(OpName, fn)
#define LINE_MOMENT_TRI(OpName, fn, out_key)
The four triangular coefficient matrices, each a function of the order n.
#define LINE_FJ_K_MU(OpName, fn, out_key)
#define LINE_QSYS_GIG1(OpName, fn)
#define LINE_AOI_MGI1_TWO(OpName, fn)
The two non-preemptive LCFS M/GI/1 laws: transform at lambda plus both moments.
#define LINE_AOI_TWO(OpName, fn, k1, k2)
#define LINE_QSYS_GIGK(OpName, fn)
Direct invocation of a single API function from named JSON arguments.
Internal to the –api dispatcher: what a per-domain translation unit needs to add entries to the table...
InputError(const std::string &what)
Definition error.h:105
UnsupportedError(const std::string &what)
Definition error.h:119
Named-argument reader over the parsed JSON object.
Definition api_json.h:391
Preconditioned stabilized biconjugate gradients, for the linear systems a generator produces.
Courtois decomposition of a nearly completely decomposable (NCD) CTMC.
Transient distribution of a CTMC by fast adaptive uniformization.
Transient distribution of a CTMC by uniformization with Fox-Glynn Poisson weights.
Restarted GMRES with an ILUT preconditioner, for the linear systems a generator produces.
Restarted GMRES for a block of right-hand sides sharing one coefficient matrix.
Koury-McAllister-Stewart aggregation-disaggregation for a nearly completely decomposable CTMC.
Two-level multigrid aggregation-disaggregation for a nearly completely decomposable CTMC.
Uniformization (randomization) of a CTMC: the embedded DTMC P = I + Q/q.
Saddlepoint approximation of Pr{N(t)=k} for the counting process of a MAP.
Sensitivity of the steady-state distribution of a CTMC to a scalar parameter.
Steady-state distribution of a continuous-time Markov chain.
Limiting distribution of a CTMC whose generator may be reducible.
Limiting distribution of a reducible CTMC by direct block decomposition of the generator.
Takahashi's aggregation-disaggregation for a nearly completely decomposable CTMC.
Transient distribution of a CTMC over a time interval, by integrating the forward equations d pi/dt =...
Sensitivity of the transient distribution of a CTMC to a scalar parameter.
Geo/Geo/1: the discrete-time single-server queue with geometric interarrival and service times.
Geo^X/Geo/1: the discrete-time single-server queue with batch arrivals.
Normalize a non-negative matrix into a stochastic transition matrix.
Equilibrium distribution of a discrete-time Markov chain, and stochastic complementation.
Limiting distribution of a discrete-time Markov chain whose transition matrix may be reducible.
Upper and lower bounds on the mean response time of a K-way fork-join system of M/M/1 branches.
Gravey's characteristic maximum M_K, an upper bound on the expected maximum of K i....
G(K) factors for the standardized-maximum approximation X_K^max ~ mu + sigma G(K).
Harmonic number H_K = sum_{k=1..K} 1/k.
Mean of the k-th smallest of n independent EXPONENTIAL branch completion times, i....
Quantile of the maximum of K i.i.d.
Mean and variance of a k-of-n (quorum) join completion time, from the mean and variance of each branc...
Exact mean response time of a 2-way fork-join system of M/M/1 branches.
Nelson-Tantawi approximation to the mean response time of a K-way fork-join system of M/M/1 branches.
Varki approximation to the mean response time of a K-way fork-join system of M/M/1 branches.
Varma-Makowski light-traffic interpolation for the mean response time of a K-way fork-join system of ...
Pessimistic (independence) fork-join response time: the expected maximum of K independent M/M/1 respo...
Expected maximum of K M/E_k/1 branch response times.
Extreme-value approximation to the maximum of K branch response times, from their mean and standard d...
Saturated (single-message) maximum throughput of a K-way fork-join system with exponential branch ser...
Mean synchronization delay of a 2-way fork-join system of M/M/1 branches, i.e.
Expected maximum of two independent, possibly unequal-rate exponentials.
Two-moment approximation to the expected maximum of K i.i.d.
EMMA (Extreme-value Maximum Moment Approximation) to the expected maximum of K i.i....
Expected maximum of K i.i.d.
Expected maximum of K i.i.d.
Expected maximum of K i.i.d.
Expected maximum and variance of K i.i.d.
Expected maximum and characteristic maximum of K i.i.d.
Binomial moments from falling-factorial moments.
Binomial moments from negative-binomial moments.
Binomial transform with alternating signs.
Inverse binomial transform.
Central moments from raw moments.
Falling-factorial moments from binomial moments.
Factorial moments from raw moments, via the signed Stirling table.
Falling-factorial moments from rising-factorial moments, via the Lah numbers.
Unsigned Lah numbers.
Negative-binomial moments from binomial moments.
Negative-binomial moments from rising-factorial moments.
Raw moments from central moments and the mean.
Raw moments from factorial moments, via the Stirling table of the second kind.
Raw moments from rising-factorial moments.
Signed Stirling numbers of the first kind.
Stirling numbers of the second kind.
Unsigned Stirling numbers of the first kind (cycle numbers), orders 0..n.
Rising-factorial moments from falling-factorial moments, via the Lah numbers.
Rising-factorial moments from negative-binomial moments.
Rising-factorial moments from raw moments, via the cycle numbers.
AoiLstResult< T > aoi_lcfspr_gim1(const Lst< T > &Y_lst, const T &mu, const T &E_Y, const T &E_Y2)
Mean Age of Information, its transform and the peak age of a GI/M/1 preemptive LCFS queue.
std::function< T(const T &)> Lst
A Laplace-Stieltjes transform evaluated at real arguments.
Definition aoi_types.h:41
AoiLstResult< T > aoi_fcfs_gim1(const Lst< T > &Y_lst, const T &mu, const T &E_Y, const T &E_Y2)
Mean Age of Information, its transform and the peak age of a GI/M/1 FCFS queue.
Lst< T > aoi_lst_exp(const T &mu)
Laplace-Stieltjes transform of an exponential distribution.
Definition aoi_lst_exp.h:36
Lst< T > aoi_lst_erlang(unsigned k, const T &mu)
Laplace-Stieltjes transform of an Erlang-k distribution.
Lst< T > aoi_lst_ph(const std::vector< T > &alpha, const Matrix< T > &Tmat)
Laplace-Stieltjes transform of a phase-type distribution PH(alpha, T).
Definition aoi_lst_ph.h:48
AoiLstResult< T > aoi_lcfspr_mgi1(const T &lambda, const Lst< T > &H_lst, const T &E_H)
Mean Age of Information, its transform and the peak age of an M/GI/1 preemptive LCFS queue.
Lst< T > aoi_lst_det(const T &d)
Laplace-Stieltjes transform of a deterministic (constant) distribution.
Definition aoi_lst_det.h:37
AoiLstResult< T > aoi_fcfs_mgi1(const T &lambda, const Lst< T > &H_lst, const T &E_H, const T &E_H2)
Mean Age of Information, its transform and the peak age of an M/GI/1 FCFS queue.
GeoXGeo1Result< T > dqsys_geoxgeo1(const T &a, const T &beta, const T &s, GeoConvention convention=GeoConvention::LAS_DA)
Geo^X/Geo/1: the discrete-time single-server queue with batch arrivals.
GeoGeo1Result< T > dqsys_geogeo1(const T &a, const T &s, GeoConvention convention=GeoConvention::LAS_DA)
Geo/Geo/1: the discrete-time single-server queue with geometric interarrival and service times.
FJCharMaxResult< T > fj_char_max(unsigned K, const T &mu)
Exponential branch.
Definition fj_char_max.h:57
FJBoundsResult< T > fj_bounds(unsigned K, const T &lambda, const T &mu)
Upper and lower bounds on the mean response time of a K-way fork-join system of M/M/1 branches.
Definition fj_bounds.h:44
T fj_rmax_erlang(unsigned K, unsigned k, const T &lambda, const T &mu)
Expected maximum of K M/E_k/1 branch response times.
T fj_synch_delay(const T &lambda, const T &mu)
Mean synchronization delay of a 2-way fork-join system of M/M/1 branches, i.e.
FJGKBoundResult< T > fj_gk_bound(unsigned K)
G(K) factors for the standardized-maximum approximation X_K^max ~ mu.
Definition fj_gk_bound.h:44
T fj_respt_2way(const T &lambda, const T &mu)
Exact mean response time of a 2-way fork-join system of M/M/1 branches.
T fj_xmax_hyperexp(unsigned K, const T &p1, const T &mu1, const T &mu2)
Expected maximum of K i.i.d.
FJNormalMethod
Bracketing methods for the normal-maximum approximation.
Definition fj_types.h:44
T fj_rmax_evd(unsigned K, const T &R, const T &sigma_R, bool calibrated=false)
Extreme-value approximation to the maximum of K branch response times, from their mean and standard d...
Definition fj_rmax_evd.h:45
T fj_xmax_2(const T &lambda1, const T &lambda2)
Expected maximum of two independent, possibly unequal-rate exponentials.
Definition fj_xmax_2.h:39
T fj_xmax_erlang(unsigned K, unsigned k, const T &mu)
Expected maximum of K i.i.d.
FJXmaxApproxResult< T > fj_xmax_approx(unsigned K, const T &mu_X, const T &sigma_X, FJDistType type=FJDistType::Exp)
Two-moment approximation to the expected maximum of K i.i.d.
T fj_ordstat_exp(const std::vector< T > &ri, std::size_t k)
Mean of the k-th smallest of n independent EXPONENTIAL branch completion times, i....
FJDistType
Distribution families for which a G(K) standardized-maximum factor exists.
Definition fj_types.h:41
FJQuorumMomentsResult< T > fj_quorum_moments(const std::vector< T > &branchMeans, const std::vector< T > &branchVars, std::size_t k)
Mean and variance of a k-of-n (quorum) join completion time, from the mean and variance of each branc...
T fj_quantile(unsigned K, const T &q)
Gumbel approximation.
Definition fj_quantile.h:41
FJXmaxParetoResult< T > fj_xmax_pareto(unsigned K, const T &beta, const T &k)
Expected maximum and characteristic maximum of K i.i.d.
T fj_harmonic(unsigned K)
Harmonic number H_K = sum_{k=1..K} 1/k.
Definition fj_harmonic.h:37
FJXmaxNormalResult< T > fj_xmax_normal(unsigned K, const T &mu, const T &sigma, FJNormalMethod method=FJNormalMethod::Johnson)
Expected maximum and variance of K i.i.d.
double delta(double t)
std::string join(const std::vector< std::string > &v, const std::string &sep)
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
BicgstabResult< T > ctmc_bicgstab(const Matrix< T > &A, const std::vector< T > &b, double tol=1e-12, long maxit=0, const std::vector< T > &x0=std::vector< T >())
Preconditioned stabilized biconjugate gradients, for the linear systems a generator produces.
ReducibleResult< T > dtmc_solve_reducible(const Matrix< T > &P, const std::vector< T > &pin, double zeroColTol=1e-12)
Limiting distribution of a discrete-time Markov chain whose transition matrix may be reducible.
BlkDecompResult< T > ctmc_solve_reducible_blkdecomp(const Matrix< T > &Qin, const std::vector< T > &pin, double reachTol=1e-15, double zeroColTol=1e-12)
Limiting distribution of a reducible CTMC by direct block decomposition of the generator.
SaddlepointMethod
Which term of the steepest-descent expansion to stop at.
@ SADDLEPOINT_DANIELS2
second order, error O(1/K2^2) – the DEFAULT
@ SADDLEPOINT_PLAIN
bare first order, amplitude set to 1
@ SADDLEPOINT_DANIELS
first order with the Perron amplitude, O(1/K2)
Matrix< T > dtmc_makestochastic(const Matrix< T > &Pin)
Normalize a non-negative matrix into a stochastic transition matrix.
Matrix< T > ctmc_makeinfgen(const Matrix< T > &Q)
Set the diagonal so that every row sums to zero (ctmc_makeinfgen).
Definition ctmc_solve.h:61
KmsResult< T > ctmc_kms(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &MS, std::size_t numSteps)
Koury-McAllister-Stewart aggregation-disaggregation for a nearly completely decomposable CTMC.
Definition ctmc_kms.h:100
GmresMultiResult< T > ctmc_gmres_multi(const Matrix< T > &A, const Matrix< T > &B, double tol=1e-12, long restart=0, long maxit=0)
Restarted GMRES for a block of right-hand sides sharing one coefficient matrix.
TakahashiResult< T > ctmc_takahashi(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &MS, std::size_t numSteps, double massTol=1e-14)
Takahashi's aggregation-disaggregation for a nearly completely decomposable CTMC.
ReducibleResult< T > ctmc_solve_reducible(const Matrix< T > &Q, const std::vector< T > &pi0, double zeroColTol=1e-12)
Limiting distribution of a CTMC whose generator may be reducible.
MultiResult< T > ctmc_multi(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &MS, const std::vector< std::vector< std::size_t > > &MSS, const T &q)
Two-level multigrid aggregation-disaggregation for a nearly completely decomposable CTMC.
Definition ctmc_multi.h:61
SccResult stronglyconncomp(const Matrix< T > &A)
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
BicgstabMultiResult< T > ctmc_bicgstab_multi(const Matrix< T > &A, const Matrix< T > &B, double tol=1e-12, long maxit=0)
Every column of B solved against the SAME equilibration, reordering and ILUT factorization,...
std::vector< T > dtmc_solve(const Matrix< T > &P)
Stationary distribution of a stochastic matrix P.
Definition dtmc_solve.h:106
SaddlepointResult< T > ctmc_saddlepoint(const Matrix< T > &D0, const Matrix< T > &D1, const std::vector< T > &t, const std::vector< long > &k, SaddlepointMethod method=SADDLEPOINT_DANIELS2, const std::vector< T > &pi0=std::vector< T >())
Pr{N(t)=k} over arrays of horizons and counts.
RandomizationResult< T > ctmc_randomization(const Matrix< T > &Q, const T &q)
Uniformization (randomization) of a CTMC: the embedded DTMC P = I + Q/q.
GmresResult< T > ctmc_gmres(const Matrix< T > &A, const std::vector< T > &b, double tol=1e-12, long restart=0, long maxit=0, const std::vector< T > &x0=std::vector< T >())
Restarted GMRES with an ILUT preconditioner, for the linear systems a generator produces.
Definition ctmc_gmres.h:653
TransientSensResult< T > ctmc_transient_sens(const Matrix< T > &Q, const Matrix< T > &dQ, const std::vector< T > &pi0, const T &t0, const T &t1, double rtol=1e-3, double atol=1e-6)
Sensitivity of the transient distribution of a CTMC to a scalar parameter.
FoxGlynnResult< T > ctmc_foxglynn(const std::vector< T > &pi0, const Matrix< T > &Q, const T &t, double tol=1e-12, long maxiter=-1)
Transient distribution of a CTMC by uniformization with Fox-Glynn Poisson weights.
TransientResult< T > ctmc_transient(const Matrix< T > &Q, const std::vector< T > &pi0, const T &t0, const T &t1, double rtol=1e-3, double atol=1e-6, bool stiff=false)
Transient distribution of a CTMC over a time interval, by integrating the forward equations d pi/dt =...
CourtoisResult< T > ctmc_courtois(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &MS, const T &q)
Courtois decomposition of a nearly completely decomposable (NCD) CTMC.
FauResult< T > ctmc_fau(const std::vector< T > &pi0, const Matrix< T > &Q, const T &t, double epsilon=1e-6, double delta=1e-12, long maxsteps=-1)
Transient distribution of a CTMC by fast adaptive uniformization.
Definition ctmc_fau.h:256
std::vector< T > ctmc_sens(const Matrix< T > &Q, const Matrix< T > &dQ, const std::vector< T > &pi)
Sensitivity of the steady-state distribution of a CTMC to a scalar parameter.
Definition ctmc_sens.h:52
const std::map< std::string, std::vector< std::string > > & table()
std::vector< T > moment_raw_from_central(const std::vector< T > &mc, const T &m1)
m_i = sum_k C(i,k) mc_k m1^(i-k).
NcResult< T > pfqn_recal(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &m0)
RECAL (REcursive CALculation) for the exact normalizing constant of a closed product-form network (Co...
Definition pfqn_recal.h:188
ProcomomResult< T > pfqn_procomom(const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z, const T &atol)
Marginal queue-length distributions of every station.
MvaResult< T > pfqn_mva(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi)
Exact Mean Value Analysis for closed product-form networks (Reiser and Lavenberg 1980).
Definition pfqn_mva.h:72
ComomResult< T > pfqn_comomrm_orig(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const T &atol)
Original CoMoM for the finite repairman model (matlab pfqn_comomrm_orig.m).
Definition pfqn_comom.h:285
ComomResult< T > pfqn_comomrm(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, int m)
CoMoM (class-oriented method of moments) for the finite repairman model: one queueing station of mult...
NcResult< T > pfqn_ca(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z)
Convolution algorithm for the exact normalizing constant of a closed product-form network (Buzen 1973...
Definition pfqn_ca.h:120
ComomRmResult< T > pfqn_comomrm_ms(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, int m, int S)
CoMoM for the MULTISERVER repairman model: one queueing station with S servers (optionally replicated...
NcResult< T > pfqn_conv(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< CdScaling< T > > &cdscaling)
Multichain convolution algorithm with class-dependent service rates (Sauer 1983, "Computational Algor...
Definition pfqn_conv.h:80
ComomResult< T > pfqn_comom(const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z, const T &atol)
CoMoM on the general basis (matlab pfqn_comom.m).
Definition pfqn_comom.h:108
NcResult< T > pfqn_gld(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &mu)
Exact normalizing constant of a closed product-form network whose stations may be load dependent (gen...
Definition pfqn_gld.h:144
MapMcResult< T > qsys_mapmc(const mam::Map< T > &arrival, const T &mu, unsigned c, std::size_t dist_size)
MAP/M/c by the matrix-geometric solution.
Definition qsys_mapmc.h:104
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.
RetrialStabilityResult< T > qsys_retrial_isstable(const std::vector< T > &lambda, const std::vector< T > &mu, unsigned c, const std::vector< T > &alpha, RetrialPolicy policy=RetrialPolicy::LINEAR, const std::vector< T > &p=std::vector< T >(), const std::vector< T > &q=std::vector< T >(), const std::vector< T > &gamma=std::vector< T >(), double maxOrbit=-1.0)
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_mm1(const T &lambda, const T &mu)
Exact mean response time of the M/M/1 queue.
Definition qsys_mm1.h:36
Mm1kLossResult< T > qsys_mm1k_loss(const T &lambda, const T &mu, unsigned K)
Blocking probability of the M/M/1/K queue.
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.
RetrialPolicy
Retrial admission policy (RetrialPolicy in MATLAB).
@ CONSTANT
the orbit retries at rate alpha whenever it is non-empty
@ LINEAR
each orbiting customer retries at rate alpha (orbit rate i*alpha)
MapMap1Result< T > qsys_phph1(const std::vector< T > &alpha, const Matrix< T > &Tm, const std::vector< T > &beta, const Matrix< T > &S, std::size_t dist_size)
PH/PH/1 by the exact QBD solution of the equivalent MAP/MAP/1 queue.
Definition qsys_phph1.h:82
@ Acyclic
three or more moments
Definition qsys_mapg1.h:120
@ ErlangMixture
0 < cv2 < 1, the moment-exact Tijms mixture
Definition qsys_mapg1.h:118
@ Exponential
one moment, or cv2 exactly 1
Definition qsys_mapg1.h:116
@ Erlang
the cv2 <= 0 branch (Erlang-100)
Definition qsys_mapg1.h:117
MmccRetrialFpResult< T > qsys_mmcc_retrial_fp(const T &lambda, const T &mu, unsigned c, const T &tol, std::size_t maxiter, const T &p=num_traits< T >::from_int(1), const T &q=num_traits< T >::from_int(1))
M/M/c/c with retrials by the Cohen fixed point.
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.
MapG1Result< T > qsys_mapg1(const mam::Map< T > &arrival, const std::vector< T > &moments, std::size_t dist_size, std::size_t numQLMoms, std::size_t numSTMoms)
The MAP/G/1 FCFS queue.
Definition qsys_mapg1.h:382
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
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
QsysRes qsys_mg1_prio_res(const std::vector< double > &lambda, const std::vector< double > &mu, const std::vector< double > &cs, const std::vector< double > &ES3=std::vector< double >())
The res output of qsys_mg1_prio (Cobham's HOL priority M/G/1).
QsysQedStaffingResult< T > qsys_mmk_qed_staffing(const T &lambda, const T &mu, const T &target, QedCriterion crit=QedCriterion::Delay, const T &deadline=num_traits< T >::from_int(0), const T &level=num_traits< T >::from_int(0), bool exact=false)
Square-root staffing of the M/M/s queue.
MmckResult< T > qsys_mmck(const T &lambda, const T &mu, unsigned c, unsigned K)
Exact analysis of the M/M/c/K queue (truncated Erlang form).
Definition qsys_mmck.h:70
GigkRqtResult< T > qsys_gig1_rqt(const T &lambda, const T &mu, const T &Gamma_a, const T &Gamma_s, const T &alpha_a, const T &alpha_s)
Robust Queueing Theory (RQT) worst-case system time of a G/G/1 FCFS queue, the single-server case of ...
QedCriterion
Which target the staffing rule is asked to meet.
QsysRes qsys_mmk_res(double lambda, double mu, unsigned k, const QsysResOptions &o=QsysResOptions())
The res output of qsys_mmk: the full M/M/k measure set.
Definition qsys_mmk.h:87
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
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...
MapD1Result< T > qsys_mapd1(const mam::Map< T > &arrival, const T &s, std::size_t dist_size, unsigned max_arrivals, std::size_t max_levels, const T &tol, std::size_t num_steps)
MAP/D/1 by the exact embedded M/G/1-type chain.
Definition qsys_mapd1.h:330
QsysRes qsys_mg1_res(double lambda, double mu, double cs, double ES3=-1.0)
The res output of qsys_mg1 (Pollaczek-Khinchine and Takacs).
Definition qsys_mg1.h:60
T qsys_mmk_qed_alpha(const T &beta)
The Halfin-Whitt delay-probability function alpha(beta); 1 at beta <= 0.
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
MapPhcResult< T > qsys_mapphc(const mam::Map< T > &arrival, const std::vector< T > &alpha, const Matrix< T > &S, unsigned c, std::size_t dist_size, std::size_t num_w_moms, const std::vector< T > &w_points)
MAP/PH/c FCFS, exactly.
Mg11RetrialResult< T > qsys_mg11_retrial(const T &lambda, const T &mu, const T &cs, const T &nu, RetrialPolicy policy=RetrialPolicy::LINEAR)
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
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.
MeanValueResult< T > qsys_mg1_vacation(const T &lambda, const T &mu, const T &cs, const T &EV, const T &EV2, const Mg1VacationOptions< T > &opt=Mg1VacationOptions< T >())
Exhaustive-service M/G/1 (or M^X/G/1) with vacations.
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
QsysRes qsys_mm1_res(double lambda, double mu, const QsysResOptions &o=QsysResOptions())
The res output of qsys_mm1: the full M/M/1 measure set.
Definition qsys_mm1.h:53
BmapPhNnRetrialResult< T > qsys_bmapphnn_retrial(const std::vector< Matrix< T > > &D, const std::vector< T > &beta, const Matrix< T > &S, int N, const T &alpha, const T &gamma, const T &p, const std::vector< long > &R, const BmapPhNnRetrialOptions &opt)
The BMAP/PH/N/N bufferless retrial 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
Mm11RetrialResult< T > qsys_mm11_retrial(const T &lambda, const T &mu, const T &nu, RetrialPolicy policy=RetrialPolicy::LINEAR, long nmax=-1)
MginfResult< T > qsys_mginf(const T &lambda, const T &mu)
Exact solution of the M/G/infinity queue.
Definition qsys_mginf.h:53
MapMap1Result< T > qsys_mapmap1(const mam::Map< T > &arrival, const mam::Map< T > &service, std::size_t dist_size, std::size_t numQLMoms, std::size_t numSTMoms)
MAP/MAP/1 FCFS queue with the service MAP honoured, correlation included.
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...
MgckSyncResult< T > qsys_mgck_sync(const T &lambda, std::size_t c, std::size_t K, const ServiceLaw< T > &svc, const std::string &variant, std::size_t nphases, const T &tol, std::size_t nmaxCap)
Synchronous approximation of the M/G/c/K queue with dual bounds.
MapMcResult< T > qsys_mapm1(const mam::Map< T > &arrival, const T &mu, std::size_t dist_size)
MAP/M/1 by the matrix-geometric solution, i.e.
Definition qsys_mapm1.h:77
MapMap1Result< T > qsys_mapph1(const mam::Map< T > &arrival, const std::vector< T > &sigma, const Matrix< T > &S, std::size_t dist_size)
MAP/PH/1 by the exact QBD solution of the equivalent MAP/MAP/1 queue.
DmcResult< T > qsys_dmc(const T &lambda, const T &mu, unsigned c, unsigned truncation, unsigned quadSteps)
D/M/c: deterministic interarrival times, exponential service.
Definition qsys_dmc.h:122
Mg11RetrialHtResult< T > qsys_mg11_retrial_ht(const T &lambda, const T &mu, const T &cs, const T &nu, RetrialPolicy policy=RetrialPolicy::LINEAR)
See the file comment; the arguments are those of qsys_mg11_retrial.
QsysRes qsys_gm1_res(double sigma, double mu, double lambda=-1.0, const QsysResOptions &o=QsysResOptions())
The res output of qsys_gm1: the GI/M/1 measure set from the root sigma.
Definition qsys_gm1.h:56
PhMcResult< T > qsys_phmc(const std::vector< T > &alpha, const Matrix< T > &Tm, const T &mu, unsigned c, unsigned maxIter, const T &tol)
Exact PH/M/c by Neuts' matrix-geometric method.
Definition qsys_phmc.h:97
QsysRes qsys_mmck_dist(double lambda, double mu, unsigned c, unsigned K, const QsysResOptions &o=QsysResOptions())
The distributional part of qsys_mmck: waiting/sojourn CDFs and percentiles.
Definition qsys_mmck.h:141
MapDcResult< T > qsys_mapdc(const mam::Map< T > &arrival, const T &s, unsigned c, std::size_t dist_size, unsigned max_arrivals, std::size_t max_levels, const T &tol, std::size_t num_steps)
MAP/D/c by Crommelin's exact embedded lattice chain.
Definition qsys_mapdc.h:157
nlohmann::json Json
Definition api_json.h:63
const std::vector< void(*)(LibraryOnlyTable &)> & api_library_only_registrars()
std::string api_render_readable(const Json &result)
Human-readable rendering of the object api_invoke returns, for -o readable.
ArithSpec parse_arith(const std::string &text)
Parse –arith.
qsys::QsysResOptions read_qsys_res_options(Args &a, bool with_nmax=true)
The 'tPoints', 'percentiles' and 'nmax' options those functions share.
std::vector< T > vector_from_json(const Json &j, const std::string &where)
A flat numeric vector: 1-D array, or a 1-row / 1-column 2-D array.
Definition api_json.h:255
Json encode_vector(const std::vector< T > &v)
Definition api_json.h:333
std::vector< std::string > api_exposed_functions()
Names exposed over this boundary, sorted; a subset of the registry.
Json encode_matrix(const Matrix< T > &m)
Definition api_json.h:340
std::string decimal_text(const Json &j, const std::string &where)
The decimal literal behind a JSON scalar, per the policy in the file header.
Definition api_json.h:199
std::map< std::string, std::string > api_library_only_functions()
Registered functions that can NEVER be carried by named JSON arguments, each with the reason (a calla...
Json encode_scalar(const T &v)
Definition api_json.h:328
Json encode_count(std::size_t n)
A count.
Definition api_json.h:378
Json encode_qsys_res(const qsys::QsysResT< T > &r)
MATLAB's res struct of the exact queueing-system functions: one key per measure, in the reference's f...
std::map< std::string, Invoker > DispatchTable
bool api_is_exposed(const std::string &name)
True when the named function has a dispatch entry.
const std::vector< void(*)(DispatchTable &)> & api_dispatch_registrars()
Json api_invoke(const std::string &name, const std::string &arith, const Json &args)
Invoke one API function.
QuestResult< T > sim_fquest(const std::vector< T > &Y, double p, double alpha=0.05, const QuestOptions &options=QuestOptions())
Fixed-sample-size confidence interval for a steady-state quantile.
Definition sim_fquest.h:130
QuestResult< T > sim_firquest(const std::vector< std::vector< T > > &Y, double p, double alpha=0.05, const QuestOptions *options=nullptr)
Fixed-sample-size quantile interval from independent replications.
StsQuantileStats< T > sim_sts_quantile_areas(const std::vector< T > &Y, std::size_t b, std::size_t m, double p, double weight=std::sqrt(12.0))
Standardized time series areas of the batched quantile process.
VonNeumannResult< T > sim_vonneumann(const std::vector< T > &x, double alpha=0.05)
Von Neumann ratio test for randomness of a sequence.
ShapiroWilkResult< T > sim_shapirowilk(const std::vector< T > &x, double alpha=0.05)
Shapiro-Wilk test for univariate normality.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Arith
Definition registry.h:26
const char * arith_name(Arith a)
Definition registry.h:28
const ApiEntry * find_api(const std::string &name)
Definition registry.h:1956
bool api_supports(const ApiEntry &e, Arith a)
Definition registry.h:1963
Convolution algorithm for the exact normalizing constant of a closed product-form network (Buzen 1973...
CoMoM (class-oriented method of moments), the general basis formulation, and the original repairman-m...
CoMoM (class-oriented method of moments) for the finite repairman model: one queueing station of mult...
CoMoM for the MULTISERVER repairman model: one queueing station with S servers (optionally replicated...
Multichain convolution algorithm with class-dependent service rates (Sauer 1983, "Computational Algor...
Exact normalizing constant of a closed product-form network whose stations may be load dependent (gen...
Exact Mean Value Analysis for closed product-form networks (Reiser and Lavenberg 1980).
ProCoMoM: marginal queue-length probabilities of a closed multiclass product-form network by the clas...
RECAL (REcursive CALculation) for the exact normalizing constant of a closed product-form network (Co...
The BMAP/PH/N/N bufferless retrial queue with flexible retrial admission control.
D/M/c: deterministic interarrival times, exponential service.
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.
Myskja's enhanced third-moment approximation of the mean response time of a G/I/G/1 queue.
Myskja's third-moment approximation of the mean response time of a G/I/G/1 queue.
Extremal two-moment bounds for the GI/GI/1 queue.
Fundamental lower bound on the mean response time of a G/G/1 queue.
Robust Queueing Theory (RQT) worst-case system time of a G/G/1 FCFS queue, the single-server case of ...
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.
Cosmetatos / Page interpolation approximation for the GI/G/k queue.
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 mean response time of the G/M/1 queue.
The MAP/D/1 FCFS queue: deterministic service of length s fed by a Markovian arrival process.
The MAP/D/c FCFS queue: c servers, deterministic service of length s, fed by a Markovian arrival proc...
The MAP/G/1 FCFS queue, by moment-matching the general service time to a phase-type distribution.
The MAP/M/1 FCFS queue, the single-server case of MAP/M/c.
The MAP/MAP/1 FCFS queue: mean number in system, waiting time, sojourn time, utilization and the queu...
The MAP/M/c FCFS queue: c identical exponential servers of rate mu fed by a Markovian arrival process...
The MAP/PH/1 FCFS queue.
The MAP/PH/c FCFS queue, solved exactly.
Exact mean measures of the single-class M/G/1/1 retrial queue.
Heavy-traffic gamma approximation of the M/G/1/1 retrial orbit size.
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 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 under SRPT (shortest remaining processing time), by the Schrage-Miller formula.
M/G/1 and M^X/G/1 exhaustive service with server vacations.
MacGregor Smith's closed-form approximation of the M/G/1/K loss probability.
Synchronous approximation of the M/G/c/K queue with dual bounds (German, EPEW 2025).
Exact solution of the M/G/infinity queue.
Engineering solution of the call-center model M/GI/s/r+GI.
Joint stationary distribution of the M/M/1/1 retrial queue.
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...
Blocking probability of the M/M/1/K queue.
Fixed-point approximation for the M/M/c/c retrial queue.
Exact analysis of the M/M/c/K queue (truncated Erlang form).
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.
Exact PH/M/c by Neuts' matrix-geometric method.
The PH/PH/1 FCFS queue.
Stability (positive recurrence) of the M/M/c/c retrial queue.
Fixed-sample-size quantile interval from independent replications.
Fixed-sample-size confidence interval for a steady-state quantile.
Options of the QUEST procedures, with the published FQUEST defaults.
Shapiro-Wilk test for univariate normality.
Standardized time series areas of the batched quantile process.
Von Neumann ratio test for randomness of a sequence.
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
std::vector< Arith > arith
arithmetic modes this function is instantiated for
Definition registry.h:40
std::string domain
api domain, e.g. "pfqn"
Definition registry.h:39
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
ErrorKind(std::string n)
Definition error.h:39
static double to_double(const double &v)
Definition number.h:137
Return value of the normalizing-constant family, mirroring Ret.pfqnNc.
Definition pfqn_ca.h:44
T G
normalizing constant in the requested arithmetic
Definition pfqn_ca.h:45
double lG
log of the constant, always a double and always finite
Definition pfqn_ca.h:46
static ServiceLaw deterministic(const T &d)
Constant service time d.
static ServiceLaw phase_type(const std::vector< T > &alpha, const Matrix< T > &Tmat)
Phase type (alpha, Tmat).
static ServiceLaw gamma(const T &shape, const T &scale)
Gamma(shape, scale).
The arithmetic a call runs at: Real also carries the precision tier.
std::string str() const
Canonical text, e.g.
unsigned digits
significant decimal digits, Real only