26#include <initializer_list>
103std::string quoted(
const char* key) {
return std::string(
"'") + key +
"'"; }
110bool long_form(
const Args& a,
const char* fn, std::initializer_list<const char*> triggers,
111 std::initializer_list<const char*> needed) {
113 for (
const char* t : triggers)
118 if (trig.empty())
return false;
119 for (
const char* n : needed)
121 throw InputError(std::string(fn) +
": '" + trig +
"' selects the long form of the C++ "
122 "port, which has no default for '" + n +
"'; give '" + n +
123 "' as well, or drop '" + trig +
"' to use the port's own defaults.");
128mam::Map<T> map_from_json(
const Json& j,
const std::string& where) {
129 if (!j.is_array() || j.size() != 2)
130 throw InputError(where +
": a MAP is a list [D0, D1] of two square matrices");
134 if (m.D0.rows() != m.D0.cols() || m.D1.rows() != m.D0.rows() || m.D1.cols() != m.D0.cols())
135 throw InputError(where +
": D0 and D1 must be square matrices of the same order");
140mam::Mmap<T> mmap_from_json(
const Json& j,
const std::string& where) {
141 if (!j.is_array() || j.size() < 3)
142 throw InputError(where +
": an MMAP is a list [D0, D1, D11, ..., D1K] of at least three "
147 for (std::size_t k = 2; k < j.size(); ++k)
149 const std::size_t n = m.D0.rows();
150 bool ok = m.D0.cols() == n && m.D1.rows() == n && m.D1.cols() == n;
151 for (
const Matrix<T>& D : m.Dc) ok = ok && D.rows() == n && D.cols() == n;
152 if (!ok)
throw InputError(where +
": every matrix of an MMAP must be square of the same order");
157mam::Map<T> read_map(
Args& a,
const char* key) {
158 return map_from_json<T>(a.get(key), quoted(key));
162mam::Mmap<T> read_mmap(
Args& a,
const char* key) {
163 return mmap_from_json<T>(a.get(key), quoted(key));
167std::vector<mam::Map<T> > read_maps(
Args& a,
const char* key) {
168 const Json& j = a.get(key);
169 if (!j.is_array() || j.empty())
170 throw InputError(quoted(key) +
": expected a non-empty list of MAPs, each [D0, D1]");
171 std::vector<mam::Map<T> > out;
172 for (std::size_t i = 0; i < j.size(); ++i)
173 out.push_back(map_from_json<T>(j[i], quoted(key) +
"[" + std::to_string(i) +
"]"));
178Json encode_map(
const mam::Map<T>& m) {
179 Json o = Json::array();
186Json encode_mmap(
const mam::Mmap<T>& m) {
187 Json o = Json::array();
190 for (
const Matrix<T>& D : m.Dc) o.push_back(
encode_matrix(D));
195Json encode_maps(
const std::vector<mam::Map<T> >& v) {
196 Json o = Json::array();
197 for (
const mam::Map<T>& m : v) o.push_back(encode_map(m));
202Json encode_mmaps(
const std::vector<mam::Mmap<T> >& v) {
203 Json o = Json::array();
204 for (
const mam::Mmap<T>& m : v) o.push_back(encode_mmap(m));
209std::vector<unsigned> unsigneds(
Args& a,
const char* key) {
210 std::vector<unsigned> out;
211 for (
int v : a.ints(key)) {
213 throw InputError(quoted(key) +
": entries must be non-negative integers, got " +
215 out.push_back(
static_cast<unsigned>(v));
221std::vector<std::size_t> one_based(
const Json& j,
const std::string& where) {
222 std::vector<std::size_t> out;
225 throw InputError(where +
": indices are 1-based, as in MATLAB; got " + std::to_string(v));
226 out.push_back(
static_cast<std::size_t
>(v - 1));
233std::vector<std::vector<T> > vectors_from_json(
const Json& j,
const std::string& where) {
234 if (!j.is_array())
throw InputError(where +
": expected a list of vectors");
235 std::vector<std::vector<T> > out;
236 for (std::size_t i = 0; i < j.size(); ++i)
242std::vector<std::vector<T> > read_vectors(
Args& a,
const char* key) {
243 return vectors_from_json<T>(a.get(key), quoted(key));
251std::vector<long> counts_with_inf(
Args& a,
const char* key) {
252 std::vector<long> out;
253 for (
double d : a.vector<
double>(key)) {
254 if (std::isinf(d) && d > 0) {
258 if (d != std::floor(d) || d < 1)
259 throw InputError(quoted(key) +
": entries must be positive integers or \"Inf\", got " +
261 out.push_back(
static_cast<long>(d));
267std::vector<long> populations(
Args& a,
const char* key,
bool open_inf) {
268 std::vector<long> out;
269 for (
double d : a.vector<
double>(key)) {
270 if (open_inf && std::isinf(d) && d > 0) {
274 if (d != std::floor(d) || d < 0)
275 throw InputError(quoted(key) +
": a population must be a non-negative integer, got " +
277 out.push_back(
static_cast<long>(d));
283std::vector<char> flags(
Args& a,
const char* key) {
284 const Json& j = a.get(key);
285 std::vector<char> out;
286 std::vector<Json> flat;
288 for (
const Json& e : j) flat.push_back(e);
291 for (
const Json& e : flat) {
292 if (e.is_boolean()) {
293 out.push_back(e.get<
bool>() ? 1 : 0);
297 if (v.size() != 1 || (v[0] != 0 && v[0] != 1))
298 throw InputError(quoted(key) +
": entries must be true, false, 0 or 1");
299 out.push_back(
static_cast<char>(v[0]));
306std::vector<Matrix<T> > per_class_routing(
Args& a,
const char* key, std::size_t R) {
307 const Json& j = a.get(key);
308 const bool single = j.is_array() && !j.empty() && j[0].is_array() && !j[0].empty() &&
312 throw InputError(quoted(key) +
": with R = " + std::to_string(R) +
313 " classes, give a list of R routing matrices (one M x M matrix per "
314 "class, P{r}(i,j) = MATLAB P(i,j,r))");
317 return a.matrices<T>(key);
321std::vector<long> reference_stations(
Args& a,
const char* key, std::size_t R) {
324 return std::vector<long>(R, -1);
326 std::vector<long> out;
327 for (
int v : a.ints(key)) {
328 if (v < 0)
throw InputError(quoted(key) +
": station indices are 1-based, 0 for the default");
329 out.push_back(v == 0 ? -1L :
static_cast<long>(v - 1));
335me::MeOptions me_options(
Args& a) {
337 const Json* j = a.opt(
"options");
339 if (!j->is_object())
throw InputError(
"'options' must be an object {tol, maxiter, verbose}");
340 for (
auto it = j->begin(); it != j->end(); ++it) {
341 const std::string k = it.key();
344 }
else if (k ==
"maxiter") {
346 if (v.size() != 1 || v[0] < 1)
347 throw InputError(
"'options.maxiter' must be a positive integer");
349 }
else if (k ==
"verbose") {
350 const bool on = it->is_boolean() ? it->get<
bool>()
354 "'options.verbose' = true prints iteration traces to the "
355 "console, which the JSON API has no channel for; omit it.");
357 throw InputError(
"'options': unknown field '" + k +
"'; accepted: tol, maxiter, verbose");
363me::MeBlkOptions me_blk_options(
Args& a) {
365 const Json* j = a.opt(
"options");
368 throw InputError(
"'options' must be an object {tol, maxiter, verbose, damping}");
369 for (
auto it = j->begin(); it != j->end(); ++it) {
370 const std::string k = it.key();
373 }
else if (k ==
"damping") {
375 }
else if (k ==
"maxiter") {
377 if (v.size() != 1 || v[0] < 1)
378 throw InputError(
"'options.maxiter' must be a positive integer");
380 }
else if (k ==
"verbose") {
381 const bool on = it->is_boolean() ? it->get<
bool>()
385 "'options.verbose' = true prints iteration traces to the "
386 "console, which the JSON API has no channel for; omit it.");
388 throw InputError(
"'options': unknown field '" + k +
389 "'; accepted: tol, maxiter, verbose, damping");
396Json encode_me_result(
const me::MeResult<T>& r,
bool with_X) {
405 o[
"iter"] =
static_cast<std::int64_t
>(r.iter);
406 o[
"converged"] = r.converged;
412mam::LevelDependentFluidBlocks<T> read_ld_blocks(
Args& a) {
413 mam::LevelDependentFluidBlocks<T> b;
414 b.masses = read_vectors<T>(a,
"masses");
415 b.iniF = read_vectors<T>(a,
"iniF");
416 b.KF = a.matrices<T>(
"KF");
417 b.cloF = a.matrices<T>(
"cloF");
418 b.iniB = read_vectors<T>(a,
"iniB");
419 b.KB = a.matrices<T>(
"KB");
420 b.cloB = a.matrices<T>(
"cloB");
421 b.Thr = a.vector<T>(
"T");
426std::vector<double> diagonal_rates(
const Json& j,
const std::string& where) {
428 if (m.empty())
return std::vector<double>();
430 if (m.rows() != m.cols())
431 throw InputError(where +
": a drift-rate matrix must be square and diagonal");
432 std::vector<double> d(m.rows());
433 for (std::size_t i = 0; i < m.rows(); ++i)
434 for (std::size_t k = 0; k < m.cols(); ++k) {
437 }
else if (m(i, k) != 0.0) {
438 throw InputError(where +
": a drift-rate matrix must be diagonal (entry (" +
439 std::to_string(i + 1) +
"," + std::to_string(k + 1) +
446std::vector<std::vector<double> > diagonal_rate_list(
Args& a,
const char* key,
bool optional) {
447 const Json* j = optional ? a.opt(key) : &a.get(key);
448 std::vector<std::vector<double> > out;
450 if (!j->is_array())
throw InputError(quoted(key) +
": expected a list of drift-rate matrices");
451 for (std::size_t i = 0; i < j->size(); ++i)
452 out.push_back(diagonal_rates((*j)[i], quoted(key) +
"[" + std::to_string(i) +
"]"));
456std::vector<mam::FluidBoundary> boundaries(
Args& a,
const char* key) {
457 std::vector<mam::FluidBoundary> out;
458 for (
int v : a.ints_or_empty(key)) {
459 if (v != 0 && v != 1)
460 throw InputError(quoted(key) +
": entries are 0 (reflective) or 1 (absorbing)");
467 const std::string w = a.text(
"what",
"");
468 if (!a.has(
"what")) a.get(
"what");
473 throw InputError(
"'what' must be one of \"pdf\", \"pdfd\", \"cdf\" or \"cdfm\", got \"" + w +
"\"");
477 if (s ==
"default" || s ==
"mixture" || s ==
"mixture.order1")
486 throw InputError(
"'config.method': unknown compression method '" + s +
487 "'; accepted: default, mixture, mixture.order1, mixture.order2, mamap2, "
488 "mamap2.fb, m3pp.approx_cov, m3pp.approx_ag, m3pp.exact_delta, "
489 "m3pp.approx_delta");
496#define LINE_MAM_MAP_UNARY(OpName, fn, outkey, enc) \
499 static Json run(Args& a) { \
500 const mam::Map<T> m = read_map<T>(a, "MAP"); \
503 o[outkey] = enc(mam::fn(m)); \
520#undef LINE_MAM_MAP_UNARY
524 static Json run(Args& a) {
525 const mam::Map<T> m = read_map<T>(a,
"MAP");
526 const std::vector<unsigned> orders = unsigneds(a,
"ORDERS");
538 static Json run(Args& a) {
539 const mam::Map<T> m = read_map<T>(a,
"MAP");
540 const std::vector<unsigned> lags = unsigneds(a,
"LAGS");
550 static Json run(Args& a) {
551 const mam::Map<T> m = read_map<T>(a,
"MAPIN");
552 const T mean = a.number<T>(
"NEWMEAN");
562 static Json run(Args& a) {
563 const mam::Map<T> m = read_map<T>(a,
"MAPIN");
571struct OpMapExponentialMean {
573 static Json run(Args& a) {
574 const T mean = a.number<T>(
"mean");
584 static Json run(Args& a) {
585 const T mean = a.number<T>(
"MEAN");
586 const unsigned k = a.uinteger(
"k");
596 static Json run(Args& a) {
597 const mam::Map<T> m = read_map<T>(a,
"MAP");
598 const unsigned n = a.uinteger(
"n");
608 static Json run(Args& a) {
609 const std::vector<mam::Map<T> > maps = read_maps<T>(a,
"MAPs");
619 static Json run(Args& a) {
620 const std::vector<T> alpha = a.vector<T>(
"alpha");
621 const std::vector<mam::Map<T> > maps = read_maps<T>(a,
"MAPs");
631 static Json run(Args& a) {
632 const Json& j = a.get(
"ph");
634 throw InputError(
"'ph' must be an object {\"alpha\": entry vector, \"subgen\": "
637 bool has_alpha =
false, has_sub =
false;
638 for (
auto it = j.begin(); it != j.end(); ++it) {
639 if (it.key() ==
"alpha") {
642 }
else if (it.key() ==
"subgen") {
646 throw InputError(
"'ph': unknown field '" + it.key() +
"'; accepted: alpha, subgen");
649 if (!has_alpha || !has_sub)
throw InputError(
"'ph' needs both 'alpha' and 'subgen'");
657struct OpMapStochcomp {
659 static Json run(Args& a) {
660 const mam::Map<T> m = read_map<T>(a,
"MAP");
661 const std::vector<std::size_t> retain = one_based(a.get(
"retain_idx"),
"'retain_idx'");
671 static Json run(Args& a) {
672 const mam::Map<T> m = read_map<T>(a,
"MAP");
673 const std::vector<unsigned> lags = unsigneds(a,
"a");
674 const std::vector<unsigned> pw = unsigneds(a,
"i");
682struct OpMapIsfeasible {
684 static Json run(Args& a) {
685 const mam::Map<T> m = read_map<T>(a,
"MAP");
686 const bool tol = a.has(
"TOL");
687 const T t = tol ? a.number<T>(
"TOL") : T();
696struct OpMapHyperexp {
698 static Json run(Args& a) {
699 const T mean = a.number<T>(
"MEAN");
700 const T scv = a.number<T>(
"SCV");
701 const bool hp = a.has(
"p");
702 const T p = hp ? a.number<T>(
"p") : T();
713 static Json run(Args& a) {
714 const mam::Map<T> m = read_map<T>(a,
"MAP");
715 const std::vector<T> prob = a.vector<T>(
"prob");
725 static Json run(Args& a) {
726 const mam::Map<T> m = read_map<T>(a,
"MAP");
727 const std::vector<unsigned> kset = unsigneds(a,
"kset");
728 const T u = a.number<T>(
"u");
736#define LINE_MAM_MAP_POINTS(OpName, fn, mapkey, ptkey, outkey) \
739 static Json run(Args& a) { \
740 const mam::Map<T> m = read_map<T>(a, mapkey); \
741 const std::vector<T> pts = a.vector<T>(ptkey); \
744 o[outkey] = encode_vector(mam::fn(m, pts)); \
754#undef LINE_MAM_MAP_POINTS
756struct OpMapCountMoment {
758 static Json run(Args& a) {
759 const mam::Map<T> m = read_map<T>(a,
"MAP");
760 const T t = a.number<T>(
"t");
761 const std::vector<unsigned> orders = unsigneds(a,
"order");
775 static Json run(Args& a) {
776 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
784struct OpMmapCountLambda {
786 static Json run(Args& a) {
787 const mam::Mmap<T> m = read_mmap<T>(a,
"mmap");
797 static Json run(Args& a) {
798 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
806struct OpMmapIsfeasible {
808 static Json run(Args& a) {
809 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
810 const bool tol = a.has(
"TOL");
811 const T t = tol ? a.number<T>(
"TOL") : T();
820struct OpMmapNormalize {
822 static Json run(Args& a) {
823 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
833 static Json run(Args& a) {
834 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
835 const Json& jm = a.get(
"M");
839 "mmap_scale: the C++ port scales to a single aggregate mean; "
840 "the per-class form (M a vector of class means) is not ported.");
841 a.unsupported(
"maxIter",
"the MATLAB reference declares it but never reads it, so it "
842 "has no effect to reproduce.");
852 static Json run(Args& a) {
853 const mam::Mmap<T> x = read_mmap<T>(a,
"MMAPa");
854 const mam::Mmap<T> y = read_mmap<T>(a,
"MMAPb");
855 const std::string opt = a.text(
"opt",
"default");
856 if (a.has(
"opt") && opt !=
"default")
858 "mmap_super: only opt = \"default\" is ported to C++; got \"" +
867struct OpMmapCountVar {
869 static Json run(Args& a) {
870 const mam::Mmap<T> m = read_mmap<T>(a,
"mmap");
871 const T t = a.number<T>(
"t");
879struct OpMmapCompress {
881 static Json run(Args& a) {
882 const mam::Mmap<T> m = read_mmap<T>(a,
"MMAP");
883 const Json* c = a.opt(
"config");
884 bool has_method =
false;
887 if (!c->is_object())
throw InputError(
"'config' must be an object {method}");
888 for (
auto it = c->begin(); it != c->end(); ++it) {
889 if (it.key() !=
"method")
890 throw InputError(
"'config': unknown field '" + it.key() +
"'; accepted: method");
891 if (!it->is_string())
throw InputError(
"'config.method' must be a string");
892 meth = compress_method(it->get<std::string>());
908template <
bool Logred>
911 static Json run(Args& a) {
912 const char* fn = Logred ?
"qbd_R_logred" :
"qbd_R";
913 const Matrix<T> B = a.matrix<T>(
"B");
914 const Matrix<T> L = a.matrix<T>(
"L");
915 const Matrix<T> F = a.matrix<T>(
"F");
916 const bool lf = long_form(a, fn, {
"iter_max",
"tol"}, {
"iter_max",
"tol"});
917 const unsigned it = lf ? a.uinteger(
"iter_max") : 0u;
918 const T tol = lf ? a.number<T>(
"tol") : T();
933 static Json run(Args& a) {
934 const Matrix<T> B = a.matrix<T>(
"B");
935 const Matrix<T> L = a.matrix<T>(
"L");
936 const Matrix<T> F = a.matrix<T>(
"F");
937 const std::string which = a.text(
"matrices",
"GR");
938 if (which !=
"G" && which !=
"R" && which !=
"GR" && which !=
"RG")
939 throw InputError(
"qbd_fundmat: 'matrices' must be \"G\", \"R\", \"GR\" or \"RG\"");
940 const bool lf = long_form(a,
"qbd_fundmat", {
"precision",
"maxNumIt"}, {
"precision",
"maxNumIt"});
941 const T tol = lf ? a.number<T>(
"precision") : T();
942 const unsigned it = lf ? a.uinteger(
"maxNumIt") : 0u;
948 if (which.find(
'G') != std::string::npos) o[
"G"] =
encode_matrix(r.G);
949 if (which.find(
'R') != std::string::npos) o[
"R"] =
encode_matrix(r.R);
956 static Json run(Args& a) {
957 const Matrix<T> R = a.matrix<T>(
"R");
958 const bool lf = long_form(a,
"qbd_caudal", {
"iter_max",
"tol"}, {
"iter_max",
"tol"});
959 const unsigned it = lf ? a.uinteger(
"iter_max") : 0u;
960 const T tol = lf ? a.number<T>(
"tol") : T();
972 static Json run(Args& a) {
973 const Matrix<T> B = a.matrix<T>(
"B");
974 const Matrix<T> Lbar = a.matrix<T>(
"Lbar");
975 const Matrix<T> R = a.matrix<T>(
"R");
976 const bool lf = long_form(a,
"qbd_pi", {
"max_levels",
"mass_tol"}, {
"max_levels",
"mass_tol"});
977 const std::size_t ml = lf ? a.count(
"max_levels") : 0u;
978 const T mt = lf ? a.number<T>(
"mass_tol") : T();
989struct OpQbdResidual {
991 static Json run(Args& a) {
992 const Matrix<T> B = a.matrix<T>(
"B");
993 const Matrix<T> L = a.matrix<T>(
"L");
994 const Matrix<T> F = a.matrix<T>(
"F");
995 const Matrix<T> X = a.matrix<T>(G ?
"G" :
"R");
1003struct OpQbdMapmap1Blocks {
1005 static Json run(Args& a) {
1006 const mam::Map<T> arr = read_map<T>(a,
"arrival");
1007 const mam::Map<T> srv = read_map<T>(a,
"service");
1020struct OpQbdQlenMoment {
1022 static Json run(Args& a) {
1023 const std::vector<T> pi0 = a.vector<T>(
"pi0");
1024 const Matrix<T> R = a.matrix<T>(
"R");
1025 const unsigned m = a.uinteger(
"m");
1038 static Json run(Args& a) {
1039 const mam::Map<T> arr = read_map<T>(a,
"MAPa");
1040 const mam::Map<T> srv = read_map<T>(a,
"MAPs");
1041 const bool hu = a.has(
"util");
1042 const T util = hu ? a.number<T>(
"util") : T();
1045 const mam::QbdRg<T> r = hu ?
mam::qbd_rg(arr, srv, util) : mam::
qbd_rg(arr, srv);
1057struct OpQbdMapmap1 {
1059 static Json run(Args& a) {
1060 const mam::Map<T> arr = read_map<T>(a,
"MAPa");
1061 const mam::Map<T> srv = read_map<T>(a,
"MAPs");
1062 const bool lf = long_form(a,
"qbd_mapmap1", {
"util",
"max_levels"}, {
"util",
"max_levels"});
1063 const T util = lf ? a.number<T>(
"util") : T();
1064 const std::size_t ml = lf ? a.count(
"max_levels") : 0u;
1066 a.opt(
"max_levels");
1081 o[
"MAPs"] = encode_map(r.service);
1086struct OpQbdMapmap1QlenTruncated {
1088 static Json run(Args& a) {
1089 const Json& j = a.get(
"res");
1090 if (!j.is_object() || j.find(
"pqueue") == j.end())
1091 throw InputError(
"'res' must be the result object of qbd_mapmap1, carrying at least "
1092 "'pqueue' (the only field this function reads)");
1093 mam::QbdMapMap1Result<T> r;
1104 static Json run(Args& a) {
1105 const Matrix<T> A0 = a.matrix<T>(
"A0");
1106 const Matrix<T> A1 = a.matrix<T>(
"A1");
1107 const Matrix<T> A2 = a.matrix<T>(
"A2");
1108 const bool lf = long_form(a,
"qbd_rap", {
"B0",
"B1",
"numLevels"}, {
"B0",
"B1",
"numLevels"});
1109 const Matrix<T> B0 = lf ? a.matrix<T>(
"B0") : Matrix<T>();
1110 const Matrix<T> B1 = lf ? a.matrix<T>(
"B1") :
Matrix<T>();
1111 const std::size_t nl = lf ? a.count(
"numLevels") : 0u;
1116 const mam::QbdRapResult<T> r = lf ?
mam::qbd_rap(A0, A1, A2, B0, B1, nl) : mam::
qbd_rap(A0, A1, A2);
1130struct OpQbdBmapbmap1 {
1132 static Json run(Args& a) {
1133 const mam::Map<T> arr = read_map<T>(a,
"MAPa");
1134 const std::vector<T> pb = a.vector<T>(
"pbatcha");
1135 const mam::Map<T> srv = read_map<T>(a,
"MAPs");
1151 static Json run(Args& a) {
1152 const std::vector<Matrix<T> > q0 = a.matrices<T>(
"Q0");
1153 const std::vector<Matrix<T> > q1 = a.matrices<T>(
"Q1");
1156 std::vector<Matrix<T> > q2(1, Matrix<T>());
1157 for (
const Matrix<T>& m : a.matrices<T>(
"Q2")) q2.push_back(m);
1158 a.unsupported(
"options",
"its fields (epsilon, maxIter, verbose) are only printed by the "
1159 "MATLAB reference under verbose and never change the result; the "
1160 "recursion is exact and takes no tolerance.");
1162 const mam::LdqbdResult<T> r =
mam::ldqbd(q0, q1, q2);
1163 std::vector<Matrix<T> > Rout;
1164 for (std::size_t n = 1; n < r.R.size(); ++n) Rout.push_back(r.R[n]);
1172struct OpLdqbdCensor {
1174 static Json run(Args& a) {
1175 const Matrix<T> Q = a.matrix<T>(
"Q");
1177 std::vector<std::vector<std::size_t> > phases;
1178 for (
const Matrix<double>& m : a.matrices<
double>(
"phases")) {
1179 std::vector<std::size_t>
P;
1180 for (std::size_t i = 0; i < m.rows(); ++i)
1181 for (std::size_t j = 0; j < m.cols(); ++j) {
1182 const double v = m(i, j);
1183 if (!(v >= 1) || v !=
static_cast<double>(
static_cast<std::size_t
>(v)))
1185 "ldqbd_censor: phases must hold positive integers");
1186 P.push_back(
static_cast<std::size_t
>(v));
1188 phases.push_back(P);
1191 a.unsupported(
"options",
"only options.tol is read by the reference and it is passed as 'tol'.");
1192 if (a.has(
"tol")) tol = a.number<
double>(
"tol");
1195 Json cells = Json::array();
1196 for (
const auto& set : r.pi_cells) cells.push_back(
encode_vectors(set));
1199 o[
"pi_cell"] = cells;
1206 static Json run(Args& a) {
1207 const Matrix<T> D0 = a.matrix<T>(
"D0");
1208 const Matrix<T> D1 = a.matrix<T>(
"D1");
1209 const std::vector<T> alpha = a.vector<T>(
"alpha");
1210 const double c = a.number<
double>(
"c");
1211 const std::vector<T> arr = a.vector<T>(
"arrRate");
1212 const std::vector<T> sf = a.vector_or_empty<T>(
"sf");
1213 const bool hc = a.has(
"carry");
1214 const bool carry = a.boolean(
"carry",
false);
1216 const mam::LdqbdMphcBlocks<T> r =
1217 hc ?
mam::ldqbd_mphc(D0, D1, alpha, c, arr, sf, carry) : mam::
ldqbd_mphc(D0, D1, alpha, c, arr, sf);
1219 std::vector<Matrix<T> > q2;
1220 for (std::size_t n = 1; n < r.Q2.size(); ++n) q2.push_back(r.Q2[n]);
1233struct OpQbdSetupdelayoff {
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 ar = a.number<T>(
"alpharate");
1239 const T as = a.number<T>(
"alphascv");
1240 const T br = a.number<T>(
"betarate");
1241 const T bs = a.number<T>(
"betascv");
1249struct OpQbdSetupdelayoffClosed {
1251 static Json run(Args& a) {
1252 const T N = a.number<T>(
"N");
1253 const T Z = a.number<T>(
"Z");
1254 const T mu = a.number<T>(
"mu");
1255 const T ar = a.number<T>(
"alpharate");
1256 const T as = a.number<T>(
"alphascv");
1257 const T br = a.number<T>(
"betarate");
1258 const T bs = a.number<T>(
"betascv");
1268struct OpQbdSetupdelayoffMmk {
1270 static Json run(Args& a) {
1271 const int k = a.required_integer(
"k");
1272 const double N = a.number<
double>(
"N");
1273 const T arv = a.number<T>(
"arv");
1274 const T mu = a.number<T>(
"mu");
1275 const T ar = a.number<T>(
"alpharate");
1276 const T as = a.number<T>(
"alphascv");
1277 const T br = a.number<T>(
"betarate");
1278 const T bs = a.number<T>(
"betascv");
1292struct OpAmap2AdjustGamma {
1294 static Json run(Args& a) {
1295 const T M1 = a.number<T>(
"M1");
1296 const T M2 = a.number<T>(
"M2");
1297 const T M3 = a.number<T>(
"M3");
1298 const T G = a.number<T>(
"GAMMA");
1299 const bool full = long_form(a,
"amap2_adjust_gamma", {
"weights",
"constraints",
"tol"},
1300 {
"weights",
"method",
"constraints",
"tol"});
1301 const bool hm = a.has(
"method");
1302 mam::Amap2AdjustGammaResult<T> r;
1304 const std::vector<T> w = a.vector<T>(
"weights");
1305 const int method = a.required_integer(
"method");
1306 const int cons = a.required_integer(
"constraints");
1307 const T tol = a.number<T>(
"tol");
1311 const int method = a.required_integer(
"method");
1313 a.opt(
"constraints");
1320 a.opt(
"constraints");
1330 o[
"feasible"] = r.feasible;
1335struct OpAmap2Assemble {
1337 static Json run(Args& a) {
1338 const T l1 = a.number<T>(
"l1");
1339 const T l2 = a.number<T>(
"l2");
1340 const T p1 = a.number<T>(
"p1");
1341 const T p2 = a.number<T>(
"p2");
1342 const int form = a.required_integer(
"form");
1350struct OpAmap2FitGamma {
1352 static Json run(Args& a) {
1353 const T M1 = a.number<T>(
"M1");
1354 const T M2 = a.number<T>(
"M2");
1355 const T M3 = a.number<T>(
"M3");
1356 const T G = a.number<T>(
"GAMMA");
1357 const bool ht = a.has(
"cvtol");
1358 const T cvtol = ht ? a.number<T>(
"cvtol") : T();
1361 const mam::Amap2FitGammaResult<T> r =
1364 o[
"AMAP"] = encode_map(r.amap);
1365 o[
"AMAPS"] = encode_maps(r.amaps);
1366 o[
"adjusted"] = r.adjusted;
1367 o[
"poisson_fallback"] = r.poisson_fallback;
1372struct OpAmap2FitallGamma {
1374 static Json run(Args& a) {
1375 const T M1 = a.number<T>(
"M1");
1376 const T M2 = a.number<T>(
"M2");
1377 const T M3 = a.number<T>(
"M3");
1378 const T G = a.number<T>(
"GAMMA");
1379 const bool lf = long_form(a,
"amap2_fitall_gamma", {
"degentol",
"r12tol"}, {
"degentol",
"r12tol"});
1380 const T dt = lf ? a.number<T>(
"degentol") : T();
1381 const T rt = lf ? a.number<T>(
"r12tol") : T();
1392struct OpAph2Adjust {
1394 static Json run(Args& a) {
1395 const T M1 = a.number<T>(
"M1");
1396 const T M2 = a.number<T>(
"M2");
1397 const T M3 = a.number<T>(
"M3");
1398 const std::string method = a.text(
"method",
"simple");
1399 if (a.has(
"method") && method !=
"simple")
1401 "aph2_adjust: only method \"simple\" is ported to C++; got \"" +
1403 const bool ht = a.has(
"tol");
1404 const T tol = ht ? a.number<T>(
"tol") : T();
1415struct OpAph2Assemble {
1417 static Json run(Args& a) {
1418 const T l1 = a.number<T>(
"l1");
1419 const T l2 = a.number<T>(
"l2");
1420 const T p1 = a.number<T>(
"p1");
1430 static Json run(Args& a) {
1431 const T M1 = a.number<T>(
"M1");
1432 const T M2 = a.number<T>(
"M2");
1433 const T M3 = a.number<T>(
"M3");
1437 o[
"APH"] = encode_map(r.aph);
1438 o[
"APHS"] = encode_maps(r.aphs);
1439 o[
"adjusted"] = r.adjusted;
1444struct OpAph2Fitall {
1446 static Json run(Args& a) {
1447 const T M1 = a.number<T>(
"M1");
1448 const T M2 = a.number<T>(
"M2");
1449 const T M3 = a.number<T>(
"M3");
1450 const bool ht = a.has(
"degentol");
1451 const T dt = ht ? a.number<T>(
"degentol") : T();
1466 static Json run(Args& a) {
1467 const T e1 = a.number<T>(
"e1");
1468 const T e2 = a.number<T>(
"e2");
1469 const bool h3 = a.has(
"e3");
1470 const T e3 = h3 ? a.number<T>(
"e3") : T();
1472 const T g2 = a.number<T>(
"g2");
1476 o[
"MAP"] = r.has_map ? encode_map(r.map) :
Json::array();
1482struct OpMap2FitIdc {
1484 static Json run(Args& a) {
1485 const T e1 = a.number<T>(
"e1");
1486 const T e2 = a.number<T>(
"e2");
1487 const T e3 = a.number<T>(
"e3");
1488 const T I = a.number<T>(
"I");
1492 o[
"MAP"] = encode_map(r.map);
1493 o[
"status"] = r.status;
1500 static Json run(Args& a) {
1501 const T E1 = a.number<T>(
"E1");
1502 const T E2 = a.number<T>(
"E2");
1503 const T E3 = a.number<T>(
"E3");
1504 const T g = a.number<T>(
"ACFLAG1");
1514 static Json run(Args& a) {
1515 const T mean = a.number<T>(
"mean");
1516 const T scv = a.number<T>(
"scv");
1517 const T skew = a.number<T>(
"skew");
1518 const T idc = a.number<T>(
"idc");
1520 const mam::Map2FitResult<T> r =
mam::mmpp2_fit1(mean, scv, skew, idc);
1522 o[
"MAP"] = r.has_map ? encode_map(r.map) :
Json::array();
1528struct OpMmpp2Fit24 {
1530 static Json run(Args& a) {
1531 const T mean = a.number<T>(
"mean");
1532 const T scv = a.number<T>(
"scv");
1533 const T skew = a.number<T>(
"skew");
1534 const T g = a.number<T>(Four ?
"acf1" :
"g2");
1538 o[
"MAP"] = encode_map(r.map);
1539 o[
"feasible"] = r.feasible;
1546 static Json run(Args& a) {
1547 const T E1 = a.number<T>(
"E1");
1548 const T E2 = a.number<T>(
"E2");
1549 const T E3 = a.number<T>(
"E3");
1550 const T G2 = a.number<T>(
"G2");
1551 const bool ht = a.has(
"g2tol");
1552 const T tol = ht ? a.number<T>(
"g2tol") : T();
1563 static Json run(Args& a) {
1564 const T mu = a.number<T>(
"mu");
1565 const T bt1 = a.number<T>(
"bt1");
1566 const T bt2 = a.number<T>(
"bt2");
1567 const T binf = a.number<T>(
"binf");
1568 const T m3t2 = a.number<T>(
"m3t2");
1569 const T t1 = a.number<T>(
"t1");
1570 const T t2 = a.number<T>(
"t2");
1572 const mam::Mmpp2FitcResult<T> r =
mam::mmpp2_fitc(mu, bt1, bt2, binf, m3t2, t1, t2);
1574 o[
"mmpp"] = encode_map(r.map);
1575 o[
"degenerate"] = r.degenerate;
1576 o[
"third_moment_ok"] = r.third_moment_ok;
1581struct OpMmpp2FitcApprox {
1583 static Json run(Args& a) {
1584 const T x = a.number<T>(
"a");
1585 const T bt1 = a.number<T>(
"bt1");
1586 const T bt2 = a.number<T>(
"bt2");
1587 const T binf = a.number<T>(
"binf");
1588 const T m3t2 = a.number<T>(
"m3t2");
1589 const T t1 = a.number<T>(
"t1");
1590 const T t2 = a.number<T>(
"t2");
1594 o[
"FIT"] = encode_map(r.map);
1597 o[
"converged"] = r.converged;
1602struct OpMmpp2FitcTheoretical {
1604 static Json run(Args& a) {
1605 const mam::Map<T> m = read_map<T>(a,
"map");
1606 const bool lf = long_form(a,
"mmpp2_fitc_theoretical", {
"t1",
"t2",
"tinf"}, {
"t1",
"t2",
"tinf"});
1607 const T t1 = lf ? a.number<T>(
"t1") : T();
1608 const T t2 = lf ? a.number<T>(
"t2") : T();
1609 const T ti = lf ? a.number<T>(
"tinf") : T();
1616 o[
"fit"] = encode_map(r.map);
1617 o[
"degenerate"] = r.degenerate;
1618 o[
"third_moment_ok"] = r.third_moment_ok;
1627struct OpM3ppSuperposFitc {
1629 static Json run(Args& a) {
1630 const std::vector<T> av = a.vector<T>(
"av");
1631 const std::vector<T> btv = a.vector<T>(
"btv");
1632 const std::vector<T> binfv = a.vector<T>(
"binfv");
1633 const std::vector<T> m3tv = a.vector<T>(
"m3tv");
1634 const T t = a.number<T>(
"t");
1635 const T tinf = a.number<T>(
"tinf");
1639 o[
"fit"] = encode_mmap(r.mmap);
1640 o[
"m3pps"] = encode_mmaps(r.parts);
1648 T a, bt1, bt2, binf, m3t2, t1, t2, t3;
1649 std::vector<T> ai, third;
1653M3pp2mChars<T> read_m3pp2m(
Args& a,
const char* third) {
1655 c.a = a.number<T>(
"a");
1656 c.bt1 = a.number<T>(
"bt1");
1657 c.bt2 = a.number<T>(
"bt2");
1658 c.binf = a.number<T>(
"binf");
1659 c.m3t2 = a.number<T>(
"m3t2");
1660 c.t1 = a.number<T>(
"t1");
1661 c.t2 = a.number<T>(
"t2");
1662 c.ai = a.vector<T>(
"ai");
1663 c.third = a.vector<T>(third);
1664 c.t3 = a.number<T>(
"t3");
1669struct OpM3pp2mFitc {
1671 static Json run(Args& a) {
1672 const M3pp2mChars<T> c = read_m3pp2m<T>(a,
"dvt3");
1673 const mam::M3pp2mFitcResult<T> r =
1674 mam::m3pp2m_fitc(c.a, c.bt1, c.bt2, c.binf, c.m3t2, c.t1, c.t2, c.ai, c.third, c.t3);
1676 o[
"mmmpp"] = encode_mmap(r.mmap);
1677 o[
"degenerate"] = r.degenerate;
1683struct OpM3pp2mFitcApprox {
1685 static Json run(Args& a) {
1686 const M3pp2mChars<T> c = read_m3pp2m<T>(a, Ag ?
"gt3" :
"dvt3");
1687 const mam::M3pp2mFitcApproxResult<T> r =
1689 : mam::
m3pp2m_fitc_approx(c.a, c.bt1, c.bt2, c.binf, c.m3t2, c.t1, c.t2, c.ai, c.third, c.t3);
1691 o[
"FIT"] = encode_mmap(r.mmap);
1695 o[
"degenerate"] = r.degenerate;
1696 o[
"feasible"] = r.feasible;
1701struct OpM3pp2mFitcTrace {
1703 static Json run(Args& a) {
1704 const std::vector<T> Tv = a.vector<T>(
"T");
1705 const std::vector<int> A = a.ints(
"A");
1706 const Json& jm = a.get(
"method");
1707 if (!jm.is_string())
throw InputError(
"'method' must be a string");
1708 const std::string method = jm.get<std::string>();
1709 const bool lf = long_form(a,
"m3pp2m_fitc_trace", {
"t1",
"tinf"}, {
"t1",
"tinf"});
1710 const T t1 = lf ? a.number<T>(
"t1") : T();
1711 const T ti = lf ? a.number<T>(
"tinf") : T();
1715 const mam::M3pp2mFitcTraceResult<T> r =
1718 o[
"fit"] = encode_mmap(r.mmap);
1727struct OpMfqSojourn {
1729 static Json run(Args& a) {
1730 const Matrix<T> Q = a.matrix<T>(
"Q");
1731 const Matrix<T> Rin = a.matrix<T>(
"Rin");
1732 const Matrix<T> Rout = a.matrix<T>(
"Rout");
1733 const bool lf = long_form(a,
"mfq_sojourn", {
"Q0",
"transToPH",
"prec"}, {
"transToPH",
"prec"});
1734 const Matrix<T> Q0 = a.matrix_or_empty<T>(
"Q0");
1735 const bool tp = a.boolean(
"transToPH",
false);
1736 const T prec = lf ? a.number<T>(
"prec") : T();
1747struct OpMfqFlufluSojourn {
1749 static Json run(Args& a) {
1750 const Matrix<T> Qin = a.matrix<T>(
"Qin");
1751 const Matrix<T> Rin = a.matrix<T>(
"Rin");
1752 const Matrix<T> Qout = a.matrix<T>(
"Qout");
1753 const Matrix<T> Rout = a.matrix<T>(
"Rout");
1754 if (!a.has(
"srv0stop")) a.get(
"srv0stop");
1755 const bool s0 = a.boolean(
"srv0stop",
false);
1756 const bool lf = long_form(a,
"mfq_fluflu_sojourn", {
"transToPH",
"prec"}, {
"transToPH",
"prec"});
1757 const bool tp = a.boolean(
"transToPH",
false);
1758 const T prec = lf ? a.number<T>(
"prec") : T();
1772 static Json run(Args& a) {
1773 const mam::LevelDependentFluidBlocks<T> b = read_ld_blocks<T>(a);
1781struct OpMfqLdDistr {
1783 static Json run(Args& a) {
1784 const mam::LevelDependentFluidBlocks<T> b = read_ld_blocks<T>(a);
1786 const std::vector<T> pts = a.vector<T>(
"points");
1794struct OpMfqLdSolve {
1796 static Json run(Args& a) {
1797 const std::vector<Matrix<T> > Q = a.matrices<T>(
"Q");
1798 const std::vector<Matrix<T> > R = a.matrices<T>(
"R");
1799 const std::vector<Matrix<T> > S = a.matrices<T>(
"S");
1800 const std::vector<T> Thr = a.vector<T>(
"T");
1801 const bool lf = long_form(a,
"mfq_ld_solve", {
"boundaryL",
"boundaryU",
"Qt",
"prec"}, {
"prec"});
1802 const std::vector<mam::FluidBoundary> bL = boundaries(a,
"boundaryL");
1803 const std::vector<mam::FluidBoundary> bU = boundaries(a,
"boundaryU");
1804 const std::vector<Matrix<T> > Qt = a.matrices_or_empty<T>(
"Qt");
1805 const T prec = lf ? a.number<T>(
"prec") : T();
1808 const mam::LevelDependentFluidBlocks<T> r =
1809 lf ?
mam::mfq_ld_solve(Q, R, S, Thr, bL, bU, Qt, prec) : mam::
mfq_ld_solve(Q, R, S, Thr);
1822struct OpMfqMultiregime {
1823 static Json run(Args& a) {
1824 const std::vector<Matrix<double> > Q = a.matrices<
double>(
"Q");
1825 const std::vector<std::vector<double> > R = diagonal_rate_list(a,
"R",
false);
1826 const std::vector<Matrix<double> > Qt = a.matrices_or_empty<
double>(
"Qt");
1827 const std::vector<std::vector<double> > Rt = diagonal_rate_list(a,
"Rt",
true);
1828 const std::vector<double> Thr = a.vector<
double>(
"T");
1829 const std::vector<double> pdfp = a.vector_or_empty<
double>(
"pdfpoints");
1830 const std::vector<double> cdfp = a.vector_or_empty<
double>(
"cdfpoints");
1842struct OpMfqPrioQueue {
1843 static Json run(Args& a) {
1844 const Matrix<double> Q = a.matrix<
double>(
"Q");
1845 const Matrix<double> R = a.matrix<
double>(
"R");
1846 const double d = a.number<
double>(
"d");
1847 mam::FluidPrioOptions opt;
1848 const bool fm = a.has(
"flMoms"), fd = a.has(
"flDistr"), sm = a.has(
"stMoms"), sd = a.has(
"stDistr");
1849 if (fm) opt.flMoms = a.count(
"flMoms");
1850 if (fd) opt.flDistr = a.vector<
double>(
"flDistr");
1851 if (sm) opt.stMoms = a.count(
"stMoms");
1852 if (sd) opt.stDistr = a.vector<
double>(
"stDistr");
1857 if (a.has(
"prec")) opt.prec = a.number<
double>(
"prec");
1859 if (a.has(
"erlMaxOrder")) opt.erlMaxOrder = a.count(
"erlMaxOrder");
1860 a.opt(
"erlMaxOrder");
1861 if (a.has(
"classes")) {
1862 for (
int c : a.ints(
"classes")) {
1863 if (c < 1)
throw InputError(
"'classes' are 1-based, as in MATLAB");
1864 opt.classes.push_back(
static_cast<std::size_t
>(c));
1869 if (!fm && !fd && !sm && !sd)
1870 throw InputError(
"mfq_prio_queue: ask for at least one measure: flMoms, flDistr, "
1871 "stMoms or stDistr");
1874 Json cls = Json::array();
1875 for (std::size_t c : r.classes) cls.push_back(
static_cast<std::uint64_t
>(c));
1889struct OpSmpPassageMoments {
1891 static Json run(Args& a) {
1892 const Matrix<T>
P = a.matrix<T>(
"P");
1893 const Json& jh = a.get(
"hmom");
1894 const std::vector<T> pi0 = a.vector_or_empty<T>(
"pi0");
1895 const std::vector<std::size_t> target = one_based(a.get(
"target"),
"'target'");
1896 const bool hn = a.has(
"nmax");
1897 const std::size_t nmax = a.count(
"nmax", 1);
1900 const bool cell = jh.is_array() && !jh.empty() && jh[0].is_array() && !jh[0].empty() &&
1901 jh[0][0].is_array();
1902 mc::PassageMoments<T> r;
1904 std::vector<std::vector<std::vector<T> > > h;
1905 for (std::size_t i = 0; i < jh.size(); ++i)
1906 h.push_back(vectors_from_json<T>(jh[i],
"'hmom'[" + std::to_string(i) +
"]"));
1925 static Json run(Args& a) {
1926 const std::size_t M = a.count(
"M");
1927 const std::size_t R = a.count(
"R");
1928 const std::vector<long> N = populations(a,
"N",
false);
1929 const Matrix<T> mu = a.matrix<T>(
"mu");
1930 const Matrix<T> Cs = a.matrix<T>(
"Cs");
1931 const std::vector<Matrix<T> >
P = per_class_routing<T>(a,
"P", R);
1932 const std::vector<long> c = counts_with_inf(a,
"c");
1933 const std::vector<long> ref = reference_stations(a,
"refstat", R);
1934 const std::vector<char> ins = flags(a,
"insens");
1935 const bool ho = a.has(
"options");
1936 const me::MeOptions opt = me_options(a);
1938 const me::MeResult<T> r = ho ?
me::me_cqn(M, R, N, mu, Cs, P, c, ref, ins, opt)
1939 : me::
me_cqn(M, R, N, mu, Cs,
P, c, ref, ins);
1940 return encode_me_result(r,
true);
1946 static Json run(Args& a) {
1947 const std::size_t M = a.count(
"M");
1948 const std::size_t R = a.count(
"R");
1949 const std::vector<char> oc = flags(a,
"openClasses");
1950 const Matrix<T> lambda0 = a.matrix<T>(
"lambda0");
1951 const Matrix<T> Ca0 = a.matrix<T>(
"Ca0");
1952 const std::vector<long> N = populations(a,
"N",
true);
1953 const Matrix<T> mu = a.matrix<T>(
"mu");
1954 const Matrix<T> Cs = a.matrix<T>(
"Cs");
1955 const std::vector<Matrix<T> >
P = per_class_routing<T>(a,
"P", R);
1956 const std::vector<long> c = counts_with_inf(a,
"c");
1957 const std::vector<long> ref = reference_stations(a,
"refstat", R);
1958 const std::vector<char> ins = flags(a,
"insens");
1959 const bool ho = a.has(
"options");
1960 const me::MeOptions opt = me_options(a);
1962 const me::MeResult<T> r = ho ?
me::me_mqn(M, R, oc, lambda0, Ca0, N, mu, Cs, P, c, ref, ins, opt)
1963 : me::
me_mqn(M, R, oc, lambda0, Ca0, N, mu, Cs,
P, c, ref, ins);
1964 return encode_me_result(r,
true);
1970 static Json run(Args& a) {
1971 const std::size_t M = a.count(
"M");
1972 const std::size_t R = a.count(
"R");
1973 const Matrix<T> lambda0 = a.matrix<T>(
"lambda0");
1974 const Matrix<T> Ca0 = a.matrix<T>(
"Ca0");
1975 const Matrix<T> mu = a.matrix<T>(
"mu");
1976 const Matrix<T> Cs = a.matrix<T>(
"Cs");
1977 const std::vector<Matrix<T> >
P = per_class_routing<T>(a,
"P", R);
1978 const std::vector<long> c = counts_with_inf(a,
"c");
1979 const std::vector<char> ins = flags(a,
"insens");
1980 const bool ho = a.has(
"options");
1981 const me::MeOptions opt = me_options(a);
1983 const me::MeResult<T> r = ho ?
me::me_oqn(M, R, lambda0, Ca0, mu, Cs, P, c, ins, opt)
1984 : me::
me_oqn(M, R, lambda0, Ca0, mu, Cs,
P, c, ins);
1985 return encode_me_result(r,
false);
1991 static Json run(Args& a) {
1992 const std::size_t M = a.count(
"M");
1993 const std::vector<T> lambda0 = a.vector<T>(
"lambda0");
1994 const std::vector<T> Ca0 = a.vector<T>(
"Ca0");
1995 const std::vector<T> mu = a.vector<T>(
"mu");
1996 const std::vector<T> Cs = a.vector<T>(
"Cs");
1997 const Matrix<T>
P = a.matrix<T>(
"P");
1998 const std::vector<long> c = counts_with_inf(a,
"c");
1999 const std::vector<long> N = counts_with_inf(a,
"N");
2000 const std::vector<int> br = a.ints(
"blockrule");
2001 const bool ho = a.has(
"options");
2002 const me::MeBlkOptions opt = me_blk_options(a);
2004 const me::MeBlkResult<T> r = ho ?
me::me_oqn_blk(M, lambda0, Ca0, mu, Cs, P, c, N, br, opt)
2005 : me::
me_oqn_blk(M, lambda0, Ca0, mu, Cs,
P, c, N, br);
2015 o[
"iter"] =
static_cast<std::int64_t
>(r.iter);
2016 o[
"converged"] = r.converged;
2021struct OpMeGegecMql {
2023 static Json run(Args& a) {
2024 const T lambda = a.number<T>(
"lambda");
2025 const T
Ca = a.number<T>(
"Ca");
2026 const T mu = a.number<T>(
"mu");
2027 const T Cs = a.number<T>(
"Cs");
2028 const long c = a.required_integer(
"c");
2038 static Json run(Args& a) {
2039 const T lambda = a.number<T>(
"lambda");
2040 const T
Ca = a.number<T>(
"Ca");
2041 const T mu = a.number<T>(
"mu");
2042 const T Cs = a.number<T>(
"Cs");
2043 const long c = a.required_integer(
"c");
2044 const long K = a.required_integer(
"K");
2045 const long N = a.required_integer(
"N");
2047 const me::GegecnResult<T> r =
me::me_gegecn(lambda, Ca, mu, Cs, c, K, N);
2058struct OpMeGegecnPb {
2060 static Json run(Args& a) {
2061 const std::vector<T> p = a.vector<T>(
"p");
2062 const long K = a.required_integer(
"K");
2063 const long N = a.required_integer(
"N");
2064 const long c = a.required_integer(
"c");
2065 const T Cs = a.number<T>(
"Cs");
2066 const T
Ca = a.number<T>(
"Ca");
2083 static Json run(Args& a) {
2084 const std::size_t K = a.count(
"order");
2085 const std::size_t classes = a.count(
"classes");
2208 const std::string callables =
2209 "its holding-time transforms hlst are callables (std::function of a complex argument, "
2210 "one per state or per state pair), which have no JSON representation.";
2211 t[
"smp_passage_lst"] =
"smp_passage_lst: " + callables;
2212 t[
"smp_passage_time"] =
"smp_passage_time: " + callables;
2213 const std::string distribs =
2214 "its arcs are lang::Distrib objects (arbitrary distribution instances with their own "
2215 "sampling and transform methods), which have no JSON representation in the --api "
2216 "argument vocabulary.";
2217 t[
"smp_stage_cif"] =
"smp_stage_cif: " + distribs;
2218 t[
"smp_stage_quad"] =
"smp_stage_quad: " + distribs;
2220 "mmap_mark: the C++ port mmap_mark(Map base, weights n x C) is a different function from "
2221 "the MATLAB reference mmap_mark(MMAP, prob K x R): it marks the arrivals of a MAP by "
2222 "phase-dependent weights, whereas the reference re-marks the K classes of an MMAP into R "
2223 "classes. Neither signature can be served from the other, so the MATLAB name is not "
2224 "exposed rather than returning a different quantity under it.";
2225 t[
"map_transform"] =
2226 "map_transform: the C++ library has no function of this name; it is the header "
2227 "map_transform.h, whose functions (map_normalize, map_scale, map_erlang, map_sum, "
2228 "map_sumind, map_mixture, map_renewal, map_stochcomp, map_hyperexp, ...) are exposed "
2229 "under their own names.";
2231 "qbd_r: the C++ library has no function of this name; it is the header qbd_r.h, whose "
2232 "functions (qbd_R, qbd_R_logred, qbd_fundmat, qbd_caudal, qbd_pi, qbd_R_residual, "
2233 "qbd_G_residual) are exposed under their own names.";
Nearest AMAP(2)-feasible (M2, M3, GAMMA) (matlab/lib/m3a/m3a/amap2/amap2_adjust_gamma....
Assemble an AMAP(2) in one of the two canonical forms (matlab/lib/m3a/m3a/amap2/amap2_assemble....
AMAP(2) fit of three moments and the autocorrelation decay rate (matlab/lib/m3a/m3a/amap2/amap2_fit_g...
All AMAP(2) representations matching three moments and the autocorrelation decay rate (matlab/lib/m3a...
Nearest APH(2)-feasible values of the second and third moments (matlab/lib/m3a/m3a/aph2/aph2_adjust....
Assemble an APH(2) from its canonical parameters (matlab/lib/m3a/m3a/aph2/aph2_assemble....
APH(2) fit of three moments, with a fallback to adjusted moments (matlab/lib/m3a/m3a/aph2/aph2_fit....
All APH(2) representations matching three moments (matlab/lib/m3a/m3a/aph2/aph2_fitall....
Internal to the –api dispatcher: what a per-domain translation unit needs to add entries to the table...
#define LINE_MAM_MAP_POINTS(OpName, fn, mapkey, ptkey, outkey)
#define LINE_MAM_MAP_UNARY(OpName, fn, outkey, enc)
UnsupportedError(const std::string &what)
Named-argument reader over the parsed JSON object.
First passage times into a target STATE SET, for Markov and semi-Markov chains.
Level-dependent QBD processes with finitely many levels: the rate matrices R^(n) by the backward matr...
Stationary distribution of a chain of connected LDQBDs by successive censoring.
Port of ldqbd_mphc.m and ph_multisets.m: the exact level-dependent QBD blocks of an M/PH/c queue.
Marked MMPP(2) with m classes, fitted to counting-process characteristics (matlab/lib/m3a/m3a/m3pp/m3...
M3PP(2, m) fitted to counting-process characteristics with an optimized per-class split (matlab/lib/m...
M3PP(2, m) fitted to the counting process of a multi-class TRACE (matlab/lib/m3a/m3a/m3pp/m3pp2m_fitc...
M3PP obtained by SUPERPOSING one second-order process per class (matlab/lib/m3a/m3a/m3pp/m3pp_superpo...
Explicit inverse characterization of a second-order acyclic MAP (matlab/lib/kpctoolbox/map/map2_fit....
Fit a MAP(2) to three moments and an asymptotic index of dispersion.
Autocorrelation of the counting process of a MAP at a given timescale.
Cumulative distribution of the inter-arrival time of a MAP.
Mean of the counting process of a MAP at resolution t.
Power moments of the counts of a MAP in a window of length t.
Variance of the counting process of a MAP at resolution t.
Mark the arrivals of a MAP with class probabilities (matlab/lib/kpctoolbox/map/map_mark....
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Probability density of the inter-arrival time of a MAP.
Random MAP, MMPP, MMAP, acyclic-PH and hyperexponential generators, plus the hyperexponential reader.
Variance of the counts of a MAP over windows of length t, in the spelling of matlab/lib/kpctoolbox/ma...
Maximum-entropy algorithm for closed multiclass queueing networks.
Mean queue length of a stable infinite-capacity GE/GE/c/FCFS queue.
Censored GE/GE/c/K;N queue by entropy maximisation.
Blocking probability seen by ONE arrival stream of a censored GE/GE/c/K;N queue.
Maximum-entropy algorithm for mixed open/closed multiclass networks.
Maximum-entropy algorithm for open multiclass queueing networks.
Maximum Entropy algorithm for single-class OPEN networks with FINITE BUFFERS, under loss or transfer ...
Sojourn-time distribution of a fluid queue whose SERVICE is itself a Markov-modulated fluid flow,...
Stationary density and distribution of a first- or second-order level-dependent (multi-regime) Markov...
Stationary mean fluid level E[X] of a first- or second-order level-dependent (multi-regime) Markovian...
First- and second-order level-dependent (multi-regime) Markovian fluid queues: the matrix-exponential...
Multi-regime FEEDBACK Markovian fluid queue: density, density derivative and distribution of the flui...
Fluid priority queue: per-class fluid level and sojourn time of an MMAP[K]/PH[K]/1-type continuous fl...
Sojourn-time distribution of a Markov-modulated fluid queue, as a matrix-exponential or phase-type re...
Compression of a marked MAP into a smaller representation, and the two M3A primitives it is built fro...
Per-class variance of the counting process of a marked MAP.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
MAP(2) matching mean, SCV, skewness and the index of dispersion for counts (matlab/lib/kpctoolbox/mmp...
MMPP(2) matching mean, SCV, skewness and the autocorrelation decay rate (matlab/lib/kpctoolbox/mmpp/m...
MMPP(2) matching three moments and the autocorrelation decay rate (matlab/lib/kpctoolbox/mmpp/mmpp2_f...
MMPP(2) matching mean, SCV, skewness and the lag-1 autocorrelation (matlab/lib/kpctoolbox/mmpp/mmpp2_...
MMPP(2) matching three moments and the lag-1 autocorrelation (matlab/lib/kpctoolbox/mmpp/mmpp2_fit....
MMPP(2) matching counting-process characteristics (matlab/lib/kpctoolbox/mmpp/mmpp2_fitc....
MMPP(2) fitted to counting-process characteristics by optimization (matlab/lib/kpctoolbox/mmpp/mmpp2_...
Map2FitResult< T > mmpp2_fit1(const T &mean, const T &scv, const T &skew, const T &idc)
MAP(2) with the given mean, SCV, skewness and IDC.
std::vector< T > map_acf(const Map< T > &m, const std::vector< unsigned > &lags)
Autocorrelation coefficients of the inter-arrival times at the given lags,.
Mmap< T > mmap_normalize(const Mmap< T > &in)
Clamp negative off-diagonal and per-class entries to zero and rebuild D1 and the diagonal of D0 from ...
Map2FitResult< T > map2_fit(const T &e1, const T &e2, const T &e3_in, const T &g2)
Fit an AMAP(2) to (e1, e2, e3, g2); see the header comment for e3 sentinels.
MultiRegimeResult mfq_multiregime(const std::vector< Matrix< double > > &Q, const std::vector< std::vector< double > > &R, const std::vector< Matrix< double > > &Qt, const std::vector< std::vector< double > > &Rt, const std::vector< double > &Thr, const std::vector< double > &pdfpoints, const std::vector< double > &cdfpoints)
Multi-regime feedback fluid queue.
M3pp2mFitcApproxResult< T > m3pp2m_fitc_approx_ag(const T &a, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2, const std::vector< T > &ai, const std::vector< T > >3, const T &t3, const std::vector< Bound< T > > &bounds, const AugLagOptions< T > &opt)
m3pp2m_fitc_approx_ag: fit the underlying MMPP(2) by optimization, then apply the 'ag' per-class spli...
MmapCompressMethod
The compression methods of mmap_compress.m.
@ M3ppApproxDelta
'm3pp.approx_delta'
@ M3ppApproxAg
'm3pp.approx_ag'
@ MixtureOrder1
'default', 'mixture', 'mixture.order1'
@ MixtureOrder2
'mixture.order2'
@ M3ppExactDelta
'm3pp.exact_delta'
@ M3ppApproxCov
'm3pp.approx_cov'
T map_joint(const Map< T > &m, const std::vector< unsigned > &a, const std::vector< unsigned > &i)
Joint moment of K consecutive inter-arrival times observed at the cumulative lags a,...
Aph2FitResult< T > aph2_fit(const T &M1, const T &M2, const T &M3)
Fit an APH(2) to (M1, M2, M3), relaxing the moments if necessary.
Mmap< T > mmap_scale(const Mmap< T > &in, const T &M)
Rescale time so that the mean inter-arrival time becomes M.
Mmpp2FitcResult< T > mmpp2_fitc(const T &mu, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2)
MMPP(2) from the arrival rate, the IDC at t1, t2 and infinity, and the third central moment of the co...
Map< T > map_hyperexp(const T &mean, const T &scv, const T &p_in)
Two-phase hyperexponential renewal MAP matching a mean and an SCV >= 1, with branching probability p ...
Amap2FitGammaResult< T > amap2_fit_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T &cvtol)
Fit an AMAP(2) to (M1, M2, M3, GAMMA).
std::vector< Map< T > > aph2_fitall(const T &M1, const T &M2, const T &M3, const T °entol)
All feasible APH(2) fits of (M1, M2, M3).
QbdMapMap1Blocks< T > qbd_mapmap1_blocks(const Map< T > &arrival, const Map< T > &service)
Level blocks of the MAP/MAP/1 QBD from the arrival and service MAPs.
M3ppSuperposResult< T > m3pp_superpos_fitc(const std::vector< T > &av, const std::vector< T > &btv, const std::vector< T > &binfv, const std::vector< T > &m3tv, const T &t, const T &tinf)
Fit one second-order M3PP per class from its counting characteristics and superpose them.
Map< T > mmpp2_fit3(const T &E1, const T &E2, const T &E3, const T &G2, const T &g2tol)
MMPP(2) with moments (E1, E2, E3) and autocorrelation decay rate G2.
std::vector< T > mmap_lambda(const Mmap< T > &m)
Alias kept for parity with the MATLAB name.
T qbd_G_residual(const Matrix< T > &B, const Matrix< T > &L, const Matrix< T > &F, const Matrix< T > &G)
Residual of the defining equation of G, ||B + L G + F G^2||_inf.
Amap2AdjustGammaResult< T > amap2_adjust_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const std::vector< T > &weights, int method, int constraints, const T &tol)
Nearest AMAP(2)-feasible characteristics.
bool mmap_isfeasible_tol(const Mmap< T > &m, const T &tol)
Feasibility of a marked MAP WITHIN A TOLERANCE, the semantics of matlab/lib/m3a/m3a/mmap/mmap_isfeasi...
std::vector< T > map_acfc(const Map< T > &m, const std::vector< unsigned > &kset, const T &u)
Autocorrelation of the counting process of a MAP at a given timescale.
M3pp2mFitcResult< T > m3pp2m_fitc(const T &a, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2, const std::vector< T > &ai, const std::vector< T > &dvt3, const T &t3)
Fit an M3PP(2, m).
T qbd_caudal(const Matrix< T > &R, unsigned iter_max, const T &tol)
Caudal characteristic eta = sp(R), the decay rate of the queue-length tail.
T mfq_ld_mean(const LevelDependentFluidBlocks< T > &b)
Stationary mean fluid level of a level-dependent fluid queue.
Map2FitIdcResult< T > map2_fit_idc(const T &e1, const T &e2, const T &e3, const T &I)
Fit a MAP(2) to three moments and an asymptotic index of dispersion.
LdqbdMphcBlocks< T > ldqbd_mphc(const Matrix< T > &D0, const Matrix< T > &D1, const std::vector< T > &alpha, double c, const std::vector< T > &arrRate, const std::vector< T > &sf, bool carry=false)
Block-tridiagonal generator of an M/PH/c queue with level-dependent arrivals.
Aph2AdjustResult< T > aph2_adjust(const T &M1, const T &M2, const T &M3, const T &tol)
Feasible (M2, M3) closest to the input, holding M1 fixed.
MeRepresentation< T > mfq_fluflu_sojourn(const Matrix< T > &Qin, const Matrix< T > &Rin, const Matrix< T > &Qout, const Matrix< T > &Rout, bool srv0stop, bool transToPH, const T &prec)
Sojourn time of a drop in a fluid queue with fluid-modulated service.
Mmpp2FitResult< T > mmpp2_fit4(const T &mean, const T &scv, const T &skew, const T &acf1)
MMPP(2) with the given mean, SCV, skewness and lag-1 autocorrelation.
QbdMapMap1Result< T > qbd_mapmap1(const Map< T > &arrival, const Map< T > &service_in, const T &util, std::size_t max_levels)
MAP/MAP/1 queue (qbd_mapmap1.m).
Mmpp2FitcResult< T > mmpp2_fitc_theoretical(const Map< T > &mp, const T &t1, const T &t2, const T &tinf)
MMPP(2) fitted to the counting characteristics of a GIVEN MAP (matlab/lib/kpctoolbox/mmpp/mmpp2_fitc_...
T qbd_mapmap1_qlen_truncated(const QbdMapMap1Result< T > &res)
The mean number in system computed the way MATLAB's qbd_mapmap1 does it, by summing k over the materi...
T qbd_setupdelayoff(const T &lambda, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean queue length of the M/M/1 queue with setup delay and delay-off (qbd_setupdelayoff....
Map< T > aph2_assemble(const T &l1, const T &l2, const T &p1)
APH(2) with phase means l1, l2 and continuation probability p1.
T qbd_qlen_moment(const std::vector< T > &pi0, const Matrix< T > &R, unsigned m)
Raw moment of order m of the number in system, E[N^m], assembled from the factorial moments with the ...
Map< T > map_renewal(const Map< T > &in)
Renewal process with the same inter-arrival distribution: D1 is replaced by (D1 e) pie,...
SetupDelayoffMMk< T > qbd_setupdelayoff_mmk(int k, double N, const T &arv, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean number present and throughput of a k-SERVER queue whose servers each pay a setup when woken from...
FluidPrioResult mfq_prio_queue(const Matrix< double > &Q, const Matrix< double > &R, double d, const FluidPrioOptions &opt)
Fluid priority queue.
Mmap< T > m3pp_rand(std::size_t K, std::size_t classes, Gen &gen)
Random M3PP of order K with classes marks (m3a/m3pp/m3pp_rand.m).
LdqbdResult< T > ldqbd(const std::vector< Matrix< T > > &q0, const std::vector< Matrix< T > > &q1, const std::vector< Matrix< T > > &q2)
Solve a level-dependent QBD: rate matrices and stationary law (ldqbd.m).
Map< T > map_erlang(const T &mean, unsigned k)
Erlang-k renewal MAP with the given mean (map_erlang.m).
MeRepresentation< T > mfq_sojourn(const Matrix< T > &Q, const Matrix< T > &Rin, const Matrix< T > &Rout, const Matrix< T > &Q0, bool transToPH, const T &prec)
Sojourn time of a drop in a Markov-modulated fluid queue.
Mmpp2FitcApproxResult< T > mmpp2_fitc_approx(const T &a, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2, const AugLagOptions< T > &opt)
Fit an MMPP(2) to counting characteristics.
std::vector< std::vector< T > > mfq_ld_distr(const LevelDependentFluidBlocks< T > &b, FluidDistrKind what, const std::vector< T > &points)
Stationary density or distribution of a level-dependent fluid queue.
bool map_isfeasible(const Map< T > &m, const T &tol)
Structural feasibility of a MAP within a tolerance (map_isfeasible.m): off-diagonal D0 and all of D1 ...
LdqbdCensorResult< T > ldqbd_censor(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &phases, double tol=1e-10)
Stationary distribution of a chain of connected LDQBDs (ldqbd_censor.m).
Mmap< T > mmap_compress(const Mmap< T > &in, MmapCompressMethod method)
Compress an MMAP (mmap_compress.m).
Map< T > map_exponential_mean(const T &mean)
Poisson process with the given mean inter-arrival time (map_exponential.m).
Map< T > map_sumind(const std::vector< Map< T > > &maps)
Sum of independent, not necessarily identical MAPs: after each component completes,...
Map< T > map_mixture(const std::vector< T > &alpha, const std::vector< Map< T > > &maps)
Probabilistic mixture of MAPs with weights alpha: after an arrival from component i the process jumps...
Map< T > map_sum(const Map< T > &in, unsigned n)
n-fold convolution of a MAP with itself: the inter-arrival time of the result is the sum of n consecu...
QbdFundMat< T > qbd_fundmat(const Matrix< T > &B, const Matrix< T > &L, const Matrix< T > &F, unsigned iter_max, const T &tol)
G and R by cyclic reduction (qbd_fundmat.m, the Bini-Meini logarithmic reduction on the raw level blo...
Map< T > ph2map(const PhType< T > &ph)
MAP whose inter-arrival time is the PH (alpha, T): the renewal MAP with D1 = (-T e) alpha.
QbdRapResult< T > qbd_rap(const Matrix< T > &A0, const Matrix< T > &A1, const Matrix< T > &A2, const Matrix< T > &B0, const Matrix< T > &B1, std::size_t numLevels)
Equilibrium analysis of a QBD with RAP components (qbd_rap.m).
Map< T > amap2_assemble(const T &l1, const T &l2, const T &p1, const T &p2, int form)
AMAP(2) in canonical form 1 (gamma >= 0) or 2 (gamma < 0).
Map< T > map_scale(const Map< T > &in, const T &new_mean)
Rescale time so that the mean inter-arrival time becomes new_mean.
M3pp2mFitcApproxResult< T > m3pp2m_fitc_approx(const T &a, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2, const std::vector< T > &ai, const std::vector< T > &dvt3, const T &t3, const std::vector< Bound< T > > &bounds, const AugLagOptions< T > &opt)
m3pp2m_fitc_approx: fit the underlying MMPP(2) by optimization, then split the classes on their varia...
Map< T > mmpp2_fit(const T &E1, const T &E2, const T &E3, const T &ACFLAG1)
MMPP(2) with moments (E1, E2, E3) and lag-1 autocorrelation ACFLAG1.
Matrix< T > qbd_R_logred(const Matrix< T > &B, const Matrix< T > &L, const Matrix< T > &F, unsigned iter_max, const T &tol)
R by logarithmic reduction (qbd_R_logred.m).
M3pp2mFitcTraceResult< T > m3pp2m_fitc_trace(const std::vector< T > &Tv, const std::vector< int > &A, const std::string &method, const T &t1, const T &tinf)
Fit a multi-class trace with an M3PP(2, m) on its counting process.
Map< T > map_stochcomp(const Map< T > &in, const std::vector< std::size_t > &retain)
Stochastic complement of a MAP on the retained phases (map_stochcomp.m): the eliminated phases are ce...
std::vector< T > map_count_moment(const Map< T > &m, const T &t, const std::vector< unsigned > &orders)
Power moments of the counts of a MAP in a window of length t.
Matrix< T > qbd_R(const Matrix< T > &B, const Matrix< T > &L, const Matrix< T > &F, unsigned iter_max, const T &tol)
R by successive substitutions (qbd_R.m): iterate R <- -(F + R^2 B) L^-1.
SetupDelayoffClosed< T > qbd_setupdelayoff_closed(const T &N, const T &Z, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean queue length and throughput of a FINITE-POPULATION queue with setup delay and delay-off,...
Mmap< T > mmap_super(const Mmap< T > &a, const Mmap< T > &b)
Superposition of two MMAPs: the phase process is the product chain, and the class list of the result ...
bool mmap_isfeasible(const Mmap< T > &m)
True when the per-class matrices partition D1 exactly and D0 is a generator.
std::vector< T > mmap_pc(const Mmap< T > &m)
Class probabilities seen by an arriving job, pc = pie (-D0)^-1 D1^(c) e.
std::vector< Map< T > > amap2_fitall_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T °entol, const T &r12tol)
Every AMAP(2) matching (M1, M2, M3, GAMMA).
Matrix< T > qbd_pi(const Matrix< T > &B, const Matrix< T > &Lbar, const Matrix< T > &R, std::size_t max_levels, const T &mass_tol)
Stationary distribution of a QBD given R (QBD_pi.m, continuous-time branch, default boundary).
T map_moment(const Map< T > &m, unsigned k)
Raw moment of order k of the inter-arrival time: k!
T qbd_qlen_factmoment(const std::vector< T > &pi0, const Matrix< T > &R, unsigned m)
Factorial moment of order m of the number in system, computed in closed form from the boundary vector...
QbdRg< T > qbd_rg(const Map< T > &arrival, const Map< T > &service_in, const T &util)
R and G of the MAP/MAP/1 QBD (qbd_rg.m).
Mmap< T > map_mark(const Map< T > &m, const std::vector< T > &prob)
MMAP with the same inter-arrival process and arrivals marked by prob.
T qbd_R_residual(const Matrix< T > &B, const Matrix< T > &L, const Matrix< T > &F, const Matrix< T > &R)
Residual of the defining equation of R, ||F + R L + R^2 B||_inf.
Mmpp2FitResult< T > mmpp2_fit2(const T &mean, const T &scv, const T &skew, const T &g2)
MMPP(2) with the given mean, SCV, skewness and decay rate g2.
std::vector< T > mmap_count_lambda(const Mmap< T > &m)
Per-class arrival rates, lambda_c = theta D1^(c) e.
std::vector< T > mmap_count_var(const Mmap< T > &mm, const T &t)
Per-class variance of the counting process of a marked MAP.
LevelDependentFluidBlocks< T > mfq_ld_solve(const std::vector< Matrix< T > > &Q, const std::vector< Matrix< T > > &R, const std::vector< Matrix< T > > &S, const std::vector< T > &Thr, const std::vector< FluidBoundary > &boundaryL, const std::vector< FluidBoundary > &boundaryU, const std::vector< Matrix< T > > &Qt, const T &prec)
Solve a first- or second-order level-dependent fluid queue.
FluidDistrKind
Which functional of the stationary level law to evaluate.
@ Pdfd
derivative of the density
@ Cdf
P(X < p), excluding an atom sitting exactly at p.
@ Cdfm
P(X <= p), including it.
QbdBmapBmap1Blocks< T > qbd_bmapbmap1(const Map< T > &arrival, const std::vector< T > &pbatch, const Map< T > &service)
Level blocks of a BMAP/MAP/1 queue.
PassageMoments< T > smp_passage_moments(const Matrix< T > &P, const Matrix< T > &hmom, const std::vector< T > &pi0, const std::vector< std::size_t > &target, std::size_t nmax=1)
Moments of the semi-Markov first passage time from the per-state holding moments m_i(r),...
GegecnResult< T > me_gegecn(const T &lambda, const T &Ca, const T &mu, const T &Cs, long c, long K, long N)
Port of me_gegecn.
MeResult< T > me_mqn(std::size_t M, std::size_t R, const std::vector< char > &open_classes, const Matrix< T > &lambda0, const Matrix< T > &Ca0, const std::vector< long > &N, const Matrix< T > &mu, const Matrix< T > &Cs, const std::vector< Matrix< T > > &P, const std::vector< long > &c, const std::vector< long > &refstat, const std::vector< char > &insens, const MeOptions &opt=MeOptions())
Maximum-entropy algorithm for mixed open/closed multiclass networks.
T me_gegecn_pb(const std::vector< T > &p, long K, long N, long c, const T &Cs, const T &Ca)
Port of me_gegecn_pb.
MeResult< T > me_cqn(std::size_t M, std::size_t R, const std::vector< long > &N, const Matrix< T > &mu, const Matrix< T > &Cs, const std::vector< Matrix< T > > &P, const std::vector< long > &c, const std::vector< long > &refstat_in, const std::vector< char > &insens, const MeOptions &opt=MeOptions())
Maximum-entropy algorithm for closed multiclass queueing networks.
T me_gegec_mql(const T &lambda, const T &Ca, const T &mu, const T &Cs, long c)
Port of me_gegec_mql.
MeBlkResult< T > me_oqn_blk(std::size_t M, const std::vector< T > &lambda0, const std::vector< T > &Ca0, const std::vector< T > &mu, const std::vector< T > &Cs, const Matrix< T > &P, const std::vector< long > &c, const std::vector< long > &N, const std::vector< int > &blockrule, const MeBlkOptions &opt=MeBlkOptions())
Port of me_oqn_blk.
MeResult< T > me_oqn(std::size_t M, std::size_t R, const Matrix< T > &lambda0, const Matrix< T > &Ca0, const Matrix< T > &mu, const Matrix< T > &Cs, const std::vector< Matrix< T > > &P, const std::vector< long > &c, const std::vector< char > &insens, const MeOptions &opt=MeOptions())
Maximum-entropy algorithm for open multiclass queueing networks.
std::uint64_t required_seed(Args &a, const std::string &fn, const char *spelled="seed")
The seed of a function whose port draws from a caller-owned generator.
Json encode_vectors(const std::vector< std::vector< T > > &v)
A list of vectors, the shape a per-class or per-segment result returns.
Matrix< T > matrix_from_json(const Json &j, const std::string &where)
A matrix from a JSON value: 2-D array as rows, 1-D array as a row vector, scalar as 1x1,...
void register_library_only_mam(LibraryOnlyTable &t)
std::vector< int > int_vector_from_json(const Json &j, const std::string &where)
An integer vector; a non-integral entry is an error, never a truncation.
Json encode_matrices(const std::vector< Matrix< T > > &v)
A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.
void register_api_mam(DispatchTable &t)
T number_from_json(const Json &j, const std::string &where)
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.
Json encode_vector(const std::vector< T > &v)
Json encode_matrix(const Matrix< T > &m)
std::string shortest_decimal(double v)
The shortest decimal literal that round-trips to v.
Json encode_scalar(const T &v)
std::map< std::string, std::string > LibraryOnlyTable
name -> why the function has no named-JSON-argument form.
std::map< std::string, Invoker > DispatchTable
Conservation laws of a layered queueing network, enumerated from its structure.
Level blocks of a BMAP/MAP/1 queue: batch Markovian arrivals against a single-departure MAP service p...
The MAP/MAP/1 queue solved as a quasi-birth-death process.
Quasi-birth-death processes: the rate matrix R, the fundamental matrix G, the caudal characteristic,...
Quasi-birth-death processes with rational arrival process components, and the RAP/RAP/1 queue built o...
Mean queue length of an M/M/1 queue with a setup delay and a delayed-off period, solved as a QBD.
Multi-server queue with setup and delayed-off servers.