LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
api_dispatch_mc.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 *
5 * --api dispatch entries for the 'mc' group (see api_dispatch_detail.h): the
6 * Markov-chain functions not already in api_dispatch.cpp, the npfqn traffic and
7 * bound functions, the discrete-time cycle constants dpfqn_nc / dpfqn_ncld and
8 * the stochastic network calculus envelopes snc_*.
9 *
10 * CONVENTIONS, shared with the mc entries of api_dispatch.cpp:
11 * - a state, station or stage INDEX is 0-based on the way in and is reported
12 * unchanged on the way out (an index is not a measurement). The one
13 * exception is npfqn_sqd's stationToStateful, which the port documents as
14 * ONE-based because it is sn.stationToStateful copied verbatim;
15 * - a MATLAB struct output (ctx, info, aux, result, out) is a nested object
16 * keyed by the MATLAB field names;
17 * - an MMAP is the MATLAB cell {D0, D1, D1^(1), ..., D1^(R)} as a list of
18 * matrices, and a list of MMAPs is a list of such lists;
19 * - a complex number is a pair [re, im]; a plain number is read as real.
20 *
21 * WHERE MATLAB TAKES AN sn. npfqn_nonexp_approx and npfqn_sqd take `sn` in
22 * MATLAB, but their ports take the handful of arrays the reference unpacks
23 * from it as their first act (see the headers). Those arrays are plain data,
24 * so the entries read them under the PORT's parameter names and refuse `sn`.
25 */
26
27#include "api_dispatch_detail.h"
28
29#include <cmath>
30#include <complex>
31#include <cstdint>
32#include <cstdlib>
33#include <string>
34#include <vector>
35
73
74namespace line {
75namespace reg {
76namespace {
77
78// ---------------------------------------------------------------------------
79// Shared readers and encoders
80// ---------------------------------------------------------------------------
81
82/** One non-negative index from a JSON number or numeric string. */
83std::size_t index_from_json(const Json& j, const std::string& where) {
84 const std::string text = decimal_text(j, where);
85 char* end = nullptr;
86 const long long v = std::strtoll(text.c_str(), &end, 10);
87 if (end == text.c_str() || *end != '\0')
88 throw InputError(where + ": an index must be an integer, got " + text);
89 if (v < 0) throw InputError(where + ": an index cannot be negative, got " + text);
90 return static_cast<std::size_t>(v);
91}
92
93/** A flat list of 0-based indices; a bare number is a one-element list. */
94std::vector<std::size_t> indices_from_json(const Json& j, const std::string& where) {
95 std::vector<std::size_t> out;
96 if (!j.is_array()) {
97 out.push_back(index_from_json(j, where));
98 return out;
99 }
100 for (std::size_t k = 0; k < j.size(); ++k)
101 out.push_back(index_from_json(j[k], where + "[" + std::to_string(k) + "]"));
102 return out;
103}
104
105std::vector<std::size_t> read_indices(Args& a, const char* key) {
106 return indices_from_json(a.get(key), a.get(key).is_null() ? key : std::string(key));
107}
108
109/** A list of index lists (sigma of npfqn_bnd_bgt). */
110std::vector<std::vector<std::size_t> > read_index_lists(Args& a, const char* key) {
111 const Json& j = a.get(key);
112 const std::string where = std::string(key);
113 if (!j.is_array()) throw InputError(where + ": expected a list of index lists");
114 std::vector<std::vector<std::size_t> > out;
115 for (std::size_t b = 0; b < j.size(); ++b)
116 out.push_back(indices_from_json(j[b], where + "[" + std::to_string(b) + "]"));
117 return out;
118}
119
120Json encode_indices(const std::vector<std::size_t>& v) {
121 Json a = Json::array();
122 for (std::size_t i = 0; i < v.size(); ++i) a.push_back(static_cast<std::uint64_t>(v[i]));
123 return a;
124}
125
126/** A per-station flag vector: an array of booleans or of 0/1. */
127std::vector<bool> read_flags(Args& a, const char* key) {
128 const Json& j = a.get(key);
129 const std::string where = std::string(key);
130 std::vector<bool> out;
131 const Json flat = j.is_array() ? j : Json::array({j});
132 for (std::size_t k = 0; k < flat.size(); ++k) {
133 const Json& e = flat[k];
134 if (e.is_boolean()) {
135 out.push_back(e.get<bool>());
136 } else {
137 const std::string text = decimal_text(e, where);
138 if (text != "0" && text != "1")
139 throw InputError(where + ": a flag must be true, false, 0 or 1, got " + text);
140 out.push_back(text == "1");
141 }
142 }
143 return out;
144}
145
146/** A list of numeric vectors (mu of npfqn_bnd_bgt). */
147template <class T>
148std::vector<std::vector<T> > read_vector_list(Args& a, const char* key) {
149 const Json& j = a.get(key);
150 const std::string where = std::string(key);
151 if (!j.is_array()) throw InputError(where + ": expected a list of vectors");
152 std::vector<std::vector<T> > out;
153 for (std::size_t i = 0; i < j.size(); ++i)
154 out.push_back(vector_from_json<T>(j[i], where + "[" + std::to_string(i) + "]"));
155 return out;
156}
157
158/** A matrix as the list of its rows (P of dpfqn_ncld, J x N). */
159template <class T>
160std::vector<std::vector<T> > rows_of(const Matrix<T>& m) {
161 std::vector<std::vector<T> > out(m.rows(), std::vector<T>(m.cols()));
162 for (std::size_t i = 0; i < m.rows(); ++i)
163 for (std::size_t k = 0; k < m.cols(); ++k) out[i][k] = m(i, k);
164 return out;
165}
166
167/** An MMAP cell {D0, D1, D1^(1), ...} as the mam::Mmap struct; [] is the empty flow. */
168template <class T>
169mam::Mmap<T> mmap_from_json(const Json& j, const std::string& where) {
170 if (!j.is_array()) throw InputError(where + ": expected an MMAP, a list of matrices");
171 mam::Mmap<T> m;
172 if (j.empty()) return m;
173 if (j.size() < 2)
174 throw InputError(where + ": an MMAP is {D0, D1, D1^(1), ...}, got one matrix");
175 m.D0 = matrix_from_json<T>(j[0], where + "[0]");
176 m.D1 = matrix_from_json<T>(j[1], where + "[1]");
177 for (std::size_t k = 2; k < j.size(); ++k)
178 m.Dc.push_back(matrix_from_json<T>(j[k], where + "[" + std::to_string(k) + "]"));
179 return m;
180}
181
182template <class T>
183std::vector<mam::Mmap<T> > read_mmap_list(Args& a, const char* key) {
184 const Json& j = a.get(key);
185 const std::string where = std::string(key);
186 if (!j.is_array()) throw InputError(where + ": expected a list of MMAPs");
187 std::vector<mam::Mmap<T> > out;
188 for (std::size_t i = 0; i < j.size(); ++i)
189 out.push_back(mmap_from_json<T>(j[i], where + "[" + std::to_string(i) + "]"));
190 return out;
191}
192
193template <class T>
194Json encode_mmap(const mam::Mmap<T>& m) {
195 std::vector<Matrix<T> > cell;
196 cell.push_back(m.D0);
197 cell.push_back(m.D1);
198 for (const Matrix<T>& d : m.Dc) cell.push_back(d);
199 return encode_matrices(cell);
200}
201
202/** Complex points: a number is real, a pair [re, im] is complex. */
203std::vector<std::complex<double> > read_complex(Args& a, const char* key) {
204 const Json& j = a.get(key);
205 const std::string where = std::string(key);
206 const Json flat = j.is_array() ? j : Json::array({j});
207 std::vector<std::complex<double> > out;
208 for (std::size_t k = 0; k < flat.size(); ++k) {
209 const Json& e = flat[k];
210 const std::string w = where + "[" + std::to_string(k) + "]";
211 if (e.is_array()) {
212 if (e.size() != 2) throw InputError(w + ": a complex number is a pair [re, im]");
213 out.emplace_back(number_from_json<double>(e[0], w), number_from_json<double>(e[1], w));
214 } else {
215 out.emplace_back(number_from_json<double>(e, w), 0.0);
216 }
217 }
218 return out;
219}
220
221Json encode_complex(const std::vector<std::complex<double> >& v) {
222 Json a = Json::array();
223 for (const std::complex<double>& z : v) a.push_back(Json::array({z.real(), z.imag()}));
224 return a;
225}
226
227/** A nested struct argument (config, options, corrections), or null when absent. */
228const Json* sub_object(Args& a, const char* key) {
229 const Json* j = a.opt(key);
230 if (j && !j->is_object())
231 throw InputError(std::string(key) + ": expected an object with named fields");
232 return j;
233}
234
235/** The C++ default arguments of options.method / options.lti_method. */
236struct PassageOptions {
237 bool hasMethod = false;
238 std::string method;
239 bool hasLti = false;
240 std::string lti;
241};
242
243/**
244 * MATLAB's `options` of ctmc_passage_time / ctmc_passage_taboo. lti_method
245 * picks the Laplace inversion of method 'lt' and has no effect under any other
246 * method, so naming it without method 'lt' is refused rather than ignored.
247 */
248PassageOptions read_passage_options(Args& a, const std::string& fn) {
249 PassageOptions o;
250 const Json* j = sub_object(a, "options");
251 if (!j) return o;
252 Args op(*j, fn + ": options");
253 o.hasMethod = op.has("method");
254 if (o.hasMethod) o.method = op.text("method", "");
255 o.hasLti = op.has("lti_method");
256 if (o.hasLti) o.lti = op.text("lti_method", "");
257 op.done();
258 if (o.hasLti && !(o.hasMethod && o.method == "lt"))
259 throw InputError(fn + ": options.lti_method selects the inversion of method 'lt' and "
260 "has no effect otherwise; set options.method to 'lt' or drop it");
261 return o;
262}
263
264// ---------------------------------------------------------------------------
265// mc
266// ---------------------------------------------------------------------------
267
268/** [S,Q11,Q12,Q21,Q22,T,X] = ctmc_stochcomp(Q, I); I is 0-based and optional. */
269struct OpCtmcStochcomp {
270 template <class T>
271 static Json run(Args& a) {
272 const Matrix<T> Q = a.matrix<T>("Q");
273 const bool hasI = a.has("I");
274 const std::vector<std::size_t> I = hasI ? read_indices(a, "I") : std::vector<std::size_t>();
275 a.done();
276 const mc::StochCompResult<T> r = hasI ? mc::ctmc_stochcomp(Q, I) : mc::ctmc_stochcomp(Q);
277 Json out;
278 out["S"] = encode_matrix(r.S);
279 out["Q11"] = encode_matrix(r.Q11);
280 out["Q12"] = encode_matrix(r.Q12);
281 out["Q21"] = encode_matrix(r.Q21);
282 out["Q22"] = encode_matrix(r.Q22);
283 out["T"] = encode_matrix(r.T12);
284 out["X"] = encode_matrix(r.X);
285 return out;
286 }
287};
288
289/** [S,Q11,Q12,Q21,Q22,T] = ctmc_pseudostochcomp(Q, I); I is 0-based and optional. */
290struct OpCtmcPseudostochcomp {
291 template <class T>
292 static Json run(Args& a) {
293 const Matrix<T> Q = a.matrix<T>("Q");
294 const bool hasI = a.has("I");
295 const std::vector<std::size_t> I = hasI ? read_indices(a, "I") : std::vector<std::size_t>();
296 a.done();
297 const mc::PseudoStochCompResult<T> r =
299 Json out;
300 out["S"] = encode_matrix(r.S);
301 out["Q11"] = encode_matrix(r.Q11);
302 out["Q12"] = encode_matrix(r.Q12);
303 out["Q21"] = encode_matrix(r.Q21);
304 out["Q22"] = encode_matrix(r.Q22);
305 out["T"] = encode_matrix(r.Tm);
306 return out;
307 }
308};
309
310/** pf = ctmc_testpf_kolmogorov(Q). */
311struct OpCtmcTestpfKolmogorov {
312 template <class T>
313 static Json run(Args& a) {
314 const Matrix<T> Q = a.matrix<T>("Q");
315 a.done();
316 Json out;
317 out["pf"] = mc::ctmc_testpf_kolmogorov(Q);
318 return out;
319 }
320};
321
322/**
323 * tol / maxiter of ctmc_uniformization and ctmc_timeaverage. They are
324 * positional in MATLAB, so maxiter cannot be named without tol there; the same
325 * holds here, which keeps every call one of the port's three arities.
326 */
327template <class R, class F>
328R call_tol_maxiter(Args& a, const std::string& fn, F f) {
329 const bool hasTol = a.has("tol"), hasMax = a.has("maxiter");
330 if (hasMax && !hasTol)
331 throw InputError(fn + ": 'maxiter' follows 'tol' in the MATLAB signature; name both");
332 const double tol = hasTol ? a.number<double>("tol") : 0.0;
333 const long maxiter = hasMax ? static_cast<long>(a.required_integer("maxiter")) : 0;
334 a.done();
335 if (hasMax) return f(3, tol, maxiter);
336 if (hasTol) return f(2, tol, maxiter);
337 return f(1, tol, maxiter);
338}
339
340/** [pi,kmax] = ctmc_uniformization(pi0,Q,t,tol,maxiter). */
341struct OpCtmcUniformization {
342 template <class T>
343 static Json run(Args& a) {
344 const std::vector<T> pi0 = a.vector<T>("pi0");
345 const Matrix<T> Q = a.matrix<T>("Q");
346 const T t = a.number<T>("t");
347 const mc::UniformizationResult<T> r = call_tol_maxiter<mc::UniformizationResult<T> >(
348 a, "ctmc_uniformization", [&](int n, double tol, long maxiter) {
349 if (n == 3) return mc::ctmc_uniformization(pi0, Q, t, tol, maxiter);
350 if (n == 2) return mc::ctmc_uniformization(pi0, Q, t, tol);
351 return mc::ctmc_uniformization(pi0, Q, t);
352 });
353 Json out;
354 out["pi"] = encode_vector(r.pi);
355 out["kmax"] = encode_count(r.kmax);
356 return out;
357 }
358};
359
360/** [piTimeAvg,piExit,kmax] = ctmc_timeaverage(pi0,Q,t,tol,maxiter). */
361struct OpCtmcTimeaverage {
362 template <class T>
363 static Json run(Args& a) {
364 const std::vector<T> pi0 = a.vector<T>("pi0");
365 const Matrix<T> Q = a.matrix<T>("Q");
366 const T t = a.number<T>("t");
367 const mc::TimeAverageResult<T> r = call_tol_maxiter<mc::TimeAverageResult<T> >(
368 a, "ctmc_timeaverage", [&](int n, double tol, long maxiter) {
369 if (n == 3) return mc::ctmc_timeaverage(pi0, Q, t, tol, maxiter);
370 if (n == 2) return mc::ctmc_timeaverage(pi0, Q, t, tol);
371 return mc::ctmc_timeaverage(pi0, Q, t);
372 });
373 Json out;
374 out["piTimeAvg"] = encode_vector(r.piTimeAvg);
375 out["piExit"] = encode_vector(r.piExit);
376 out["kmax"] = encode_count(r.kmax);
377 return out;
378 }
379};
380
381/**
382 * [p,flag,relres,iter] = ctmc_power / ctmc_jacobi / ctmc_gaussseidel(Q,tol,maxiter,p0)
383 * and [p,flag,relres,iter,omega] = ctmc_sor(Q,tol,maxiter,omega,p0). Every
384 * argument but Q is optional and named, a nonpositive tol / maxiter / omega
385 * selecting the default (omega <= 0 is the adaptive SOR rule).
386 */
387template <mc::detail::SweepKind K>
388struct OpCtmcClassical {
389 template <class T>
390 static Json run(Args& a) {
391 const Matrix<T> Q = a.matrix<T>("Q");
392 const double tol = a.scalar<double>("tol", mc::CLASSICAL_DEFAULT_TOL);
393 const long maxiter = static_cast<long>(a.integer("maxiter", static_cast<int>(mc::CLASSICAL_DEFAULT_MAXITER)));
394 const double omega = (K == mc::detail::SweepKind::Sor) ? a.scalar<double>("omega", 0.0)
395 : (K == mc::detail::SweepKind::GaussSeidel) ? 1.0 : 0.0;
396 const std::vector<T> p0 = a.vector_or_empty<T>("p0");
397 a.done();
398 const mc::ClassicalResult<T> r = mc::detail::stationary_sweep_iterate(K, Q, tol, maxiter, omega, p0);
399 Json out;
400 out["p"] = encode_vector(r.p);
401 out["flag"] = r.flag;
402 out["relres"] = encode_scalar(r.relres);
403 out["iter"] = static_cast<std::int64_t>(r.iter);
404 if (K == mc::detail::SweepKind::Sor) out["omega"] = encode_scalar(r.omega);
405 return out;
406 }
407};
408
409/**
410 * [p,flag] = ctmc_gth(Q) / dtmc_gth(P): GTH elimination at every arithmetic
411 * (no subtraction, so exact at --arith exact). With several closed classes p is
412 * NaN and flag 1, as the MATLAB two-output form returns.
413 */
414template <bool Dtmc>
415struct OpGth {
416 template <class T>
417 static Json run(Args& a) {
418 const Matrix<T> Q = a.matrix<T>(Dtmc ? "P" : "Q");
419 a.done();
420 const mc::GthResult<T> r = mc::ctmc_gth_flag(Q);
421 Json out;
422 if (r.flag == 0) {
423 out["p"] = encode_vector(r.p);
424 } else {
425 Json nan = Json::array();
426 for (std::size_t i = 0; i < Q.rows(); ++i) nan.push_back("NaN");
427 out["p"] = nan;
428 }
429 out["flag"] = r.flag;
430 return out;
431 }
432};
433
434/** J = ctmc_cesaro(Q) / dtmc_cesaro(P): limit matrix of any finite chain. */
435template <bool Dtmc>
436struct OpCesaro {
437 template <class T>
438 static Json run(Args& a) {
439 const Matrix<T> Q = a.matrix<T>(Dtmc ? "P" : "Q");
440 a.done();
441 Json out;
442 out["J"] = encode_matrix(mc::ctmc_cesaro(Q));
443 return out;
444 }
445};
446
447/** p = ctmc_ssd(C,R) / dtmc_ssd(C,R); an absent edge is R = "Inf" or C = 0. */
448struct OpSsd {
449 static Json run(Args& a) {
450 const Matrix<double> C = a.matrix<double>("C");
451 const Matrix<double> R = a.matrix<double>("R");
452 a.done();
453 Json out;
454 out["p"] = encode_vector(mc::ctmc_ssd(C, R));
455 return out;
456 }
457};
458
459/** [L,piT,kmax] = ctmc_accumulated(pi0,Q,t,tol,maxiter); t may be a vector. */
460struct OpCtmcAccumulated {
461 template <class T>
462 static Json run(Args& a) {
463 const std::vector<T> pi0 = a.vector<T>("pi0");
464 const Matrix<T> Q = a.matrix<T>("Q");
465 const std::vector<T> t = a.vector<T>("t");
466 const mc::AccumulatedResult<T> r = call_tol_maxiter<mc::AccumulatedResult<T> >(
467 a, "ctmc_accumulated", [&](int n, double tol, long maxiter) {
468 if (n == 3) return mc::ctmc_accumulated(pi0, Q, t, tol, maxiter);
469 if (n == 2) return mc::ctmc_accumulated(pi0, Q, t, tol);
470 return mc::ctmc_accumulated(pi0, Q, t);
471 });
472 Json out;
473 out["L"] = encode_matrix(r.L);
474 out["piT"] = encode_matrix(r.piT);
475 out["kmax"] = encode_count(r.kmax);
476 return out;
477 }
478};
479
480/**
481 * [ok,msg] = ctmc_memory_gate(logNstates,force,verbose,safetyFraction). The
482 * kernel is double-valued whatever the arithmetic; 'verbose' is refused because
483 * it prints the calibration on stdout, the stream that carries the JSON reply.
484 */
485struct OpCtmcMemoryGate {
486 template <class T>
487 static Json run(Args& a) {
488 const double logN = a.number<double>("logNstates");
489 a.unsupported("verbose",
490 "ctmc_memory_gate: 'verbose' prints to stdout, which carries the JSON "
491 "reply; the decision and its message are returned as ok and msg");
492 const bool hasForce = a.has("force"), hasSafety = a.has("safetyFraction");
493 const bool force = hasForce ? a.boolean("force", false) : false;
494 const double safety = hasSafety ? a.number<double>("safetyFraction") : 0.0;
495 a.done();
496 mc::CtmcGateResult r;
497 if (hasSafety)
498 r = mc::ctmc_memory_gate(logN, force, safety);
499 else if (hasForce)
500 r = mc::ctmc_memory_gate(logN, force);
501 else
502 r = mc::ctmc_memory_gate(logN);
503 Json out;
504 out["ok"] = r.ok;
505 out["msg"] = r.message;
506 return out;
507 }
508};
509
510/** bool = ctmc_isfeasible(Q, tol). */
511struct OpCtmcIsfeasible {
512 template <class T>
513 static Json run(Args& a) {
514 const Matrix<T> Q = a.matrix<T>("Q");
515 const bool hasTol = a.has("tol");
516 const T tol = hasTol ? a.number<T>("tol") : T();
517 a.done();
518 Json out;
519 out["bool"] = hasTol ? mc::ctmc_isfeasible(Q, tol) : mc::ctmc_isfeasible(Q);
520 return out;
521 }
522};
523
524/** h = ctmc_hitting_time(Q, targetStates) and h = dtmc_hitting_time(P, targetStates). */
525struct OpCtmcHittingTime {
526 template <class T>
527 static Json run(Args& a) {
528 const Matrix<T> Q = a.matrix<T>("Q");
529 const std::vector<std::size_t> target = read_indices(a, "targetStates");
530 a.done();
531 Json out;
532 out["h"] = encode_vector(mc::ctmc_hitting_time(Q, target));
533 return out;
534 }
535};
536
537struct OpDtmcHittingTime {
538 template <class T>
539 static Json run(Args& a) {
540 const Matrix<T> P = a.matrix<T>("P");
541 const std::vector<std::size_t> target = read_indices(a, "targetStates");
542 a.done();
543 Json out;
544 out["h"] = encode_vector(mc::dtmc_hitting_time(P, target));
545 return out;
546 }
547};
548
549/**
550 * pi_t = dtmc_transient(P, pi0, steps). An absent pi0 is the uniform law (the
551 * port's empty-vector form). The port has no (P, pi0) overload, so a call that
552 * names pi0 but not steps passes MATLAB's steps = 1 explicitly.
553 */
554struct OpDtmcTransient {
555 template <class T>
556 static Json run(Args& a) {
557 const Matrix<T> P = a.matrix<T>("P");
558 const bool hasPi0 = a.has("pi0"), hasSteps = a.has("steps");
559 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
560 const std::size_t steps = hasSteps ? a.count("steps") : 1;
561 a.done();
562 Json out;
563 out["pi_t"] = encode_matrix((hasPi0 || hasSteps) ? mc::dtmc_transient(P, pi0, steps)
564 : mc::dtmc_transient(P));
565 return out;
566 }
567};
568
569/** [alpha,S,s0,keep,atom] = ctmc_passage_ph(Q,pi0,target); an absent pi0 is the stationary law. */
570struct OpCtmcPassagePh {
571 template <class T>
572 static Json run(Args& a) {
573 const Matrix<T> Q = a.matrix<T>("Q");
574 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
575 const std::vector<std::size_t> target = read_indices(a, "target");
576 a.done();
577 const mc::PassagePh<T> r = mc::ctmc_passage_ph(Q, pi0, target);
578 Json out;
579 out["alpha"] = encode_vector(r.alpha);
580 out["S"] = encode_matrix(r.S);
581 out["s0"] = encode_vector(r.s0);
582 out["keep"] = encode_indices(r.keep);
583 out["atom"] = encode_scalar(r.atom);
584 return out;
585 }
586};
587
588/** L = ctmc_passage_lst(Q,pi0,target,s); s and L are lists of [re, im]. */
589struct OpCtmcPassageLst {
590 template <class T>
591 static Json run(Args& a) {
592 const Matrix<T> Q = a.matrix<T>("Q");
593 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
594 const std::vector<std::size_t> target = read_indices(a, "target");
595 const std::vector<std::complex<double> > s = read_complex(a, "s");
596 a.done();
597 Json out;
598 out["L"] = encode_complex(mc::ctmc_passage_lst(Q, pi0, target, s));
599 return out;
600 }
601};
602
603/** [mall,m] = ctmc_passage_moments(Q,pi0,target,nmax). */
604struct OpCtmcPassageMoments {
605 template <class T>
606 static Json run(Args& a) {
607 const Matrix<T> Q = a.matrix<T>("Q");
608 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
609 const std::vector<std::size_t> target = read_indices(a, "target");
610 const bool hasN = a.has("nmax");
611 const std::size_t nmax = hasN ? a.count("nmax") : 0;
612 a.done();
613 const mc::PassageMoments<T> r = hasN ? mc::ctmc_passage_moments(Q, pi0, target, nmax)
614 : mc::ctmc_passage_moments(Q, pi0, target);
615 Json out;
616 out["mall"] = encode_matrix(r.mall);
617 out["m"] = encode_vector(r.m);
618 return out;
619 }
620};
621
622/**
623 * [F,f,out] = ctmc_passage_time(Q,pi0,target,tset,options). out carries atom
624 * and the phase-type representation (alpha, S, s0, keep) the curve is computed
625 * from, which is ctmc_passage_ph of the same arguments.
626 */
627struct OpCtmcPassageTime {
628 template <class T>
629 static Json run(Args& a) {
630 const Matrix<T> Q = a.matrix<T>("Q");
631 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
632 const std::vector<std::size_t> target = read_indices(a, "target");
633 const std::vector<double> tset = a.vector<double>("tset");
634 const PassageOptions o = read_passage_options(a, "ctmc_passage_time");
635 a.done();
636 const mc::PassageCurve<T> c =
637 o.hasLti ? mc::ctmc_passage_time(Q, pi0, target, tset, o.method, o.lti)
638 : o.hasMethod ? mc::ctmc_passage_time(Q, pi0, target, tset, o.method)
639 : mc::ctmc_passage_time(Q, pi0, target, tset);
640 const mc::PassagePh<T> ph = mc::ctmc_passage_ph(Q, pi0, target);
641 Json out;
642 out["F"] = encode_vector(c.F);
643 out["f"] = encode_vector(c.f);
644 Json o2;
645 o2["atom"] = encode_scalar(c.atom);
646 o2["alpha"] = encode_vector(ph.alpha);
647 o2["S"] = encode_matrix(ph.S);
648 o2["s0"] = encode_vector(ph.s0);
649 o2["keep"] = encode_indices(ph.keep);
650 out["out"] = o2;
651 return out;
652 }
653};
654
655/** [F,f,out] = ctmc_passage_taboo(Q,pi0,target,taboo,tset,options). */
656struct OpCtmcPassageTaboo {
657 template <class T>
658 static Json run(Args& a) {
659 const Matrix<T> Q = a.matrix<T>("Q");
660 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
661 const std::vector<std::size_t> target = read_indices(a, "target");
662 const std::vector<std::size_t> taboo = read_indices(a, "taboo");
663 const bool hasT = a.has("tset");
664 const std::vector<double> tset = a.vector_or_empty<double>("tset");
665 const PassageOptions o = read_passage_options(a, "ctmc_passage_taboo");
666 a.done();
667 const mc::PassageTaboo<T> r =
668 o.hasLti ? mc::ctmc_passage_taboo(Q, pi0, target, taboo, tset, o.method, o.lti)
669 : o.hasMethod ? mc::ctmc_passage_taboo(Q, pi0, target, taboo, tset, o.method)
670 : hasT ? mc::ctmc_passage_taboo(Q, pi0, target, taboo, tset)
671 : mc::ctmc_passage_taboo(Q, pi0, target, taboo);
672 Json out;
673 out["F"] = encode_vector(r.F);
674 out["f"] = encode_vector(r.f);
675 Json o2;
676 o2["atom"] = encode_scalar(r.atom);
677 o2["reachprob"] = encode_scalar(r.reachprob);
678 o2["tabooprob"] = encode_scalar(r.tabooprob);
679 o2["pB"] = encode_vector(r.pB);
680 o2["pC"] = encode_vector(r.pC);
681 o2["alpha"] = encode_vector(r.alpha);
682 o2["S"] = encode_matrix(r.S);
683 o2["sB"] = encode_vector(r.sB);
684 o2["sC"] = encode_vector(r.sC);
685 o2["keep"] = encode_indices(r.keep);
686 o2["target"] = encode_indices(r.target);
687 o2["taboo"] = encode_indices(r.taboo);
688 o2["method"] = r.method;
689 out["out"] = o2;
690 return out;
691 }
692};
693
694/** [mall,m,pB] = ctmc_passage_taboo_moments(Q,pi0,target,taboo,nmax). */
695struct OpCtmcPassageTabooMoments {
696 template <class T>
697 static Json run(Args& a) {
698 const Matrix<T> Q = a.matrix<T>("Q");
699 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
700 const std::vector<std::size_t> target = read_indices(a, "target");
701 const std::vector<std::size_t> taboo = read_indices(a, "taboo");
702 const bool hasN = a.has("nmax");
703 const std::size_t nmax = hasN ? a.count("nmax") : 0;
704 a.done();
705 const mc::PassageTabooMoments<T> r =
706 hasN ? mc::ctmc_passage_taboo_moments(Q, pi0, target, taboo, nmax)
707 : mc::ctmc_passage_taboo_moments(Q, pi0, target, taboo);
708 Json out;
709 out["mall"] = encode_matrix(r.mall);
710 out["m"] = encode_vector(r.m);
711 out["pB"] = encode_vector(r.pB);
712 return out;
713 }
714};
715
716// ---------------------------------------------------------------------------
717// dpfqn
718// ---------------------------------------------------------------------------
719
720/** [lG,G,G1] = dpfqn_nc(p, N). */
721struct OpDpfqnNc {
722 template <class T>
723 static Json run(Args& a) {
724 const std::vector<T> p = a.vector<T>("p");
725 const std::size_t N = a.count("N");
726 a.done();
727 const dpfqn::DtNcResult<T> r = dpfqn::dpfqn_nc(p, N);
728 Json out;
729 out["lG"] = encode_scalar(r.lG);
730 out["G"] = encode_scalar(r.G);
731 out["G1"] = encode_vector(r.G1);
732 return out;
733 }
734};
735
736/** [lG,G,W,Gc,Wa] = dpfqn_ncld(P, N), P a J-by-N matrix with P(j,n) = p_j(n). */
737struct OpDpfqnNcld {
738 template <class T>
739 static Json run(Args& a) {
740 const Matrix<T> P = a.matrix<T>("P");
741 const std::size_t N = a.count("N");
742 a.done();
743 const dpfqn::DtNcLdResult<T> r = dpfqn::dpfqn_ncld(rows_of(P), N);
744 Json out;
745 out["lG"] = encode_scalar(r.lG);
746 out["G"] = encode_vector(r.G);
747 out["W"] = encode_vectors(r.W);
748 out["Gc"] = encode_vectors(r.Gc);
749 out["Wa"] = encode_vectors(r.Wa);
750 return out;
751 }
752};
753
754// ---------------------------------------------------------------------------
755// npfqn
756// ---------------------------------------------------------------------------
757
758/**
759 * ctx = npfqn_traffic_idc(lambda0,P,c2a0,a0IdcFun,mu,cs2,sIdcFun,corrections).
760 * The two IDC callables are stored in MATLAB's ctx only for npfqn_traffic_idc_at
761 * (library-only) and play no part in ctx itself, so they are refused by name.
762 */
763struct OpNpfqnTrafficIdc {
764 template <class T>
765 static Json run(Args& a) {
766 const std::vector<T> lambda0 = a.vector<T>("lambda0");
767 const Matrix<T> P = a.matrix<T>("P");
768 const std::vector<T> c2a0 = a.vector<T>("c2a0");
769 const std::vector<T> mu = a.vector<T>("mu");
770 const std::vector<T> cs2 = a.vector<T>("cs2");
771 a.unsupported("a0IdcFun", "npfqn_traffic_idc: a0IdcFun is a function handle with no "
772 "JSON form; it is used only by npfqn_traffic_idc_at");
773 a.unsupported("sIdcFun", "npfqn_traffic_idc: sIdcFun is a function handle with no "
774 "JSON form; it is used only by npfqn_traffic_idc_at");
775 const Json* cj = sub_object(a, "corrections");
776 npfqn::TrafficIdcCorrections corr;
777 if (cj) {
778 Args c(*cj, "npfqn_traffic_idc: corrections");
779 if (c.has("alpha")) corr.alpha = c.boolean("alpha", corr.alpha);
780 if (c.has("beta")) corr.beta = c.boolean("beta", corr.beta);
781 c.done();
782 }
783 a.done();
784 const npfqn::TrafficIdcContext<T> x = cj ? npfqn::npfqn_traffic_idc(lambda0, P, c2a0, mu, cs2, corr)
785 : npfqn::npfqn_traffic_idc(lambda0, P, c2a0, mu, cs2);
786 Json ctx;
787 ctx["K"] = encode_count(x.K);
788 ctx["lambda"] = encode_vector(x.lambda);
789 ctx["lambda0"] = encode_vector(x.lambda0);
790 ctx["mu"] = encode_vector(x.mu);
791 ctx["rho"] = encode_vector(x.rho);
792 ctx["cs2"] = encode_vector(x.cs2);
793 ctx["c2a0"] = encode_vector(x.c2a0);
794 ctx["c2a"] = encode_vector(x.c2a);
795 ctx["c2d"] = encode_vector(x.c2d);
796 ctx["c2x"] = encode_vector(x.c2x);
797 ctx["P"] = encode_matrix(x.P);
798 ctx["Xi"] = encode_matrix(x.Xi);
799 ctx["lam_ji"] = encode_matrix(x.lam_ji);
800 ctx["c2aij"] = encode_matrix(x.c2aij);
801 ctx["c2alpha"] = encode_matrix(x.c2alpha);
802 ctx["zetaAll"] = encode_matrices(x.zetaAll);
803 Json out;
804 out["ctx"] = ctx;
805 return out;
806 }
807};
808
809/**
810 * SMMAP = npfqn_traffic_split_cs(MMAP, P, config). The reference never reads
811 * config, so naming it is refused rather than silently dropped.
812 */
813struct OpNpfqnTrafficSplitCs {
814 template <class T>
815 static Json run(Args& a) {
816 const std::vector<Matrix<T> > M = a.matrices<T>("MMAP");
817 const Matrix<T> P = a.matrix<T>("P");
818 a.unsupported("config", "npfqn_traffic_split_cs: the reference accepts config but never "
819 "reads it; there is nothing for it to select");
820 a.done();
821 const std::vector<npfqn::Mmap<T> > s = npfqn::npfqn_traffic_split_cs(M, P);
822 Json out = Json::array();
823 for (const npfqn::Mmap<T>& m : s) out.push_back(encode_matrices(m));
824 Json r;
825 r["SMMAP"] = out;
826 return r;
827 }
828};
829
830npfqn::Merge merge_from_text(const std::string& s, const std::string& fn) {
831 if (s == "default") return npfqn::Merge::Default;
832 if (s == "super") return npfqn::Merge::Super;
833 if (s == "mixture") return npfqn::Merge::Mixture;
834 if (s == "interpos") return npfqn::Merge::Interpos;
835 throw InputError(fn + ": config.merge must be 'default', 'super', 'mixture' or 'interpos', got '" +
836 s + "'");
837}
838
839npfqn::Compress compress_from_text(const std::string& s, const std::string& fn) {
840 if (s == "default") return npfqn::Compress::Default;
841 if (s == "none") return npfqn::Compress::None;
842 throw InputError(fn + ": config.compress must be 'default' or 'none', got '" + s + "'");
843}
844
845/** SMMAP = npfqn_traffic_merge_cs(MMAP, prob, config); config.merge only. */
846struct OpNpfqnTrafficMergeCs {
847 template <class T>
848 static Json run(Args& a) {
849 const std::vector<mam::Mmap<T> > flows = read_mmap_list<T>(a, "MMAP");
850 const Matrix<T> prob = a.matrix<T>("prob");
851 const Json* cj = sub_object(a, "config");
852 bool hasMerge = false;
854 if (cj) {
855 Args c(*cj, "npfqn_traffic_merge_cs: config");
856 hasMerge = c.has("merge");
857 if (hasMerge) merge = merge_from_text(c.text("merge", ""), "npfqn_traffic_merge_cs");
858 c.done();
859 }
860 a.done();
861 const mam::Mmap<T> s = hasMerge ? npfqn::npfqn_traffic_merge_cs(flows, prob, merge)
862 : npfqn::npfqn_traffic_merge_cs(flows, prob);
863 Json out;
864 out["SMMAP"] = encode_mmap(s);
865 return out;
866 }
867};
868
869/** SMMAP = npfqn_traffic_merge(MMAP, config); config.merge and config.compress. */
870struct OpNpfqnTrafficMerge {
871 template <class T>
872 static Json run(Args& a) {
873 const std::vector<mam::Mmap<T> > flows = read_mmap_list<T>(a, "MMAP");
874 const Json* cj = sub_object(a, "config");
875 npfqn::MergeConfig cfg;
876 if (cj) {
877 Args c(*cj, "npfqn_traffic_merge: config");
878 if (c.has("merge")) cfg.merge = merge_from_text(c.text("merge", ""), "npfqn_traffic_merge");
879 if (c.has("compress"))
880 cfg.compress = compress_from_text(c.text("compress", ""), "npfqn_traffic_merge");
881 c.done();
882 }
883 a.done();
884 const mam::Mmap<T> s = cj ? npfqn::npfqn_traffic_merge(flows, cfg) : npfqn::npfqn_traffic_merge(flows);
885 Json out;
886 out["SMMAP"] = encode_mmap(s);
887 return out;
888 }
889};
890
891/** w = npfqn_rqna_weight(t): a scalar t gives a scalar w, an array an array. */
892struct OpNpfqnRqnaWeight {
893 template <class T>
894 static Json run(Args& a) {
895 const bool vec = a.get("t").is_array();
896 Json out;
897 if (vec) {
898 const std::vector<T> t = a.vector<T>("t");
899 a.done();
901 } else {
902 const T t = a.number<T>("t");
903 a.done();
905 }
906 return out;
907 }
908};
909
910/** [lambda,Gamma,alpha] = npfqn_traffic_rqt(lambda0,Gamma0,alpha0,F). */
911struct OpNpfqnTrafficRqt {
912 template <class T>
913 static Json run(Args& a) {
914 const std::vector<T> lambda0 = a.vector<T>("lambda0");
915 const std::vector<T> Gamma0 = a.vector<T>("Gamma0");
916 const std::vector<T> alpha0 = a.vector<T>("alpha0");
917 const Matrix<T> F = a.matrix<T>("F");
918 a.done();
919 const npfqn::TrafficRqt<T> r = npfqn::npfqn_traffic_rqt(lambda0, Gamma0, alpha0, F);
920 Json out;
921 out["lambda"] = encode_vector(r.lambda);
922 out["Gamma"] = encode_vector(r.Gamma);
923 out["alpha"] = encode_vector(r.alpha);
924 return out;
925 }
926};
927
928/**
929 * [zlb,x,info] = npfqn_bnd_bpt(lambda0,mu,P,stationOf,c); stationOf is 0-based
930 * and an absent c is MATLAB's empty c (all ones).
931 */
932struct OpNpfqnBndBpt {
933 template <class T>
934 static Json run(Args& a) {
935 const std::vector<T> lambda0 = a.vector<T>("lambda0");
936 const std::vector<T> mu = a.vector<T>("mu");
937 const Matrix<T> P = a.matrix<T>("P");
938 const std::vector<std::size_t> stationOf = read_indices(a, "stationOf");
939 const std::vector<T> c = a.vector_or_empty<T>("c");
940 a.done();
941 const npfqn::BndBpt<T> r = npfqn::npfqn_bnd_bpt(lambda0, mu, P, stationOf, c);
942 Json out;
943 out["zlb"] = encode_scalar(r.zlb);
944 out["x"] = encode_vector(r.x);
945 Json info;
946 info["lambda"] = encode_vector(r.lambda);
947 info["rho"] = encode_vector(r.rho);
948 info["rhoStation"] = encode_vector(r.rhoStation);
949 info["nvars"] = encode_count(r.nvars);
950 info["nrows"] = encode_count(r.nrows);
951 out["info"] = info;
952 return out;
953 }
954};
955
956/**
957 * [Qub,info] = npfqn_bnd_bgt(lambda,mu,sigma,J). mu and sigma are lists with
958 * one entry per type; sigma holds 0-based stations. An absent J is derived from
959 * sigma as MATLAB derives it (one past the largest station index); the port has
960 * no shorter overload. info.finite marks where Qub is a bound at all (MATLAB
961 * writes Inf there, which JSON cannot carry).
962 */
963struct OpNpfqnBndBgt {
964 template <class T>
965 static Json run(Args& a) {
966 const std::vector<T> lambda = a.vector<T>("lambda");
967 const std::vector<std::vector<T> > mu = read_vector_list<T>(a, "mu");
968 const std::vector<std::vector<std::size_t> > sigma = read_index_lists(a, "sigma");
969 std::size_t J = 0;
970 if (a.has("J")) {
971 J = a.count("J");
972 } else {
973 for (const std::vector<std::size_t>& s : sigma)
974 for (std::size_t j : s) J = std::max(J, j + 1);
975 }
976 a.done();
977 const npfqn::BndBgt<T> r = npfqn::npfqn_bnd_bgt(lambda, mu, sigma, J);
978 Json out;
979 out["Qub"] = encode_vectors(r.Qub);
980 Json info;
981 Json fin = Json::array();
982 for (bool b : r.finite) fin.push_back(b);
983 info["finite"] = fin;
984 info["gamma"] = encode_scalar(r.gamma);
985 info["Lmax"] = encode_scalar(r.Lmax);
986 info["L"] = encode_vectors(r.L);
987 info["V"] = encode_vector(r.V);
988 info["B"] = encode_scalar(r.B);
989 info["U"] = encode_scalar(r.U);
990 info["tailRatio"] = encode_scalar(r.tailRatio);
991 info["tailStep"] = encode_scalar(r.tailStep);
992 info["rho"] = encode_vector(r.rho);
993 info["rhoStation"] = encode_vector(r.rhoStation);
994 info["scale"] = encode_scalar(r.scale);
995 info["classType"] = encode_indices(r.classType);
996 info["classStage"] = encode_indices(r.classStage);
997 info["classStation"] = encode_indices(r.classStation);
998 out["info"] = info;
999 return out;
1000 }
1001};
1002
1003/**
1004 * [ST,gamma,nservers,rho,scva,scvs,eta] =
1005 * npfqn_nonexp_approx(method,sn,ST,V,SCV,T,U,gamma,nservers).
1006 * The two fields the reference reads from sn are named as the port names them:
1007 * isFCFS (sn.sched(i) == FCFS) and rates (sn.rates).
1008 */
1009struct OpNpfqnNonexpApprox {
1010 template <class T>
1011 static Json run(Args& a) {
1012 a.unsupported("sn", "npfqn_nonexp_approx: pass the two sn fields the routine reads, "
1013 "isFCFS (sn.sched == FCFS per station) and rates (sn.rates)");
1014 const std::string method = a.text("method", "");
1015 if (method.empty()) throw InputError("npfqn_nonexp_approx: missing required argument 'method'");
1016 const std::vector<bool> isFCFS = read_flags(a, "isFCFS");
1017 const Matrix<T> rates = a.matrix<T>("rates");
1018 const Matrix<T> ST = a.matrix<T>("ST");
1019 const Matrix<T> V = a.matrix<T>("V");
1020 const Matrix<T> SCV = a.matrix<T>("SCV");
1021 const Matrix<T> Tput = a.matrix<T>("T");
1022 const Matrix<T> U = a.matrix<T>("U");
1023 const std::vector<T> gamma = a.vector<T>("gamma");
1024 const std::vector<T> nservers = a.vector<T>("nservers");
1025 a.done();
1026 const npfqn::NonexpApproxResult<T> r =
1027 npfqn::npfqn_nonexp_approx(method, isFCFS, rates, ST, V, SCV, Tput, U, gamma, nservers);
1028 Json out;
1029 out["ST"] = encode_matrix(r.ST);
1030 out["gamma"] = encode_vector(r.gamma);
1031 out["nservers"] = encode_vector(r.nservers);
1032 out["rho"] = encode_vector(r.rho);
1033 out["scva"] = encode_vector(r.scva);
1034 out["scvs"] = encode_vector(r.scvs);
1035 out["eta"] = encode_vector(r.eta);
1036 return out;
1037 }
1038};
1039
1040/**
1041 * [X,Q,U,R] = npfqn_sqd(sn,N,calibrationMode,serverBlockingTime,neighborMode,
1042 * v1Policy,initialV1). The sn is replaced by the arrays the port takes (see
1043 * npfqn_sqd.h): ST, V, cap, isDelay, rt, stationToStateful (ONE-based, as in
1044 * sn) and nclasses. N is required: MATLAB's fallback reads sn.nclosedjobs.
1045 */
1046struct OpNpfqnSqd {
1047 template <class T>
1048 static Json run(Args& a) {
1049 a.unsupported("sn", "npfqn_sqd: pass the arrays the routine unpacks from sn: ST, V, cap, "
1050 "isDelay, rt, stationToStateful and nclasses (see npfqn_sqd.h)");
1051 const std::vector<T> ST = a.vector<T>("ST");
1052 const std::vector<T> V = a.vector<T>("V");
1053 const std::vector<T> cap = a.vector<T>("cap");
1054 const std::vector<bool> isDelay = read_flags(a, "isDelay");
1055 const Matrix<T> rt = a.matrix<T>("rt");
1056 const std::vector<std::size_t> s2s = read_indices(a, "stationToStateful");
1057 const std::size_t nclasses = a.count("nclasses");
1058 const int N = a.required_integer("N");
1059 npfqn::SqdOptions<T> opt;
1060 bool any = false;
1061 if (a.has("calibrationMode")) {
1062 opt.calibrationMode = a.required_integer("calibrationMode");
1063 any = true;
1064 }
1065 if (a.has("serverBlockingTime")) {
1066 opt.serverBlockingTime = a.boolean("serverBlockingTime", opt.serverBlockingTime);
1067 any = true;
1068 }
1069 if (a.has("neighborMode")) {
1070 const std::string m = a.text("neighborMode", "");
1071 if (m != "downstream" && m != "ownserver")
1072 throw InputError("npfqn_sqd: neighborMode must be 'downstream' or 'ownserver', got '" + m + "'");
1073 opt.ownServerNeighbor = (m == "ownserver");
1074 any = true;
1075 }
1076 if (a.has("v1Policy")) {
1077 const std::string m = a.text("v1Policy", "");
1078 if (m != "compound" && m != "fresh")
1079 throw InputError("npfqn_sqd: v1Policy must be 'compound' or 'fresh', got '" + m + "'");
1080 opt.freshV1 = (m == "fresh");
1081 any = true;
1082 }
1083 if (a.has("initialV1")) {
1084 opt.initialV1 = a.vector_or_empty<T>("initialV1");
1085 any = true;
1086 }
1087 a.done();
1088 const npfqn::SqdResult<T> r =
1089 any ? npfqn::npfqn_sqd(ST, V, cap, isDelay, rt, s2s, nclasses, N, opt)
1090 : npfqn::npfqn_sqd(ST, V, cap, isDelay, rt, s2s, nclasses, N);
1091 Json out;
1092 out["X"] = encode_vector(r.X);
1093 out["Q"] = encode_vector(r.Q);
1094 out["U"] = encode_vector(r.U);
1095 out["R"] = encode_vector(r.R);
1096 return out;
1097 }
1098};
1099
1100/** [Q,R,X,aux] = npfqn_dps_morrison(N,Z,S,w). */
1101struct OpNpfqnDpsMorrison {
1102 template <class T>
1103 static Json run(Args& a) {
1104 const std::vector<T> N = a.vector<T>("N");
1105 const std::vector<T> Z = a.vector<T>("Z");
1106 const std::vector<T> S = a.vector<T>("S");
1107 const std::vector<T> w = a.vector<T>("w");
1108 a.done();
1109 const npfqn::DpsMorrisonResult<T> r = npfqn::npfqn_dps_morrison(N, Z, S, w);
1110 Json out;
1111 out["Q"] = encode_vector(r.Q);
1112 out["R"] = encode_vector(r.R);
1113 out["X"] = encode_vector(r.X);
1114 Json aux;
1115 aux["rho"] = encode_scalar(r.rho);
1116 aux["a"] = encode_scalar(r.a);
1117#define LINE_MC_AUX(f) aux[#f] = encode_scalar(r.f);
1121 LINE_MC_AUX(cV)
1122#undef LINE_MC_AUX
1123 aux["sigma"] = encode_vector(r.sigma);
1124 aux["W"] = encode_vector(r.W);
1125 aux["Qlead"] = encode_vector(r.Qlead);
1126 aux["Rlead"] = encode_vector(r.Rlead);
1127 out["aux"] = aux;
1128 return out;
1129 }
1130};
1131
1132/**
1133 * result = npfqn_feedback_elim(P, rho, 'cs2', .., 'lambda', .., 'immediateOnly', ..).
1134 * An absent cs2 or lambda is MATLAB's empty option, which skips that output.
1135 */
1136struct OpNpfqnFeedbackElim {
1137 template <class T>
1138 static Json run(Args& a) {
1139 const Matrix<T> P = a.matrix<T>("P");
1140 const std::vector<T> rho = a.vector<T>("rho");
1141 const std::vector<T> cs2 = a.vector_or_empty<T>("cs2");
1142 const std::vector<T> lambda = a.vector_or_empty<T>("lambda");
1143 const bool hasImm = a.has("immediateOnly");
1144 const bool imm = hasImm ? a.boolean("immediateOnly", false) : false;
1145 a.done();
1146 const npfqn::FeedbackElimResult<T> r = hasImm ? npfqn::npfqn_feedback_elim(P, rho, cs2, lambda, imm)
1147 : npfqn::npfqn_feedback_elim(P, rho, cs2, lambda);
1148 Json res;
1149 res["feedbackProb"] = encode_vector(r.feedbackProb);
1150 res["visitInflation"] = encode_vector(r.visitInflation);
1151 if (!r.modifiedScv.empty()) res["modifiedScv"] = encode_vector(r.modifiedScv);
1152 if (!r.modifiedRates.empty()) res["modifiedRates"] = encode_vector(r.modifiedRates);
1153 res["modifiedRouting"] = encode_matrix(r.modifiedRouting);
1154 res["reductionExact"] = r.reductionExact;
1155 Json out;
1156 out["result"] = res;
1157 return out;
1158 }
1159};
1160
1161// ---------------------------------------------------------------------------
1162// snc: every envelope function returns [sigma, rho]
1163// ---------------------------------------------------------------------------
1164
1165Json env_json(const snc::Env& e) {
1166 Json out;
1167 out["sigma"] = e.sigma;
1168 out["rho"] = e.rho;
1169 return out;
1170}
1171
1172/** The (sigma, rho) pair of an envelope passed as two scalars. */
1173snc::Env read_env(Args& a, const char* s, const char* r) {
1174 snc::Env e;
1175 e.sigma = a.number<double>(s);
1176 e.rho = a.number<double>(r);
1177 return e;
1178}
1179
1180struct OpSncEnvPoisson {
1181 static Json run(Args& a) {
1182 const double lambda = a.number<double>("lambda"), theta = a.number<double>("theta");
1183 a.done();
1184 return env_json(snc::snc_env_poisson(lambda, theta));
1185 }
1186};
1187
1188struct OpSncEnvCpoisson {
1189 static Json run(Args& a) {
1190 const double lambda = a.number<double>("lambda"), mu = a.number<double>("mu");
1191 const double theta = a.number<double>("theta");
1192 a.done();
1193 return env_json(snc::snc_env_cpoisson(lambda, mu, theta));
1194 }
1195};
1196
1197/** [sigma,rho] = snc_env_tokenbucket(b, r, theta); theta is optional and only validated. */
1198struct OpSncEnvTokenbucket {
1199 static Json run(Args& a) {
1200 const double b = a.number<double>("b"), r = a.number<double>("r");
1201 const bool hasTheta = a.has("theta");
1202 const double theta = hasTheta ? a.number<double>("theta") : 0.0;
1203 a.done();
1204 return env_json(hasTheta ? snc::snc_env_tokenbucket(b, r, theta) : snc::snc_env_tokenbucket(b, r));
1205 }
1206};
1207
1208struct OpSncEnvMap {
1209 static Json run(Args& a) {
1210 const Matrix<double> D0 = a.matrix<double>("D0"), D1 = a.matrix<double>("D1");
1211 const double theta = a.number<double>("theta");
1212 a.done();
1213 return env_json(snc::snc_env_map(D0, D1, theta));
1214 }
1215};
1216
1217/** [sigma,rho] = snc_srv_rate(C, theta); theta is optional and only validated. */
1218struct OpSncSrvRate {
1219 static Json run(Args& a) {
1220 const double C = a.number<double>("C");
1221 const bool hasTheta = a.has("theta");
1222 const double theta = hasTheta ? a.number<double>("theta") : 0.0;
1223 a.done();
1224 return env_json(hasTheta ? snc::snc_srv_rate(C, theta) : snc::snc_srv_rate(C));
1225 }
1226};
1227
1228struct OpSncSrvExp {
1229 static Json run(Args& a) {
1230 const double mu = a.number<double>("mu"), theta = a.number<double>("theta");
1231 a.done();
1232 return env_json(snc::snc_srv_exp(mu, theta));
1233 }
1234};
1235
1236struct OpSncLeftover {
1237 static Json run(Args& a) {
1238 const snc::Env srv = read_env(a, "sigmaS", "rhoS");
1239 const snc::Env cross = read_env(a, "sigmaX", "rhoX");
1240 a.done();
1241 return env_json(snc::snc_leftover(srv, cross));
1242 }
1243};
1244
1245/** [sigma,rho] = snc_conv(sigma1,rho1,sigma2,rho2,theta,delta). */
1246struct OpSncConv {
1247 static Json run(Args& a) {
1248 const snc::Env s1 = read_env(a, "sigma1", "rho1");
1249 const snc::Env s2 = read_env(a, "sigma2", "rho2");
1250 const double theta = a.number<double>("theta");
1251 const bool hasDelta = a.has("delta");
1252 const double delta = hasDelta ? a.number<double>("delta") : 0.0;
1253 a.done();
1254 return env_json(hasDelta ? snc::snc_conv(s1, s2, theta, delta) : snc::snc_conv(s1, s2, theta));
1255 }
1256};
1257
1258struct OpSncOutput {
1259 static Json run(Args& a) {
1260 const snc::Env arv = read_env(a, "sigmaA", "rhoA");
1261 const snc::Env srv = read_env(a, "sigmaS", "rhoS");
1262 const double theta = a.number<double>("theta");
1263 a.done();
1264 return env_json(snc::snc_output(arv, srv, theta));
1265 }
1266};
1267
1268
1269/**
1270 * Q = ctmc_rand(n, seed). The uniforms come from mc::LcgUniform seeded by the
1271 * caller: its variates are dyadic rationals, so the exact arm returns the same
1272 * generator the double arm does, entry for entry. MATLAB draws from the session
1273 * RNG instead, so the matrices agree with it in law, not draw for draw.
1274 */
1275struct OpCtmcRand {
1276 template <class T>
1277 static Json run(Args& a) {
1278 const std::size_t n = a.count("n");
1279 mc::LcgUniform gen(required_seed(a, "ctmc_rand"));
1280 a.done();
1281 Json out;
1282 out["Q"] = encode_matrix(mc::ctmc_rand<T>(n, gen));
1283 return out;
1284 }
1285};
1286
1287/**
1288 * [soujt, sts] = ctmc_simulate(Q, pi0, n, seed). pi0 may be empty, which draws
1289 * the initial state the way the reference does; sts is 0-based.
1290 */
1291struct OpCtmcSimulate {
1292 template <class T>
1293 static Json run(Args& a) {
1294 const Matrix<T> Q = a.matrix<T>("Q");
1295 const std::vector<T> pi0 = a.vector_or_empty<T>("pi0");
1296 const std::size_t n = a.count("n");
1297 pfqn::McRng rng(required_seed(a, "ctmc_simulate"));
1298 a.done();
1299 const mc::CtmcPath<T> p = mc::ctmc_simulate(Q, pi0, n, rng);
1300 Json out;
1301 out["soujt"] = encode_vector(p.sojourn);
1302 out["sts"] = encode_indices(p.states);
1303 return out;
1304 }
1305};
1306
1307/** Qub = ctmc_stmonotone(Q) / Pub = dtmc_stmonotone(P): st-monotone upper bound. */
1308template <bool Dtmc>
1309struct OpStmonotone {
1310 template <class T>
1311 static Json run(Args& a) {
1312 const Matrix<T> M = a.matrix<T>(Dtmc ? "P" : "Q");
1313 a.done();
1314 Json out;
1315 out[Dtmc ? "Q" : "Qub"] = encode_matrix(Dtmc ? mc::dtmc_stmonotone(M) : mc::ctmc_stmonotone(M));
1316 return out;
1317 }
1318};
1319
1320} // namespace
1321
1323 // mc
1324 t["ctmc_stochcomp"] = make<OpCtmcStochcomp>();
1325 t["ctmc_uniformization"] = make<NeedsTranscendental<OpCtmcUniformization> >();
1326 t["ctmc_timeaverage"] = make<NeedsTranscendental<OpCtmcTimeaverage> >();
1327 t["ctmc_accumulated"] = make<NeedsTranscendental<OpCtmcAccumulated> >();
1332 t["ctmc_gth"] = make<OpGth<false> >();
1333 t["dtmc_gth"] = make<OpGth<true> >();
1334 t["ctmc_pseudostochcomp"] = make<OpCtmcPseudostochcomp>();
1335 t["ctmc_testpf_kolmogorov"] = make<OpCtmcTestpfKolmogorov>();
1336 t["ctmc_stmonotone"] = make<OpStmonotone<false> >();
1337 t["dtmc_stmonotone"] = make<OpStmonotone<true> >();
1338 t["ctmc_cesaro"] = make<OpCesaro<false> >();
1339 t["dtmc_cesaro"] = make<OpCesaro<true> >();
1340 t["ctmc_ssd"] = make<DoubleOnly<OpSsd> >();
1341 t["dtmc_ssd"] = make<DoubleOnly<OpSsd> >();
1342 t["ctmc_memory_gate"] = make<NeedsTranscendental<OpCtmcMemoryGate> >();
1343 t["ctmc_isfeasible"] = make<OpCtmcIsfeasible>();
1344 t["ctmc_hitting_time"] = make<NeedsTranscendental<OpCtmcHittingTime> >();
1345 // The registry lists Exact for dtmc_hitting_time, but the port static_asserts
1346 // an arithmetic with an infinity (an unreachable state's time is Inf), so the
1347 // exact arm is refused with that reason instead of failing to compile.
1348 t["dtmc_hitting_time"] = make<NeedsTranscendental<OpDtmcHittingTime> >();
1349 t["dtmc_transient"] = make<OpDtmcTransient>();
1350 t["ctmc_passage_ph"] = make<OpCtmcPassagePh>();
1351 t["ctmc_passage_lst"] = make<NeedsTranscendental<OpCtmcPassageLst> >();
1352 t["ctmc_passage_moments"] = make<NeedsTranscendental<OpCtmcPassageMoments> >();
1353 t["ctmc_passage_time"] = make<NeedsTranscendental<OpCtmcPassageTime> >();
1354 t["ctmc_passage_taboo"] = make<NeedsTranscendental<OpCtmcPassageTaboo> >();
1355 t["ctmc_passage_taboo_moments"] = make<NeedsTranscendental<OpCtmcPassageTabooMoments> >();
1356 // dpfqn
1357 t["dpfqn_nc"] = make<OpDpfqnNc>();
1358 t["dpfqn_ncld"] = make<OpDpfqnNcld>();
1359 // npfqn
1360 t["npfqn_traffic_idc"] = make<OpNpfqnTrafficIdc>();
1361 t["npfqn_traffic_split_cs"] = make<OpNpfqnTrafficSplitCs>();
1362 t["npfqn_traffic_merge_cs"] = make<OpNpfqnTrafficMergeCs>();
1363 t["npfqn_traffic_merge"] = make<NeedsTranscendental<OpNpfqnTrafficMerge> >();
1364 t["npfqn_rqna_weight"] = make<NeedsTranscendental<OpNpfqnRqnaWeight> >();
1365 t["npfqn_traffic_rqt"] = make<NeedsTranscendental<OpNpfqnTrafficRqt> >();
1366 t["npfqn_bnd_bpt"] = make<OpNpfqnBndBpt>();
1367 t["npfqn_bnd_bgt"] = make<OpNpfqnBndBgt>();
1368 t["npfqn_nonexp_approx"] = make<NeedsTranscendental<OpNpfqnNonexpApprox> >();
1369 t["npfqn_sqd"] = make<NeedsTranscendental<OpNpfqnSqd> >();
1370 t["npfqn_dps_morrison"] = make<NeedsTranscendental<OpNpfqnDpsMorrison> >();
1371 t["npfqn_feedback_elim"] = make<OpNpfqnFeedbackElim>();
1372 // snc (double-only kernels)
1373 t["snc_env_poisson"] = make<DoubleOnly<OpSncEnvPoisson> >();
1374 t["snc_env_cpoisson"] = make<DoubleOnly<OpSncEnvCpoisson> >();
1375 t["snc_env_tokenbucket"] = make<DoubleOnly<OpSncEnvTokenbucket> >();
1376 t["snc_env_map"] = make<DoubleOnly<OpSncEnvMap> >();
1377 t["snc_srv_rate"] = make<DoubleOnly<OpSncSrvRate> >();
1378 t["snc_srv_exp"] = make<DoubleOnly<OpSncSrvExp> >();
1379 t["snc_leftover"] = make<DoubleOnly<OpSncLeftover> >();
1380 t["snc_conv"] = make<DoubleOnly<OpSncConv> >();
1381 t["snc_output"] = make<DoubleOnly<OpSncOutput> >();
1382 t["ctmc_rand"] = make<OpCtmcRand>();
1383 t["ctmc_simulate"] = make<NeedsTranscendental<OpCtmcSimulate> >();
1384}
1385
1387 const std::string sn =
1388 "it takes a NetworkStruct; build the model and run line-cli -s ctmc -a <analysis> "
1389 "on it instead.";
1390 t["ctmc_ssg"] = sn;
1391 t["ctmc_ssg_reachability"] = sn;
1392 t["ctmc_state_space_logsize"] = sn;
1393 t["npfqn_traffic_split_rr"] =
1394 "it takes a NetworkStruct; build the model and run line-cli -s <solver> -a <analysis> "
1395 "on it instead.";
1396 t["npfqn_traffic_idc_at"] =
1397 "it evaluates two caller-supplied IDC functions (a0IdcFun and sIdcFun), which are "
1398 "callables with no JSON form.";
1399 const std::string env =
1400 "its arrival and service envelopes are functions of theta (e.g. snc_env_poisson as a "
1401 "handle), callables with no JSON form; the envelope values at one theta are exposed "
1402 "through the snc_env_* and snc_srv_* entries.";
1403 t["snc_bound_backlog"] = env;
1404 t["snc_bound_delay"] = env;
1405 t["snc_perc_backlog"] = env;
1406 t["snc_perc_delay"] = env;
1407 t["snc_mean_backlog"] = env;
1408 t["snc_mean_delay"] = env;
1409 t["snc_thetaopt"] =
1410 "its objective is a function of theta passed as a callable, which has no JSON form.";
1411 const std::string cosimla =
1412 "its transition function (successors and probabilities or rates of a state) and its "
1413 "reward function are callables with no JSON form.";
1414 t["ctmc_cosimla"] = cosimla;
1415 t["dtmc_cosimla"] = cosimla;
1416 t["ctmc_hitting_dist"] =
1417 "its transition function, target predicate and change of measure are callables with no "
1418 "JSON form in its function form, and its seeded estimator option set and result record "
1419 "have no JSON spelling yet.";
1420}
1421
1422} // namespace reg
1423} // namespace line
Internal to the –api dispatcher: what a per-domain translation unit needs to add entries to the table...
#define LINE_MC_AUX(f)
InputError(const std::string &what)
Definition error.h:105
Named-argument reader over the parsed JSON object.
Definition api_json.h:391
Accumulated state probabilities L(t) = int_0^t pi(s) ds of a CTMC by uniformisation (Reibman and Triv...
Classical stationary iterative solvers for pi Q = 0, sum(pi) = 1: the power method on the uniformised...
Grassmann-Taksar-Heyman (GTH) elimination for the stationary vector, and the limit matrix J = lim exp...
Feasibility predicates for generators and stochastic matrices.
Host-aware memory pre-gate for SolverCTMC.
First passage times into a target STATE SET, for Markov and semi-Markov chains.
Pseudo stochastic complement of a CTMC partition.
Random infinitesimal generator of a CTMC.
Sample path of a continuous-time Markov chain given its generator.
Stochastically stable distribution of a perturbed Markov chain (Wicks 2009).
Stochastically monotone upper bound of a Markov chain.
Kolmogorov reversibility criterion, used as a product-form test.
Transient distribution of a CTMC by uniformization (Jensen's method), and the time-averaged distribut...
Normalizing constants of a discrete-time closed cycle of Bernoulli servers.
Equilibrium distribution of a discrete-time Markov chain, and stochastic complementation.
Discrete-time transient distributions, hitting times and uniformization.
DtNcLdResult< T > dpfqn_ncld(const std::vector< std::vector< T > > &P, std::size_t N)
Theorem 3.2 for a cycle whose service probabilities depend on the local queue length.
Definition dpfqn_nc.h:205
DtNcResult< T > dpfqn_nc(const std::vector< T > &p, std::size_t N)
Propositions 3.18 and 3.19 for a cycle with state independent service probabilities.
Definition dpfqn_nc.h:113
double z(double v)
Definition lqn_focus.h:261
double delta(double t)
Matrix< T > dtmc_stmonotone(const Matrix< T > &P)
std::vector< std::complex< double > > ctmc_passage_lst(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target, const std::vector< std::complex< double > > &s)
L(s) = alpha (sI-S)^{-1} s0 + atom at the (complex) points s.
PassageMoments< T > ctmc_passage_moments(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target, std::size_t nmax=1)
Moments of order 1..nmax of the first passage time into target.
Matrix< T > ctmc_cesaro(const Matrix< T > &Q)
Limit matrix J = lim expm(Q t) of any finite CTMC (Agaev-Chebotarev 2000).
Definition ctmc_gth.h:180
std::vector< double > ctmc_ssd(const Matrix< double > &Cin, const Matrix< double > &Rin)
Stochastically stable distribution, rates C(i,j) eps^R(i,j) (Wicks 2009).
Definition ctmc_ssd.h:216
StochCompResult< T > ctmc_stochcomp(const Matrix< T > &Q, const std::vector< std::size_t > &I)
Definition dtmc_solve.h:158
CtmcGateResult ctmc_memory_gate(double log_nstates, bool force=false, double safety_fraction=CTMC_DEFAULT_SAFETY_FRACTION, bool verbose=false)
Decide whether a state space of log-size log_nstates can be solved here.
UniformizationResult< T > ctmc_uniformization(const std::vector< T > &pi0, const Matrix< T > &Q, const T &t, double tol=1e-12, long maxiter=-1)
Transient distribution of a CTMC by uniformization (Jensen's method), and the time-averaged distribut...
PassageCurve< T > ctmc_passage_time(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target, const std::vector< double > &tset, const std::string &method="expm", const std::string &lti_method="euler")
CDF and density of the first passage time on the grid tset: F(t) = 1 - alpha exp(St) 1 and f(t) = alp...
Matrix< T > ctmc_rand(std::size_t n, Gen &gen)
Random infinitesimal generator of a CTMC.
Definition ctmc_rand.h:71
std::vector< T > dtmc_hitting_time(const Matrix< T > &P, const std::vector< std::size_t > &target)
Expected number of steps to reach the target set, zero on the target set itself.
TimeAverageResult< T > ctmc_timeaverage(const std::vector< T > &pi0, const Matrix< T > &Q, const T &t, double tol=1e-12, long maxiter=-1)
Time-averaged distribution (1/t) int_0^t pi(u) du, plus pi(t) itself.
GthResult< T > ctmc_gth_flag(const Matrix< T > &Q)
Stationary vector of a CTMC by GTH elimination, with a flag.
Definition ctmc_gth.h:135
PassagePh< T > ctmc_passage_ph(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target)
Phase-type representation of the first passage time from pi0 into target.
bool ctmc_isfeasible(const Matrix< T > &Q, const T &tol)
True when Q is square, has nonnegative off-diagonals, nonpositive diagonal and zero row sums.
constexpr long CLASSICAL_DEFAULT_MAXITER
PseudoStochCompResult< T > ctmc_pseudostochcomp(const Matrix< T > &Q, const std::vector< std::size_t > &keep)
Pseudo stochastic complement of a CTMC partition.
bool ctmc_testpf_kolmogorov(const Matrix< T > &Qin)
Kolmogorov reversibility criterion, used as a product-form test.
Matrix< T > ctmc_stmonotone(const Matrix< T > &Q)
Stochastically monotone upper bound of a Markov chain.
PassageTabooMoments< T > ctmc_passage_taboo_moments(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target, const std::vector< std::size_t > &taboo, std::size_t nmax=1)
Moments of order 1..nmax of the first passage time into target, CONDITIONAL on entering it before tab...
CtmcPath< T > ctmc_simulate(const Matrix< T > &Q, const std::vector< T > &pi0, std::size_t n, pfqn::McRng &rng)
Simulate n steps of the CTMC with generator Q.
PassageTaboo< T > ctmc_passage_taboo(const Matrix< T > &Q, const std::vector< T > &pi0, const std::vector< std::size_t > &target, const std::vector< std::size_t > &taboo, const std::vector< double > &tset=std::vector< double >(), const std::string &method="expm", const std::string &lti_method="euler")
First passage into target under the taboo set taboo, the reference's ctmc_passage_taboo.
Matrix< T > dtmc_transient(const Matrix< T > &P, const std::vector< T > &pi0, std::size_t steps)
Trajectory of the law over steps transitions, row k holding pi0 P^k.
std::vector< T > ctmc_hitting_time(const Matrix< T > &Q, const std::vector< std::size_t > &target)
Mean time to reach any state in target from each state of a CTMC.
AccumulatedResult< T > ctmc_accumulated(const std::vector< T > &pi0, const Matrix< T > &Q, const std::vector< T > &t, double tol=1e-12, long maxiter=-1)
Accumulated state probabilities int_0^t pi(s) ds at each time point.
constexpr double CLASSICAL_DEFAULT_TOL
Merge
Merge rule, MATLAB's config.merge.
@ Interpos
'interpos', lumped interleaving of per-flow M3PP(2, m) fits
@ Default
'default', identical to 'super'
@ Mixture
'mixture', superpose then refit with mmap_mixture_fit_mmap
TrafficIdcContext< T > npfqn_traffic_idc(const std::vector< T > &lambda0, const Matrix< T > &P, const std::vector< T > &c2a0, const std::vector< T > &mu, const std::vector< T > &cs2, const TrafficIdcCorrections &corrections)
Traffic variability equations of the Robust Queueing Network Analyzer (W.
T npfqn_rqna_weight(const T &t)
Canonical reflected-Brownian-motion correlation weight w*(t) used by the Robust Queueing Network Anal...
SqdResult< T > npfqn_sqd(const std::vector< T > &ST, const std::vector< T > &V, const std::vector< T > &cap, const std::vector< bool > &isDelay, const Matrix< T > &rt, const std::vector< std::size_t > &stationToStateful, std::size_t nclasses, int N, const SqdOptions< T > &opt)
Smith Queue Decomposition (SQD): approximate MVA for closed networks under Blocking-After-Service (ma...
Definition npfqn_sqd.h:432
NonexpApproxResult< T > npfqn_nonexp_approx(const std::string &method, const std::vector< bool > &isFCFS, const Matrix< T > &rates, const Matrix< T > &ST, const Matrix< T > &V, const Matrix< T > &SCV, const Matrix< T > &Tput, const Matrix< T > &U, const std::vector< T > &gamma, const std::vector< T > &nservers)
Handler for non-exponential service and arrival processes in AMVA and NC.
mam::Mmap< T > npfqn_traffic_merge_cs(const std::vector< mam::Mmap< T > > &flows, const Matrix< T > &prob, Merge merge=Merge::Default)
Merge flows that switch class on departure.
std::vector< Mmap< T > > npfqn_traffic_split_cs(const Mmap< T > &MMAP, const Matrix< T > &P)
Splitting of a marked MAP departure flow with class switching.
FeedbackElimResult< T > npfqn_feedback_elim(const Matrix< T > &P, const std::vector< T > &rho, const std::vector< T > &cs2=std::vector< T >(), const std::vector< T > &lambda=std::vector< T >(), bool immediateOnly=false)
Near-immediate feedback elimination for the robust queueing network analyzer.
BndBpt< T > npfqn_bnd_bpt(const std::vector< T > &lambda0, const std::vector< T > &mu, const Matrix< T > &P, const std::vector< std::size_t > &stationOf, const std::vector< T > &c)
First-order linear-programming relaxation of the achievable region of a multiclass open Markovian que...
TrafficRqt< T > npfqn_traffic_rqt(const std::vector< T > &lambda0, const std::vector< T > &Gamma0, const std::vector< T > &alpha0, const Matrix< T > &F)
Effective arrival processes of a network under the Robust Queueing calculus.
Compress
Post-merge compression, MATLAB's config.compress.
@ Default
'default', mmap_compress with its own default method
std::vector< Matrix< T > > Mmap
An MMAP as the MATLAB cell {D0, D1, D1^(1), ..., D1^(R)}.
BndBgt< T > npfqn_bnd_bgt(const std::vector< T > &lambda, const std::vector< std::vector< T > > &mu, const std::vector< std::vector< std::size_t > > &sigma, std::size_t J)
Piecewise-linear Lyapunov UPPER bound on the steady-state queue lengths of a multitype (deterministic...
DpsMorrisonResult< T > npfqn_dps_morrison(const std::vector< T > &N, const std::vector< T > &Z, const std::vector< T > &S, const std::vector< T > &w)
Evaluates Morrison's two-term approximation.
mam::Mmap< T > npfqn_traffic_merge(const std::vector< mam::Mmap< T > > &flows, const MergeConfig &config=MergeConfig())
Merge a list of MMAPs carrying the same classes.
std::mt19937_64 McRng
The generator type every Monte Carlo entry point in this tree accepts.
nlohmann::json Json
Definition api_json.h:63
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.
Definition api_json.h:366
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,...
Definition api_json.h:223
Json encode_matrices(const std::vector< Matrix< T > > &v)
A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.
Definition api_json.h:358
void register_library_only_mc(LibraryOnlyTable &t)
T number_from_json(const Json &j, const std::string &where)
Definition api_json.h:210
std::vector< T > vector_from_json(const Json &j, const std::string &where)
A flat numeric vector: 1-D array, or a 1-row / 1-column 2-D array.
Definition api_json.h:255
Json encode_vector(const std::vector< T > &v)
Definition api_json.h:333
Json encode_matrix(const Matrix< T > &m)
Definition api_json.h:340
std::string decimal_text(const Json &j, const std::string &where)
The decimal literal behind a JSON scalar, per the policy in the file header.
Definition api_json.h:199
void register_api_mc(DispatchTable &t)
Json encode_scalar(const T &v)
Definition api_json.h:328
Json encode_count(std::size_t n)
A count.
Definition api_json.h:378
std::map< std::string, std::string > LibraryOnlyTable
name -> why the function has no named-JSON-argument form.
std::map< std::string, Invoker > DispatchTable
Env snc_leftover(const Env &srv, const Env &cross)
Leftover service envelope under blind (arbitrary) multiplexing.
Env snc_conv(const Env &s1, const Env &s2, double theta, double delta=-1.0)
Min-plus convolution of two service envelopes (tandem concatenation).
Definition snc_conv.h:49
Env snc_output(const Env &arv, const Env &srv, double theta)
Output (departure) arrival envelope of a flow leaving a server.
Definition snc_output.h:40
Env snc_srv_exp(double mu, double theta)
MGF service envelope of an exponential server, in JOB units.
Definition snc_srv_exp.h:46
Env snc_env_map(const Matrix< double > &D0, const Matrix< double > &D1, double theta)
MGF arrival envelope of a MAP/MMPP flow with unit-size jobs.
Definition snc_env_map.h:56
Env snc_srv_rate(double C)
MGF service envelope of a constant-rate work-conserving server.
Env snc_env_tokenbucket(double b, double r)
Deterministic token-bucket arrival envelope.
Env snc_env_poisson(double lambda, double theta)
MGF arrival envelope of a Poisson flow with unit-size jobs.
Env snc_env_cpoisson(double lambda, double mu, double theta)
MGF arrival envelope of a compound Poisson flow with Exp job sizes.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Piecewise-linear Lyapunov UPPER bound on the steady-state queue lengths of a multitype (deterministic...
First-order linear-programming relaxation of the achievable region of a multiclass open Markovian que...
Two-term heavy-usage asymptotic approximation for a closed queueing network with one infinite-server ...
Near-immediate feedback elimination for the robust queueing network analyzer.
Handler for non-exponential service and arrival processes in AMVA and NC.
Canonical reflected-Brownian-motion correlation weight w*(t) used by the Robust Queueing Network Anal...
Smith Queue Decomposition (SQD): approximate MVA for closed networks under Blocking-After-Service (ma...
Traffic variability equations of the Robust Queueing Network Analyzer (W.
Superposition of several marked arrival flows into one.
Merge of marked arrival flows with class switching.
Effective arrival processes of a network under the Robust Queueing calculus.
Splitting of a marked MAP departure flow with class switching.
Min-plus convolution of two service envelopes (tandem concatenation).
MGF arrival envelope of a compound Poisson flow with Exp job sizes.
MGF arrival envelope of a MAP/MMPP flow with unit-size jobs.
MGF arrival envelope of a Poisson flow with unit-size jobs.
Deterministic token-bucket arrival envelope.
Leftover service envelope under blind (arbitrary) multiplexing.
Output (departure) arrival envelope of a flow leaving a server.
MGF service envelope of an exponential server, in JOB units.
MGF service envelope of a constant-rate work-conserving server.