30#include <initializer_list>
135std::size_t prefix_count(
const Args& a, std::initializer_list<const char*> keys,
136 const std::string& fn) {
139 const char* missing =
nullptr;
140 for (
const char* k : keys) {
143 throw InputError(fn +
": '" + k +
"' follows '" + missing +
144 "' positionally in the port; give '" + missing +
"' as well");
155bool all_or_none(
const Args& a, std::initializer_list<const char*> keys,
const std::string& fn) {
158 for (
const char* k : keys) {
160 if (!names.empty()) names +=
", ";
161 names += std::string(
"'") + k +
"'";
163 if (n != 0 && n != keys.size())
164 throw InputError(fn +
": " + names +
" tune one computation together; give all of them "
169std::vector<unsigned> read_uints(
Args& a,
const char* key,
const std::string& fn) {
170 const std::vector<int> v = a.ints(key);
171 std::vector<unsigned> out;
172 for (std::size_t i = 0; i < v.size(); ++i) {
174 throw InputError(fn +
": '" + key +
"' holds counts and cannot be negative");
175 out.push_back(
static_cast<unsigned>(v[i]));
181bool required_flag(
Args& a,
const char* key,
const std::string& fn) {
182 if (!a.has(key))
throw InputError(fn +
": missing required argument '" + key +
"'");
183 return a.boolean(key,
false);
188mam::Map<T> read_map(
Args& a,
const char* d0,
const char* d1) {
190 m.D0 = a.matrix<T>(d0);
191 m.D1 = a.matrix<T>(d1);
197mam::Map<T> map_from_pair(
const Json& j,
const std::string& where) {
198 if (!j.is_array() || j.size() != 2)
199 throw InputError(where +
": expected the MAP as a list [D0, D1] of two matrices");
208std::vector<mam::Map<T> > maps_from_json(
const Json& j,
const std::string& where) {
209 if (!j.is_array())
throw InputError(where +
": expected a list of [D0, D1] pairs");
210 std::vector<mam::Map<T> > out;
211 for (std::size_t i = 0; i < j.size(); ++i)
212 out.push_back(map_from_pair<T>(j[i], where +
"[" + std::to_string(i) +
"]"));
223lang::Distrib<T> dist_record(
const Json& j,
const std::string& where) {
224 if (!j.is_object() || !j.contains(
"type"))
225 throw InputError(where +
": expected a distribution record {\"type\": ..., ...} as "
226 "written to model.json");
228 return io::detail::dist_from_json<T>(j);
229 }
catch (
const Json::exception& e) {
230 throw InputError(where +
": malformed distribution record: " + e.what());
240qsys::ServiceLaw<T> read_svc(
Args& a,
const std::string& fn) {
241 Args sv(a.get(
"svc"), fn +
": svc");
242 const std::string type = sv.text(
"type",
"");
243 qsys::ServiceLaw<T> svc;
246 }
else if (type ==
"gamma") {
247 const T al = sv.number<T>(
"alpha");
249 }
else if (type ==
"ph") {
250 const std::vector<T> al = sv.vector<T>(
"alpha");
252 }
else if (type ==
"density") {
254 fn +
": a 'density' service law is a function handle and has no named-JSON form; "
255 "use 'det', 'gamma' or 'ph', or call it from the library");
258 fn +
": svc.type must be 'det', 'gamma' or 'ph', got '" + type +
"'");
266Json encode_shaped(
const std::vector<T>& v,
bool scalar) {
272std::string sim_exact_refusal(
const char* fn,
const char* why) {
273 return std::string(fn) +
": " + why +
274 ", so exact rational arithmetic has nothing to preserve and is refused; rerun with "
275 "--arith double or --arith real";
283void tensor_fill(
const Json& node, std::size_t depth, std::size_t offset,
284 const std::vector<std::size_t>& sz,
const std::vector<std::size_t>& stride,
285 std::vector<T>& data,
const std::string& where) {
286 if (depth == sz.size()) {
288 throw InputError(where +
": the tensor is nested deeper than its first element");
292 if (!node.is_array() || node.size() != sz[depth])
293 throw InputError(where +
": ragged tensor, dimension " + std::to_string(depth + 1) +
294 " must have " + std::to_string(sz[depth]) +
" entries throughout");
295 for (std::size_t i = 0; i < sz[depth]; ++i)
296 tensor_fill<T>(node[i], depth + 1, offset + i * stride[depth], sz, stride, data, where);
305moment::MomentTensor<T> tensor_from_json(
const Json& j,
const std::string& where) {
306 std::vector<std::size_t> sz;
311 while (p->is_array()) {
312 sz.push_back(p->size());
313 if (p->empty())
break;
317 std::vector<std::size_t> stride(sz.size(), 1);
318 for (std::size_t l = 1; l < sz.size(); ++l) stride[l] = stride[l - 1] * sz[l - 1];
319 moment::MomentTensor<T> t(sz);
322 else if (t.numel() > 0)
323 tensor_fill<T>(j, 0, 0, sz, stride, t.data, where);
328Json tensor_nest(
const moment::MomentTensor<T>& t, std::size_t depth, std::size_t offset) {
329 Json out = Json::array();
330 const std::size_t st = t.stride(depth);
331 for (std::size_t i = 0; i < t.sz[depth]; ++i) {
332 if (depth + 1 == t.order())
335 out.push_back(tensor_nest(t, depth + 1, offset + i * st));
342Json encode_tensor(
const moment::MomentTensor<T>& t) {
343 return tensor_nest(t, 0, 0);
346Json encode_sizes(
const std::vector<std::size_t>& v) {
347 Json out = Json::array();
348 for (std::size_t i = 0; i < v.size(); ++i) out.push_back(
encode_count(v[i]));
356#define LINE_MOMENT_VEC_OP(OPNAME, FN, IN, OUT) \
359 static Json run(Args& a) { \
360 const std::vector<T> x = a.vector<T>(IN); \
363 out[OUT] = encode_vector(moment::FN<T>(x)); \
370LINE_MOMENT_VEC_OP(OpMomentFactcumulantFromFactorial, moment_factcumulant_from_factorial,
"f",
372LINE_MOMENT_VEC_OP(OpMomentFactorialFromFactcumulant, moment_factorial_from_factcumulant,
376#undef LINE_MOMENT_VEC_OP
382#define LINE_MOMENT_TENSOR_OP(OPNAME, FN, IN, OUT) \
385 static Json run(Args& a) { \
386 const moment::MomentTensor<T> x = \
387 tensor_from_json<T>(a.get(IN), std::string(#FN ": ") + IN); \
390 out[OUT] = encode_tensor(moment::FN<T>(x)); \
423#undef LINE_MOMENT_TENSOR_OP
425struct OpMjCentralFromRawMean {
427 static Json run(Args& a) {
428 const moment::MomentTensor<T> m =
429 tensor_from_json<T>(a.get(
"m"),
"moment_joint_central_from_raw_mean: m");
430 const std::vector<T> mu = a.vector<T>(
"mu");
438struct OpMjRawFromCentral {
440 static Json run(Args& a) {
441 const moment::MomentTensor<T> mc =
442 tensor_from_json<T>(a.get(
"mc"),
"moment_joint_raw_from_central: mc");
443 const std::vector<T> mu = a.vector<T>(
"mu");
451struct OpMjAggregate {
453 static Json run(Args& a) {
454 const moment::MomentTensor<T> F =
455 tensor_from_json<T>(a.get(
"F"),
"moment_joint_aggregate: F");
465 static Json run(Args& a) {
466 const std::vector<T> f = a.vector<T>(
"f");
467 const std::vector<T> p = a.vector<T>(
"p");
468 const std::vector<unsigned> d = read_uints(a,
"dims",
"moment_joint_marking");
470 const std::vector<std::size_t> dims(d.begin(), d.end());
477struct OpMomentHousematrix {
479 static Json run(Args& a) {
480 const std::string edge = a.text(
"edge",
"");
481 if (edge.empty())
throw InputError(
"moment_housematrix: missing required argument 'edge'");
482 const int n = a.required_integer(
"n");
490struct OpMomentTensorsize {
492 static Json run(Args& a) {
493 const moment::MomentTensor<T> A = tensor_from_json<T>(a.get(
"A"),
"moment_tensorsize: A");
501struct OpMomentTensortrans {
503 static Json run(Args& a) {
504 const moment::MomentTensor<T> A = tensor_from_json<T>(a.get(
"A"),
"moment_tensortrans: A");
505 const Matrix<T> Tm = a.matrix<T>(
"T");
506 const std::size_t mode = a.count(
"mode");
509 if (mode < 1)
throw InputError(
"moment_tensortrans: 'mode' is 1-based and must be >= 1");
516struct OpMomentJointtrans {
518 static Json run(Args& a) {
519 const moment::MomentTensor<T> A = tensor_from_json<T>(a.get(
"A"),
"moment_jointtrans: A");
520 const std::string edge = a.text(
"edge",
"");
521 if (edge.empty())
throw InputError(
"moment_jointtrans: missing required argument 'edge'");
539 static Json run(Args& a) {
540 const std::vector<T> D = a.vector<T>(
"D");
541 const std::vector<unsigned>
P = read_uints(a,
"P",
"fj_amva");
542 const unsigned M = a.uinteger(
"M");
543 const T Z = a.number<T>(
"Z");
557 static Json run(Args& a) {
558 const std::vector<T> D = a.vector<T>(
"D");
559 const std::vector<unsigned>
P = read_uints(a,
"P",
"fj_qgb");
560 const unsigned M = a.uinteger(
"M");
561 const T Z = a.number<T>(
"Z");
571struct OpFjCharMaxBlom {
573 static Json run(Args& a) {
574 const unsigned K = a.uinteger(
"K");
575 a.unsupported(
"Finv",
"it is a quantile function handle; omit it for the standard "
576 "normal the port selects");
577 const std::size_t n = prefix_count(a, {
"alpha",
"beta"},
"fj_char_max_blom");
578 const T alpha = n >= 1 ? a.number<T>(
"alpha") : T();
579 const T beta = n >= 2 ? a.number<T>(
"beta") : T();
581 const std::function<T(
const T&)> none;
582 const fj::FJCharMaxBlomResult<T> r =
590 if (r.bracket_available) {
598struct OpFjCharMaxDiscrete {
600 static Json run(Args& a) {
601 const unsigned K = a.uinteger(
"K");
602 std::string type = a.text(
"dist_type",
"");
603 const T par = a.number<T>(
"param");
605 for (std::size_t i = 0; i < type.size(); ++i)
606 type[i] =
static_cast<char>(std::tolower(
static_cast<unsigned char>(type[i])));
608 if (type ==
"geometric" || type ==
"geom")
610 else if (type ==
"poisson" || type ==
"pois")
614 "fj_char_max_discrete: dist_type must be 'geometric' or 'poisson', got '" + type +
619 out[
"mK"] =
static_cast<long long>(r.mK);
627 static Json run(Args& a) {
628 const T m1 = a.number<T>(
"m1");
629 const T c2 = a.number<T>(
"c2");
636 out[
"kmin"] =
static_cast<long long>(r.kmin);
637 out[
"kmax"] =
static_cast<long long>(r.kmax);
642struct OpFjDagMakespan {
644 static Json run(Args& a) {
645 const Matrix<T> pred = a.matrix<T>(
"pred");
646 Matrix<T> rate = a.matrix<T>(
"rate");
650 const std::size_t n = pred.rows();
651 if ((rate.rows() == 1 || rate.cols() == 1) && rate.rows() * rate.cols() == n && n > 1) {
652 Matrix<T> full(n, n);
653 for (std::size_t i = 0; i < n; ++i)
654 for (std::size_t k = 0; k < n; ++k)
655 full(i, k) = rate.rows() == 1 ? rate(0, i) : rate(i, 0);
669unsigned panels_from_npoints(
Args& o,
const std::string& fn) {
670 const unsigned np = o.uinteger(
"npoints");
671 if (np < 2)
throw InputError(fn +
": options.npoints must be at least 2");
683 static Json run(Args& a) {
684 const std::vector<unsigned> shape = read_uints(a,
"shape",
"fj_delay_opt");
685 const std::vector<T> rate = a.vector<T>(
"rate");
687 unsigned maxsweeps = 0, npanels = 0;
689 if (
const Json* oj = a.opt(
"options")) {
690 Args o(*oj,
"fj_delay_opt: options");
691 o.unsupported(
"tol",
"the port fixes the dispersion tolerance of the inner "
692 "fj_dispersion calls and takes no argument for it");
693 n = prefix_count(o, {
"maxsweeps",
"dtol",
"npoints"},
"fj_delay_opt: options");
694 if (n >= 1) maxsweeps = o.uinteger(
"maxsweeps");
695 if (n >= 2) dtol = o.number<T>(
"dtol");
696 if (n >= 3) npanels = panels_from_npoints(o,
"fj_delay_opt");
700 fj::FJDelayOptResult<T> r;
718struct OpFjDispersion {
720 static Json run(Args& a) {
721 const std::vector<unsigned> shape = read_uints(a,
"shape",
"fj_dispersion");
722 const std::vector<T> rate = a.vector<T>(
"rate");
723 const bool hasD = a.has(
"d");
724 const std::vector<T> d = a.vector_or_empty<T>(
"d");
726 unsigned npanels = 0;
728 if (
const Json* oj = a.opt(
"options")) {
730 throw InputError(
"fj_dispersion: 'options' follows 'd' positionally in the port; "
732 Args o(*oj,
"fj_dispersion: options");
733 n = prefix_count(o, {
"tol",
"npoints"},
"fj_dispersion: options");
734 if (n >= 1) tol = o.number<T>(
"tol");
735 if (n >= 2) npanels = panels_from_npoints(o,
"fj_dispersion");
739 fj::FJDispersionResult<T> r;
754 static Json run(Args& a) {
755 const T lambda = a.number<T>(
"lambda");
756 const T mu = a.number<T>(
"mu");
757 const unsigned s = a.uinteger(
"s");
758 const std::vector<T> c = a.vector<T>(
"c");
782struct OpFjLstMaxHet {
784 static Json run(Args& a) {
785 const std::vector<T> lambda = a.vector<T>(
"lambda");
786 const T s = a.number<T>(
"s");
794struct OpFjResptBulk {
796 static Json run(Args& a) {
797 const unsigned K = a.uinteger(
"K");
798 const T lambda = a.number<T>(
"lambda");
799 const T mu = a.number<T>(
"mu");
800 const unsigned c = a.uinteger(
"c");
801 const bool hasN = a.has(
"nmax");
802 const std::size_t nmax = a.count(
"nmax", 0);
815struct OpFjResptClosed {
817 static Json run(Args& a) {
818 const unsigned K = a.uinteger(
"K");
819 const T x = a.number<T>(
"x");
820 const unsigned M = a.uinteger(
"M");
821 const bool hasA = a.has(
"A");
822 const T A = hasA ? a.number<T>(
"A") : T();
824 const fj::FJResptClosedResult<T> r =
828 out[
"exact"] = r.exact;
833struct OpFjResptNosplit {
835 static Json run(Args& a) {
836 const unsigned K = a.uinteger(
"K");
837 const T lambda = a.number<T>(
"lambda");
838 const T mu = a.number<T>(
"mu");
848struct OpFjSerialization {
850 static Json run(Args& a) {
851 const std::vector<T> Rs = a.vector<T>(
"Rs");
852 const T R0 = a.number<T>(
"R0");
853 const unsigned M = a.uinteger(
"M");
854 const bool hasAlpha = a.has(
"alpha");
855 const T alpha = hasAlpha ? a.number<T>(
"alpha") : T();
857 const fj::FJSerializationResult<T> r = hasAlpha
868struct OpFjTsmCapacity {
870 static Json run(Args& a) {
871 const unsigned s = a.uinteger(
"s");
872 const std::vector<T> f = a.vector<T>(
"f");
873 const std::vector<unsigned> rr = read_uints(a,
"r",
"fj_tsm_capacity");
874 const std::vector<T> x = a.vector<T>(
"x");
882 Json states = Json::array();
883 for (std::size_t i = 0; i < r.states.size(); ++i) {
884 Json row = Json::array();
885 for (std::size_t k = 0; k < r.states[i].size(); ++k)
886 row.push_back(
static_cast<long long>(r.states[i][k]));
887 states.push_back(row);
890 p[
"states"] = states;
897struct OpFjXmaxCoxian {
899 static Json run(Args& a) {
900 const unsigned K = a.uinteger(
"K");
901 const T mu1 = a.number<T>(
"mu1");
902 const T mu2 = a.number<T>(
"mu2");
903 const T q = a.number<T>(
"q");
916 static Json run(Args& a) {
917 const std::vector<T> lambda = a.vector<T>(
"lambda");
918 const bool hasN = a.has(
"n");
919 const unsigned n = a.uinteger(
"n", 0);
927struct OpFjXmaxMomentsHet {
929 static Json run(Args& a) {
930 const std::vector<T> lambda = a.vector<T>(
"lambda");
931 const bool hasN = a.has(
"n");
932 const unsigned n = a.uinteger(
"n", 0);
943 static Json run(Args& a) {
944 const T m1 = a.number<T>(
"m1");
945 const T m2 = a.number<T>(
"m2");
946 const unsigned K = a.uinteger(
"K");
956struct OpFjMg1ResptMoments {
958 static Json run(Args& a) {
959 const T lambda = a.number<T>(
"lambda");
960 const T ES = a.number<T>(
"ES");
961 const T ES2 = a.number<T>(
"ES2");
962 const T ES3 = a.number<T>(
"ES3");
973Json forktail_results(
const fj::ForkTailResult<T>& r) {
982struct OpFjTailForktail {
984 static Json run(Args& a) {
985 const std::vector<T> ET = a.vector<T>(
"ET");
986 const std::vector<T> VT = a.vector<T>(
"VT");
987 const std::size_t n = prefix_count(a, {
"K",
"p",
"P"},
"fj_tail_forktail");
988 const std::vector<T> K = n >= 1 ? a.vector<T>(
"K") : std::vector<T>();
989 const T p = n >= 2 ? a.number<T>(
"p") : T();
990 const std::vector<T>
P = n >= 3 ? a.vector<T>(
"P") : std::vector<T>();
1000struct OpFjTailOrdstat {
1002 static Json run(Args& a) {
1003 const std::vector<T> ET = a.vector<T>(
"ET");
1004 const std::vector<T> VT = a.vector<T>(
"VT");
1005 const std::size_t n = prefix_count(a, {
"K",
"p",
"kreq"},
"fj_tail_ordstat");
1006 const std::size_t K = n >= 1 ? a.count(
"K") : 0;
1007 const T p = n >= 2 ? a.number<T>(
"p") : T();
1008 const std::size_t kreq = n >= 3 ? a.count(
"kreq") : 0;
1022struct OpFjBranchMembers {
1024 static Json run(Args& a) {
1025 Args l(a.get(
"lqn"),
"fj_branch_members: lqn");
1026 fj::LqnBranchView<T> v;
1027 v.graph = l.matrix<T>(
"graph");
1028 v.ashift = l.count(
"ashift");
1029 v.nacts = l.count(
"nacts");
1030 v.actposttype = l.ints(
"actposttype");
1032 const std::size_t joinaidx = a.count(
"joinaidx");
1035 Json members = Json::array();
1036 for (std::size_t i = 0; i < m.size(); ++i) members.push_back(encode_sizes(m[i]));
1038 out[
"members"] = members;
1050 static Json run(Args& a) {
1051 const mam::Map<T> m = map_from_pair<T>(a.get(
"lineMAP"),
"fj_dist2fj: lineMAP");
1052 const std::string distType = a.text(
"distType",
"");
1053 Args sn(a.get(
"sn"),
"fj_dist2fj: sn");
1054 const Matrix<double> procid = sn.matrix<
double>(
"procid");
1056 const std::size_t ist = a.count(
"ist");
1057 const std::size_t r = a.count(
"r");
1060 if (distType ==
"arrival")
1062 else if (distType ==
"service")
1065 throw InputError(
"fj_dist2fj: distType must be 'arrival' or 'service', got '" +
1067 if (ist < 1 || r < 1 || ist > procid.rows() || r > procid.cols())
1068 throw InputError(
"fj_dist2fj: (ist, r) are 1-based and must index sn.procid");
1069 const double code = procid(ist - 1, r - 1);
1077 "fj_dist2fj: sn.procid(ist, r) = " + std::to_string(code) +
1078 " is not a process FJ_codes takes (EXP=0, ERLANG=1, HYPEREXP=2, MAP=5)");
1087 out[
"ArrChoice"] = d.choice;
1093 out[
"SerChoice"] = d.choice;
1109 const std::vector<T> s = a.vector<T>(
"s");
1111 std::vector<T> v(s.size());
1112 for (std::size_t i = 0; i < s.size(); ++i) v[i] = L(s[i]);
1120 static Json run(Args& a) {
1121 const T d = a.number<T>(
"d");
1126struct OpAoiLstErlang {
1128 static Json run(Args& a) {
1129 const unsigned k = a.uinteger(
"k");
1130 const T mu = a.number<T>(
"mu");
1137 static Json run(Args& a) {
1138 const T mu = a.number<T>(
"mu");
1145 static Json run(Args& a) {
1146 const std::vector<T> alpha = a.vector<T>(
"alpha");
1147 const Matrix<T> Tm = a.matrix<T>(
"T");
1153struct OpAoiDist2ph {
1155 static Json run(Args& a) {
1156 const mam::Map<T> m = map_from_pair<T>(a.get(
"proc"),
"aoi_dist2ph: proc");
1175 std::size_t nmax = 0;
1179Truncation<T> read_truncation(
Args& a,
const std::string& fn) {
1181 tr.given = all_or_none(a, {
"tol",
"nmax"}, fn);
1183 tr.tol = a.number<T>(
"tol");
1184 tr.nmax = a.count(
"nmax");
1192struct OpQsysMapg1k {
1194 static Json run(Args& a) {
1195 const mam::Map<T> arrival = read_map<T>(a,
"D0",
"D1");
1196 const qsys::ServiceLaw<T> svc = read_svc<T>(a,
"qsys_mapg1k");
1197 const std::size_t K = a.count(
"K");
1198 const Truncation<T> tr = read_truncation<T>(a,
"qsys_mapg1k");
1200 const qsys::MapG1kResult<T> r = tr.given
1218 out[
"countingResidual"] =
encode_scalar(r.countingResidual);
1223struct OpQsysMmapg1k {
1225 static Json run(Args& a) {
1226 const Matrix<T> D0 = a.matrix<T>(
"D0");
1227 const std::vector<Matrix<T> > D1c = a.matrices<T>(
"D1c");
1228 const qsys::ServiceLaw<T> svc = read_svc<T>(a,
"qsys_mmapg1k");
1229 const std::size_t K = a.count(
"K");
1230 const Truncation<T> tr = read_truncation<T>(a,
"qsys_mmapg1k");
1232 const qsys::MmapG1kResult<T> r =
1240 out[
"throughputAggregate"] =
encode_scalar(r.throughputAggregate);
1255struct OpQsysMapg1kPerflow {
1257 static Json run(Args& a) {
1258 const std::vector<mam::Map<T> > flows =
1259 maps_from_json<T>(a.get(
"MAPS"),
"qsys_mapg1k_perflow: MAPS");
1260 const qsys::ServiceLaw<T> svc = read_svc<T>(a,
"qsys_mapg1k_perflow");
1261 const std::size_t K = a.count(
"K");
1262 const Truncation<T> tr = read_truncation<T>(a,
"qsys_mapg1k_perflow");
1264 const qsys::MapG1kPerflowResult<T> r =
1272 out[
"throughputAggregate"] =
encode_scalar(r.throughputAggregate);
1282struct OpQsysSvclawCoeffs {
1284 static Json run(Args& a) {
1285 const qsys::ServiceLaw<T> svc = read_svc<T>(a,
"qsys_svclaw_coeffs");
1286 const T theta = a.number<T>(
"theta");
1287 const T tol = a.number<T>(
"tol");
1288 const std::size_t nmaxCap = a.count(
"nmaxCap");
1311struct OpQsysLdpsWorkload {
1313 static Json run(Args& a) {
1314 const T lambda = a.number<T>(
"lambda");
1315 const lang::Distrib<T> law = dist_record<T>(a.get(
"B"),
"qsys_ldps_workload: B");
1316 const std::vector<T> alpha = a.vector<T>(
"alpha");
1317 const std::size_t N = a.count(
"N");
1318 const bool tuned = a.has(
"t") || a.has(
"ngrid");
1319 if (tuned && !a.has(
"ngrid"))
1320 throw InputError(
"qsys_ldps_workload: the port takes 't' and 'ngrid' together; give "
1321 "'ngrid' with 't'");
1322 const std::vector<T> t = a.vector_or_empty<T>(
"t");
1323 const std::size_t ngrid = a.count(
"ngrid", 0);
1325 qsys::WorkloadServiceLaw<T> B;
1328 B.scv = T(m2 / (B.mean * B.mean) - num_traits<T>::from_int(1));
1330 const qsys::LdpsWorkloadResult<T> r =
1349struct OpQsysMmapgk1 {
1351 static Json run(Args& a) {
1352 const std::vector<Matrix<T> >
MMAP = a.matrices<T>(
"MMAP");
1353 const Json& sj = a.get(
"svc");
1354 if (!sj.is_array())
throw InputError(
"qsys_mmapgk1: svc must be a list, one law per type");
1355 std::vector<qsys::MmapGk1Service<T> > svc;
1356 for (std::size_t k = 0; k < sj.size(); ++k) {
1357 const std::string where =
"qsys_mmapgk1: svc[" + std::to_string(k) +
"]";
1358 if (sj[k].is_array()) {
1359 svc.push_back(qsys::MmapGk1Service<T>(map_from_pair<T>(sj[k], where)));
1360 }
else if (sj[k].is_object() && sj[k].contains(
"lst")) {
1362 where +
": a transform struct carries an lst function handle, which cannot "
1363 "cross the JSON API boundary; give the law as a distribution record "
1364 "or a [D0, D1] pair");
1366 svc.push_back(qsys::MmapGk1Service<T>(dist_record<T>(sj[k], where)));
1369 const bool tuned = all_or_none(a, {
"wPoints",
"numWMoms",
"tol",
"iterMax"},
"qsys_mmapgk1");
1370 if (a.has(
"quadNodes") && !tuned)
1371 throw InputError(
"qsys_mmapgk1: 'quadNodes' follows 'wPoints', 'numWMoms', 'tol' and "
1372 "'iterMax' positionally in the port; give them as well");
1373 const std::vector<T> w = a.vector_or_empty<T>(
"wPoints");
1374 const std::size_t
nm = a.count(
"numWMoms", 0);
1375 const double tol = a.scalar<
double>(
"tol", 0.0);
1376 const std::size_t iterMax = a.count(
"iterMax", 0);
1377 const bool hasQ = a.has(
"quadNodes");
1378 const std::size_t q = a.count(
"quadNodes", 0);
1380 qsys::MmapGk1Result<T> r;
1406struct OpQsysMmapgk1Lcfspr {
1408 static Json run(Args& a) {
1409 const std::vector<Matrix<T> >
MMAP = a.matrices<T>(
"MMAP");
1410 const Json& sj = a.get(
"svc");
1412 throw InputError(
"qsys_mmapgk1_lcfspr: svc must be a list, one law per type");
1413 std::vector<qsys::MmapGk1Service<T> > svc;
1414 for (std::size_t k = 0; k < sj.size(); ++k) {
1415 const std::string where =
"qsys_mmapgk1_lcfspr: svc[" + std::to_string(k) +
"]";
1416 if (sj[k].is_array()) {
1417 svc.push_back(qsys::MmapGk1Service<T>(map_from_pair<T>(sj[k], where)));
1418 }
else if (sj[k].is_object() && sj[k].contains(
"lst")) {
1420 where +
": a transform struct carries an lst function handle, which cannot "
1421 "cross the JSON API boundary; give the law as a distribution record "
1422 "or a [D0, D1] pair");
1424 svc.push_back(qsys::MmapGk1Service<T>(dist_record<T>(sj[k], where)));
1427 qsys::MmapGk1LcfsprOptions<T> opt;
1428 if (a.has(
"nMax")) opt.nMax =
static_cast<long>(a.count(
"nMax"));
1429 opt.wPoints = a.vector_or_empty<T>(
"wPoints");
1430 opt.quadNodes = a.count(
"quadNodes", 120);
1431 opt.tol = a.scalar<
double>(
"tol", 1e-12);
1432 const bool wantLst = a.has(
"s");
1433 const std::vector<T> sPts = wantLst ? a.vector<T>(
"s") : std::vector<T>();
1444 out[
"classMeanQueueLength"] =
encode_vector(r.classMeanQueueLength);
1447 out[
"queueLengthDistr"] =
encode_vector(r.queueLengthDistr);
1448 out[
"classQueueLengthDistr"] =
encode_vectors(r.classQueueLengthDistr);
1452 const std::size_t K = r.lambdas.size();
1453 std::vector<std::vector<T> > lv(K, std::vector<T>(sPts.size()));
1454 for (std::size_t i = 0; i < sPts.size(); ++i) {
1455 const std::vector<std::complex<double> > w =
1456 r.respLST(std::complex<double>(num_traits<T>::to_double(sPts[i]), 0.0));
1457 for (std::size_t k = 0; k < K; ++k) lv[k][i] = num_traits<T>::from_double(w[k].real());
1461 out[
"analyzer"] = r.analyzer;
1472struct OpQsysTandemUbCiucu {
1474 static Json run(Args& a) {
1475 const std::vector<T> x = a.vector<T>(
"x");
1476 const lang::Distrib<T> law = dist_record<T>(a.get(
"lst"),
"qsys_tandem_ub_ciucu: lst");
1477 const std::vector<T> p = a.vector<T>(
"p");
1478 const std::vector<T> mu = a.vector<T>(
"mu");
1479 a.unsupported(
"dlst",
"it is a function handle; omit it and the port differentiates the "
1480 "transform of lst numerically");
1482 const std::function<T(
const T&)> lst = [law](
const T& s) {
return lang::dist_lst(law, s); };
1493 out[
"analyzer"] = r.analyzer;
1503Json lindley_results(
const qsys::LindleyResult<T>& r,
bool scalar) {
1505 out[
"mean"] = encode_shaped(r.mean, scalar);
1506 out[
"var"] = encode_shaped(r.var, scalar);
1508 out[
"mmax"] =
static_cast<long long>(r.mmax);
1509 out[
"analyzer"] = r.analyzer;
1513struct OpQsysHh1Lindley {
1515 static Json run(Args& a) {
1516 const std::vector<T> lambda = a.vector<T>(
"lambda");
1517 const std::vector<T> pa = a.vector<T>(
"pa");
1518 const std::vector<T> mu = a.vector<T>(
"mu");
1519 const std::vector<T> ps = a.vector<T>(
"ps");
1520 const bool scalar = !a.get(
"Wn").is_array();
1521 const std::vector<T> Wn = a.vector<T>(
"Wn");
1522 const bool hasM = a.has(
"mmax");
1523 const unsigned mmax = a.uinteger(
"mmax", 0);
1526 return lindley_results(
1536struct OpQsysMm1Lindley {
1538 static Json run(Args& a) {
1539 const T lambda = a.number<T>(
"lambda");
1540 const T mu = a.number<T>(
"mu");
1541 const bool scalar = !a.get(
"Wn").is_array();
1542 const std::vector<T> Wn = a.vector<T>(
"Wn");
1543 const bool hasM = a.has(
"mmax");
1544 const unsigned mmax = a.uinteger(
"mmax", 0);
1556struct OpQsysLindleyMoment {
1558 static Json run(Args& a) {
1559 const T lambda = a.number<T>(
"lambda");
1560 const T mu = a.number<T>(
"mu");
1561 const bool scalar = !a.get(
"Wn").is_array();
1562 const std::vector<T> Wn = a.vector<T>(
"Wn");
1563 const unsigned m = a.uinteger(
"m");
1574struct OpQsysMm1TandemLindley {
1576 static Json run(Args& a) {
1577 const T lambda = a.number<T>(
"lambda");
1578 const T mu1 = a.number<T>(
"mu1");
1579 const T mu2 = a.number<T>(
"mu2");
1580 const bool s1 = !a.get(
"Wk").is_array();
1581 const bool s2 = !a.get(
"Wk1").is_array();
1582 const std::vector<T> Wk = a.vector<T>(
"Wk");
1583 const std::vector<T> Wk1 = a.vector<T>(
"Wk1");
1585 const bool scalar = s1 && s2;
1586 const qsys::Mm1TandemLindleyResult<T> r =
1590 out[
"mean"] = encode_shaped(r.mean, scalar);
1591 out[
"interdepMean"] = encode_shaped(r.interdepMean, scalar);
1592 out[
"idleProb"] = encode_shaped(r.idleProb, scalar);
1593 out[
"analyzer"] = r.analyzer;
1598struct OpQsysTandemLindley {
1600 static Json run(Args& a) {
1601 const std::vector<T> A = a.vector<T>(
"A");
1602 const Matrix<T> S = a.matrix<T>(
"S");
1603 const bool hasW0 = a.has(
"W0");
1604 const std::vector<T> W0 = a.vector_or_empty<T>(
"W0");
1606 const qsys::TandemLindleyResult<T> r =
1613 out[
"analyzer"] = r.analyzer;
1620 static Json run(Args& a) {
1621 const std::vector<T> lambda = a.vector<T>(
"lambda");
1622 const std::vector<T> mu = a.vector<T>(
"mu");
1645 static Json run(Args& a) {
1646 const double lambda = a.number<
double>(
"lambda");
1647 if (a.get(
"svc").is_string())
1649 "qsys_mg1_ps: argument 'svc' cannot cross the JSON API boundary as a transform "
1650 "handle; give the phase-type initial vector alpha, with svcparam its "
1652 const std::vector<double> alpha = a.vector<
double>(
"svc");
1653 const Matrix<double> Tm = a.matrix<
double>(
"svcparam");
1654 qsys::Mg1PsOptions opt;
1655 if (a.has(
"x")) opt.x = a.vector<
double>(
"x");
1656 if (a.has(
"s")) opt.s = a.vector<
double>(
"s");
1657 if (a.has(
"t")) opt.t = a.vector<
double>(
"t");
1658 opt.nterms = a.count(
"nterms", opt.nterms);
1659 a.unsupported(
"pdf",
"it is a density function handle; on the phase-type path the port "
1660 "derives the density itself");
1673 out[
"atomUncond"] = r.atomUncond;
1677 out[
"meanUncond"] = r.meanUncond;
1678 out[
"m2Uncond"] = r.m2Uncond;
1679 out[
"varUncond"] = r.varUncond;
1695struct OpQsysBmapm1 {
1697 static Json run(Args& a) {
1698 const std::vector<Matrix<T> > D = a.matrices<T>(
"D");
1699 const T mu = a.number<T>(
"mu");
1700 const bool tuned = a.has(
"Uniformization") || a.has(
"MaxLevel") || a.has(
"MaxIter") ||
1701 a.has(
"Tolerance") || a.has(
"TailTolerance");
1702 if (tuned && !(a.has(
"MaxIter") && a.has(
"Tolerance") && a.has(
"TailTolerance")))
1703 throw InputError(
"qsys_bmapm1: the port takes its options together; with any of them "
1704 "give 'MaxIter', 'Tolerance' and 'TailTolerance'");
1705 const T q = a.scalar<T>(
"Uniformization", num_traits<T>::from_int(0));
1706 const std::size_t maxLevel = a.count(
"MaxLevel", 0);
1707 const unsigned maxIter = a.uinteger(
"MaxIter", 0);
1708 const T tol = a.scalar<T>(
"Tolerance", num_traits<T>::from_int(0));
1709 const double tailTol = a.scalar<
double>(
"TailTolerance", 0.0);
1711 const qsys::BmapM1Result<T> r =
1727 out[
"decayRate"] = r.decayRate;
1734 out[
"truncError"] = r.truncError;
1735 out[
"gConverged"] = r.gConverged;
1741struct OpQsysMaximaTwomoment {
1743 static Json run(Args& a) {
1744 const std::size_t n = a.count(
"n");
1745 const T mean = a.number<T>(
"mean_");
1746 const T cs2 = a.number<T>(
"cs2");
1747 const std::size_t k = prefix_count(a, {
"q",
"exactFitted"},
"qsys_maxima_twomoment");
1748 const T q = k >= 1 ? a.number<T>(
"q") : T();
1749 const bool ef = k >= 2 ? a.boolean(
"exactFitted",
false) :
false;
1751 const qsys::MaximaResult<T> r =
1760 out[
"reliable"] = r.reliable;
1761 out[
"family"] = r.family;
1762 if (r.hasFitted) out[
"exactFittedValue"] =
encode_scalar(r.exactFittedValue);
1773struct OpQsysMgisrgiWhitt {
1775 static Json run(Args& a) {
1776 const T lambda = a.number<T>(
"lambda");
1777 const T mu = a.number<T>(
"mu");
1778 const unsigned s = a.uinteger(
"s");
1779 const double r = a.number<
double>(
"r");
1780 const Json& pj = a.get(
"patience");
1781 if (pj.is_object() || pj.is_string())
1783 "qsys_mgisrgi_whitt: argument 'patience' cannot cross the JSON API boundary as a "
1784 "hazard or ccdf function handle; give the exponential rate theta as a number");
1785 const qsys::Patience<T> patience =
1787 qsys::MgisrgiOptions opt;
1788 if (a.has(
"wPoints")) opt.wPoints = a.vector<
double>(
"wPoints");
1789 opt.maxQueue = a.count(
"maxQueue", opt.maxQueue);
1790 opt.tol = a.scalar<
double>(
"tol", opt.tol);
1791 opt.invMethod = a.text(
"invMethod", opt.invMethod);
1792 opt.invN = a.count(
"invN", opt.invN);
1794 const qsys::QsysAbandonResult<T> res =
1797 out[
"queueLengthDist"] =
encode_vector(res.queueLengthDist);
1804 out[
"meanQueueLength"] =
encode_scalar(res.meanQueueLength);
1811 out[
"meanWaitAbandon"] =
encode_scalar(res.meanWaitAbandon);
1814 out[
"secondMomentWait"] =
encode_scalar(res.secondMomentWait);
1816 out[
"totalAbandonRates"] =
encode_vector(res.totalAbandonRates);
1817 out[
"numWaitingSpaces"] =
encode_count(res.numWaitingSpaces);
1818 out[
"exponentialPatience"] = res.exponentialPatience;
1829struct OpQsysMapmapc {
1831 static Json run(Args& a) {
1832 const mam::Map<T> arrival = read_map<T>(a,
"D0",
"D1");
1833 const mam::Map<T> service = read_map<T>(a,
"S0",
"S1");
1834 const unsigned c = a.uinteger(
"c");
1835 const std::size_t k = prefix_count(a, {
"maxNumComp",
"numWMoms"},
"qsys_mapmapc");
1836 const std::size_t dsz = k >= 1 ? a.count(
"maxNumComp") : 0;
1837 const std::size_t nw = k >= 2 ? a.count(
"numWMoms") : 0;
1839 const qsys::MapPhcResult<T> r =
1841 : (k == 1 ? qsys::
qsys_mapmapc<T>(arrival, service, c, dsz)
1842 : qsys::
qsys_mapmapc<T>(arrival, service, c, dsz, nw));
1849 out[
"waitingTimeMoments"] =
encode_vector(r.waitingTimeMoments);
1851 out[
"waitingTimePoints"] =
encode_vector(r.waitingTimePoints);
1863struct OpQsysMmapmap1 {
1865 static Json run(Args& a) {
1866 const std::vector<Matrix<T> > D = a.matrices<T>(
"D");
1867 const std::vector<mam::Map<T> > svc = maps_from_json<T>(a.get(
"svc"),
"qsys_mmapmap1: svc");
1868 const bool hasCarry = a.has(
"carry");
1869 const std::vector<int> ci = a.ints_or_empty(
"carry");
1872 throw InputError(
"qsys_mmapmap1: D must be {D0, D1_1, ..., D1_K} with K >= 1");
1876 mm.Dc.push_back(D[1]);
1877 for (std::size_t k = 2; k < D.size(); ++k) {
1878 if (D[k].rows() != mm.D1.rows() || D[k].cols() != mm.D1.cols())
1879 throw InputError(
"qsys_mmapmap1: the blocks of D must share one size");
1880 for (std::size_t i = 0; i < mm.D1.rows(); ++i)
1881 for (std::size_t j = 0; j < mm.D1.cols(); ++j)
1882 mm.D1(i, j) = T(mm.D1(i, j) + D[k](i, j));
1883 mm.Dc.push_back(D[k]);
1885 std::vector<bool> carry;
1886 for (std::size_t i = 0; i < ci.size(); ++i) {
1887 if (ci[i] != 0 && ci[i] != 1)
1888 throw InputError(
"qsys_mmapmap1: 'carry' holds flags, 0 or 1");
1889 carry.push_back(ci[i] != 0);
1897 Json cj = Json::array();
1898 for (std::size_t i = 0; i < r.carry.size(); ++i) cj.push_back(
static_cast<bool>(r.carry[i]));
1910struct OpSimQuestOptions {
1911 static Json run(Args& a) {
1912 sim::QuestOptions
in;
1913 const Json* oj = a.opt(
"options");
1915 Args o(*oj,
"sim_quest_options: options");
1916 in.b0 =
static_cast<long>(o.integer(
"b0",
static_cast<int>(
in.b0)));
1917 in.m0 =
static_cast<long>(o.integer(
"m0",
static_cast<int>(
in.m0)));
1919 const std::vector<int> s = o.ints(
"s");
1920 in.s.assign(s.begin(), s.end());
1922 in.beta = o.scalar<
double>(
"beta",
in.beta);
1923 in.eta = o.scalar<
double>(
"eta",
in.eta);
1924 in.theta = o.scalar<
double>(
"theta",
in.theta);
1925 in.weight = o.scalar<
double>(
"weight",
in.weight);
1926 in.force = o.boolean(
"force",
in.force);
1932 opt[
"b0"] =
static_cast<long long>(r.b0);
1933 opt[
"m0"] =
static_cast<long long>(r.m0);
1934 Json s = Json::array();
1935 for (std::size_t i = 0; i < r.s.size(); ++i) s.push_back(
static_cast<long long>(r.s[i]));
1937 opt[
"beta"] = r.beta;
1939 opt[
"theta"] = r.theta;
1940 opt[
"weight"] = r.weight;
1941 opt[
"force"] = r.force;
1948struct OpSimQuestHeuristicCi {
1950 static Json run(Args& a) {
1951 if constexpr (!num_traits<T>::has_transcendental) {
1953 "sim_quest_heuristic_ci",
"the interval is a quantile times a square root"));
1955 const std::vector<T> bqe = a.vector<T>(
"bqe");
1956 const T centre = a.number<T>(
"centre");
1957 const T Ap = a.number<T>(
"Ap");
1958 const T Np = a.number<T>(
"Np");
1959 const std::size_t nstar = a.count(
"nstar");
1960 const double alpha = a.number<
double>(
"alpha");
1961 const bool ac = required_flag(a,
"useAutocorr",
"sim_quest_heuristic_ci");
1963 const sim::QuestInterval<T> r =
1974struct OpSimRunlength {
1976 static Json run(Args& a) {
1977 if constexpr (!num_traits<T>::has_transcendental) {
1979 "sim_runlength",
"the run length is set by a normal quantile"));
1981 const T mean = a.number<T>(
"mean_");
1982 const T av = a.number<T>(
"asymVar");
1983 const std::size_t k =
1984 prefix_count(a, {
"relPrecision",
"confidence",
"runLength"},
"sim_runlength");
1985 const T rp = k >= 1 ? a.number<T>(
"relPrecision") : T();
1986 const T cf = k >= 2 ? a.number<T>(
"confidence") : T();
1987 const T rl = k >= 3 ? a.number<T>(
"runLength") : T();
1989 sim::RunLengthResult<T> r;
1995 out[
"requiredRunLength"] =
encode_scalar(r.requiredRunLength);
1999 out[
"achievedRelPrecision"] =
encode_scalar(r.achievedRelPrecision);
2013[[noreturn]]
void refuse_lst_handle(
const std::string& fn,
const char* key) {
2015 fn +
": argument '" + key +
"' cannot cross the JSON API boundary as an LST function "
2016 "handle; give it as a distribution record {\"type\": ..., ...}");
2021 static Json run(Args& a) {
2022 const double alpha = a.number<
double>(
"alpha");
2023 const double mu = a.number<
double>(
"mu");
2024 const unsigned c = a.uinteger(
"c");
2025 const unsigned K = a.uinteger(
"K");
2037struct OpQsysFcfsAlis {
2039 static Json run(Args& a) {
2040 const std::vector<T> lambda = a.vector<T>(
"lambda");
2041 const std::vector<T> mu = a.vector<T>(
"mu");
2042 const Matrix<T> cm = a.matrix<T>(
"compat");
2044 const T
zero = num_traits<T>::from_int(0);
2045 std::vector<std::vector<bool> > compat(cm.rows(), std::vector<bool>(cm.cols(),
false));
2046 for (std::size_t c = 0; c < cm.rows(); ++c)
2047 for (std::size_t m = 0; m < cm.cols(); ++m) compat[c][m] = cm(c, m) !=
zero;
2049 Json out = Json::object();
2055 out[
"stable"] = r.stable;
2061struct OpQsysEngset {
2062 static Json run(Args& a) {
2063 const double alpha = a.number<
double>(
"alpha");
2064 const double mu = a.number<
double>(
"mu");
2065 const unsigned c = a.uinteger(
"c");
2066 const unsigned K = a.uinteger(
"K");
2074 static Json run(Args& a) {
2075 const double alpha = a.number<
double>(
"alpha");
2076 const unsigned K = a.uinteger(
"K");
2077 if (a.get(
"svc").is_string()) refuse_lst_handle(
"qsys_mg1kk",
"svc");
2078 const lang::Distrib<double> svc = dist_record<double>(a.get(
"svc"),
"qsys_mg1kk: svc");
2080 if (a.has(
"ES")) (void)a.number<
double>(
"ES");
2089 static Json run(Args& a) {
2090 const T EO = a.number<T>(
"EO");
2091 const T ES = a.number<T>(
"ES");
2092 const unsigned c = a.uinteger(
"c");
2093 const unsigned K = a.uinteger(
"K");
2100struct OpQsysMg1Setup {
2102 static Json run(Args& a) {
2103 const T lambda = a.number<T>(
"lambda");
2104 const T mu = a.number<T>(
"mu");
2105 const T cs = a.number<T>(
"cs");
2106 qsys::Mg1SetupResult<T> r;
2107 if (a.get(
"EU").is_object()) {
2108 const lang::Distrib<T> U = dist_record<T>(a.get(
"EU"),
"qsys_mg1_setup: EU");
2112 const T EU = a.number<T>(
"EU");
2115 "qsys_mg1_setup: qsys_mg1_setup needs the second moment EU2 of the setup time "
2116 "after EU, or a setup Distribution in place of EU");
2117 const T EU2 = a.number<T>(
"EU2");
2132struct OpQsysMg1Exceptional {
2134 static Json run(Args& a) {
2135 const T lambda = a.number<T>(
"lambda");
2136 const T mu = a.number<T>(
"mu");
2137 const T cs = a.number<T>(
"cs");
2138 const T muf = a.number<T>(
"muf");
2139 const T csf = a.number<T>(
"csf");
2154 static Json run(Args& a) {
2155 const double lambda = a.number<
double>(
"lambda");
2156 const double mu = a.number<
double>(
"mu");
2157 const unsigned c = a.uinteger(
"c");
2165 static Json run(Args& a) {
2166 const double lambda = a.number<
double>(
"lambda");
2167 const double mu = a.number<
double>(
"mu");
2168 const unsigned c = a.uinteger(
"c");
2175struct OpQsysMg1PrioPr {
2177 static Json run(Args& a) {
2178 const std::vector<T> lambda = a.vector<T>(
"lambda");
2179 const std::vector<T> mu = a.vector<T>(
"mu");
2180 const std::vector<T> cs = a.vector<T>(
"cs");
2181 const std::vector<T> ES3 = a.vector_or_empty<T>(
"ES3");
2193struct OpQsysMmcPrio {
2195 static Json run(Args& a) {
2196 const std::vector<T> lambda = a.vector<T>(
"lambda");
2197 const T mu = a.number<T>(
"mu");
2198 const unsigned c = a.uinteger(
"c");
2210struct OpQsysMmcPrioTardiness {
2211 static Json run(Args& a) {
2212 const std::vector<double> lambda = a.vector<
double>(
"lambda");
2213 const double mu = a.number<
double>(
"mu");
2214 const unsigned c = a.uinteger(
"c");
2215 const std::vector<double> d = a.vector<
double>(
"d");
2216 const std::string type = a.text(
"type",
"np");
2217 const std::string method = a.text(
"method",
"euler");
2229struct OpQsysMmcPrioEta {
2230 static Json run(Args& a) {
2231 const std::vector<double> lambda = a.vector<
double>(
"lambda");
2232 const double mu = a.number<
double>(
"mu");
2233 const unsigned c = a.uinteger(
"c");
2234 const unsigned r = a.uinteger(
"r");
2235 const unsigned v = a.uinteger(
"v");
2236 const unsigned q = a.uinteger(
"q");
2237 const std::vector<double> d = a.vector<
double>(
"d");
2238 const std::string type = a.text(
"type",
"np");
2239 const std::string method = a.text(
"method",
"euler");
2257struct OpQsysMtmstmDets {
2258 static Json run(Args& a) {
2259 const double mu = a.number<
double>(
"mu");
2260 const double theta = a.number<
double>(
"theta");
2261 const int s0 = a.required_integer(
"s0");
2262 const std::vector<double> tk = a.vector_or_empty<
double>(
"tk");
2263 const Matrix<double> dm = a.matrix_or_empty<
double>(
"dsk");
2264 const int nq = a.required_integer(
"nq");
2265 const std::vector<double> tau = a.vector<
double>(
"tau");
2266 const std::string policy = a.text(
"policy",
"");
2267 const std::string wait = a.text(
"wait",
"pwt");
2269 const auto to_int = [](
double v) {
2270 if (!std::isfinite(v) || v != std::floor(v) || std::fabs(v) > 2147483647.0)
2271 throw InputError(ErrorKind{
"Argument"},
"qsys_mtmstm_dets: The staffing changes must be integers.");
2272 return static_cast<int>(v);
2274 const std::size_t K = tk.size();
2276 if (dm.rows() == K && dm.cols() == 2 && !((dm.rows() == 1 || dm.cols() == 1) && dm.rows() * dm.cols() == K)) {
2277 std::vector<std::array<int, 2> > pairs(K);
2278 for (std::size_t k = 0; k < K; ++k) pairs[k] = {{
to_int(dm(k, 0)),
to_int(dm(k, 1))}};
2281 std::vector<int> net;
2282 for (std::size_t i = 0; i < dm.rows(); ++i)
2283 for (std::size_t j = 0; j < dm.cols(); ++j) net.push_back(
to_int(dm(i, j)));
2288 info[
"meanPWT"] = std::isinf(r.meanPWT) ?
Json(
"Inf") :
Json(r.meanPWT);
2300struct OpQsysMg1Conservation {
2302 static Json run(Args& a) {
2303 const std::vector<T> lambda = a.vector<T>(
"lambda");
2304 const std::vector<T> mu = a.vector<T>(
"mu");
2305 const std::vector<T> cs = a.vector<T>(
"cs");
2306 const std::vector<T> W = a.vector_or_empty<T>(
"W");
2309 Json res = Json::object();
2322struct OpQsysMg1Sjf {
2323 static Json run(Args& a) {
2324 const std::vector<double> lambda = a.vector<
double>(
"lambda");
2325 const std::vector<double> mu = a.vector<
double>(
"mu");
2326 const std::vector<double> cs = a.vector<
double>(
"cs");
2331 out[
"rhohat"] = r.rhohat;
2338struct OpQsysMg1Busy {
2339 static Json run(Args& a) {
2340 const double lambda = a.number<
double>(
"lambda");
2341 const double mu = a.number<
double>(
"mu");
2342 const double cs = a.number<
double>(
"cs");
2343 qsys::Mg1BusyOptions o;
2344 if (a.has(
"ES3")) o.ES3 = a.number<
double>(
"ES3");
2346 if (a.get(
"lst").is_string()) refuse_lst_handle(
"qsys_mg1_busy",
"lst");
2347 const lang::Distrib<double> d = dist_record<double>(a.get(
"lst"),
"qsys_mg1_busy: lst");
2350 if (a.has(
"sPoints")) o.sPoints = a.vector<
double>(
"sPoints");
2358 static Json run(Args& a) {
2359 if (a.get(
"LA").is_string()) refuse_lst_handle(
"qsys_gimc",
"LA");
2360 const lang::Distrib<double> LA = dist_record<double>(a.get(
"LA"),
"qsys_gimc: LA");
2361 const double mu = a.number<
double>(
"mu");
2362 const unsigned c = a.uinteger(
"c");
2363 const double lambda = a.has(
"lambda") ? a.number<
double>(
"lambda") : -1.0;
2372 static Json run(Args& a) {
2373 const double lambda = a.number<
double>(
"lambda");
2374 const double mu = a.number<
double>(
"mu");
2375 const long nmax = a.has(
"nmax") ?
static_cast<long>(a.count(
"nmax")) : -1L;
2382Json encode_cplx_pairs(
const std::vector<std::complex<double> >& v) {
2383 Json out = Json::array();
2384 for (
const std::complex<double>& z : v) out.push_back(Json::array({
z.real(),
z.imag()}));
2390 static Json run(Args& a) {
2391 const double lambda = a.number<
double>(
"lambda");
2392 const double mu = a.number<
double>(
"mu");
2393 const unsigned r = a.uinteger(
"r");
2399 out[
"roots"] = encode_cplx_pairs(m.roots);
2400 out[
"coeffs"] = encode_cplx_pairs(m.coeffs);
2407 static Json run(Args& a) {
2408 const double lambda = a.number<
double>(
"lambda");
2409 const double p1 = a.number<
double>(
"p1");
2410 const double mu1 = a.number<
double>(
"mu1");
2411 const double mu2 = a.number<
double>(
"mu2");
2419struct OpQsysMm1Transient {
2420 static Json run(Args& a) {
2421 const double lambda = a.number<
double>(
"lambda");
2422 const double mu = a.number<
double>(
"mu");
2423 const double n0 = a.number<
double>(
"n0");
2424 const std::vector<double> t = a.vector<
double>(
"t");
2425 const double nmax = a.has(
"nmax") ? a.number<
double>(
"nmax") : std::numeric_limits<double>::quiet_NaN();
2426 const double tol = a.has(
"tol") ? a.number<
double>(
"tol") : 1e-14;
2427 const std::string method = a.text(
"method",
"auto");
2432 res[
"nmax"] = r.nmax;
2434 res[
"method"] = r.method;
2439 Json win = Json::array();
2440 for (std::size_t i = 0; i < r.window.rows(); ++i) {
2441 Json row = Json::array();
2442 for (std::size_t k = 0; k < r.window.cols(); ++k)
2443 row.push_back(std::isnan(r.window(i, k)) ?
Json(
"NaN") :
Json(r.window(i, k)));
2446 res[
"window"] = win;
2457struct OpQsysMm1kTransient {
2458 static Json run(Args& a) {
2459 const double lambda = a.number<
double>(
"lambda");
2460 const double mu = a.number<
double>(
"mu");
2461 const double K = a.number<
double>(
"K");
2462 const double n0 = a.number<
double>(
"n0");
2463 const std::vector<double> t = a.vector<
double>(
"t");
2464 const double tol = a.has(
"tol") ? a.number<
double>(
"tol") : 1e-14;
2465 const std::string method = a.text(
"method",
"auto");
2470 res[
"method"] = r.method;
2471 res[
"kappa"] = r.kappa;
2489struct OpQsysMatchFcfm {
2490 static Json finite_or_text(
double v) {
2491 if (std::isnan(v))
return Json(
"NaN");
2492 if (std::isinf(v))
return Json(v > 0 ?
"Inf" :
"-Inf");
2495 static Json vec(
const std::vector<double>& v) {
2496 Json a = Json::array();
2497 for (
double x : v) a.push_back(finite_or_text(x));
2500 static Json mat(
const std::vector<std::vector<double> >& m) {
2501 Json a = Json::array();
2502 for (
const auto& row : m) a.push_back(vec(row));
2505 static Json run(Args& a) {
2506 const std::vector<double> lambda = a.vector<
double>(
"lambda");
2507 const Matrix<double>
Gm = a.matrix<
double>(
"G");
2508 const double K = a.has(
"K") ? a.number<
double>(
"K") : std::numeric_limits<double>::infinity();
2510 std::vector<std::vector<double> > G(
Gm.rows(), std::vector<double>(
Gm.cols(), 0.0));
2511 for (std::size_t i = 0; i <
Gm.rows(); ++i)
2512 for (std::size_t j = 0; j <
Gm.cols(); ++j) G[i][j] =
Gm(i, j);
2514 Json res = Json::object();
2515 res[
"Q"] = vec(r.Q);
2516 res[
"W"] = vec(r.W);
2517 res[
"X"] = vec(r.X);
2518 res[
"omega"] = vec(r.omega);
2519 res[
"pblock"] = vec(r.pblock);
2520 res[
"pmatch"] = mat(r.pmatch);
2521 res[
"rmatch"] = mat(r.rmatch);
2522 res[
"P0"] = finite_or_text(r.P0);
2523 res[
"Z"] = finite_or_text(r.Z);
2524 res[
"piSet"] = vec(r.piSet);
2525 res[
"stable"] = r.stable;
2526 res[
"analyzer"] =
"qsys_match_fcfm";
2528 out[
"result"] = res;
2664 "its order-independent service rate mu is a callable of the per-class count vector "
2665 "(std::function), which has no JSON representation.";
2667 "its interarrival law IaFun is a function handle (a CDF or transform evaluated by the "
2668 "port), and the port offers no constructor that builds it from a named law.";
2669 t[
"qsys_mg1k_loss"] =
2670 "its service law svc_density is a density function handle the port integrates, and the "
2671 "port takes no named-law form for it.";
2672 t[
"qsys_ggingi_tga"] =
2673 "its patience law (patienceCcdf, patiencePdf) and service law (serviceCcdf) are function "
2674 "handles the port integrates, with no named-law form.";
2675 t[
"qsys_ggisgi_fluid"] =
2676 "its patience and service laws (patienceCcdf, servingCcdf) are function handles the port "
2677 "integrates, with no named-law form.";
2678 t[
"qsys_gtmtst_fluid"] =
2679 "its time-varying arrival rate, staffing and service rate (lambdaFun, sFun, muFun) and "
2680 "its patience law (patienceCcdf) are function handles of time.";
2682 "its time-varying arrival rate lambdaFun is a function handle of time and its service law "
2683 "serviceCcdf a function handle, with no named-law form.";
2684 t[
"qsys_mtgs0_mol"] =
2685 "its time-varying arrival rate lambdaFun is a function handle of time and its service law "
2686 "serviceCcdf a function handle, with no named-law form.";
2687 t[
"fj_order_stat"] =
2688 "its branch law F_X is a CDF function handle the port evaluates, with no named-law form.";
2689 t[
"fj_xmax_hz_het"] =
2690 "its branch laws are a list of CDF function handles the port integrates, with no "
MAP to PH conversion for the age-of-information solvers.
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).
Internal to the –api dispatcher: what a per-domain translation unit needs to add entries to the table...
#define LINE_MOMENT_TENSOR_OP(OPNAME, FN, IN, OUT)
#define LINE_MOMENT_VEC_OP(OPNAME, FN, IN, OUT)
UnsupportedError(const std::string &what)
Named-argument reader over the parsed JSON object.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
Mean value analysis of a closed network of fork-join subnetworks.
Activities belonging to each branch of an AND-join.
Blom-corrected plotting position for the characteristic maximum.
Characteristic maximum of a lattice random variable.
Two-stage Coxian fit of a mean and a squared coefficient of variation.
Makespan of a task system with precedence constraints.
Deterministic subtask delays that minimise mean dispersion.
Mean subtask dispersion of a split-merge system with Erlang branches.
Conversion of a LINE MAP into the arrival or service descriptor of the fork-join response-time-tail a...
Green's independent server model of simultaneous server requests.
Laplace-Stieltjes transform of the maximum of heterogeneous exponentials.
Mean and variance of the M/G/1 response time, as ForkTail inputs.
Geometric bound on the queue length of a fork-join subnetwork.
Centralized splitting analysed as an M[K]/M/c bulk arrival system.
Varki bound on the residence time of a closed fork-join subnetwork.
Mean response time of the distributed no-splitting parallel system.
Blocking probability and pseudoserver delay of serialization phases.
ForkTail black-box tail-latency approximation for fork-join requests.
Tail latency of a k-of-n (QUORUM) fork-join request.
Saturation throughput of the team service model.
Expected maximum of K i.i.d.
Exact moments of the maximum of heterogeneous exponentials.
Harrison-Zertal approximation of the maximum of i.i.d.
Moments of the maximum of heterogeneous exponentials by recurrence.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Cumulants from raw moments and the inverse, plus the factorial-cumulant pair.
Conversion matrix of one edge of the house of moments.
Joint moment conversions on the house of moments.
Binomial moments from tail moments and the inverse.
Joint moment arrays and the mode products used by every joint conversion.
std::function< T(const T &)> Lst
A Laplace-Stieltjes transform evaluated at real arguments.
Lst< T > aoi_lst_exp(const T &mu)
Laplace-Stieltjes transform of an exponential distribution.
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).
AoiPh< T > aoi_dist2ph(const Matrix< T > &D0, const Matrix< T > &D1)
Convert a MAP (D0, D1) into the PH pair (alpha, T).
Lst< T > aoi_lst_det(const T &d)
Laplace-Stieltjes transform of a deterministic (constant) distribution.
std::string nm(const char *tag, std::size_t i, std::size_t r)
std::vector< T > fj_xmax_moments_het(const std::vector< T > &lambda, unsigned n=1)
Moments of the maximum of heterogeneous exponentials by recurrence.
FjDistKind
Which of the two descriptors to build.
FJCharMaxBlomResult< T > fj_char_max_blom(unsigned K, const std::function< T(const T &)> &Finv=std::function< T(const T &)>(), const T &alpha=num_traits< T >::from_double(0.4886), const T &beta=num_traits< T >::from_double(0.3140))
Blom-corrected plotting position for the characteristic maximum.
T fj_lst_max_het(const std::vector< T > &lambda, const T &s)
Laplace-Stieltjes transform of the maximum of heterogeneous exponentials.
FJIsmGreenResult< T > fj_ism_green(const T &lambda, const T &mu, unsigned s, const std::vector< T > &c)
Green's independent server model of simultaneous server requests.
FJDelayOptResult< T > fj_delay_opt(const std::vector< unsigned > &shape, const std::vector< T > &rate, unsigned maxsweeps=40, const T &dtol=num_traits< T >::from_double(1e-8), unsigned npanels=2000)
Deterministic subtask delays that minimise mean dispersion.
FJXmaxCoxianResult< T > fj_xmax_coxian(unsigned K, const T &mu1, const T &mu2, const T &q)
Expected maximum of K i.i.d.
std::vector< std::vector< std::size_t > > fj_branch_members(const LqnBranchView< T > &lqn, std::size_t joinaidx)
Branch membership of an AND-join.
FJDagMakespanResult< T > fj_dag_makespan(const Matrix< T > &pred, const Matrix< T > &rate)
Makespan of a task system with precedence constraints.
FJResptNosplitResult< T > fj_respt_nosplit(unsigned K, const T &lambda, const T &mu)
Mean response time of the distributed no-splitting parallel system.
FJTsmCapacityResult< T > fj_tsm_capacity(unsigned s, const std::vector< T > &f, const std::vector< unsigned > &r, const std::vector< T > &x)
Saturation throughput of the team service model.
T fj_xmax_het(const std::vector< T > &lambda, unsigned n=1)
Exact moments of the maximum of heterogeneous exponentials.
FJCharMaxDiscreteResult< T > fj_char_max_discrete(unsigned K, FJDiscreteDist dist, const T &par)
Characteristic maximum of a lattice random variable.
FJSerializationResult< T > fj_serialization(const std::vector< T > &Rs, const T &R0, unsigned M, const T &alpha=num_traits< T >::from_double(0.5))
Blocking probability and pseudoserver delay of serialization phases.
Mg1ResptMoments< T > fj_mg1_respt_moments(const T &lambda, const T &ES, const T &ES2, const T &ES3)
Mean and variance of the M/G/1 response time, as ForkTail inputs.
FjDist< T > fj_dist2fj(const mam::Map< T > &m, FjDistKind kind, FjProcType procType)
Build the fork-join descriptor of a MAP.
ForkTailResult< T > fj_tail_forktail(const std::vector< T > &ET, const std::vector< T > &VT, const std::vector< T > &K=std::vector< T >(), const T &p_in=num_traits< T >::from_int(99), const std::vector< T > &P=std::vector< T >())
ForkTail black-box tail-latency approximation for fork-join requests.
FJResptClosedResult< T > fj_respt_closed(unsigned K, const T &x, unsigned M, const T &A)
Varki bound on the residence time of a closed fork-join subnetwork.
FJQgbResult< T > fj_qgb(const std::vector< T > &D, const std::vector< unsigned > &P, unsigned M, const T &Z)
Geometric bound on the queue length of a fork-join subnetwork.
FJXmaxHzResult< T > fj_xmax_hz(const T &m1, const T &m2, unsigned K)
Harrison-Zertal approximation of the maximum of i.i.d.
ForkTailResult< T > fj_tail_ordstat(const std::vector< T > &ET, const std::vector< T > &VT, std::size_t K=1, const T &p_in=num_traits< T >::from_int(99), std::size_t kreq=0)
Tail latency of a k-of-n (QUORUM) fork-join request.
FJAmvaResult< T > fj_amva(const std::vector< T > &D, const std::vector< unsigned > &P, unsigned M, const T &Z)
Mean value analysis of a closed network of fork-join subnetworks.
FJCoxFitResult< T > fj_cox_fit(const T &m1, const T &c2)
Two-stage Coxian fit of a mean and a squared coefficient of variation.
FJDispersionResult< T > fj_dispersion(const std::vector< unsigned > &shape, const std::vector< T > &rate, const std::vector< T > &d, const T &tol=num_traits< T >::from_double(1e-10), unsigned npanels=4000)
Mean subtask dispersion of a split-merge system with Erlang branches.
FjProcType
The subset of ProcessType that the fork-join algorithm accepts.
FJResptBulkResult< T > fj_respt_bulk(unsigned K, const T &lambda, const T &mu, unsigned c, std::size_t nmax=0)
Centralized splitting analysed as an M[K]/M/c bulk arrival system.
FJDiscreteDist
The lattice laws for which the characteristic maximum is closed.
long to_int(const std::string &s)
Python int(token): an optionally signed run of decimal digits.
T dist_lst(const Distrib< T > &d, const T &s)
sn.lst: the Laplace-Stieltjes transform E[exp(-sX)].
T dist_cdf(const Distrib< T > &d, const T &x)
F(x) = P{X <= x}, MATLAB's Distribution.evalCDF.
T dist_moment(const Distrib< T > &d, unsigned k)
The k-th raw moment.
bool in(const std::string &s, std::initializer_list< const char * > set)
std::vector< T > moment_joint_aggregate(const MomentTensor< T > &F)
Factorial moments of a total count from the joint factorial moments of its parts.
MomentTensor< T > moment_joint_marking(const std::vector< T > &f, const std::vector< T > &p, const std::vector< std::size_t > &dims)
Joint factorial moments of a multinomially marked count from the aggregate ones.
std::vector< std::size_t > moment_tensorsize(const MomentTensor< T > &A)
Extents with the trailing singleton dimensions removed.
Matrix< T > moment_housematrix(MomentEdge edge, int n)
(n+1)x(n+1) conversion table of the given edge.
MomentTensor< T > moment_tensortrans(const MomentTensor< T > &A, const Matrix< T > &Tm, std::size_t mode)
Mode product: every fibre of A along dimension mode is replaced by Tm times that fibre.
MomentTensor< T > moment_joint_central_from_raw_mean(const MomentTensor< T > &m, const std::vector< T > &mu)
Joint central moments from joint raw moments about a given mean vector.
MomentTensor< T > moment_jointtrans(const MomentTensor< T > &A, MomentEdge edge)
Applies the conversion matrix of one edge along every dimension of A.
MomentTensor< T > moment_joint_raw_from_central(const MomentTensor< T > &mc, const std::vector< T > &mu)
Joint raw moments from joint central moments about a given mean vector.
@ Gm
the reference's alias of 'cub'
Mg1ConservationResult< T > qsys_mg1_conservation(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs, const std::vector< T > &W=std::vector< T >())
The M/G/1 conservation-law invariant.
MaximaResult< T > qsys_maxima_twomoment(std::size_t n, const T &mean, const T &cs2, const T &q=num_traits< T >::from_int(0), bool exactFitted=true)
Two-moment approximation for the maximum of n iid non-negative variables.
MapG1kResult< T > qsys_mapg1k(const mam::Map< T > &arrival, const ServiceLaw< T > &svc, std::size_t K, const T &tol, std::size_t nmaxCap)
MAP/G/1/K with tail drop.
QsysRes qsys_gimc(const std::function< double(double)> &lst, double lambda, double mu, unsigned c, const QsysResOptions &o=QsysResOptions())
LindleyResult< T > qsys_hh1_lindley(const std::vector< T > &lambda, const std::vector< T > &pa, const std::vector< T > &mu, const std::vector< T > &ps, const std::vector< T > &Wn, unsigned mmax=2)
Conditional waiting-time moments of the Hl/Hn/1 Lindley recursion.
Mer1Result qsys_mer1(double lambda, double mu, unsigned r, const QsysResOptions &o=QsysResOptions())
Exact M/Er/1 queue.
LdpsWorkloadResult< T > qsys_ldps_workload(const T &lambda, const WorkloadServiceLaw< T > &B, const std::vector< T > &alpha, std::size_t N, const std::vector< T > &t, std::size_t ngrid)
Workload distribution of the load-dependent PS station with blocking.
MapPhcResult< T > qsys_mapmapc(const mam::Map< T > &arrival, const mam::Map< T > &service, unsigned c, std::size_t dist_size=500, std::size_t num_w_moms=3)
MAP/MAP/c FCFS with the service phase carried in start order, exactly.
FcfsAlisResult< T > qsys_fcfs_alis(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< std::vector< bool > > &compat)
Exact means of the isolated FCFS-ALIS pool.
Mg1SjfResult qsys_mg1_sjf(const std::vector< double > &lambda, const std::vector< double > &mu, const std::vector< double > &cs)
M/G/1 non-preemptive SJF.
Mm1TandemLindleyResult< T > qsys_mm1_tandem_lindley(const T &lambda, const T &mu1, const T &mu2, const std::vector< T > &Wk, const std::vector< T > &Wk1)
Conditional waiting time at the SECOND station of an M/M/1 -> /M/1 tandem.
Mm1PsResult< T > qsys_mm1_ps(const std::vector< T > &lambda, const std::vector< T > &mu)
Exact sojourn-time moments of the multiclass M/M/1-PS queue.
Mg1ExceptionalResult< T > qsys_mg1_exceptional(const T &lambda, const T &mu, const T &cs, const T &muf, const T &csf)
M/G/1 with exceptional first service.
MmapGk1Result< T > qsys_mmapgk1(const std::vector< Matrix< T > > &MMAP, const std::vector< MmapGk1Service< T > > &svc, const std::vector< T > &w_points, std::size_t num_w_moms, double tol, std::size_t iter_max, std::size_t quad_nodes)
MMAP[K]/G[K]/1 FCFS, per type.
SvclawCoeffsResult< T > qsys_svclaw_coeffs(const ServiceLaw< T > &svc, const T &theta, const T &tol, std::size_t nmaxCap)
qsys_svclaw_coeffs: uniformization coefficients of a service-time descriptor; see qsys_svclaw_coeffs....
Mm1TransientResult qsys_mm1_transient(double lambda, double mu, double n0, const std::vector< double > &t, double nmax=std::numeric_limits< double >::quiet_NaN(), double tol=1e-14, const std::string &method_in="auto")
Transient distribution of the M/M/1 queue (Rubino 2020).
MmcPrioTardinessResult qsys_mmc_prio_tardiness(const std::vector< double > &lambda, double mu, unsigned c, const std::vector< double > &d, const std::string &type="np", const std::string &method="euler")
Stationary per-class expected tardiness of a priority M/M/c queue.
MmcPrioResult< T > qsys_mmc_prio(const std::vector< T > &lambda, const T &mu, unsigned c)
M/M/c with head-of-line priorities.
DetsResult qsys_mtmstm_dets(double mu, double theta, int s0, const std::vector< double > &tk, const std::vector< int > &dsk, int nq, const std::vector< double > &tau, const std::string &policy, const std::string &wait="pwt")
DETS waiting-time CCDF with the staffing changes given as net signed changes.
QsysRes qsys_mmckk(double alpha, double mu, unsigned c, unsigned K, const QsysResOptions &o=QsysResOptions())
Exact M/M/c/K/K finite-source queue.
QsysAbandonResult< T > qsys_mgisrgi_whitt(const T &lambda, const T &mu, unsigned s, double r, const Patience< T > &patience, const MgisrgiOptions &opts=MgisrgiOptions())
Engineering solution of the call-center model M/GI/s/r+GI.
MatchFcfmResult qsys_match_fcfm(const std::vector< double > &lam, const std::vector< std::vector< double > > &Gm, double Kcap=std::numeric_limits< double >::infinity())
Exact FCFM matching model.
QsysRes qsys_mh21(double lambda, double p1, double mu1, double mu2, const QsysResOptions &o=QsysResOptions())
Exact M/H2/1 queue.
TandemLindleyResult< T > qsys_tandem_lindley(const std::vector< T > &A, const Matrix< T > &S, const std::vector< T > &W0=std::vector< T >())
Sample-path Lindley recursion along a tandem of single-server FCFS queues.
QsysResT< T > qsys_ddckk(const T &EO, const T &ES, unsigned c, unsigned K)
Exact D/D/c/K/K finite-source queue.
LindleyResult< T > qsys_mm1_lindley(const T &lambda, const T &mu, const std::vector< T > &Wn, unsigned mmax=2)
Conditional waiting-time moments of the M/M/1 Lindley recursion.
Mg1SetupResult< T > qsys_mg1_setup(const T &lambda, const T &mu, const T &cs, const T &EU, const T &EU2)
M/G/1 with setup times, setup given by its first two moments.
BmapM1Result< T > qsys_bmapm1(const std::vector< Matrix< T > > &D, const T &mu, const T &qParam, std::size_t maxLevelParam, unsigned maxIter, const T &tol, double tailTol)
BMAP/M/1 by the matrix-analytic (M/G/1-type) method.
TandemUbResult< T > qsys_tandem_ub_ciucu(const std::vector< T > &x, const std::function< T(const T &)> &lst, const std::vector< T > &p, const std::vector< T > &mu, const std::function< T(const T &)> &dlst=std::function< T(const T &)>())
Tail bounds for a GI/Hn/1 -> .
MmapMap1Result< T > qsys_mmapmap1(const mam::Mmap< T > &arrival, const std::vector< mam::Map< T > > &svc, std::vector< bool > carry=std::vector< bool >())
MMAP[K]/MAP[K]/1 FCFS with per-class carried service phases, exactly.
QsysRes qsys_engset(double alpha, double mu, unsigned c, unsigned K)
Exact Engset M/G/c/c/K loss system.
QsysRes qsys_mmcc(double lambda, double mu, unsigned c)
Exact M/M/c/c Erlang loss system.
Mg1PsResult qsys_mg1_ps(double lambda, const std::vector< double > &alpha, const Matrix< double > &Tmat, const Mg1PsOptions &opt)
Sojourn-time distribution of the M/G/1 processor-sharing queue.
QsysRes qsys_mg1_busy(double lambda, double mu, double cs, const Mg1BusyOptions &o=Mg1BusyOptions())
Busy-period measures of the M/G/1 queue.
QsysRes qsys_mgc_ps(double lambda, double mu, unsigned c)
Exact M/G/c-PS queue.
Mg1PrioPrResult< T > qsys_mg1_prio_pr(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs, const std::vector< T > &ES3=std::vector< T >())
M/G/1 with preemptive-resume priorities.
MmapG1kResult< T > qsys_mmapg1k(const Matrix< T > &D0, const std::vector< Matrix< T > > &D1c, const ServiceLaw< T > &svc, std::size_t K, const T &tol, std::size_t nmaxCap)
MMAP[K]/G/1/K with tail drop.
Mm1kTransientResult qsys_mm1k_transient(double lambda, double mu, double K, double n0, const std::vector< double > &t, double tol=1e-14, const std::string &method_in="auto")
Transient distribution of the M/M/1/K queue (Takacs; Rubino 2020).
MmapGk1LcfsprResult< T > qsys_mmapgk1_lcfspr(const std::vector< Matrix< T > > &MMAP, const std::vector< MmapGk1Service< T > > &svc, const MmapGk1LcfsprOptions< T > &opt)
MMAP[K]/G[K]/1 LCFS-PR, per type, by Takine's matrix product form.
MapG1kPerflowResult< T > qsys_mapg1k_perflow(const std::vector< mam::Map< T > > &flows, const ServiceLaw< T > &svc, std::size_t K, const T &tol, std::size_t nmaxCap)
Per-flow analysis of a MAP-fed tail-drop buffer.
QsysRes qsys_md1(double lambda, double mu, long nmax=-1)
Exact M/D/1 queue.
std::vector< T > qsys_lindley_moment(const T &lambda, const T &mu, const std::vector< T > &Wn, unsigned m)
One conditional Lindley moment for exponential primitives.
MmcPrioEtaResult qsys_mmc_prio_eta(const std::vector< double > &lambda, double mu, unsigned c, unsigned r, unsigned v, unsigned q, const std::vector< double > &d, const std::string &type="np", const std::string &method="euler")
Expected tardiness at arrival of a class-r order.
QsysRes qsys_mg1kk(double alpha, unsigned K, const std::function< double(double)> &lst, double ES, bool means_only=false)
Exact M/G/1/K/K finite-source queue, service given by its LST.
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,...
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_qsys(DispatchTable &t)
qsys::QsysResOptions read_qsys_res_options(Args &a, bool with_nmax=true)
The 'tPoints', 'percentiles' and 'nmax' options those functions share.
T number_from_json(const Json &j, const std::string &where)
Json encode_vector(const std::vector< T > &v)
Json encode_matrix(const Matrix< T > &m)
void register_library_only_qsys(LibraryOnlyTable &t)
Json encode_scalar(const T &v)
Json encode_count(std::size_t n)
A count.
std::map< std::string, std::string > LibraryOnlyTable
name -> why the function has no named-JSON-argument form.
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...
Json encode_ints(const std::vector< int > &v)
std::map< std::string, Invoker > DispatchTable
QuestOptions sim_quest_options(const QuestOptions &options=QuestOptions())
Validates an option set and returns it.
QuestInterval< T > sim_quest_heuristic_ci(const std::vector< T > &bqe, const T ¢re, const T &Ap, const T &Np, std::size_t nstar, double alpha, bool useAutocorr)
Fallback interval used when a QUEST stage test fails.
RunLengthResult< T > sim_runlength(const T &mean, const T &asymVar, const T &relPrecision=num_traits< T >::from_rational(1, 20), const T &confidence=num_traits< T >::from_rational(19, 20), const T &runLength=num_traits< T >::from_int(0))
Run length for a steady-state estimate of a given relative precision.
Conservation laws of a layered queueing network, enumerated from its structure.
Reader for the LINE model.json interchange (a Network model) into a qn::Network<T> built through the ...
BMAP/M/1 by the matrix-analytic (M/G/1-type) method.
Exact analysis of the finite-source D/D/c/K/K machine-repair model.
Exact analysis of the Engset loss system M/G/c/c/K: K sources, each idle for an Exp(alpha) time,...
Exact steady-state means of an isolated FCFS parallel-server system with job-server compatibilities u...
Exact analysis of the GI/M/c queue (Takacs, 1962).
Conditional waiting-time moments of the Hl/Hn/1 Lindley recursion.
Stationary distribution of the unfinished work in a single-stage load-dependent generalized-processor...
One conditional Lindley moment for exponential primitives.
The MAP/G/1/K queue with tail drop: Markovian arrivals, an arbitrary service law F,...
Per-flow throughput and loss ratio of a tail-drop FIFO buffer fed by N flows of mutually different st...
The MAP/MAP/c FCFS queue whose service MAP is CARRIED in service-start order.
Exact analysis of the first-come-first-matched (FCFM) stochastic matching model (Comte 2022).
Two-moment approximation for the maximum of n iid non-negative variables.
Exact analysis of the M/D/1 queue: the M/G/1 moments with deterministic service plus the queue-length...
Exact analysis of the M/Er/1 queue (Erlang-r service of total rate mu/r per phase-sum,...
Busy-period measures of the M/G/1 queue.
Kleinrock's conservation law for work-conserving non-preemptive M/G/1 disciplines.
M/G/1 with exceptional first service: the job that starts a busy period has service law Bf,...
M/G/1 with preemptive-resume priorities: per-class mean (and optionally variance of the) response tim...
Sojourn-time distribution of the M/G/1 processor-sharing queue.
M/G/1 with setup times: the server switches off when empty and needs a setup time U before serving th...
M/G/1 with non-preemptive shortest-job-first scheduling: per-class mean response times.
Exact analysis of the finite-source M/G/1/K/K (machine-repair) queue.
Exact analysis of the M/G/c processor-sharing queue.
Engineering solution of the call-center model M/GI/s/r+GI.
Exact analysis of the M/H2/1 queue: hyperexponential service with branch probabilities (p1,...
Conditional waiting-time moments of the M/M/1 Lindley recursion.
Exact sojourn-time moments of the multiclass M/M/1-PS queue.
Conditional waiting time at the SECOND station of an M/M/1 -> /M/1 tandem.
Transient queue-length distribution of the M/M/1 queue.
Transient queue-length distribution of the M/M/1/K queue.
Exact per-class throughput and loss ratio of an MMAP[K]/G/1/K tail-drop queue.
The MMAP[K]/G[K]/1 FCFS queue: K customer types with class-dependent GENERAL service,...
The MMAP[K]/G[K]/1 LCFS-PR queue: K customer types with class-dependent GENERAL service under preempt...
The MMAP[K]/MAP[K]/1 FCFS queue in which each class's service phase is CARRIED.
M/M/c with non-preemptive (head-of-line) priorities and a common exponential service rate (Cobham,...
Expected tardiness at arrival (ETA) in a multiclass priority M/M/c queue, conditional on the state th...
Exact stationary expected tardiness in a multiclass priority M/M/c queue (Hafizoglu,...
Exact analysis of the M/M/c/c (Erlang loss) system.
Exact analysis of the finite-source M/M/c/K/K (machine-repair) queue.
DETS, the delay estimator under time-varying staffing of Konrad and Liu (WSC 2023): waiting-time dist...
Sample-path Lindley recursion along a tandem of single-server FCFS queues.
Tail bounds for a GI/Hn/1 -> .
Fallback interval used when a QUEST stage test fails.
Options of the QUEST procedures, with the published FQUEST defaults.
Run-length planning for steady-state simulation.
static Patience exponential(const T &theta)
Exponential patience of rate theta, h(t) = theta, the Erlang A case.
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).