5#ifndef LINE_IO_NETWORK_READER_H
6#define LINE_IO_NETWORK_READER_H
54using json = nlohmann::json;
84inline double num_from_json(
const json& v) {
85 if (v.is_null())
return std::numeric_limits<double>::quiet_NaN();
87 const std::string s = v.get<std::string>();
88 if (s ==
"Infinity" || s ==
"inf" || s ==
"Inf")
89 return std::numeric_limits<double>::infinity();
90 if (s ==
"-Infinity" || s ==
"-inf" || s ==
"-Inf")
91 return -std::numeric_limits<double>::infinity();
92 if (s ==
"NaN" || s ==
"nan")
return std::numeric_limits<double>::quiet_NaN();
95 const char* begin = s.c_str();
97 const double parsed = std::strtod(begin, &end);
98 if (end == begin || *end !=
'\0')
99 throw InputError(ErrorKind{
"Format"},
"network_reader: expected a number, got the string '" + s +
"'");
102 if (v.is_boolean())
return v.get<
bool>() ? 1.0 : 0.0;
105 return v.get<
double>();
109inline double num_value(
const json& obj,
const char* key,
double def) {
110 return obj.contains(key) ? num_from_json(obj.at(key)) : def;
119inline std::function<double(
double)> fluiddep_table_to_fun(
const json& lv,
const json& vv,
const std::string& who) {
120 std::vector<double> levels, values;
121 for (
const json& x : lv) levels.push_back(num_from_json(x));
122 for (
const json& x : vv) values.push_back(num_from_json(x));
123 if (levels.empty() || levels.size() != values.size())
124 throw InputError(ErrorKind{
"Format"},
"network_reader: the fluid rate dependence of " + who +
125 " needs as many 'values' as 'levels', and at least one");
126 for (std::size_t i = 0; i < levels.size(); ++i) {
127 if (!std::isfinite(levels[i]) || !std::isfinite(values[i]) || (i > 0 && levels[i] <= levels[i - 1]))
128 throw InputError(ErrorKind{
"Format"},
"network_reader: the fluid rate dependence of " + who +
129 " needs finite values over strictly increasing finite levels");
131 if (levels.size() == 1) {
132 const double v = values[0];
133 return [v](double) {
return v; };
135 return [levels, values](
double f) {
136 const double x = std::min(std::max(f, levels.front()), levels.back());
137 std::size_t hi =
static_cast<std::size_t
>(std::upper_bound(levels.begin(), levels.end(), x) - levels.begin());
138 if (hi >= levels.size()) hi = levels.size() - 1;
140 const std::size_t lo = hi - 1;
141 const double w = (x - levels[lo]) / (levels[hi] - levels[lo]);
142 return values[lo] + w * (values[hi] - values[lo]);
154inline std::size_t fork_dest_index(
const json& ov,
155 const std::map<std::string, std::size_t>& node_idx,
156 const std::string& fork_name) {
157 if (!ov.contains(
"dest"))
return 0;
158 const std::string d = ov.at(
"dest").get<std::string>();
159 if (d.empty())
return 0;
160 const std::map<std::string, std::size_t>::const_iterator it = node_idx.find(d);
161 if (it == node_idx.end())
162 throw InputError(ErrorKind{
"Format"},
"network_reader: the Fork node '" + fork_name +
163 "' declares an override towards '" + d +
"', which is not a node");
170 if (s ==
"INF" || s ==
"inf")
return S::INF;
171 if (s ==
"FCFS" || s ==
"fcfs")
return S::FCFS;
172 if (s ==
"PS" || s ==
"ps")
return S::PS;
173 if (s ==
"LCFS" || s ==
"lcfs")
return S::LCFS;
174 if (s ==
"LCFSPR" || s ==
"lcfspr")
return S::LCFSPR;
175 if (s ==
"SIRO" || s ==
"siro")
return S::SIRO;
176 if (s ==
"HOL" || s ==
"hol")
return S::HOL;
177 if (s ==
"DPS" || s ==
"dps")
return S::DPS;
178 if (s ==
"GPS" || s ==
"gps")
return S::GPS;
179 if (s ==
"SEPT" || s ==
"sept")
return S::SEPT;
180 if (s ==
"LEPT" || s ==
"lept")
return S::LEPT;
181 if (s ==
"SJF" || s ==
"sjf")
return S::SJF;
182 if (s ==
"LJF" || s ==
"ljf")
return S::LJF;
183 if (s ==
"SRPT" || s ==
"srpt")
return S::SRPT;
184 if (s ==
"LPS" || s ==
"lps")
return S::LPS;
185 if (s ==
"POLLING" || s ==
"polling")
return S::POLLING;
191 if (s ==
"FCFSPR" || s ==
"fcfspr")
return S::FCFSPR;
192 if (s ==
"FCFSPI" || s ==
"fcfspi")
return S::FCFSPI;
193 if (s ==
"FCFSPRIO" || s ==
"fcfsprio")
return S::HOL;
194 if (s ==
"FCFSPRPRIO" || s ==
"fcfsprprio")
return S::FCFSPRPRIO;
195 if (s ==
"FCFSPIPRIO" || s ==
"fcfspiprio")
return S::FCFSPIPRIO;
196 if (s ==
"LCFSPI" || s ==
"lcfspi")
return S::LCFSPI;
197 if (s ==
"LCFSPRIO" || s ==
"lcfsprio")
return S::LCFSPRIO;
198 if (s ==
"LCFSPRPRIO" || s ==
"lcfsprprio")
return S::LCFSPRPRIO;
199 if (s ==
"LCFSPIPRIO" || s ==
"lcfspiprio")
return S::LCFSPIPRIO;
200 if (s ==
"PSPRIO" || s ==
"psprio")
return S::PSPRIO;
201 if (s ==
"DPSPRIO" || s ==
"dpsprio")
return S::DPSPRIO;
202 if (s ==
"GPSPRIO" || s ==
"gpsprio")
return S::GPSPRIO;
203 if (s ==
"SRPT" || s ==
"srpt")
return S::SRPT;
204 if (s ==
"SRPTPRIO" || s ==
"srptprio")
return S::SRPTPRIO;
205 if (s ==
"PSJF" || s ==
"psjf")
return S::PSJF;
206 if (s ==
"FB" || s ==
"fb")
return S::FB;
207 if (s ==
"LAS" || s ==
"las")
return S::LAS;
208 if (s ==
"LRPT" || s ==
"lrpt")
return S::LRPT;
209 if (s ==
"SETF" || s ==
"setf")
return S::SETF;
210 if (s ==
"FSP" || s ==
"fsp")
return S::FSP;
211 if (s ==
"EDD" || s ==
"edd")
return S::EDD;
212 if (s ==
"EDF" || s ==
"edf")
return S::EDF;
213 if (s ==
"PAS" || s ==
"pas")
return S::PAS;
214 if (s ==
"OI" || s ==
"oi")
return S::OI;
215 if (s ==
"RR" || s ==
"rr")
return S::RR;
216 if (s ==
"REF" || s ==
"ref")
return S::REF;
217 if (s ==
"EXT" || s ==
"ext")
return S::EXT;
218 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported scheduling discipline '" + s +
"'");
225 if (s ==
"drop")
return D::DROP;
226 if (s ==
"waitingQueue")
return D::WAITQ;
227 if (s ==
"blockingAfterService")
return D::BAS;
228 if (s ==
"retrial")
return D::RETRIAL;
229 if (s ==
"retrialWithLimit")
return D::RETRIAL_WITH_LIMIT;
235 if (s ==
"RR" || s ==
"rr")
return R::RR;
236 if (s ==
"FIFO" || s ==
"fifo")
return R::FIFO;
237 if (s ==
"SFIFO" || s ==
"sfifo")
return R::SFIFO;
238 if (s ==
"LRU" || s ==
"lru")
return R::LRU;
239 if (s ==
"HLRU" || s ==
"hlru")
return R::HLRU;
240 if (s ==
"CLIMB" || s ==
"climb")
return R::CLIMB;
241 if (s ==
"QLRU" || s ==
"qlru")
return R::QLRU;
242 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported cache replacement strategy '" + s +
"'");
247 if (s ==
"GATED" || s ==
"gated")
return P::GATED;
248 if (s ==
"EXHAUSTIVE" || s ==
"exhaustive")
return P::EXHAUSTIVE;
249 if (s ==
"KLIMITED" || s ==
"klimited" || s ==
"K-LIMITED")
return P::KLIMITED;
250 if (s ==
"DECREMENTING" || s ==
"decrementing")
return P::DECREMENTING;
251 if (s ==
"GLIMITED" || s ==
"glimited" || s ==
"G-LIMITED")
return P::GLIMITED;
252 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported polling type '" + s +
"'");
257 if (s ==
"CYCLIC" || s ==
"cyclic")
return O::CYCLIC;
258 if (s ==
"SKIPEMPTY" || s ==
"skipempty")
return O::SKIPEMPTY;
259 if (s ==
"LQF" || s ==
"lqf")
return O::LQF;
260 if (s ==
"THRESHOLD" || s ==
"threshold")
return O::THRESHOLD;
261 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported polling order '" + s +
"'");
266 if (s ==
"NONE" || s ==
"none")
return P::NONE;
267 if (s ==
"LOCAL" || s ==
"local")
return P::LOCAL;
268 if (s ==
"GLOBAL" || s ==
"global")
return P::GLOBAL;
269 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported polling timer scope '" + s +
"'");
279lang::Distrib<T> hyperexp_fit_mean_scv(
double mean,
double scv) {
281 throw InputError(ErrorKind{
"Format"},
"network_reader: HyperExp fitMeanAndSCV needs SCV >= 1, got " +
282 std::to_string(scv));
283 const double p = 0.5 * (1.0 + std::sqrt((scv - 1.0) / (scv + 1.0)));
284 const double mu1 = 2.0 * p / mean;
285 const double mu2 = 2.0 * (1.0 - p) / mean;
287 num_traits<T>::from_double(mu1),
288 num_traits<T>::from_double(mu2));
301inline bool has_cache_key(
const json& nd,
const json& cj,
const char* key) {
302 return nd.contains(key) || cj.contains(key);
304inline const json& cache_key(
const json& nd,
const json& cj,
const char* key) {
305 return nd.contains(key) ? nd.at(key) : cj.at(key);
311 if (s ==
"PROB")
return R::PROB;
312 if (s ==
"RAND")
return R::RAND;
313 if (s ==
"RROBIN")
return R::RROBIN;
314 if (s ==
"WRROBIN")
return R::WRROBIN;
315 if (s ==
"JSQ")
return R::JSQ;
316 if (s ==
"SQ" || s ==
"KCHOICES")
return R::SQ;
319 if (s ==
"SDR")
return R::SDR;
320 if (s ==
"FIRING")
return R::FIRING;
321 if (s ==
"DISABLED")
return R::DISABLED;
322 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported routing strategy '" + s +
"'");
328 if (s ==
"RENEGING")
return I::RENEGING;
329 if (s ==
"BALKING")
return I::BALKING;
330 if (s ==
"RETRIAL")
return I::RETRIAL;
331 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported impatience type '" + s +
"'");
337 if (s ==
"QUEUE_LENGTH")
return B::QUEUE_LENGTH;
338 if (s ==
"EXPECTED_WAIT")
return B::EXPECTED_WAIT;
339 if (s ==
"COMBINED")
return B::COMBINED;
340 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported balking strategy '" + s +
"'");
346 if (s ==
"ORDER")
return H::ORDER;
347 if (s ==
"ALIS")
return H::ALIS;
348 if (s ==
"ALFS")
return H::ALFS;
349 if (s ==
"FAIRNESS")
return H::FAIRNESS;
350 if (s ==
"FSF")
return H::FSF;
351 if (s ==
"RAIS")
return H::RAIS;
352 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported heterogeneous scheduling policy '" + s +
"'");
359 for (
char& ch : u) ch =
static_cast<char>(std::toupper(
static_cast<unsigned char>(ch)));
362 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported departure discipline '" + s +
"'");
367std::vector<T> num_vec_from_json(
const json& v) {
374 for (
const json& x : v) out.push_back(num_traits<T>::from_double(num_from_json(x)));
376 out.push_back(num_traits<T>::from_double(num_from_json(v)));
382Matrix<T> mat_from_json(
const json& v) {
384 throw InputError(ErrorKind{
"Format"},
"network_reader: expected an array of rows");
385 Matrix<T> M(v.size(), v.empty() ? 0 : v.at(0).size());
386 for (std::size_t i = 0; i < v.size(); ++i) {
387 const json& row = v.at(i);
388 for (std::size_t j = 0; j < row.size(); ++j)
389 M(i, j) = num_traits<T>::from_double(num_from_json(row.at(j)));
396std::vector<Matrix<T> > mat_list_from_json(
const json& v) {
397 std::vector<Matrix<T> > out;
398 for (
const json& m : v) out.push_back(mat_from_json<T>(m));
404lang::Distrib<T> dist_from_fit(
const std::string& type,
const json& fit) {
405 const std::string method = fit.at(
"method").get<std::string>();
406 if (method ==
"fitMean" || method ==
"fitMeanAndOrder") {
407 const double mean = fit.at(
"mean").get<
double>();
409 if (type ==
"Erlang") {
410 const long order = fit.contains(
"order") ? fit.at(
"order").get<
long>() : 1L;
411 const T rate = num_traits<T>::from_double(
double(order) / mean);
417 if (method ==
"fitMeanAndSCV") {
418 const double mean = fit.at(
"mean").get<
double>();
419 const double scv = fit.at(
"scv").get<
double>();
420 if (type ==
"Erlang")
422 num_traits<T>::from_double(scv));
423 if (type ==
"HyperExp")
return hyperexp_fit_mean_scv<T>(mean, scv);
424 if (std::fabs(scv - 1.0) < 1e-12)
426 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: fitMeanAndSCV for family '" + type +
427 "' is not reconstructed; use explicit params");
429 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported fit method '" + method +
"' for '" + type +
435lang::Distrib<T> dist_from_json(
const json& obj) {
436 const std::string type = obj.at(
"type").get<std::string>();
450 if (type ==
"Prior") {
451 const std::string kind =
452 obj.contains(
"kind") ? obj.at(
"kind").get<std::string>() : std::string(
"discrete");
453 if (kind !=
"discrete" && kind !=
"continuous")
454 throw InputError(ErrorKind{
"Format"},
"network_reader: a Prior's 'kind' is 'discrete' or 'continuous', got '" +
456 if (kind ==
"continuous") {
457 if (!obj.contains(
"paramDist") || !obj.contains(
"factory"))
459 "network_reader: a continuous Prior carries 'paramDist' and 'factory' (a "
460 "template distribution plus the parameter slots it fills)");
461 const json& fac = obj.at(
"factory");
462 if (!fac.contains(
"template") || !fac.contains(
"slots"))
464 "network_reader: a continuous Prior's 'factory' carries 'template' and "
466 const json tmpl = fac.at(
"template");
467 std::vector<std::string> slots;
468 for (
const json& s : fac.at(
"slots")) slots.push_back(s.get<std::string>());
471 "network_reader: a continuous Prior's factory names no parameter slot, so the "
472 "parameter would not reach the distribution it builds");
473 if (!tmpl.contains(
"params"))
475 "network_reader: a continuous Prior's factory template carries its parameters "
476 "as 'params'; a fitted or phase-type representation has no named slot");
477 for (std::size_t l = 0; l < slots.size(); ++l)
478 if (!tmpl.at(
"params").contains(slots[l]))
479 throw InputError(ErrorKind{
"Format"},
"network_reader: a continuous Prior's factory names '" +
480 slots[l] +
"' as a parameter slot, but its template has no "
486 const std::function<lang::Distrib<T>(
const T&)> factory =
487 [tmpl, slots](
const T& theta) {
489 for (std::size_t l = 0; l < slots.size(); ++l)
490 j[
"params"][slots[l]] = num_traits<T>::to_double(theta);
491 return dist_from_json<T>(j);
495 if (!obj.contains(
"distributions") || !obj.contains(
"probabilities"))
496 throw InputError(ErrorKind{
"Format"},
497 "network_reader: a discrete Prior carries 'distributions' and 'probabilities'");
498 std::vector<lang::Distrib<T> > alts;
499 for (
const json& a : obj.at(
"distributions")) alts.push_back(dist_from_json<T>(a));
500 std::vector<T> probs;
501 for (
const json& p : obj.at(
"probabilities"))
502 probs.push_back(num_traits<T>::from_double(p.get<
double>()));
512 if (type ==
"NNPP") {
513 const json& p = obj.contains(
"params") ? obj.at(
"params") : obj;
514 const json& rate = p.at(
"rate");
515 auto vec = [](
const json& a) {
516 std::vector<double> v;
518 v.push_back(a.get<
double>());
521 for (
const json& x : a) v.push_back(x.get<
double>());
524 const double disp = p.contains(
"dispersion") ? p.at(
"dispersion").get<
double>() : 1.0;
525 const bool cyc = !p.contains(
"cyclic") || p.at(
"cyclic").get<
bool>();
526 const int Q = p.contains(
"Q") ? p.at(
"Q").get<
int>() : 200;
527 const std::string kind = rate.at(
"kind").get<std::string>();
528 if (kind ==
"eptmp") {
529 if (!p.contains(
"horizon"))
530 throw InputError(ErrorKind{
"Format"},
"network_reader: an eptmp NNPP needs a 'horizon'");
532 vec(rate.at(
"omega")), vec(rate.at(
"phi")),
533 p.at(
"horizon").get<
double>(), disp, cyc, Q);
535 if (kind ==
"pwlinear") {
536 const std::vector<double> times = vec(rate.at(
"times"));
537 if (p.contains(
"horizon") && !times.empty()) {
538 const double S = p.at(
"horizon").get<
double>();
539 if (std::abs(S - times.back()) > 1e-9 * std::max(1.0, std::abs(S)))
541 "network_reader: an NNPP 'horizon' disagrees with the last pwlinear time");
545 throw InputError(ErrorKind{
"Format"},
"network_reader: NNPP rate kind '" + kind +
546 "' is not one of eptmp, pwlinear");
553 if (type ==
"NHPP" || type ==
"MAPt" || type ==
"PHt" || type ==
"MMAPt" ||
554 type ==
"MPHt" || type ==
"BMMAPt") {
555 const json& p = obj.at(
"params");
557 for (
const json& b : p.at(
"breakpoints"))
558 bp.push_back(num_traits<T>::from_double(b.get<
double>()));
564 const bool cyc = !p.contains(
"cyclic") || p.at(
"cyclic").get<
bool>();
574 auto read_seg = [&](
const json& seg) {
575 if (seg.is_number()) {
577 M(0, 0) = num_traits<T>::from_double(num_from_json(seg));
581 throw InputError(ErrorKind{
"Format"},
"network_reader: a schedule segment must be a matrix, "
582 "a row of numbers, or a single number");
583 if (!seg.empty() && seg.at(0).is_number()) {
584 Matrix<T> M(1, seg.size());
585 for (std::size_t b = 0; b < seg.size(); ++b)
586 M(0, b) = num_traits<T>::from_double(num_from_json(seg.at(b)));
589 return mat_from_json<T>(seg);
591 auto read_mats = [&](
const char* key) {
592 std::vector<Matrix<T> > out;
593 for (
const json& seg : p.at(key)) out.push_back(read_seg(seg));
596 if (type ==
"NHPP") {
597 std::vector<T> rates;
598 for (
const json& r : p.at(
"rates"))
599 rates.push_back(num_traits<T>::from_double(r.get<
double>()));
607 auto read_mark_mats = [&](
const char* key) {
608 std::vector<std::vector<Matrix<T> > > out;
609 for (
const json& per_mark : p.at(key)) {
610 if (!per_mark.is_array())
611 throw InputError(ErrorKind{
"Format"},
"network_reader: the marked schedule key '" +
612 std::string(key) +
"' must nest marks over segments");
613 std::vector<Matrix<T> > segs;
614 for (
const json& seg : per_mark) segs.push_back(read_seg(seg));
621 if (type ==
"BMMAPt") {
625 std::vector<std::vector<std::vector<Matrix<T> > > > blocks;
626 for (
const json& per_mark : p.at(
"D1kb")) {
627 if (!per_mark.is_array())
628 throw InputError(ErrorKind{
"Format"},
"network_reader: 'D1kb' must nest marks over batch sizes "
630 std::vector<std::vector<Matrix<T> > > per_batch;
631 for (
const json& batch : per_mark) {
632 if (!batch.is_array())
633 throw InputError(ErrorKind{
"Format"},
"network_reader: 'D1kb' must nest marks over batch "
634 "sizes over segments");
635 std::vector<Matrix<T> > segs;
636 for (
const json& seg : batch) segs.push_back(read_seg(seg));
637 per_batch.push_back(segs);
639 blocks.push_back(per_batch);
643 std::vector<std::vector<T> > alphas;
644 for (
const json& a : p.at(
"alpha")) {
645 const std::vector<double> row = a.get<std::vector<double> >();
647 for (
double v : row) av.push_back(num_traits<T>::from_double(v));
648 alphas.push_back(av);
650 if (type ==
"MPHt") {
653 const std::vector<std::vector<Matrix<T> > > ex = read_mark_mats(
"exit");
654 std::vector<std::vector<std::vector<T> > > exits;
655 for (
const std::vector<Matrix<T> >& per_mark : ex) {
656 std::vector<std::vector<T> > segs;
657 for (
const Matrix<T>& M : per_mark) {
659 for (std::size_t i = 0; i < M.rows(); ++i)
660 for (std::size_t j = 0; j < M.cols(); ++j) v.push_back(M(i, j));
663 exits.push_back(segs);
676 if (type ==
"Replayer" || type ==
"Trace") {
677 if (obj.contains(
"params") && obj.at(
"params").contains(
"fileName")) {
678 const std::string path = obj.at(
"params").at(
"fileName").get<std::string>();
679 std::ifstream tr(path.c_str());
681 std::vector<T> samples;
683 while (tr >> v) samples.push_back(num_traits<T>::from_double(v));
684 if (!samples.empty()) {
691 if (obj.contains(
"ph")) {
692 const json& ph = obj.at(
"ph");
693 const std::vector<double> a = ph.at(
"alpha").get<std::vector<double> >();
694 const std::vector<std::vector<double> > rows =
695 ph.at(
"T").get<std::vector<std::vector<double> > >();
696 std::vector<T> alpha;
697 for (
double x : a) alpha.push_back(num_traits<T>::from_double(x));
698 Matrix<T> A(rows.size(), rows.empty() ? 0 : rows[0].size());
699 for (std::size_t i = 0; i < rows.size(); ++i)
700 for (std::size_t j = 0; j < rows[i].size(); ++j)
701 A(i, j) = num_traits<T>::from_double(rows[i][j]);
704 if (obj.contains(
"params") && obj.at(
"params").contains(
"mean"))
706 num_traits<T>::from_double(obj.at(
"params").at(
"mean").get<
double>()));
708 "network_reader: a Replayer carries neither a readable trace file, nor the APH fit "
709 "the writers add beside it, nor a mean; there is nothing to reconstruct");
714 if (type ==
"MMPP2") {
715 const json& p = obj.at(
"params");
716 const double l0 = p.at(
"lambda0").get<
double>(), l1 = p.at(
"lambda1").get<
double>();
717 const double s0 = p.at(
"sigma0").get<
double>(), s1 = p.at(
"sigma1").get<
double>();
718 Matrix<T> D0(2, 2), D1(2, 2);
719 D1(0, 0) = num_traits<T>::from_double(l0);
720 D1(1, 1) = num_traits<T>::from_double(l1);
721 D0(0, 0) = num_traits<T>::from_double(-(l0 + s0));
722 D0(0, 1) = num_traits<T>::from_double(s0);
723 D0(1, 0) = num_traits<T>::from_double(s1);
724 D0(1, 1) = num_traits<T>::from_double(-(l1 + s1));
727 if (type ==
"MAP" || type ==
"MMPP") {
728 if (!obj.contains(
"map"))
729 throw InputError(ErrorKind{
"Format"},
"network_reader: " + type +
" carries no 'map' (D0, D1) object");
730 const json& mp = obj.at(
"map");
732 mat_from_json<T>(mp.at(
"D1")),
741 if (type ==
"MPH" || type ==
"MarkedPH") {
742 if (!obj.contains(
"mph"))
743 throw InputError(ErrorKind{
"Format"},
"network_reader: " + type +
744 " carries no 'mph' (alpha, S, exit) object");
745 const json& mp = obj.at(
"mph");
746 const Matrix<T> alpha_m = mat_from_json<T>(mp.at(
"alpha"));
747 const Matrix<T> S = mat_from_json<T>(mp.at(
"S"));
748 const std::size_t H = S.rows();
749 if (alpha_m.rows() * alpha_m.cols() != H)
750 throw InputError(ErrorKind{
"Format"},
"network_reader: an MPH's alpha and S disagree in order");
751 std::vector<T> alpha;
752 for (std::size_t i = 0; i < alpha_m.rows(); ++i)
753 for (std::size_t j = 0; j < alpha_m.cols(); ++j) alpha.push_back(alpha_m(i, j));
754 const std::vector<Matrix<T> > ex = mat_list_from_json<T>(mp.at(
"exit"));
755 std::vector<std::vector<T> > exits;
756 for (
const Matrix<T>& sk : ex) {
757 if (sk.rows() * sk.cols() != H)
758 throw InputError(ErrorKind{
"Format"},
"network_reader: an MPH exit vector and S disagree in order");
760 for (std::size_t i = 0; i < sk.rows(); ++i)
761 for (std::size_t j = 0; j < sk.cols(); ++j) sv.push_back(sk(i, j));
768 if (type ==
"MMAP" || type ==
"MarkedMAP") {
769 if (!obj.contains(
"mmap"))
770 throw InputError(ErrorKind{
"Format"},
"network_reader: " + type +
" carries no 'mmap' (D0, D1k) object");
771 const json& mp = obj.at(
"mmap");
773 mat_list_from_json<T>(mp.at(
"D1k")));
778 if (type ==
"BMAP" || type ==
"MarkedMMPP") {
779 const json& p = obj.at(
"params");
780 const std::vector<Matrix<T> > D = mat_list_from_json<T>(p.at(
"D"));
783 throw InputError(ErrorKind{
"Format"},
"network_reader: a MarkedMMPP carries D0 and at least one marked block");
788 std::size_t first = 1;
789 if (p.contains(
"K")) {
790 const std::size_t K = p.at(
"K").get<std::size_t>();
791 if (K + 2 == D.size()) first = 2;
792 else if (K + 1 != D.size())
793 throw InputError(ErrorKind{
"Format"},
"network_reader: a MarkedMMPP's K matches neither "
794 "{D0, D11..D1K} nor {D0, D1, D11..D1K}");
798 if (type ==
"DMAP") {
799 const json& p = obj.at(
"params");
803 const json& p = obj.at(
"params");
808 if (type ==
"ME" || type ==
"CME") {
809 const json& p = obj.at(
"params");
810 const std::vector<double> a = p.at(
"alpha").get<std::vector<double> >();
811 std::vector<T> alpha;
812 for (
double v : a) alpha.push_back(num_traits<T>::from_double(v));
824 if (obj.contains(
"ph")) {
825 const json& ph = obj.at(
"ph");
826 const std::vector<double> a = ph.at(
"alpha").get<std::vector<double> >();
827 const std::vector<std::vector<double> > rows =
828 ph.at(
"T").get<std::vector<std::vector<double> > >();
829 if (a.empty() || rows.size() != a.size())
830 throw InputError(ErrorKind{
"Format"},
"network_reader: distribution '" + type +
831 "' has a 'ph' block whose alpha and T disagree in order");
832 std::vector<T> alpha;
833 alpha.reserve(a.size());
834 for (
double v : a) alpha.push_back(num_traits<T>::from_double(v));
835 Matrix<T> A(rows.size(), rows.empty() ? 0 : rows[0].size());
836 for (std::size_t i = 0; i < rows.size(); ++i)
837 for (std::size_t j = 0; j < rows[i].size(); ++j)
838 A(i, j) = num_traits<T>::from_double(rows[i][j]);
846 if (!obj.contains(
"params") && obj.contains(
"fit"))
847 return dist_from_fit<T>(type, obj.at(
"fit"));
848 if (!obj.contains(
"params"))
849 throw InputError(ErrorKind{
"Format"},
"network_reader: distribution '" + type +
850 "' has neither params nor a fit block");
851 const json& p = obj.at(
"params");
853 const double lam = p.contains(
"lambda") ? p.at(
"lambda").get<
double>()
854 : p.at(
"rate").
get<double>();
857 if (type ==
"Det")
return lang::Distrib<T>::det(num_traits<T>::from_double(p.at(
"value").get<
double>()));
858 if (type ==
"Erlang") {
859 const double lam = p.at(
"lambda").get<
double>();
860 const long k = p.at(
"k").get<
long>();
863 if (type ==
"HyperExp") {
864 const std::vector<T> pv = num_vec_from_json<T>(p.at(
"p"));
865 const std::vector<T> lv = num_vec_from_json<T>(p.at(
"lambda"));
868 if (pv.size() == 2 && lv.size() == 2)
872 if (type ==
"Coxian")
874 num_vec_from_json<T>(p.at(
"phi")));
877 num_traits<T>::from_double(p.at(
"mu2").get<
double>()),
878 num_traits<T>::from_double(p.at(
"phi1").get<
double>()));
879 if (type ==
"Uniform")
881 num_traits<T>::from_double(p.at(
"b").get<
double>()));
885 num_traits<T>::from_double(p.at(
"beta").get<
double>()));
886 if (type ==
"Lognormal")
888 num_traits<T>::from_double(p.at(
"sigma").get<
double>()));
894 if (type ==
"Normal")
896 num_traits<T>::from_double(p.at(
"sigma").get<
double>()));
900 if (type ==
"Pareto")
902 num_traits<T>::from_double(p.at(
"scale").get<
double>()));
903 if (type ==
"Weibull")
905 num_traits<T>::from_double(p.at(
"beta").get<
double>()));
907 if (type ==
"LogLogistic")
909 num_traits<T>::from_double(p.at(
"alpha").get<
double>()));
911 if (type ==
"MassAtOrigin" || type ==
"Defective") {
912 if (!obj.contains(
"dist"))
913 throw InputError(ErrorKind{
"Format"},
"network_reader: '" + type +
914 "' has no inner `dist` block");
915 const lang::Distrib<T>
in = dist_from_json<T>(obj.at(
"dist"));
916 if (type ==
"MassAtOrigin")
920 if (type ==
"DiscreteUniform")
922 num_traits<T>::from_double(p.at(
"min").get<
double>()),
923 num_traits<T>::from_double(p.at(
"max").get<
double>()));
924 if (type ==
"Bernoulli")
926 if (type ==
"Binomial")
928 num_traits<T>::from_double(p.at(
"p").get<
double>()));
929 if (type ==
"Poisson")
931 if (type ==
"Geometric")
935 std::size_t(p.at(
"n").get<
long>()));
936 if (type ==
"DiscreteSampler") {
937 const std::vector<T> pv = num_vec_from_json<T>(p.at(
"p"));
938 const std::vector<T> xv =
939 p.contains(
"x") ? num_vec_from_json<T>(p.at(
"x")) : std::vector<T>();
942 if (type ==
"EmpiricalCDF" || type ==
"EmpiricalCdf")
944 num_vec_from_json<T>(p.at(
"F")));
955 if (p.contains(
"mean") && !p.contains(
"scv"))
957 if (p.contains(
"mean") && p.contains(
"scv")) {
958 const double mean = p.at(
"mean").get<
double>();
959 const double scv = p.at(
"scv").get<
double>();
960 if (std::fabs(scv - 1.0) < 1e-12)
964 num_traits<T>::from_double(scv));
965 return hyperexp_fit_mean_scv<T>(mean, scv);
967 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: unsupported distribution family '" + type +
979typename qn::CacheParam<T>::Popularity popularity_kind_from_json(
const json& obj,
980 std::size_t nitems) {
981 typename qn::CacheParam<T>::Popularity k;
982 const std::string type = obj.value(
"type", std::string());
983 const json& p = obj.contains(
"params") ? obj.at(
"params") : obj;
984 if (type ==
"Zipf") {
986 k.s = p.at(
"s").get<
double>();
987 k.n = p.contains(
"n") ? std::size_t(p.at(
"n").get<
long>()) : nitems;
988 }
else if (type ==
"DiscreteSampler" || p.contains(
"p")) {
990 k.n = p.contains(
"p") ? p.at(
"p").size() : nitems;
1006std::vector<T> pmf_from_json(
const json& obj, std::size_t nitems) {
1007 const std::string type = obj.value(
"type", std::string());
1008 const json& p = obj.contains(
"params") ? obj.at(
"params") : obj;
1014 if (type ==
"DiscreteSampler" || (p.contains(
"p") && p.at(
"p").is_array())) {
1015 for (
const json& v : p.at(
"p")) out.push_back(num_traits<T>::from_double(v.get<
double>()));
1018 if (type ==
"Zipf") {
1019 const double s = p.at(
"s").get<
double>();
1020 const std::size_t n = p.contains(
"n") ? std::size_t(p.at(
"n").get<
long>()) : nitems;
1022 for (std::size_t k = 1; k <= n; ++k) h += std::pow(
double(k), -s);
1023 for (std::size_t k = 1; k <= n; ++k)
1024 out.push_back(num_traits<T>::from_double(std::pow(
double(k), -s) / h));
1028 "network_reader: a cache popularity is written as '" + type +
1029 "', and the discrete families carrying an item pmf are DiscreteSampler and Zipf");
1042constexpr std::size_t REMOVAL_PMF_MAX_TERMS = 4096;
1064std::vector<T> removal_pmf_from_json(
const json& obj) {
1065 const std::string type = obj.value(
"type", std::string());
1066 const json& p = obj.contains(
"params") ? obj.at(
"params") : obj;
1068 auto put = [&out](std::size_t k,
double v) {
1069 if (out.size() <= k) out.resize(k + 1, num_traits<T>::from_int(0));
1070 out[k] = num_traits<T>::from_double(num_traits<T>::to_double(out[k]) + v);
1072 if (type ==
"DiscreteSampler" || (p.contains(
"p") && p.at(
"p").is_array())) {
1076 const json& pv = p.at(
"p");
1077 const bool has_x = p.contains(
"x") && p.at(
"x").is_array();
1078 for (std::size_t i = 0; i < pv.size(); ++i) {
1080 has_x ? p.at(
"x").at(i).get<
double>() : static_cast<double>(i + 1);
1081 if (xi < 0)
throw InputError(ErrorKind{
"Format"},
"network_reader: a batch size cannot be negative");
1082 put(
static_cast<std::size_t
>(xi + 0.5), pv.at(i).get<
double>());
1086 if (type ==
"Bernoulli") {
1087 const double q = p.at(
"p").get<
double>();
1092 if (type ==
"Binomial") {
1093 const double q = p.at(
"p").get<
double>();
1094 const std::size_t n =
static_cast<std::size_t
>(p.at(
"n").get<double>() + 0.5);
1095 double term = std::pow(1.0 - q,
static_cast<double>(n));
1096 for (std::size_t k = 0; k <= n; ++k) {
1098 if (k < n && q < 1.0)
1099 term *= (
static_cast<double>(n - k) /
static_cast<double>(k + 1)) * q / (1.0 - q);
1103 if (type ==
"Poisson") {
1104 const double lam = p.at(
"lambda").get<
double>();
1105 double term = std::exp(-lam), acc = 0.0;
1106 for (std::size_t k = 0; k < REMOVAL_PMF_MAX_TERMS; ++k) {
1109 if (acc > 1.0 - 1e-15)
break;
1110 term *= lam /
static_cast<double>(k + 1);
1114 if (type ==
"Geometric") {
1117 const double q = p.at(
"p").get<
double>();
1118 if (q <= 0.0 || q > 1.0)
throw InputError(ErrorKind{
"Format"},
"network_reader: Geometric(p) needs 0 < p <= 1");
1120 double term = q, acc = 0.0;
1121 for (std::size_t k = 1; k <= REMOVAL_PMF_MAX_TERMS; ++k) {
1124 if (acc > 1.0 - 1e-15)
break;
1129 if (type ==
"DiscreteUniform") {
1130 const long lo =
static_cast<long>(p.at(
"min").get<double>());
1131 const long hi =
static_cast<long>(p.at(
"max").get<double>());
1132 if (hi < lo || lo < 0)
1133 throw InputError(ErrorKind{
"Format"},
"network_reader: DiscreteUniform(min,max) needs 0 <= min <= max");
1134 const double w = 1.0 /
static_cast<double>(hi - lo + 1);
1135 for (
long k = lo; k <= hi; ++k) put(static_cast<std::size_t>(k), w);
1138 if (type ==
"Det") {
1139 const double v = p.contains(
"t") ? p.at(
"t").get<
double>() : p.at(
"mean").
get<double>();
1140 if (v < 0)
throw InputError(ErrorKind{
"Format"},
"network_reader: a batch size cannot be negative");
1141 put(
static_cast<std::size_t
>(v + 0.5), 1.0);
1145 "network_reader: a signal removal law is written as '" + type +
1146 "', and the discrete families a batch size can be drawn from are DiscreteSampler, "
1147 "Bernoulli, Binomial, Poisson, Geometric, DiscreteUniform and Det");
1165lang::CdScaling<T> cd_scaling_from_json(
const json& tbl,
const std::vector<int>& cutoffs,
1167 std::map<std::string, std::vector<T> >
table;
1168 for (
auto it = tbl.begin(); it != tbl.end(); ++it)
1169 table[it.key()] = num_vec_from_json<T>(it.value());
1170 const std::vector<int> cut = cutoffs;
1171 return [
table, cut, K](
const std::vector<T>& n) {
1173 for (std::size_t r = 0; r < K; ++r) {
1174 int v = r < n.size()
1175 ?
static_cast<int>(std::lround(num_traits<T>::to_double(n[r])))
1178 if (r < cut.size() && v > cut[r]) v = cut[r];
1180 key += std::to_string(v);
1182 std::vector<T> out(K, num_traits<T>::from_int(1));
1183 typename std::map<std::string, std::vector<T> >::const_iterator it =
table.find(key);
1184 if (it ==
table.end())
return out;
1185 for (std::size_t r = 0; r < K && r < it->second.size(); ++r) out[r] = it->second[r];
1213std::function<T(
const std::vector<std::size_t>&)> oi_rate_from_json(
const json& tbl,
1214 const std::vector<int>& cutoffs,
1216 std::map<std::string, T>
table;
1217 for (
auto it = tbl.begin(); it != tbl.end(); ++it)
1218 table[it.key()] = num_traits<T>::from_double(it.value().get<
double>());
1219 const std::vector<int> cut = cutoffs;
1220 return [
table, cut, K](
const std::vector<std::size_t>& micro) {
1221 std::vector<int> cnt(K, 0);
1222 for (std::size_t j = 0; j < micro.size(); ++j)
1223 if (micro[j] >= 1 && micro[j] <= K) ++cnt[micro[j] - 1];
1225 for (std::size_t r = 0; r < K; ++r) {
1227 if (r < cut.size() && v > cut[r]) v = cut[r];
1229 key += std::to_string(v);
1231 typename std::map<std::string, T>::const_iterator it =
table.find(key);
1232 return it ==
table.end() ? num_traits<T>::from_int(0) : it->second;
1248std::vector<T> cd_peak_from_json(
const json& blk,
const json& tbl) {
1249 if (blk.contains(
"peak") && !blk.at(
"peak").
empty())
1250 return num_vec_from_json<T>(blk.at(
"peak"));
1252 for (
auto it = tbl.begin(); it != tbl.end(); ++it) {
1253 if (it.key().find_first_not_of(
"0,") == std::string::npos)
continue;
1254 const std::vector<double> row = num_vec_from_json<double>(it.value());
1255 for (
double x : row)
1256 if (std::isfinite(x) && x > bmax) bmax = x;
1258 return std::vector<T>(1, num_traits<T>::from_double(bmax));
1269inline void reject_unconsumed_model_keys(
const json& model) {
1270 static const char* kModelKeys[] = {
"name",
"type",
"nodes",
1271 "classes",
"routing",
"format",
1272 "version",
"rewards",
"finiteCapacityRegions",
1273 "routingStrategies",
"routingWeights",
"routingParams",
1274 "logPath",
"globalDependence",
"stateDepRouting"};
1281 static const char* kNodeKeys[] = {
1282 "name",
"type",
"scheduling",
"servers",
"service",
1283 "buffer",
"capacity",
"dropRule",
"schedParams",
"pollingType",
1284 "pollingPar",
"classSwitchMatrix",
"csMatrix",
"forkNode",
1285 "tasksPerLink",
"fanOutByDest",
"fanOutDist",
"fanOutProb",
1286 "items",
"numItems",
"itemLevelCap",
"popularity",
"replacementStrategy",
1287 "itemSizes",
"costCaps",
"accessProb",
"admissionProb",
"accessGraph",
1289 "cache",
"initialState",
1290 "retrievalSystem",
"queues",
"hitClass",
"missClass",
1291 "immediateFeedback",
"loadDependence",
1292 "classDependence",
"jointDependence",
1293 "modes",
"classCap",
"departureDiscipline",
1294 "oiServiceRate",
"oiCutoffs",
"swapGraph",
1295 "arrivalBatch",
"markedClasses",
1296 "stateSpace",
"statePrior",
"joinStrategy",
"joinQuorum",
1297 "setupTime",
"delayOffTime",
"switchoverTimes",
"breakdown",
1299 "pollingTable",
"pollingOrder",
"pollingOrderClass",
1300 "pollingOrderThreshold",
"pollingTimer",
1301 "serverTypes",
"heteroSchedPolicy",
"serverParallelism",
1302 "fluid",
"fluidCapacity",
"fluidLevel",
1303 "balking",
"retrial",
"patience",
"orbitImpatience",
1306 "fileName",
"filePath",
"startTime",
"loggerName",
"timestamp",
1307 "jobID",
"jobClass",
"timeSameClass",
"timeAnyClass"};
1312 static const char* kClassKeys[] = {
1313 "name",
"type",
"population",
"refNode",
"priority",
1314 "openOrClosed",
"signalType",
"targetClass",
"removalPolicy",
"removalDistribution",
1315 "isReferenceClass",
"deadline",
"patience",
"impatienceType",
1316 "spawnClass",
"replySignalClass",
"immediateFeedback"};
1317 auto known = [](
const char*
const* tab, std::size_t n,
const std::string& k) {
1318 for (std::size_t i = 0; i < n; ++i)
1319 if (k == tab[i])
return true;
1322 const std::string why =
1323 "', which this reader does not implement. Refusing rather than dropping it: a "
1324 "constraint silently discarded here would make every solver return a confident "
1325 "answer for a different model";
1326 for (
auto it = model.begin(); it != model.end(); ++it)
1327 if (!known(kModelKeys,
sizeof(kModelKeys) /
sizeof(*kModelKeys), it.key()))
1328 throw UnsupportedError(ErrorKind{
"Import"},
"network_reader: the model carries '" + it.key() + why);
1329 if (model.contains(
"classes"))
1330 for (
const json& cl : model.at(
"classes"))
1331 for (
auto it = cl.begin(); it != cl.end(); ++it)
1332 if (!known(kClassKeys,
sizeof(kClassKeys) /
sizeof(*kClassKeys), it.key()))
1334 cl.value(
"name", std::string(
"?")) +
"' carries '" +
1336 if (!model.contains(
"nodes"))
return;
1337 for (
const json& nd : model.at(
"nodes"))
1338 for (
auto it = nd.begin(); it != nd.end(); ++it)
1339 if (!known(kNodeKeys,
sizeof(kNodeKeys) /
sizeof(*kNodeKeys), it.key()))
1341 nd.value(
"name", std::string(
"?")) +
"' carries '" +
1358 const json& model = root.contains(
"model") ? root.at(
"model") : root;
1359 const std::string mtype = model.value(
"type", std::string(
"Network"));
1360 if (mtype !=
"Network") {
1364 if (mtype ==
"Environment")
1366 "network_reader: this is an Environment model (a network per stage plus the "
1367 "stage transitions); solve it with -s env, which reads it through "
1368 "environment_reader.h");
1370 "' is not a Network; only Network models are solved by this path");
1383 detail::reject_unconsumed_model_keys(model);
1386 net.
set_log_path(model.value(
"logPath", std::string()));
1394 const json& nodes = model.at(
"nodes");
1395 std::map<std::string, std::size_t> node_idx;
1396 std::vector<std::string> node_type(nodes.size());
1397 for (std::size_t i = 0; i < nodes.size(); ++i)
1398 node_type[i] = nodes[i].at(
"type").get<std::string>();
1401 for (std::size_t i = 0; i < nodes.size(); ++i) {
1402 const json& nd = nodes[i];
1403 const std::string& type = node_type[i];
1409 if (type ==
"ClassSwitch" || type ==
"Cache" || type ==
"Transition")
continue;
1410 const std::string name = nd.at(
"name").get<std::string>();
1411 std::size_t idx = 0;
1412 if (type ==
"Source") {
1414 }
else if (type ==
"Sink") {
1416 }
else if (type ==
"Delay") {
1418 }
else if (type ==
"Queue") {
1420 detail::sched_from_json(nd.value(
"scheduling", std::string(
"FCFS"))));
1421 }
else if (type ==
"Router") {
1423 }
else if (type ==
"Logger" || type ==
"LogTunnel") {
1424 idx = net.
add_logger(name, nd.value(
"fileName", std::string()));
1426 if (nd.contains(
"filePath")) lg.
file_path = nd.at(
"filePath").get<std::string>();
1434 }
else if (type ==
"Place") {
1443 detail::sched_from_json(nd.value(
"scheduling", std::string(
"INF"))));
1445 if (nd.contains(
"fluid") && !nd.at(
"fluid").is_null() && detail::num_from_json(nd.at(
"fluid")) != 0.0) {
1447 if (nd.contains(
"fluidCapacity") && !nd.at(
"fluidCapacity").is_null())
1449 if (nd.contains(
"fluidLevel") && !nd.at(
"fluidLevel").is_null())
1452 }
else if (type ==
"Join") {
1454 }
else if (type ==
"Fork") {
1455 idx = net.
add_fork(name, detail::num_value(nd,
"tasksPerLink", 1.0));
1460 node_idx[name] = idx;
1464 const json& classes = model.at(
"classes");
1465 std::map<std::string, std::size_t> class_idx;
1468 std::vector<std::size_t> signal_classes;
1469 for (std::size_t r = 0; r < classes.size(); ++r) {
1470 const json& cl = classes[r];
1471 const std::string name = cl.at(
"name").get<std::string>();
1472 const std::string type = cl.at(
"type").get<std::string>();
1473 std::size_t idx = 0;
1474 if (type ==
"Open") {
1476 }
else if (type ==
"Closed" || type ==
"SelfLooping") {
1481 const double pop = cl.at(
"population").get<
double>();
1482 const std::string ref = cl.at(
"refNode").get<std::string>();
1483 auto it = node_idx.find(ref);
1484 if (it == node_idx.end())
1485 throw InputError(
ErrorKind{
"Format"},
"network_reader: class '" + name +
"' references unknown node '" +
1487 idx = type ==
"SelfLooping"
1490 }
else if (type ==
"Signal") {
1496 const std::string kind = cl.value(
"openOrClosed", std::string(
"Open"));
1497 if (kind ==
"Closed") {
1498 const std::string ref = cl.at(
"refNode").get<std::string>();
1499 auto it = node_idx.find(ref);
1500 if (it == node_idx.end())
1502 "' references unknown node '" + ref +
"'");
1509 cl.value(
"priority", 0));
1513 signal_classes.push_back(r);
1516 "' for class '" + name +
"'");
1527 if (cl.contains(
"deadline")) {
1528 const double due = cl.at(
"deadline").get<
double>();
1533 if (cl.contains(
"patience")) {
1534 const json& pt = cl.at(
"patience");
1539 cl.contains(
"impatienceType")
1540 ? detail::impatience_from_json(cl.at(
"impatienceType").get<std::string>())
1543 class_idx[name] = idx;
1547 for (std::size_t r = 0; r < classes.size(); ++r) {
1548 const json& cl = classes[r];
1549 const std::size_t idx = class_idx.at(cl.at(
"name").get<std::string>());
1550 if (cl.contains(
"spawnClass")) {
1551 const std::string sp = cl.at(
"spawnClass").get<std::string>();
1552 auto sit = class_idx.find(sp);
1553 if (sit == class_idx.end())
1554 throw InputError(
ErrorKind{
"Format"},
"network_reader: class '" + cl.at(
"name").get<std::string>() +
1555 "' spawns class '" + sp +
"', which the model does not declare");
1560 if (cl.contains(
"replySignalClass")) {
1561 const std::string rp = cl.at(
"replySignalClass").get<std::string>();
1562 auto rit = class_idx.find(rp);
1563 if (rit == class_idx.end())
1564 throw InputError(
ErrorKind{
"Format"},
"network_reader: class '" + cl.at(
"name").get<std::string>() +
1565 "' replies with class '" + rp +
1566 "', which the model does not declare");
1571 for (std::size_t si = 0; si < signal_classes.size(); ++si) {
1572 const json& cl = classes[signal_classes[si]];
1573 const std::string name = cl.at(
"name").get<std::string>();
1574 const std::string st = cl.value(
"signalType", std::string(
"negative"));
1578 else if (st !=
"negative" && st !=
"NEGATIVE")
1580 "', and the kinds on the wire are negative, catastrophe and "
1583 const std::string rp = cl.value(
"removalPolicy", std::string(
"RANDOM"));
1586 std::size_t target = 0;
1587 if (cl.contains(
"targetClass")) {
1588 auto tit = class_idx.find(cl.at(
"targetClass").get<std::string>());
1589 if (tit == class_idx.end())
1590 throw InputError(
ErrorKind{
"Format"},
"network_reader: signal class '" + name +
"' targets class '" +
1591 cl.at(
"targetClass").get<std::string>() +
1592 "', which the model does not declare");
1593 target = tit->second;
1595 std::vector<T> remdist;
1596 if (cl.contains(
"removalDistribution"))
1597 remdist = detail::removal_pmf_from_json<T>(cl.at(
"removalDistribution"));
1598 net.
set_signal(class_idx.at(name), kind, pol, target, remdist);
1600 const std::size_t K = class_idx.size();
1604 for (std::size_t i = 0; i < nodes.size(); ++i) {
1605 const json& nd = nodes[i];
1606 const std::string& type = node_type[i];
1607 if (type !=
"ClassSwitch" && type !=
"Join" && type !=
"Cache" && type !=
"Fork")
continue;
1608 const std::string name = nd.at(
"name").get<std::string>();
1609 std::size_t idx = 0;
1610 if (type ==
"Fork") {
1616 if (!nd.contains(
"fanOutByDest") && !nd.contains(
"fanOutDist") &&
1617 !nd.contains(
"fanOutProb"))
1619 idx = node_idx.at(name);
1620 if (nd.contains(
"fanOutByDest")) {
1621 const json& ovs = nd.at(
"fanOutByDest");
1622 for (std::size_t e = 0; e < ovs.size(); ++e)
1624 ovs[e].at(
"value").get<
double>(),
1625 detail::fork_dest_index(ovs[e], node_idx, name));
1627 if (nd.contains(
"fanOutDist")) {
1628 const json& ovs = nd.at(
"fanOutDist");
1629 for (std::size_t e = 0; e < ovs.size(); ++e) {
1630 const std::vector<double> pv = ovs[e].at(
"p").get<std::vector<double> >();
1631 const std::vector<double> xv = ovs[e].at(
"x").get<std::vector<double> >();
1632 std::vector<T> p, x;
1633 for (std::size_t q = 0; q < pv.size(); ++q)
1635 for (std::size_t q = 0; q < xv.size(); ++q)
1639 detail::fork_dest_index(ovs[e], node_idx, name));
1642 if (nd.contains(
"fanOutProb")) {
1643 const json& ovs = nd.at(
"fanOutProb");
1644 for (std::size_t e = 0; e < ovs.size(); ++e)
1646 idx, ovs[e].at(
"class").get<std::size_t>(),
1647 detail::fork_dest_index(ovs[e], node_idx, name),
1648 ovs[e].at(
"value").get<
double>());
1652 if (type ==
"Cache") {
1660 const json empty_obj = json::object();
1661 const json& cj = nd.contains(
"cache") ? nd.at(
"cache") : empty_obj;
1663 cp.
nitems = detail::has_cache_key(nd, cj,
"numItems")
1664 ? detail::cache_key(nd, cj,
"numItems").get<std::size_t>()
1665 : cj.at(
"items").get<std::size_t>();
1666 cp.
itemcap = detail::has_cache_key(nd, cj,
"itemLevelCap")
1667 ? detail::cache_key(nd, cj,
"itemLevelCap").get<std::vector<int> >()
1668 : cj.at(
"capacity").get<std::vector<int> >();
1671 if (detail::has_cache_key(nd, cj,
"itemSizes"))
1672 cp.
itemsize = detail::cache_key(nd, cj,
"itemSizes").get<std::vector<int> >();
1673 if (detail::has_cache_key(nd, cj,
"costCaps")) {
1674 const json& cc = detail::cache_key(nd, cj,
"costCaps");
1675 if (cc.is_array()) {
1676 cp.
costcap = cc.get<std::vector<int> >();
1683 detail::has_cache_key(nd, cj,
"replacementStrategy")
1684 ? detail::cache_key(nd, cj,
"replacementStrategy").get<std::string>()
1685 : cj.value(
"replacement", std::string(
"RR")));
1686 cp.
pread.assign(K, std::vector<T>());
1691 if (detail::has_cache_key(nd, cj,
"popularity")) {
1692 const json& pop = detail::cache_key(nd, cj,
"popularity");
1693 for (
auto it = pop.begin(); it != pop.end(); ++it) {
1697 if (it.value().value(
"type", std::string()) ==
"Disabled")
continue;
1698 cp.
pread[class_idx.at(it.key()) - 1] =
1699 detail::pmf_from_json<T>(it.value(), cp.
nitems);
1700 cp.
preadkind[class_idx.at(it.key()) - 1] =
1701 detail::popularity_kind_from_json<T>(it.value(), cp.
nitems);
1704 auto fill_switch = [&](
const char* key, std::vector<std::size_t>& dst) {
1705 if (!detail::has_cache_key(nd, cj, key))
return;
1706 const json& blk = detail::cache_key(nd, cj, key);
1707 for (
auto it = blk.begin(); it != blk.end(); ++it)
1708 dst[class_idx.at(it.key()) - 1] = class_idx.at(it.value().get<std::string>());
1710 fill_switch(
"hitClass", cp.
hitclass);
1715 if (detail::has_cache_key(nd, cj,
"itemClass")) {
1716 const json& blk = detail::cache_key(nd, cj,
"itemClass");
1717 for (
auto it = blk.begin(); it != blk.end(); ++it)
1718 cp.
classitem[class_idx.at(it.key()) - 1] =
1719 static_cast<std::size_t
>(it.value().get<double>());
1730 if (detail::has_cache_key(nd, cj,
"admissionProb"))
1732 if (detail::has_cache_key(nd, cj,
"accessProb")) {
1733 const json& ap = detail::cache_key(nd, cj,
"accessProb");
1735 for (
const json& per_class : ap) {
1736 std::vector<Matrix<T> > row;
1737 for (
const json& g : per_class) {
1738 if (g.is_null() || g.empty()) {
1742 row.push_back(detail::mat_from_json<T>(g));
1744 cp.
accost.push_back(row);
1746 }
else if (detail::has_cache_key(nd, cj,
"accessGraph")) {
1752 const std::vector<Matrix<T> > shared =
1753 detail::mat_list_from_json<T>(detail::cache_key(nd, cj,
"accessGraph"));
1754 cp.
accost.assign(K, shared);
1758 if (detail::has_cache_key(nd, cj,
"initialState"))
1759 cp.
initstate = detail::num_vec_from_json<T>(detail::cache_key(nd, cj,
"initialState"));
1769 if (detail::has_cache_key(nd, cj,
"retrievalSystem")) {
1770 const json& rs = detail::cache_key(nd, cj,
"retrievalSystem");
1773 if (rs.contains(
"byClass")) {
1774 for (
auto rc = rs.at(
"byClass").begin(); rc != rs.at(
"byClass").end(); ++rc) {
1775 const std::size_t rdcls = class_idx.at(rc.key());
1776 std::vector<std::size_t> qnodes;
1777 for (
const auto&
qn : rc.value().at(
"queues"))
1778 qnodes.push_back(node_idx.at(
qn.get<std::string>()));
1781 if (!rc.value().contains(
"items"))
continue;
1782 for (
auto it2 = rc.value().at(
"items").begin();
1783 it2 != rc.value().at(
"items").end(); ++it2) {
1784 const std::size_t item = std::stoul(it2.key());
1787 class_idx.at(it2.value().get<std::string>());
1793 node_idx[name] = idx;
1796 if (type ==
"Join") {
1801 if (!nd.contains(
"forkNode"))
1803 "' names no 'forkNode': the document declares no "
1804 "Fork for it to close.");
1805 auto it = node_idx.find(nd.at(
"forkNode").get<std::string>());
1806 if (it == node_idx.end())
1808 "' references unknown fork '" +
1809 nd.at(
"forkNode").get<std::string>() +
"'");
1810 const std::size_t fork = it->second;
1813 idx = node_idx.at(name);
1818 if (nd.contains(
"joinStrategy") || nd.contains(
"joinQuorum")) {
1819 const std::string js = nd.value(
"joinStrategy", std::string(
"STD"));
1820 if (js !=
"STD" && js !=
"PARTIAL")
1822 js +
"', and the rules on the wire are STD and PARTIAL");
1826 nd.value(
"joinQuorum", 0.0));
1835 if (nd.contains(
"classSwitchMatrix") || nd.contains(
"csMatrix")) {
1837 nd.contains(
"classSwitchMatrix") ? nd.at(
"classSwitchMatrix") : nd.at(
"csMatrix");
1838 for (
auto ri = csm.begin(); ri != csm.end(); ++ri) {
1839 const std::size_t rr = class_idx.at(ri.key()) - 1;
1841 for (
auto ci = ri.value().begin(); ci != ri.value().end(); ++ci)
1842 C(rr, class_idx.at(ci.key()) - 1) =
1848 node_idx[name] = idx;
1860 for (std::size_t i = 0; i < nodes.size(); ++i) {
1861 if (node_type[i] !=
"Transition")
continue;
1862 const json& nd = nodes[i];
1863 const std::string name = nd.at(
"name").get<std::string>();
1864 if (!nd.contains(
"modes") || nd.at(
"modes").empty())
1865 throw InputError(
ErrorKind{
"Format"},
"network_reader: transition '" + name +
"' declares no mode");
1866 const json& modes = nd.at(
"modes");
1868 tp.
nmodes = modes.size();
1869 const std::size_t nn = nodes.size();
1870 const double inf = std::numeric_limits<double>::infinity();
1871 for (std::size_t m = 0; m < modes.size(); ++m) {
1872 const json& mj = modes[m];
1873 tp.
modenames.push_back(mj.value(
"name", std::string(
"Mode") + std::to_string(m + 1)));
1882 tp.
firingdep.push_back(std::function<T(
const std::vector<T>&)>());
1883 if (mj.contains(
"firingRateDependence")) {
1884 const json& frm = mj.at(
"firingRateDependence");
1885 if (!frm.contains(
"slots") || !frm.contains(
"scaling"))
1886 throw InputError(
ErrorKind{
"Format"},
"network_reader: the marking-dependent firing rate of mode " +
1887 std::to_string(m + 1) +
" of transition '" + name +
1888 "' carries no 'slots'/'scaling' lattice");
1889 std::vector<std::size_t> slot_pos;
1890 for (
const json& sm : frm.at(
"slots")) {
1891 const std::string on = sm.at(
"node").get<std::string>();
1892 const std::map<std::string, std::size_t>::const_iterator ni = node_idx.find(on);
1893 if (ni == node_idx.end())
1894 throw InputError(
ErrorKind{
"Format"},
"network_reader: the marking-dependent firing rate of "
1896 name +
"' reads node '" + on +
1897 "', which the model does not declare");
1900 if (sm.contains(
"class")) {
1901 const std::string scn = sm.at(
"class").get<std::string>();
1902 const std::map<std::string, std::size_t>::const_iterator sci = class_idx.find(scn);
1903 if (sci == class_idx.end())
1904 throw InputError(
ErrorKind{
"Format"},
"network_reader: the marking-dependent firing rate of "
1906 name +
"' reads class '" + scn +
1907 "', which the model does not declare");
1910 slot_pos.push_back((ni->second - 1) * K + (sr - 1));
1912 std::vector<long> cutoffs;
1913 if (frm.contains(
"cutoffs"))
1914 for (
const json& c : frm.at(
"cutoffs")) cutoffs.push_back(c.get<
long>());
1915 std::map<std::string, double> table;
1916 const json& sc = frm.at(
"scaling");
1917 for (json::const_iterator it = sc.begin(); it != sc.end(); ++it)
1918 table[it.key()] = it.value().get<
double>();
1919 tp.
firingdep.back() = [slot_pos, cutoffs,
1920 table](
const std::vector<T>& mk) -> T {
1922 for (std::size_t s = 0; s < slot_pos.size(); ++s) {
1923 long c = slot_pos[s] < mk.size()
1924 ?
static_cast<long>(std::llround(
1928 if (s < cutoffs.size() && c > cutoffs[s]) c = cutoffs[s];
1930 key += std::to_string(c);
1932 const std::map<std::string, double>::const_iterator hit = table.find(key);
1939 const bool immediate =
1940 mj.value(
"timingStrategy", std::string(
"TIMED")) ==
"IMMEDIATE";
1944 if (mj.contains(
"distribution")) proc = detail::dist_from_json<T>(mj.at(
"distribution"));
1948 tp.
nmodeservers.push_back(detail::num_value(mj,
"numServers", 1.0));
1956 tp.
firingprio.push_back(mj.value(
"firingPriority", 1.0));
1958 const std::size_t K = classes.size();
1962 const char* kArcKey[3] = {
"enablingConditions",
"inhibitingConditions",
1964 for (
int which = 0; which < 3; ++which) {
1965 if (!mj.contains(kArcKey[which]))
continue;
1966 for (
const json& arc : mj.at(kArcKey[which])) {
1967 const std::string on = arc.at(
"node").get<std::string>();
1968 const std::map<std::string, std::size_t>::const_iterator ni = node_idx.find(on);
1969 if (ni == node_idx.end())
1970 throw InputError(
ErrorKind{
"Format"},
"network_reader: transition '" + name +
"' names node '" +
1971 on +
"', which the model does not declare");
1977 if (arc.contains(
"class")) {
1978 const std::string cn = arc.at(
"class").get<std::string>();
1979 const std::map<std::string, std::size_t>::const_iterator ci =
1981 if (ci == class_idx.end())
1983 "' names class '" + cn +
1984 "', which the model does not declare");
1988 const std::size_t q = ni->second - 1;
1989 if (which == 0) enab(q, rr - 1) = enab(q, rr - 1) + cnt;
1990 else if (which == 1) inhib(q, rr - 1) = cnt;
1991 else fire(q, rr - 1) = fire(q, rr - 1) + cnt;
1996 tp.
firing.push_back(fire);
2004 const std::string mlabel =
"mode " + std::to_string(m + 1) +
" of transition '" + name +
"'";
2005 auto fluid_place = [&](
const json& e,
const char* key) -> std::size_t {
2006 const std::string on = e.at(
"node").get<std::string>();
2007 const std::map<std::string, std::size_t>::const_iterator ni = node_idx.find(on);
2008 bool is_place =
false;
2009 for (std::size_t j = 0; j < nodes.size() && !is_place; ++j)
2010 is_place = node_type[j] ==
"Place" && nodes[j].at(
"name").get<std::string>() == on;
2011 if (ni == node_idx.end() || !is_place)
2012 throw InputError(
ErrorKind{
"Format"},
"network_reader: the " + std::string(key) +
" of " +
2013 mlabel +
" names '" + on +
"', which is not a Place of the model");
2016 auto finite_num = [&](
const json& e,
const char* field,
const char* key) ->
double {
2017 const double x = detail::num_from_json(e.at(field));
2018 if (!std::isfinite(x))
2019 throw InputError(
ErrorKind{
"Format"},
"network_reader: the " + std::string(key) +
" of " +
2020 mlabel +
" carries a non-finite '" + field +
"'");
2023 if (mj.contains(
"fluidRates"))
2024 for (
const json& e : mj.at(
"fluidRates")) {
2026 a.
node = fluid_place(e,
"fluidRates");
2027 a.
value = finite_num(e,
"rate",
"fluidRates");
2030 if (mj.contains(
"fluidGuards"))
2031 for (
const json& e : mj.at(
"fluidGuards")) {
2033 g.
node = fluid_place(e,
"fluidGuards");
2034 const std::string op = e.at(
"op").get<std::string>();
2035 if (op !=
">=" && op !=
"<=")
2037 " has operator '" + op +
"'; the operators are '>=' and '<='");
2038 g.
sgn = op ==
">=" ? 1 : -1;
2039 g.
thr = finite_num(e,
"threshold",
"fluidGuards");
2042 " has a negative threshold");
2045 if (mj.contains(
"fluidImpulses"))
2046 for (
const json& e : mj.at(
"fluidImpulses")) {
2048 a.
node = fluid_place(e,
"fluidImpulses");
2049 a.
value = finite_num(e,
"delta",
"fluidImpulses");
2052 if (mj.contains(
"fluidRateDependence"))
2053 for (
const json& e : mj.at(
"fluidRateDependence")) {
2055 d.
node = fluid_place(e,
"fluidRateDependence");
2058 " is IMMEDIATE and declares a fluid rate dependence");
2061 " declares a fluid rate dependence on a non-exponential firing law");
2062 d.
fun = detail::fluiddep_table_to_fun(e.at(
"levels"), e.at(
"values"), mlabel);
2069 if (mj.contains(
"fluidFlowDependence")) {
2070 const std::size_t KF = classes.size();
2071 for (
const json& e : mj.at(
"fluidFlowDependence")) {
2073 fd.
node = fluid_place(e,
"fluidFlowDependence");
2074 if (e.contains(
"read")) {
2075 const json& rd = e.at(
"read");
2076 const json rl = rd.is_array() ? rd : json::array({rd});
2077 for (
const json& rn : rl) {
2080 fd.
read.push_back(fluid_place(probe,
"fluidFlowDependence read"));
2082 std::sort(fd.
read.begin(), fd.
read.end());
2086 if (!e.contains(
"slots") || !e.contains(
"scaling"))
2087 throw InputError(
ErrorKind{
"Format"},
"network_reader: the fluid flow dependence of " + mlabel +
2088 " carries no 'slots'/'scaling' lattice");
2089 std::vector<std::size_t> sflat;
2090 for (
const json& sm : e.at(
"slots")) {
2091 const std::string on = sm.at(
"node").get<std::string>();
2092 const std::map<std::string, std::size_t>::const_iterator ni = node_idx.find(on);
2093 if (ni == node_idx.end())
2095 mlabel +
" reads node '" + on +
"', which the model does not declare");
2097 if (sm.contains(
"class")) {
2098 const std::string cn = sm.at(
"class").get<std::string>();
2099 const std::map<std::string, std::size_t>::const_iterator ci = class_idx.find(cn);
2100 if (ci == class_idx.end())
2102 mlabel +
" names class '" + cn +
2103 "', which the model does not declare");
2106 sflat.push_back((ni->second - 1) * KF + (rr - 1));
2108 std::vector<long> cutoffs;
2109 if (e.contains(
"cutoffs"))
2110 for (
const json& c : e.at(
"cutoffs")) cutoffs.push_back(c.get<
long>());
2111 std::map<std::string, double> table;
2112 const json& sc = e.at(
"scaling");
2113 for (json::const_iterator it = sc.begin(); it != sc.end(); ++it)
2114 table[it.key()] = it.value().get<
double>();
2115 fd.
fun = [sflat, cutoffs, table](
const std::vector<double>& mk) ->
double {
2117 for (std::size_t s = 0; s < sflat.size(); ++s) {
2118 long c = sflat[s] < mk.size() ?
static_cast<long>(std::llround(mk[sflat[s]])) : 0L;
2120 if (s < cutoffs.size() && c > cutoffs[s]) c = cutoffs[s];
2122 key += std::to_string(c);
2124 const std::map<std::string, double>::const_iterator hit = table.find(key);
2125 return hit == table.end() ? 1.0 : hit->second;
2135 for (std::size_t i = 0; i < nodes.size(); ++i) {
2136 const json& nd = nodes[i];
2137 const std::string& type = node_type[i];
2138 const std::size_t idx = node_idx.at(nd.at(
"name").get<std::string>());
2143 if (nd.contains(
"servers") && (type ==
"Queue" || type ==
"Place"))
2146 if (nd.contains(
"service")) {
2147 const json& svc = nd.at(
"service");
2148 for (
auto it = svc.begin(); it != svc.end(); ++it) {
2149 auto cit = class_idx.find(it.key());
2150 if (cit == class_idx.end())
2151 throw InputError(
ErrorKind{
"Format"},
"network_reader: service names unknown class '" + it.key() +
2152 "' at node '" + nd.at(
"name").get<std::string>() +
"'");
2154 if (type ==
"Source") net.
set_arrival(idx, cit->second, d);
2159 if (type ==
"Queue" && nd.contains(
"scheduling") &&
2160 nd.at(
"scheduling").get<std::string>() ==
"POLLING") {
2161 if (nd.contains(
"pollingType"))
2164 net.
set_polling_type(idx, detail::polling_from_json(nd.at(
"pollingType").get<std::string>()),
2165 static_cast<int>(std::lround(nd.value(
"pollingPar", 0.0))));
2170 if (nd.contains(
"schedParams") && (type ==
"Queue" || type ==
"Delay")) {
2171 const json& sp = nd.at(
"schedParams");
2172 for (
auto it = sp.begin(); it != sp.end(); ++it) {
2173 auto cit = class_idx.find(it.key());
2174 if (cit != class_idx.end())
2186 const bool station_node =
2187 type ==
"Queue" || type ==
"Delay" || type ==
"Join" || type ==
"Place";
2188 if (nd.contains(
"dropRule") && station_node) {
2189 const json& dr = nd.at(
"dropRule");
2190 for (
auto it = dr.begin(); it != dr.end(); ++it) {
2191 auto cit = class_idx.find(it.key());
2192 if (cit != class_idx.end())
2194 detail::drop_from_json(it.value().get<std::string>()));
2197 if (nd.contains(
"buffer") && station_node)
2198 net.
set_capacity(idx, detail::num_from_json(nd.at(
"buffer")));
2200 if (nd.contains(
"classCap")) {
2201 const json& cc = nd.at(
"classCap");
2202 for (
auto it = cc.begin(); it != cc.end(); ++it) {
2203 auto cit = class_idx.find(it.key());
2204 if (cit != class_idx.end())
2216 if (nd.contains(
"patience")) {
2217 const json& pt = nd.at(
"patience");
2218 for (
auto it = pt.begin(); it != pt.end(); ++it) {
2219 auto cit = class_idx.find(it.key());
2220 if (cit == class_idx.end())
continue;
2221 const json& pj = it.value();
2223 pj.contains(
"impatienceType")
2224 ? detail::impatience_from_json(pj.at(
"impatienceType").get<std::string>())
2226 net.
set_patience(idx, cit->second, detail::dist_from_json<T>(pj.at(
"distribution")),
2230 if (nd.contains(
"orbitImpatience")) {
2231 const json& oi = nd.at(
"orbitImpatience");
2232 for (
auto it = oi.begin(); it != oi.end(); ++it) {
2233 auto cit = class_idx.find(it.key());
2234 if (cit != class_idx.end())
2238 if (nd.contains(
"batchRejectProb")) {
2239 const json& br = nd.at(
"batchRejectProb");
2240 for (
auto it = br.begin(); it != br.end(); ++it) {
2241 auto cit = class_idx.find(it.key());
2242 if (cit != class_idx.end())
2247 if (nd.contains(
"balking")) {
2248 const json& bk = nd.at(
"balking");
2249 for (
auto it = bk.begin(); it != bk.end(); ++it) {
2250 auto cit = class_idx.find(it.key());
2251 if (cit == class_idx.end())
continue;
2252 const json& bj = it.value();
2253 std::vector<typename qn::Station<T>::BalkingThreshold> ths;
2254 if (bj.contains(
"thresholds"))
2255 for (
const json& tj : bj.at(
"thresholds")) {
2257 th.
min_jobs = tj.value(
"minJobs", 0.0);
2261 th.
max_jobs = tj.value(
"maxJobs", -1.0);
2266 detail::balking_from_json(bj.at(
"strategy").get<std::string>()), ths);
2269 if (nd.contains(
"retrial")) {
2270 const json& rt = nd.at(
"retrial");
2271 for (
auto it = rt.begin(); it != rt.end(); ++it) {
2272 auto cit = class_idx.find(it.key());
2273 if (cit == class_idx.end())
continue;
2274 const lang::Distrib<T> delay = detail::dist_from_json<T>(it.value().at(
"delay"));
2279 int(detail::num_value(it.value(),
"maxAttempts", 0.0)));
2282 if (it.value().contains(
"policy") || it.value().contains(
"maxOrbit")) {
2284 if (it.value().contains(
"policy")) {
2285 const std::string p = it.value().at(
"policy").get<std::string>();
2286 if (p ==
"linear" || p ==
"per-customer" || p ==
"falin") policy = 1;
2287 else if (p ==
"constant" || p ==
"fixed" || p ==
"controller") policy = 2;
2290 "network_reader: unrecognized retrial policy '" + p +
"'");
2293 int(detail::num_value(it.value(),
"maxOrbit", -1.0)),
2298 if (it.value().contains(
"joinProb") || it.value().contains(
"persistProb"))
2302 if (it.value().contains(
"searchProb"))
2309 if (nd.contains(
"setupTime")) {
2310 if (!nd.contains(
"delayOffTime"))
2312 "network_reader: node '" + nd.at(
"name").get<std::string>() +
2313 "' declares a setup time with no delay-off time; a server that never powers "
2314 "down never pays the setup, so the pair is meaningless alone");
2315 const json& su = nd.at(
"setupTime");
2316 const json& doff = nd.at(
"delayOffTime");
2317 for (
auto it = su.begin(); it != su.end(); ++it) {
2318 auto cit = class_idx.find(it.key());
2319 if (cit == class_idx.end() || !doff.contains(it.key()))
continue;
2321 detail::dist_from_json<T>(doff.at(it.key())));
2330 if (nd.contains(
"breakdown")) {
2331 const json& bd = nd.at(
"breakdown");
2332 if (!bd.contains(
"failure") || !bd.contains(
"repair"))
2334 "network_reader: node '" + nd.at(
"name").get<std::string>() +
2335 "' declares a breakdown without both a failure and a repair time; a server "
2336 "that never recovers is an absorbing model, not a breakdown");
2337 std::vector<lang::Distrib<T> > down(class_idx.size(),
2339 if (bd.contains(
"downService")) {
2340 const json& ds = bd.at(
"downService");
2341 for (
auto it = ds.begin(); it != ds.end(); ++it) {
2342 auto cit = class_idx.find(it.key());
2343 if (cit == class_idx.end())
continue;
2344 if (cit->second >= 1 && cit->second <= down.size())
2345 down[cit->second - 1] = detail::dist_from_json<T>(it.value());
2348 net.
set_breakdown(idx, detail::dist_from_json<T>(bd.at(
"failure")),
2349 detail::dist_from_json<T>(bd.at(
"repair")), down);
2351 if (nd.contains(
"switchoverTimes")) {
2365 const bool polling = type ==
"Queue" &&
2366 nd.value(
"scheduling", std::string()) ==
"POLLING";
2367 for (
const json& so : nd.at(
"switchoverTimes")) {
2368 auto cit = class_idx.find(so.at(
"from").get<std::string>());
2369 if (cit == class_idx.end())
continue;
2370 const std::string to = so.value(
"to", std::string());
2374 "network_reader: node '" + nd.at(
"name").get<std::string>() +
2375 "' is POLLING-scheduled but declares a switchover that names the "
2376 "class moved TO; a polling switchover is the walk out of one buffer");
2378 detail::dist_from_json<T>(so.at(
"distribution")));
2383 "network_reader: node '" + nd.at(
"name").get<std::string>() +
2384 "' declares a switchover without the class moved TO, which only a "
2385 "POLLING station's per-buffer walk may omit");
2386 auto tit = class_idx.find(to);
2387 if (tit == class_idx.end())
continue;
2389 detail::dist_from_json<T>(so.at(
"distribution")));
2392 if (nd.contains(
"quantum")) {
2396 const json& qm = nd.at(
"quantum");
2397 for (
auto it = qm.begin(); it != qm.end(); ++it) {
2398 auto cit = class_idx.find(it.key());
2399 if (cit == class_idx.end())
continue;
2400 net.
set_quantum(idx, cit->second, detail::dist_from_json<T>(it.value()));
2405 if (nd.contains(
"pollingTable") && !nd.at(
"pollingTable").empty()) {
2406 std::vector<std::size_t> tab;
2407 std::vector<lang::Distrib<T>> swl;
2408 for (
const json& te : nd.at(
"pollingTable")) {
2409 auto cit = class_idx.find(te.at(
"class").get<std::string>());
2410 if (cit == class_idx.end())
2411 throw InputError(
ErrorKind{
"Model"},
"network_reader: node '" + nd.at(
"name").get<std::string>() +
2412 "' has a polling table entry naming an unknown class");
2413 tab.push_back(cit->second);
2414 swl.push_back(te.contains(
"switchover") && !te.at(
"switchover").is_null()
2415 ? detail::dist_from_json<T>(te.at(
"switchover"))
2420 if (nd.contains(
"pollingOrder") && nd.at(
"pollingOrder").is_string()) {
2421 const lang::PollingOrder po = detail::polling_order_from_json(nd.at(
"pollingOrder").get<std::string>());
2423 auto cit = class_idx.find(nd.at(
"pollingOrderClass").get<std::string>());
2424 if (cit == class_idx.end())
2425 throw InputError(
ErrorKind{
"Model"},
"network_reader: node '" + nd.at(
"name").get<std::string>() +
2426 "' has a THRESHOLD polling order naming an unknown class");
2428 static_cast<long>(std::lround(nd.at(
"pollingOrderThreshold").get<
double>())));
2433 if (nd.contains(
"pollingTimer") && nd.at(
"pollingTimer").is_object()) {
2434 const json& tm = nd.at(
"pollingTimer");
2436 if (tm.contains(
"distributions"))
2437 for (
const json& td : tm.at(
"distributions")) {
2438 auto cit = class_idx.find(td.at(
"class").get<std::string>());
2439 if (cit == class_idx.end())
continue;
2440 tl[cit->second - 1] = detail::dist_from_json<T>(td.at(
"distribution"));
2445 for (
const auto& d : tl)
2446 if (!d.disabled) { first = &d;
break; }
2447 if (first !=
nullptr) {
2450 if (d.disabled) d = f;
2451 const bool preempt = tm.contains(
"preemptive") &&
2452 (tm.at(
"preemptive").is_boolean() ? tm.at(
"preemptive").get<
bool>()
2453 : tm.at(
"preemptive").get<
double>() != 0.0);
2454 net.
set_polling_timer(idx, tl, detail::polling_timer_from_json(tm.value(
"scope", std::string(
"LOCAL"))),
2458 if (nd.contains(
"serverTypes")) {
2459 for (
const json& st : nd.at(
"serverTypes")) {
2461 stype.
name = st.value(
"name", std::string());
2462 stype.
count = st.value(
"count", 1.0);
2463 if (st.contains(
"compatibleClasses")) {
2464 stype.
compatible.assign(classes.size(),
false);
2465 for (
const json& cn : st.at(
"compatibleClasses")) {
2466 auto cit = class_idx.find(cn.get<std::string>());
2467 if (cit != class_idx.end()) stype.
compatible[cit->second - 1] =
true;
2470 if (st.contains(
"service")) {
2472 const json& sv = st.at(
"service");
2473 for (
auto it = sv.begin(); it != sv.end(); ++it) {
2474 auto cit = class_idx.find(it.key());
2475 if (cit != class_idx.end())
2476 stype.
service[cit->second - 1] = detail::dist_from_json<T>(it.value());
2481 if (nd.contains(
"heteroSchedPolicy"))
2483 idx, detail::hetero_from_json(nd.at(
"heteroSchedPolicy").get<std::string>()));
2487 if (nd.contains(
"serverParallelism")) {
2488 const json& sp = nd.at(
"serverParallelism");
2489 for (
auto it = sp.begin(); it != sp.end(); ++it) {
2490 auto cit = class_idx.find(it.key());
2491 if (cit != class_idx.end())
2497 if (nd.contains(
"arrivalBatch")) {
2498 const json& ab = nd.at(
"arrivalBatch");
2499 for (
auto it = ab.begin(); it != ab.end(); ++it) {
2500 auto cit = class_idx.find(it.key());
2501 if (cit != class_idx.end())
2505 if (nd.contains(
"markedClasses")) {
2506 std::vector<std::size_t> marks;
2507 for (
const json& cn : nd.at(
"markedClasses")) {
2508 auto cit = class_idx.find(cn.get<std::string>());
2509 if (cit == class_idx.end())
2510 throw InputError(
ErrorKind{
"Format"},
"network_reader: node '" + nd.at(
"name").get<std::string>() +
2511 "' binds mark " + std::to_string(marks.size() + 1) +
2512 " to class '" + cn.get<std::string>() +
2513 "', which the model does not declare");
2514 marks.push_back(cit->second);
2528 if (nd.contains(
"oiServiceRate")) {
2529 std::vector<int> cut;
2530 if (nd.contains(
"oiCutoffs")) {
2531 const std::vector<double> cv = detail::num_vec_from_json<double>(nd.at(
"oiCutoffs"));
2532 for (std::size_t r = 0; r < classes.size() && r < cv.size(); ++r)
2533 cut.push_back(
static_cast<int>(std::lround(cv[r])));
2535 std::vector<std::vector<bool> > swap;
2536 if (nd.contains(
"swapGraph")) {
2537 const Matrix<T> sg = detail::mat_from_json<T>(nd.at(
"swapGraph"));
2538 swap.assign(sg.
rows(), std::vector<bool>(sg.
cols(),
false));
2539 for (std::size_t a = 0; a < sg.
rows(); ++a)
2540 for (std::size_t b = 0; b < sg.
cols(); ++b)
2544 detail::oi_rate_from_json<T>(nd.at(
"oiServiceRate"), cut, classes.size()),
2549 if (nd.contains(
"initialState") && type ==
"Place") {
2551 }
else if (nd.contains(
"initialState") && !nd.contains(
"stateSpace")) {
2560 const std::vector<T> row = detail::num_vec_from_json<T>(nd.at(
"initialState"));
2563 for (std::size_t k = 0; k < row.size(); ++k) space(0, k) = row[k];
2567 if (nd.contains(
"statePrior") || nd.contains(
"stateSpace")) {
2568 if (!nd.contains(
"statePrior") || !nd.contains(
"stateSpace"))
2570 "network_reader: node '" + nd.at(
"name").get<std::string>() +
2571 "' declares one of stateSpace / statePrior without the other; the prior is a "
2572 "distribution over the ROWS of that space and means nothing alone");
2573 net.
set_state_prior(idx, detail::mat_from_json<T>(nd.at(
"stateSpace")),
2574 detail::num_vec_from_json<T>(nd.at(
"statePrior")));
2576 if (nd.contains(
"departureDiscipline")) {
2577 const json& dd = nd.at(
"departureDiscipline");
2578 for (
auto it = dd.begin(); it != dd.end(); ++it) {
2579 auto cit = class_idx.find(it.key());
2580 if (cit != class_idx.end())
2582 idx, cit->second, detail::departure_from_json(it.value().get<std::string>()));
2590 for (
int kind = 0; kind < 3; ++kind) {
2591 static const char* kKeys[] = {
"loadDependence",
"classDependence",
2593 static const char* kTypes[] = {
"loadDependent",
"classDependent",
2595 if (!nd.contains(kKeys[kind]))
continue;
2596 if (type !=
"Queue" && type !=
"Delay")
2598 std::string(
"network_reader: node '") + nd.at(
"name").get<std::string>() +
2599 "' carries '" + kKeys[kind] +
2600 "', which scales a SERVICE rate and is only meaningful at a Queue or a "
2602 const detail::json& blk = nd.at(kKeys[kind]);
2603 if (blk.value(
"type", std::string(kTypes[kind])) != kTypes[kind])
2605 "' at node '" + nd.at(
"name").get<std::string>() +
2606 "' declares type '" +
2607 blk.value(
"type", std::string(
"?")) +
2608 "', which this reader does not implement");
2609 if (!blk.contains(
"scaling"))
2611 "' at node '" + nd.at(
"name").get<std::string>() +
2612 "' carries no 'scaling'");
2622 std::vector<int> cut;
2623 if (blk.contains(
"cutoffs")) {
2624 const std::vector<double> cv = detail::num_vec_from_json<double>(blk.at(
"cutoffs"));
2625 for (std::size_t r = 0; r < classes.size() && r < cv.size(); ++r)
2626 cut.push_back(
static_cast<int>(std::lround(cv[r])));
2629 detail::cd_scaling_from_json<T>(blk.at(
"scaling"), cut, classes.size());
2630 const std::vector<T> peak = detail::cd_peak_from_json<T>(blk, blk.at(
"scaling"));
2637 if (nd.contains(
"immediateFeedback")) {
2638 const json& imf = nd.at(
"immediateFeedback");
2639 for (
auto it = imf.begin(); it != imf.end(); ++it) {
2640 auto cit = class_idx.find(it.key());
2641 if (cit != class_idx.end() && it.value().get<
bool>())
2648 const json& routing = model.at(
"routing");
2650 const json& mat = routing.at(
"matrix");
2651 for (
auto ck = mat.begin(); ck != mat.end(); ++ck) {
2653 const std::string key = ck.key();
2654 const std::size_t comma = key.find(
',');
2655 const std::string cs = comma == std::string::npos ? key : key.substr(0, comma);
2656 const std::string cd = comma == std::string::npos ? key : key.substr(comma + 1);
2657 const std::size_t r = class_idx.at(cs);
2658 const std::size_t s = class_idx.at(cd);
2659 for (
auto si = ck.value().begin(); si != ck.value().end(); ++si) {
2660 const std::size_t from = node_idx.at(si.key());
2661 for (
auto di = si.value().begin(); di != si.value().end(); ++di)
2662 P.set(r, s, from, node_idx.at(di.key()),
2675 if (model.contains(
"routingStrategies")) {
2676 const json& rs = model.at(
"routingStrategies");
2677 for (
auto ni = rs.begin(); ni != rs.end(); ++ni) {
2678 auto nit = node_idx.find(ni.key());
2679 for (
auto ci = ni.value().begin(); ci != ni.value().end(); ++ci) {
2681 detail::routing_from_json(ci.value().get<std::string>());
2689 if (nit == node_idx.end()) {
2691 throw InputError(
ErrorKind{
"Format"},
"network_reader: routingStrategies names node '" + ni.key() +
2692 "', which the model does not declare");
2695 auto cit = class_idx.find(ci.key());
2696 if (cit == class_idx.end())
continue;
2701 if (model.contains(
"routingWeights")) {
2702 const json& rw = model.at(
"routingWeights");
2703 for (
auto ni = rw.begin(); ni != rw.end(); ++ni) {
2704 auto nit = node_idx.find(ni.key());
2705 if (nit == node_idx.end())
continue;
2706 for (
auto ci = ni.value().begin(); ci != ni.value().end(); ++ci) {
2707 auto cit = class_idx.find(ci.key());
2708 if (cit == class_idx.end())
continue;
2709 std::map<std::size_t, double> w;
2710 for (
auto di = ci.value().begin(); di != ci.value().end(); ++di) {
2711 auto dit = node_idx.find(di.key());
2712 if (dit != node_idx.end()) w[dit->second] = di.value().get<
double>();
2718 if (model.contains(
"routingParams")) {
2719 const json& rp = model.at(
"routingParams");
2720 for (
auto ni = rp.begin(); ni != rp.end(); ++ni) {
2721 auto nit = node_idx.find(ni.key());
2722 if (nit == node_idx.end())
continue;
2723 for (
auto ci = ni.value().begin(); ci != ni.value().end(); ++ci) {
2724 auto cit = class_idx.find(ci.key());
2725 if (cit == class_idx.end() || !ci.value().contains(
"d"))
continue;
2740 if (model.contains(
"stateDepRouting")) {
2741 const json& sd = model.at(
"stateDepRouting");
2742 for (
const char* k : {
"entry",
"departure",
"class",
"branches",
"level",
"C",
"d"})
2743 if (!sd.contains(k))
2744 throw InputError(
ErrorKind{
"Format"}, std::string(
"network_reader: 'stateDepRouting' carries no '") + k +
2746 auto node_of = [&](
const std::string& nm) -> std::size_t {
2747 const std::map<std::string, std::size_t>::const_iterator it = node_idx.find(nm);
2748 if (it == node_idx.end())
2749 throw InputError(
ErrorKind{
"Format"},
"network_reader: 'stateDepRouting' names node '" + nm +
2750 "', which the model does not declare");
2753 const std::map<std::string, std::size_t>::const_iterator ci =
2754 class_idx.find(sd.at(
"class").get<std::string>());
2755 if (ci == class_idx.end())
2757 sd.at(
"class").get<std::string>() +
2758 "', which the model does not declare");
2759 std::vector<std::vector<std::size_t>> branches;
2760 for (
const json& b : sd.at(
"branches")) {
2761 std::vector<std::size_t> centres;
2762 for (
const json& nm : b) centres.push_back(node_of(nm.get<std::string>()));
2763 branches.push_back(centres);
2765 std::vector<std::size_t> level;
2766 for (
const json& v : sd.at(
"level")) level.push_back(
static_cast<std::size_t
>(v.get<
double>()));
2767 std::vector<double> C;
2768 for (
const json& v : sd.at(
"C")) C.push_back(v.get<
double>());
2769 const json& dj = sd.at(
"d");
2770 Matrix<double> d(dj.size(), dj.empty() ? 0 : dj.at(0).size(), 0.0);
2771 for (std::size_t t = 0; t < dj.size(); ++t) {
2772 if (dj.at(t).size() != d.
cols())
2773 throw InputError(
ErrorKind{
"Format"},
"network_reader: 'stateDepRouting' carries a ragged coefficient "
2775 for (std::size_t b = 0; b < d.
cols(); ++b) d(t, b) = dj.at(t).at(b).get<
double>();
2778 node_of(sd.at(
"departure").get<std::string>()), branches, level, C,
2790 if (model.contains(
"globalDependence")) {
2791 const json& blk = model.at(
"globalDependence");
2792 if (blk.value(
"type", std::string(
"globalDependent")) !=
"globalDependent")
2794 std::string(
"network_reader: 'globalDependence' declares type '") +
2795 blk.value(
"type", std::string(
"?")) +
"', which this reader does not implement");
2796 if (!blk.contains(
"scaling"))
2797 throw InputError(
ErrorKind{
"Format"},
"network_reader: 'globalDependence' carries no 'scaling'");
2799 const std::size_t M = sn0.nstations, K = sn0.nclasses;
2800 std::vector<std::size_t> slot_st, slot_cl;
2801 if (blk.contains(
"slots"))
2802 for (
const json& sm : blk.at(
"slots")) {
2803 auto nit = node_idx.find(sm.at(
"station").get<std::string>());
2804 auto cit = class_idx.find(sm.at(
"class").get<std::string>());
2805 if (nit == node_idx.end() || cit == class_idx.end())
2807 "network_reader: 'globalDependence' names a station or class the model "
2808 "does not declare");
2809 slot_st.push_back(sn0.nodes[nit->second - 1].station - 1);
2810 slot_cl.push_back(cit->second - 1);
2812 const std::size_t P = slot_st.size();
2813 std::vector<int> cuts(P, 0);
2814 if (blk.contains(
"cutoffs")) {
2815 const std::vector<double> cv = detail::num_vec_from_json<double>(blk.at(
"cutoffs"));
2816 for (std::size_t d = 0; d < P && d < cv.size(); ++d)
2817 cuts[d] =
static_cast<int>(std::lround(cv[d]));
2819 const int wcut = blk.value(
"cutoff", 10);
2820 std::map<std::string, std::vector<T>> tbl;
2821 for (
auto it = blk.at(
"scaling").begin(); it != blk.at(
"scaling").end(); ++it)
2822 tbl[it.key()] = detail::num_vec_from_json<T>(it.value());
2824 if (blk.contains(
"peak")) {
2825 const std::vector<T> pv = detail::num_vec_from_json<T>(blk.at(
"peak"));
2826 for (std::size_t j = 0; j < peak.size() && j < pv.size(); ++j) peak[j] = pv[j];
2830 [slot_st, slot_cl, cuts, tbl,
ones, K, P](
const std::vector<T>& n) {
2832 if (P == 0) key =
"0";
2834 for (std::size_t d = 0; d < P; ++d) {
2837 if (x > cuts[d]) x = cuts[d];
2839 key += std::to_string(x);
2841 typename std::map<std::string, std::vector<T>>::const_iterator it = tbl.find(key);
2842 return it == tbl.end() ?
ones : it->second;
2853 if (model.contains(
"finiteCapacityRegions")) {
2854 for (
const json& rj : model.at(
"finiteCapacityRegions")) {
2855 std::vector<std::size_t> members;
2859 std::vector<double> cap(classes.size(), -1.0);
2860 auto read_class_map = [&](
const json& blk, std::vector<double>& dst) {
2861 for (
auto it = blk.begin(); it != blk.end(); ++it) {
2862 auto cit = class_idx.find(it.key());
2863 if (cit == class_idx.end())
continue;
2864 const double v = it.value().get<
double>();
2865 double& slot = dst[cit->second - 1];
2866 slot = slot == -1.0 ? v : std::min(slot, v);
2869 if (rj.contains(
"classMaxJobs")) read_class_map(rj.at(
"classMaxJobs"), cap);
2870 for (
const json& sj : rj.at(
"stations")) {
2871 auto nit = node_idx.find(sj.at(
"node").get<std::string>());
2872 if (nit == node_idx.end())
2874 rj.value(
"name", std::string(
"?")) +
"' names node '" +
2875 sj.at(
"node").get<std::string>() +
2876 "', which the model does not declare");
2877 members.push_back(nit->second);
2878 if (sj.contains(
"classCap")) read_class_map(sj.at(
"classCap"), cap);
2880 std::vector<double> mem(classes.size(), -1.0);
2881 if (rj.contains(
"classMaxMemory")) read_class_map(rj.at(
"classMaxMemory"), mem);
2884 for (
const json& sj : rj.at(
"stations")) {
2885 if (sj.contains(
"classSize"))
2886 for (
auto it = sj.at(
"classSize").begin(); it != sj.at(
"classSize").end(); ++it) {
2887 auto cit = class_idx.find(it.key());
2888 if (cit != class_idx.end())
2889 size[cit->second - 1] =
2892 if (sj.contains(
"classWeight"))
2893 for (
auto it = sj.at(
"classWeight").begin(); it != sj.at(
"classWeight").end();
2895 auto cit = class_idx.find(it.key());
2896 if (cit != class_idx.end())
2897 weight[cit->second - 1] =
2902 if (rj.contains(
"dropRule"))
2903 for (
auto it = rj.at(
"dropRule").begin(); it != rj.at(
"dropRule").end(); ++it) {
2904 auto cit = class_idx.find(it.key());
2905 if (cit != class_idx.end())
2906 rule[cit->second - 1] = detail::drop_from_json(it.value().get<std::string>());
2908 const std::size_t
reg =
2909 net.
add_region(members, cap, rj.value(
"globalMaxJobs", -1.0), rule, mem, size,
2910 rj.value(
"globalMaxMemory", -1.0),
2911 rj.value(
"name", std::string()));
2913 if (rj.contains(
"constraintA") && rj.contains(
"constraintB"))
2915 detail::num_vec_from_json<T>(rj.at(
"constraintB")));
2928 if (model.contains(
"rewards")) {
2929 const std::size_t K = classes.size();
2930 for (
const json& rw : model.at(
"rewards")) {
2931 const std::string nm = rw.at(
"name").get<std::string>();
2932 const std::string kind = rw.at(
"type").get<std::string>();
2933 const std::string node_name = rw.at(
"node").get<std::string>();
2934 auto nit = node_idx.find(node_name);
2935 if (nit == node_idx.end())
2936 throw InputError(
ErrorKind{
"Format"},
"network_reader: reward '" + nm +
"' names node '" + node_name +
2937 "', which the model does not declare");
2940 std::size_t ist = 0;
2941 for (std::size_t s = 0; s < net.
get_struct().station_to_node.size(); ++s)
2942 if (net.
get_struct().station_to_node[s] == nit->second) ist = s + 1;
2946 "', which is not a station and so has no job count");
2950 std::size_t cls = 0;
2951 if (rw.contains(
"class")) {
2952 auto cit = class_idx.find(rw.at(
"class").get<std::string>());
2953 if (cit == class_idx.end())
2954 throw InputError(
ErrorKind{
"Format"},
"network_reader: reward '" + nm +
"' names class '" +
2955 rw.at(
"class").get<std::string>() +
2956 "', which the model does not declare");
2959 const double nservers = net.
get_struct().stations[ist - 1].nservers;
2960 const double cap = net.
get_struct().stations[ist - 1].cap;
2961 const std::size_t base = (ist - 1) * K;
2965 if (kind ==
"QLen") {
2966 net.
set_reward(nm, [base, K, cls](
const std::vector<T>& n) {
2967 if (cls)
return n[base + cls - 1];
2969 for (std::size_t k = 0; k < K; ++k) s = T(s + n[base + k]);
2971 }, kind, nit->second, cls);
2972 }
else if (kind ==
"Util") {
2975 net.
set_reward(nm, [base, K, cls, nservers](
const std::vector<T>& n) {
2977 if (cls) s = n[base + cls - 1];
2979 for (std::size_t k = 0; k < K; ++k) s = T(s + n[base + k]);
2982 }, kind, nit->second, cls);
2983 }
else if (kind ==
"Blocking") {
2984 net.
set_reward(nm, [base, K, cap](
const std::vector<T>& n) {
2986 for (std::size_t k = 0; k < K; ++k) s = T(s + n[base + k]);
2989 }, kind, nit->second, cls);
2992 "network_reader: reward '" + nm +
"' is of type '" + kind +
2993 "', and the reproducible templates are QLen, Util and Blocking; a Custom "
2994 "reward wraps an arbitrary function and is not on the wire at all");
3004 std::ifstream in(path.c_str());
3009 }
catch (
const detail::json::parse_error& e) {
3010 throw InputError(
ErrorKind{
"Format"},
"network_reader: malformed JSON in " + path +
": " + e.what());
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
A queueing network under construction.
void set_drop_rule(std::size_t node, std::size_t cls, DropStrategy rule)
station.setDropRule(class, rule).
void set_state_prior(std::size_t node, const Matrix< T > &space, const std::vector< T > &prior)
StatefulNode.setStatePrior(space, prior): a distribution over the rows of a DECLARED state space.
void set_departure_discipline(std::size_t node, std::size_t cls, lang::DepartureDiscipline rule)
Place.setDepartureDiscipline(class, rule).
std::size_t add_logger(const std::string &nm, const std::string &log_file=std::string())
A Logger node: a pass-through that records every job crossing it.
void set_load_dependence(std::size_t node, const std::vector< T > &alpha)
station.setLoadDependence(alpha): the rate multiplier at population 1, 2, ... The vector is indexed f...
void set_class_capacity(std::size_t node, std::size_t cls, double k)
station.setChainCapacity(class, k).
std::size_t add_source(const std::string &nm)
The external arrival station.
std::size_t add_fork(const std::string &nm, double tasks_per_link=1.0)
A Fork node.
void bind_join(std::size_t join_node, std::size_t fork_node)
Record which Fork a Join created by add_join_unbound closes.
void set_arrival_batch(std::size_t node, std::size_t cls, const Distrib< T > &dist)
Source.setArrivalBatch(class, dist): the batch-size law released at each arrival epoch.
std::size_t add_open_class(const std::string &nm, int prio=0)
An open class.
void set_class_patience(std::size_t cls, const Distrib< T > &dist, lang::ImpatienceType kind=lang::ImpatienceType::RENEGING)
JobClass.setPatience(kind, dist): the CLASS-WIDE abandonment law.
std::size_t add_delay(const std::string &nm)
An infinite-server station (a Delay, MATLAB's Delay / DelayStation).
void set_orbital_search(std::size_t node, std::size_t cls, const T &prob)
Queue.setOrbitalSearch(class, prob): orbital search (Artalejo, Joshua and Krishnamoorthy 2002).
void set_class_spawn(std::size_t cls, std::size_t spawn_cls)
JobClass.spawnClass (sn.classspawn): the class injected at the same station on every completion of cl...
void set_polling_timer(std::size_t node, const std::vector< Distrib< T > > &dists, lang::PollingTimer scope=lang::PollingTimer::LOCAL, bool preemptive=false)
Queue.setPollingTimer(dist, scope, preemptive): a visit timer per class (one law for all classes,...
void set_region_constraint(std::size_t region, const Matrix< T > &A, const std::vector< T > &b)
The optional linear constraint A n <= b a region may carry beyond its caps.
void set_class_immediate_feedback(std::size_t cls)
jobclass.setImmediateFeedback(): the same property, class-wide.
std::size_t add_router(const std::string &nm)
A stateless routing node.
void set_initial_marking(std::size_t node, const std::vector< T > &tokens)
Place.setState(marking): the initial token count of the place, per class.
void set_orbit_persistence(std::size_t node, std::size_t cls, const T &join_prob, const T &persist_prob=num_traits< T >::from_int(1))
Queue.setOrbitPersistence(class, joinProb, persistProb): non-persistent retrial customers (Phung-Duc ...
void set_number_of_servers(std::size_t node, double n)
queue.setNumberOfServers(n).
void set_joint_dependence(std::size_t node, const CdScaling< T > &fun, const std::vector< T > &peak)
station.setJointDependence(eta, peakRatePerClass): MATLAB's Station.ljdScaling / ljdScalingPeak.
void set_fork_tasks_per_link(std::size_t fork_node, std::size_t jobclass, double tasks, std::size_t dest_node=0)
Variable forking levels on an existing Fork, the twin of MATLAB Fork.setTasksPerLink(jobclass,...
void set_patience(std::size_t node, std::size_t cls, const Distrib< T > &dist, lang::ImpatienceType kind=lang::ImpatienceType::RENEGING)
Queue.setPatience(class, dist, type): the abandonment timer of a job WAITING at the station,...
void set_reply_signal_class(std::size_t call_cls, std::size_t reply_cls)
JobClass.setReplySignalClass(reply) (sn.syncreply), plus the sn.replyblock the state layer needs.
std::size_t add_queue(const std::string &nm, SchedStrategy sched=SchedStrategy::FCFS)
A queueing station.
void set_routing(std::size_t node, std::size_t cls, RoutingStrategy rs)
node.setRouting(class, strategy).
void set_join_strategy(std::size_t node, lang::JoinStrategy strategy, double quorum=0.0)
Join.setStrategy(...): STD waits for every sibling, PARTIAL for a quorum.
void set_fork_branch_probability(std::size_t fork_node, std::size_t jobclass, std::size_t dest_node, double prob)
A branch that fires only with probability prob.
std::size_t add_cache(const std::string &nm, const CacheParam< T > &par)
A Cache node with its item population, list capacities and popularity.
void set_reward(const std::string &nm, const std::function< T(const std::vector< T > &)> &fn, const std::string &kind=std::string(), std::size_t node=0, std::size_t cls=0)
model.setReward(name, fn): a named reward evaluated on the AGGREGATE state row, the per-(station,...
void set_fluid_capacity(std::size_t node, double cap)
Place.setFluidCapacity(B): the level ceiling of a fluid place, Inf when unbounded.
std::size_t add_self_looping_class(const std::string &nm, double njobs, std::size_t refstat_node, int prio=0)
SelfLoopingClass(model, name, njobs, refstat, prio): a closed class whose jobs perpetually cycle at t...
void set_marked_classes(std::size_t node, const std::vector< std::size_t > &classes)
Source.markedClasses: the 1-based class carried by each mark of an MMAP.
std::size_t add_closed_class(const std::string &nm, double njobs, std::size_t refstat_node, int prio=0)
A closed class of the given population, referencing a station node.
void set_sched_param(std::size_t node, std::size_t cls, const T &weight)
The DPS / GPS weight of a class at a station.
std::size_t add_class_switch(const std::string &nm, const Matrix< T > &C)
A ClassSwitch node carrying the (nclasses x nclasses) switching matrix.
void set_fork_tasks_per_link_dist(std::size_t fork_node, std::size_t jobclass, const lang::Distrib< T > &dist, std::size_t dest_node=0)
A random jobs-per-link degree, redrawn per link and per forked job.
std::size_t add_sink(const std::string &nm)
The external departure node.
const NetworkStruct< T > & get_struct()
The refreshed struct, MATLAB's model.getStruct().
void set_batch_reject(std::size_t node, std::size_t cls, const T &p)
Queue.setBatchRejectProbability(class, p).
void set_polling_order(std::size_t node, lang::PollingOrder order, std::size_t prioclass=0, long threshold=-1)
Queue.setPollingOrder(order, prioclass, L): the visit-order rule.
void set_class_dependence(std::size_t node, const CdScaling< T > &fun, const std::vector< T > &peak=std::vector< T >())
station.setClassDependence(beta, peakRatePerClass).
void set_fluid_level(std::size_t node, double level)
Place.setFluidLevel(x0): the initial level of a fluid place.
void set_state_dep_routing(std::size_t entry, std::size_t departure, const std::vector< std::vector< std::size_t > > &branches, const std::vector< std::size_t > &level, const std::vector< double > &C, const Matrix< double > &d, std::size_t cls=0)
node.setStateDepRouting(class, departure, branches, level, C, d).
std::size_t add_place(const std::string &nm)
A Place: an SPN token container.
void set_routing_weights(std::size_t node, std::size_t cls, const std::map< std::size_t, double > &weights)
The per-destination weights of a WRROBIN dispatcher, per (node, class).
void set_log_path(const std::string &path)
Network.setLogPath: the directory every Logger of this model writes into.
void set_capacity(std::size_t node, double k)
station.setCapacity(k), the K of Kendall's notation.
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
void set_switchover(std::size_t node, std::size_t cls, const Distrib< T > &so)
Queue.setSwitchover(jobclass, distrib): the switchover time of a class.
void set_place_fluid(std::size_t node, bool fluid)
Place.setFluid(flag): the place holds one real level in [0, fluid capacity] instead of tokens,...
void set_immediate_feedback(std::size_t node, std::size_t cls)
queue.setImmediateFeedback(class): a completing job of that class is fed straight back into service,...
void set_balking(std::size_t node, std::size_t cls, lang::BalkingStrategy strategy, const std::vector< typename Station< T >::BalkingThreshold > &thresholds)
Queue.setBalking(class, strategy, thresholds): an arrival that refuses to JOIN, on the state it finds...
void set_polling_table(std::size_t node, const std::vector< std::size_t > &table, const std::vector< Distrib< T > > &swlegs=std::vector< Distrib< T > >())
Queue.setPollingTable(table, swlegs): the visit sequence of a POLLING station (1-based classes,...
void add_server_type(std::size_t node, const typename Station< T >::ServerType &stype)
Queue.addServerType(...): one heterogeneous server pool of the station.
void set_quantum(std::size_t node, std::size_t cls, const Distrib< T > &q)
Queue.setQuantum(jobclass, distrib): the time slice of a class at a round-robin station.
void set_setup_delayoff(std::size_t node, std::size_t cls, const Distrib< T > &setup, const Distrib< T > &delayoff)
Queue.setDelayOff(class, setupTime, delayoffTime): the station powers down after sitting idle for the...
void set_class_deadline(std::size_t cls, double due)
JobClass.deadline: the soft deadline EDD, EDF and JMT's tardiness use.
void link(const RoutingMatrix< T > &Pm)
model.link(P): install the routing.
void set_routing_param(std::size_t node, std::size_t cls, int d)
The d of a power-of-d (SQ) dispatcher, per (node, class).
void set_retrial(std::size_t node, std::size_t cls, const Distrib< T > &proc, const T &rate, int max_attempts=0)
Queue.setRetrial(...): a station with an ORBIT instead of a waiting line.
void set_service(std::size_t node, std::size_t cls, const Distrib< T > &d)
station.setService(class, dist).
void set_reference_class(std::size_t cls)
JobClass.setReferenceClass(true): sn.refclass(c) picks this class.
std::size_t add_join_unbound(const std::string &nm)
The Join station on its own, with the fork left to bind_join.
void set_hetero_sched_policy(std::size_t node, lang::HeteroSchedPolicy policy)
Queue.setHeteroSchedPolicy(...): how the server pools are picked among.
void set_breakdown(std::size_t node, const Distrib< T > &failure, const Distrib< T > &repair, const std::vector< Distrib< T > > &down_service=std::vector< Distrib< T > >())
Queue.setBreakdown(failure, repair, downService): the server alternates up and down on the two clocks...
void set_pas(std::size_t node, const std::function< T(const std::vector< std::size_t > &)> &mu, const std::vector< std::vector< bool > > &swap_graph=std::vector< std::vector< bool > >())
Queue.setService(@(c) ...) for a pass-and-swap / order-independent station: the total service rate mu...
std::size_t add_transition(const std::string &nm, const TransitionParam< T > &par)
A Transition: the firing rules of an SPN, as Transition in MATLAB.
void set_orbit_impatience(std::size_t node, std::size_t cls, const Distrib< T > &dist)
Queue.setOrbitImpatience(class, dist): abandonment from the retrial orbit.
void set_signal(std::size_t cls, lang::SignalType type, lang::RemovalPolicy policy=lang::RemovalPolicy::RANDOM, std::size_t target=0, const std::vector< T > &remdist=std::vector< T >())
Declare a class to be a G-network SIGNAL rather than a job.
void set_global_dependence(const GdScaling< T > &fun, const std::vector< T > &peak)
model.setGlobalDependence(phi, peak): MATLAB's Network.gdScaling.
void set_server_parallelism(std::size_t node, std::size_t cls, std::size_t n)
Queue.setServerParallelism(class, n): the servers a job seizes for the whole of its service.
void set_orbit_policy(std::size_t node, std::size_t cls, int policy, int max_orbit, bool size_buffer=true)
The policy and bound of Queue.setOrbit(class, dist, policy, maxOrbit) on a class already declared by ...
void set_region_weights(std::size_t region, const std::vector< T > &weight)
FiniteCapacityRegion.setClassWeight: the per-class weight the region's global cap counts a job agains...
void set_arrival(std::size_t node, std::size_t cls, const Distrib< T > &d)
source.setArrival(class, dist): the same table, at the Source.
std::size_t add_region(const std::vector< std::size_t > &nodes, const std::vector< double > &class_max_jobs, double global_max_jobs=-1.0, const std::vector< DropStrategy > &rule=std::vector< DropStrategy >(), const std::vector< double > &class_max_memory=std::vector< double >(), const std::vector< T > &class_size=std::vector< T >(), double global_max_memory=-1.0, const std::string &name=std::string())
FiniteCapacityRegion(model, nodes): a cap on the jobs held ACROSS a set of stations.
void set_polling_type(std::size_t node, lang::PollingType rule, int par=0)
Queue.setPollingType(rule, par): the polling discipline of a POLLING station, identical across all cl...
The routing matrix a model script fills in, MATLAB's P cell array.
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
qn::Network< T > read_network_json(const std::string &path)
Parse a model.json file into a qn::Network<T>.
qn::Network< T > build_network_from_json(const detail::json &root)
Build a qn::Network<T> from a parsed model.json envelope.
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
@ IMMEDIATE
fires with zero delay, resolved by weight and priority
@ TIMED
fires after its firing distribution elapses
BalkingStrategy
Balking rules, with the values of MATLAB BalkingStrategy.
SignalType
G-network signal classes, with the values of MATLAB SignalType.
@ REPLY
completes a synchronous call, releasing a held server
@ NEGATIVE
removes a batch of jobs (Gelenbe's negative customer)
@ CATASTROPHE
removes EVERY job at the station
PollingOrder
Visit-order rules of a polling server, with the values of MATLAB PollingOrder.
@ THRESHOLD
a priority buffer above its threshold, else SKIPEMPTY
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
PollingTimer
Visit-timer scopes of a polling server, with the values of MATLAB PollingTimer.
DepartureDiscipline
When a Place releases a served token, MATLAB DepartureDiscipline.
Distrib< T > prior_continuous(const Distrib< T > ¶m_dist, const std::function< Distrib< T >(const T &)> &factory)
Prior(paramDist, distFactory): the continuous form.
RemovalPolicy
Which job a negative signal removes, with the values of MATLAB RemovalPolicy.
@ FCFS
the oldest waiting job; servers only once nobody waits
@ LCFS
the newest waiting job; servers only once nobody waits
@ RANDOM
uniform over waiting AND in-service jobs
HeteroSchedPolicy
How a heterogeneous station picks among its server types, MATLAB HeteroSchedPolicy.
PollingType
Polling service disciplines, with the values of MATLAB PollingType.
Distrib< T > prior_discrete(const std::vector< Distrib< T > > &alternatives, const std::vector< T > &probabilities)
Prior(distributions, probabilities): the discrete form.
std::function< std::vector< T >(const std::vector< T > &)> CdScaling
A class-dependent scaling map, sn.cdscaling.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
ImpatienceType
Impatience kinds, with the values of MATLAB ImpatienceType.
bool in(const std::string &s, std::initializer_list< const char * > set)
const std::string * get(const Element *el, const std::string &key)
el.get(key), with Python's None as a null pointer.
const std::map< std::string, std::vector< std::string > > & table()
void put(Matrix< double > &A, std::size_t r0, std::size_t c0, const Matrix< double > &S)
A(r0:, c0:) = S.
Conservation laws of a layered queueing network, enumerated from its structure.
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
Number-type abstraction for the templated API port.
Prior: parameter uncertainty as a weighted set of alternative models.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
static Distrib empirical_cdf(const std::vector< T > &x, const std::vector< T > &F)
EmpiricalCDF(x, F): the moments of the MIDPOINT rule over the CDF bins, which is what MATLAB Empirica...
static Distrib nhpp(const std::vector< T > &breakpoints, const std::vector< T > &rates, bool cyclic)
NHPP(breakpoints, rates, cyclic): a MAPt of ORDER ONE, which is what an inhomogeneous Poisson process...
static Distrib mph(const std::vector< T > &alpha, const Matrix< T > &S, const std::vector< std::vector< T > > &exits)
MPH(alpha, S, {s_k}): the marked phase-type law, a PH with K labelled exits.
static Distrib mmapt(const std::vector< T > &breakpoints, const std::vector< Matrix< T > > &D0segs, const std::vector< std::vector< Matrix< T > > > &Dmarksegs, bool cyclic)
MMAPt(breakpoints, {D0_k}, {{D1^(c)_k}}, cyclic): the marked schedule.
static Distrib loglogistic(const T &shape, const T &scale)
LogLogistic(shape, scale), stored in getParam order {alpha = scale, beta = shape}.
static Distrib nnpp_piecewise_linear(const std::vector< double > ×, const std::vector< double > &rates, double dispersion=1.0, bool cyclic=true, int Q=200)
NNPP.piecewiseLinear(times, rates, dispersion, cyclic, Q): linear interpolation of knots.
static Distrib replayer(const std::vector< T > &samples)
Replayer / Trace: the samples, with their empirical first two moments.
static Distrib marked_mmpp(const Matrix< T > &D0, const std::vector< Matrix< T > > &D1k)
MarkedMMPP(D0, {D1k}): the marked MMPP (M3PP), i.e.
static Distrib normal(const T &mu, const T &sigma)
Normal(mu, sigma): the Gaussian, for use as a continuous Prior's parameter density.
static Distrib defective(const Distrib &in, const T &pInf)
Defective(inner, pInf): infinite with probability pInf, else inner.
static Distrib dmap(const Matrix< T > &D0, const Matrix< T > &D1)
DMAP(D0, D1): a DISCRETE-time MAP, where D0 + D1 is stochastic rather than a generator.
static Distrib exp_rate(const T &r)
static Distrib phase_type(const std::vector< T > &alpha, const Matrix< T > &A, bool acyclic)
PH / APH given by (alpha, A): D0 = A and D1 = (-A e) alpha.
static Distrib mapt(const std::vector< T > &breakpoints, const std::vector< Matrix< T > > &D0segs, const std::vector< Matrix< T > > &D1segs, bool cyclic)
MAPt(breakpoints, {D0_k}, {D1_k}, cyclic): a piecewise-constant (D0(t), D1(t)).
static Distrib weibull(const T &scale, const T &shape)
static Distrib bmap(const std::vector< Matrix< T > > &D)
BMAP: the batch-size blocks D0, D1, ..., Dk, where Dj carries an arrival of batch size j.
static Distrib mass_at_origin(const Distrib &in, const T &p0)
MassAtOrigin(inner, p0): zero with probability p0, else inner.
static Distrib mmap(const Matrix< T > &D0, const std::vector< Matrix< T > > &D1k)
MMAP: D0 plus one D1 block per mark.
static Distrib disabled_dist()
static Distrib pht(const std::vector< T > &breakpoints, const std::vector< std::vector< T > > &alphas, const std::vector< Matrix< T > > &Ssegs, bool cyclic)
PHt(breakpoints, {alpha_k}, {S_k}, cyclic), stored as its equivalent MAP schedule: D0 = S and D1 = (-...
static Distrib erlang_fit(const T &m, const T &c2)
Erlang fitted to a mean and an SCV, as MATLAB's Erlang.fitMeanAndSCV.
static Distrib pareto(const T &shape, const T &scale)
Pareto(shape, scale), with the MATLAB parameter order (alpha, k).
static Distrib gamma_dist(const T &shape, const T &scale)
Gamma(shape, scale), Weibull(scale, shape) and Lognormal(mu, sigma).
static Distrib cox2(const T &mu1, const T &mu2, const T &phi1)
Cox2(mu1, mu2, phi1), MATLAB's two-phase Coxian constructor.
static Distrib map_dist(const Matrix< T > &D0, const Matrix< T > &D1, ProcessType tag)
A MAP given by its two matrices; the moments are those of its stationary phase.
static Distrib poisson(const T &lambda)
Poisson(lambda), whose SCV is 1/lambda – the count's variance is lambda and its mean is lambda,...
static Distrib bernoulli(const T &p)
Bernoulli(p): one trial, mean p and variance p(1-p).
static Distrib hyperexp_n(const std::vector< T > &p, const std::vector< T > &lambda)
The same for any number of branches, which is what MATLAB HyperExp accepts and what the writers emit ...
static Distrib discrete_uniform(const T &a, const T &b)
DiscreteUniform(a, b) over the integers a..b inclusive.
static Distrib geometric(const T &p)
Geometric(p) on the MATLAB convention: the NUMBER OF TRIALS to the first success, support {1,...
static Distrib det(const T &m)
static Distrib bmmapt(const std::vector< T > &breakpoints, const std::vector< Matrix< T > > &D0segs, const std::vector< std::vector< std::vector< Matrix< T > > > > &Dbatchsegs, bool cyclic)
BMMAPt(breakpoints, {D0_k}, {{{D^(c,b)_k}}}, cyclic): the BATCH marked schedule.
static Distrib rap(const Matrix< T > &H0, const Matrix< T > &H1)
RAP(H0, H1): a rational arrival process, whose moments are the MAP ones.
static Distrib uniform(const T &a, const T &b)
Uniform(a, b).
static Distrib nnpp_eptmp(const std::vector< double > &alpha, const std::vector< double > &gamma, const std::vector< double > &omega, const std::vector< double > &phi, double horizon, double dispersion=1.0, bool cyclic=true, int Q=200)
NNPP.eptmp(alpha, gamma, omega, phi, horizon, dispersion, cyclic, Q): lambda(t) = exp(sum alpha_i t^i...
static Distrib lognormal(const T &logmean, const T &logsigma)
static Distrib hyperexp(const T &p, const T &lambda1, const T &lambda2)
HyperExp(p, lambda1, lambda2): phase i chosen with probability p_i.
static Distrib me(const std::vector< T > &alpha, const Matrix< T > &A)
ME(alpha, A): the matrix-exponential distribution, whose moments are the phase-type ones – k!
static Distrib immediate()
The point mass at zero.
static Distrib erlang(const T &phase_rate, std::size_t r)
Erlang(alpha, r): r phases of rate alpha, as MATLAB's Erlang(phaseRate, nphases).
static Distrib exp_mean(const T &m)
static Distrib mpht(const std::vector< T > &breakpoints, const std::vector< std::vector< T > > &alphas, const std::vector< Matrix< T > > &Ssegs, const std::vector< std::vector< std::vector< T > > > &exits, bool cyclic)
MPHt(breakpoints, {alpha_k}, {S_k}, {{s^(c)_k}}, cyclic), stored LOWERED to MMAPt form segment by seg...
static Distrib coxian(const std::vector< T > &mu, const std::vector< T > &phi)
Coxian(mu, phi): phase i completes with probability phi(i) and otherwise moves to phase i+1.
static Distrib discrete_sampler(const std::vector< T > &p, const std::vector< T > &x)
DiscreteSampler(p, x): the pmf p over the points x.
static Distrib binomial(const T &n, const T &p)
Binomial(n, p).
static Distrib zipf(const T &s, std::size_t n)
Zipf(s, n) over the ranks 1..n, with the generalized harmonic moments H(s-1,n)/H(s,...
The popularity LAW each class declared, beside the pmf it expands to.
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
int retrieval_capacity
Delayed-hit retrieval system (Cache.setRetrievalSystem).
T qlru
q-LRU admission probability; 1 admits every miss (plain LRU).
std::vector< Popularity > preadkind
per class, parallel to pread
std::vector< T > initstate
The DECLARED initial contents of the cache, as the reference dumps the node's state row: the per-clas...
std::vector< int > itemsize
Per-item storage cost (size) and per-list cap on the total cost of the resident items (ton21cache Sec...
std::vector< int > costcap
std::map< std::size_t, std::vector< std::size_t > > retrieval_queues
read class(0-based)->nodes
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< std::vector< std::size_t > > retrieval_classes
(nitems x nclasses), 1-based
std::vector< int > itemcap
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
lang::ReplacementStrategy replacestrat
std::vector< std::size_t > classitem
Item read by each per-item class of a cache network (MATLAB Cache.setItemReadClasses,...
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN
A Logger node's trace configuration, MATLAB's Logger properties and sn.nodeparam{ind}...
std::string file_path
directory, MATLAB's model.getLogPath
One balking threshold: with min_jobs <= n <= max_jobs at the station, an arriving job of the class re...
A heterogeneous server pool: count servers that serve only compatible classes, each with its own serv...
std::vector< bool > compatible
per class; empty = every class
std::vector< Distrib< T > > service
per class
One fluid arc of a mode: node is the 1-based fluid place, value a rate or an impulse.
A fluid rate dependence: the firing rate is multiplied by fun(level(node)).
std::function< double(double)> fun
A marking-dependent fluid flow (setFluidFlowDependence): the flow of the mode on fluid place node is ...
std::vector< std::size_t > read
std::function< double(const std::vector< double > &)> fun
A fluid guard: the mode is enabled only while level(node) >= thr (sgn = +1) or <= thr (sgn = -1).
The parameters of a Transition node: MATLAB sn.nodeparam{ind} for an SPN transition,...
std::vector< std::vector< FluidDep > > fluiddep
std::vector< double > firingprio
firing priority per mode
std::vector< std::vector< FluidGuard > > fluidguard
std::vector< std::vector< FluidFlowDep > > fluidflowdep
std::vector< lang::TimingStrategy > timing
immediate or timed
std::vector< std::string > modenames
std::vector< std::vector< FluidArc > > fluidimpulse
std::vector< lang::Distrib< T > > firingproc
firing distribution per mode
std::vector< double > nmodeservers
servers per mode, may be infinite
std::vector< T > fireweight
weight among simultaneously enabled modes
std::vector< Matrix< T > > firing
firing[m](p,r): class-r tokens mode m moves to/from place p when it fires.
std::vector< Matrix< T > > enabling
enabling[m](p,r): class-r tokens of place p (0-based node) mode m needs.
std::vector< std::function< T(const std::vector< T > &)> > firingdep
Marking-dependent firing-rate multiplier g_m(marking); an empty entry is the unit multiplier.
std::vector< Matrix< T > > inhibiting
inhibiting[m](p,r): class-r tokens of p that BLOCK mode m (Inf = never).
std::vector< std::vector< FluidArc > > fluidrate
FSPN arcs per mode, MATLAB sn.transparam{ind}.fluidrate/fluidguard/fluidimpulse/fluiddep.
std::vector< std::size_t > firingphases
phase count per mode, 0 when non-Markovian