LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
network_decl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_LANG_LAL_NETWORK_DECL_H
6#define LINE_LANG_LAL_NETWORK_DECL_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * LINE Agent Language (LAL): the declarative queueing-network, layered and
12 * random-environment subset (`lal/network.py`, `lal/layered.py` and
13 * `lal/environment.py`).
14 *
15 * Each line is one declaration, split by the POSIX shell-word rules of
16 * Python's `shlex.split(line, comments=True)`: names are words, a quoted
17 * string may carry blanks, and an unquoted `#` starts a comment. The compiler
18 * builds native C++ models through their own builders and evaluates no code:
19 *
20 * - `build_network` gives a `qn::Network<double>`;
21 * - `build_layered` gives a `LayeredModel` around an `lqn::LqnBuilder<double>`;
22 * - `build_environment` gives an `env::Environment<double>` whose stages are
23 * fresh builds of a base network with one service rate overridden.
24 *
25 * Every error is an `InputError` whose message starts with `line N:`, as the
26 * reference wraps its `ValueError`, except the post-pass checks (unknown
27 * parameters, routing probabilities, mixed route/link), which the reference
28 * also raises without a line number. A declaration that has no counterpart in
29 * this port is refused with `LINE:unsupported:LAL_<construct>`.
30 */
31
32#include <cmath>
33#include <cstdlib>
34#include <filesystem>
35#include <map>
36#include <set>
37#include <string>
38#include <utility>
39#include <vector>
40
43#include "json.hpp"
44#include "line/lang/lal/core.h"
49#include "line/lang/prior.h"
52#include "line/util/error.h"
53
54namespace line {
55namespace lal {
56
57/** One declaration: its 1-based source line and its shell words. */
58using Declaration = std::pair<std::size_t, std::vector<std::string>>;
59
60/** `NetworkSpec`: the network name and the declarations after the header line. */
62 std::string name;
63 std::vector<Declaration> declarations;
64};
65
66namespace decl_detail {
67
68/**
69 * `shlex.split(line, comments=True)`: POSIX words with `'...'`, `"..."` and
70 * backslash escapes, adjacent pieces concatenated, `#` outside quotes ending
71 * the line. Throws `value_error` with shlex's own messages.
72 */
73inline std::vector<std::string> shell_words(const std::string& line) {
74 std::vector<std::string> out;
75 std::string tok;
76 bool in_word = false; // a token is open (possibly an empty quoted one)
77 enum { WS, WORD, SQ, DQ } st = WS;
78 for (std::size_t k = 0; k < line.size(); ++k) {
79 const char c = line[k];
80 switch (st) {
81 case WS:
82 case WORD:
83 if (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
84 if (in_word) out.push_back(tok);
85 tok.clear();
86 in_word = false;
87 st = WS;
88 } else if (c == '#') {
89 if (in_word) out.push_back(tok);
90 return out;
91 } else if (c == '\\') {
92 if (k + 1 >= line.size()) throw value_error("No escaped character");
93 tok += line[++k];
94 in_word = true;
95 st = WORD;
96 } else if (c == '\'') {
97 in_word = true;
98 st = SQ;
99 } else if (c == '"') {
100 in_word = true;
101 st = DQ;
102 } else {
103 tok += c;
104 in_word = true;
105 st = WORD;
106 }
107 break;
108 case SQ:
109 if (c == '\'') st = WORD;
110 else tok += c;
111 break;
112 case DQ:
113 if (c == '"') {
114 st = WORD;
115 } else if (c == '\\' && k + 1 < line.size() && (line[k + 1] == '"' || line[k + 1] == '\\')) {
116 tok += line[++k];
117 } else if (c == '\\' && k + 1 >= line.size()) {
118 throw value_error("No closing quotation");
119 } else {
120 tok += c;
121 }
122 break;
123 }
124 }
125 if (st == SQ || st == DQ) throw value_error("No closing quotation");
126 if (in_word) out.push_back(tok);
127 return out;
128}
129
130/** The nonblank lines of `text`, numbered from 1 as `str.splitlines()` numbers them. */
131inline std::vector<Declaration> split_rows(const std::string& text) {
132 std::vector<Declaration> rows;
133 std::size_t number = 0, start = 0;
134 while (start <= text.size()) {
135 std::size_t end = text.find_first_of("\r\n", start);
136 const bool last = end == std::string::npos;
137 if (last) end = text.size();
138 if (last && start == text.size()) break; // splitlines drops the empty tail
139 ++number;
140 const std::string line = text.substr(start, end - start);
141 std::vector<std::string> words;
142 try {
143 words = shell_words(line);
144 } catch (const InputError& e) {
145 throw value_error("line " + std::to_string(number) + ": " + e.what());
146 }
147 if (!words.empty()) rows.push_back(Declaration(number, words));
148 if (last) break;
149 start = end + ((text[end] == '\r' && end + 1 < text.size() && text[end + 1] == '\n') ? 2 : 1);
150 }
151 return rows;
152}
153
154/** Python `float(token)`: the whole word must be a number (`inf` and `nan` included). */
155inline double to_float(const std::string& s) {
156 std::size_t i = 0, j = s.size();
157 while (i < j && std::isspace(static_cast<unsigned char>(s[i]))) ++i;
158 while (j > i && std::isspace(static_cast<unsigned char>(s[j - 1]))) --j;
159 const std::string t = s.substr(i, j - i);
160 if (t.empty()) throw value_error("could not convert string to float: '" + s + "'");
161 const char* b = t.c_str();
162 char* e = nullptr;
163 const double v = std::strtod(b, &e);
164 if (e != b + t.size() || (t.size() > 1 && (t[0] == '0') && (t[1] == 'x' || t[1] == 'X')))
165 throw value_error("could not convert string to float: '" + s + "'");
166 return v;
167}
168
169/** Python `int(token)`: an optionally signed run of decimal digits. */
170inline long to_int(const std::string& s) {
171 std::size_t i = 0, j = s.size();
172 while (i < j && std::isspace(static_cast<unsigned char>(s[i]))) ++i;
173 while (j > i && std::isspace(static_cast<unsigned char>(s[j - 1]))) --j;
174 std::size_t k = i;
175 if (k < j && (s[k] == '+' || s[k] == '-')) ++k;
176 bool digits = k < j;
177 for (std::size_t m = k; m < j; ++m)
178 if (!std::isdigit(static_cast<unsigned char>(s[m]))) digits = false;
179 if (!digits) throw value_error("invalid literal for int() with base 10: '" + s + "'");
180 return std::stol(s.substr(i, j - i));
181}
182
183/** A nonnegative count, `int(token)` then checked for a sign. */
184inline std::size_t to_count(const std::string& s, const std::string& what) {
185 const long v = to_int(s);
186 if (v < 0) throw value_error(what + " must be nonnegative");
187 return static_cast<std::size_t>(v);
188}
189
190/** `getattr(SchedStrategy, name)` over the strategies this port enumerates. */
191inline lang::SchedStrategy sched_by_name(const std::string& name) {
192 static const std::map<std::string, lang::SchedStrategy> table = [] {
193 std::map<std::string, lang::SchedStrategy> m;
194 for (int v = 0; v <= 40; ++v) {
195 const lang::SchedStrategy s = static_cast<lang::SchedStrategy>(v);
196 std::string t = lang::sched_to_text(s);
197 if (t == "none") continue;
198 for (char& c : t) c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
199 m[t] = s;
200 }
201 m["LAS"] = lang::SchedStrategy::LAS;
202 m["FCFSPRIO"] = lang::SchedStrategy::HOL; // the reference's alias of HOL
203 return m;
204 }();
205 const auto it = table.find(name);
206 if (it == table.end()) throw value_error("unknown scheduling strategy " + name);
207 return it->second;
208}
209
210/** `getattr(RoutingStrategy, name)`. */
211inline lang::RoutingStrategy routing_by_name(const std::string& name) {
212 static const std::map<std::string, lang::RoutingStrategy> table = {
218 const auto it = table.find(name);
219 if (it == table.end()) throw value_error("unknown routing strategy " + name);
220 return it->second;
221}
222
223/** `getattr(ReplacementStrategy, name)`. */
224inline lang::ReplacementStrategy replacement_by_name(const std::string& name) {
225 static const std::map<std::string, lang::ReplacementStrategy> table = {
230 const auto it = table.find(name);
231 if (it == table.end()) throw value_error("unknown replacement strategy " + name);
232 return it->second;
233}
234
235/**
236 * The LINE repository root, the base a relative trace path falls back to:
237 * `$LINE_ROOT` when set, else five levels above this header
238 * (`cpp/include/line/lang/lal/`), which is the reference's `parents[3]` of
239 * `python/line_solver/lal/network.py`.
240 */
241inline std::filesystem::path repo_root() {
242 if (const char* env = std::getenv("LINE_ROOT"))
243 if (*env) return std::filesystem::path(env);
244 std::filesystem::path p = std::filesystem::absolute(std::filesystem::path(__FILE__));
245 for (int k = 0; k < 6; ++k) p = p.parent_path();
246 return p;
247}
248
249/** `_trace_path`: as given, else relative to the repository root; then made absolute. */
250inline std::string trace_path(const std::string& name) {
251 namespace fs = std::filesystem;
252 fs::path p(name);
253 if (!p.is_absolute() && !fs::exists(p)) {
254 const fs::path alt = repo_root() / p;
255 if (fs::exists(alt)) p = alt;
256 }
257 return fs::weakly_canonical(fs::absolute(p)).string();
258}
259
260/**
261 * `Replayer(path).fit_aph()`: the population mean and variance and the
262 * bias-corrected sample skewness (scipy `skew(bias=False)`) of the trace,
263 * matched by `APH.fitCentral`.
264 */
265inline lang::Distrib<double> replayer_fit_aph(const std::string& path) {
266 const Replayer rep(path);
267 const std::vector<double>& x = rep.trace;
268 const double n = static_cast<double>(x.size());
269 double mean = 0.0;
270 for (double v : x) mean += v;
271 mean /= n;
272 double m2 = 0.0, m3 = 0.0;
273 for (double v : x) {
274 const double d = v - mean;
275 m2 += d * d;
276 m3 += d * d * d;
277 }
278 m2 /= n;
279 m3 /= n;
280 if (!(x.size() > 2) || !(m2 > 0.0))
281 throw value_error("Replayer.fit_aph: the trace needs three distinct samples to fix a skewness");
282 const double g1 = m3 / std::pow(m2, 1.5);
283 const double skew = g1 * std::sqrt(n * (n - 1.0)) / (n - 2.0);
284 return lang::aph_fit_central(mean, m2, skew);
285}
286
287/** `numpy.linspace(lo, hi, count)`, endpoint included and pinned. */
288inline std::vector<double> linspace(double lo, double hi, std::size_t count) {
289 std::vector<double> y(count);
290 if (count == 0) return y;
291 if (count == 1) {
292 y[0] = lo;
293 return y;
294 }
295 const double step = (hi - lo) / static_cast<double>(count - 1);
296 for (std::size_t i = 0; i < count; ++i) y[i] = static_cast<double>(i) * step + lo;
297 y[count - 1] = hi;
298 return y;
299}
300
301/** The refusal of a construct this port does not carry: `LINE:unsupported:LAL_<kind>`. */
302[[noreturn]] inline void unsupported(const std::string& kind, const std::string& what) {
303 throw UnsupportedError(ErrorKind("LAL_" + kind), what);
304}
305
306/** A vector or matrix argument written as JSON, e.g. `[[-2,1],[0,-3]]` (`_matrix_arg`). */
307inline nlohmann::json json_arg(const std::string& token) {
308 try {
309 const nlohmann::json j = nlohmann::json::parse(token);
310 if (j.is_array()) return j;
311 } catch (const std::exception&) {
312 }
313 throw value_error("expected a JSON vector or matrix, got '" + token + "'");
314}
315
316inline std::vector<double> vector_arg(const std::string& token) {
317 const nlohmann::json j = json_arg(token);
318 std::vector<double> v;
319 for (const auto& x : j) {
320 if (!x.is_number()) throw value_error("expected a JSON vector or matrix, got '" + token + "'");
321 v.push_back(x.get<double>());
322 }
323 return v;
324}
325
326inline Matrix<double> matrix_arg(const std::string& token) {
327 const nlohmann::json j = json_arg(token);
328 if (j.empty()) throw value_error("expected a JSON vector or matrix, got '" + token + "'");
329 if (!j.front().is_array()) {
330 // a vector is a one-row matrix, as numpy reads it
331 Matrix<double> m(1, j.size(), 0.0);
332 for (std::size_t c = 0; c < j.size(); ++c) m(0, c) = j[c].get<double>();
333 return m;
334 }
335 const std::size_t cols = j.front().size();
336 Matrix<double> m(j.size(), cols, 0.0);
337 for (std::size_t r = 0; r < j.size(); ++r) {
338 if (!j[r].is_array() || j[r].size() != cols)
339 throw value_error("expected a JSON vector or matrix, got '" + token + "'");
340 for (std::size_t c = 0; c < cols; ++c) m(r, c) = j[r][c].get<double>();
341 }
342 return m;
343}
344
345/**
346 * Build one of the Markovian laws LAL admits from a declaration
347 * (`markovian_distribution`): `exp RATE`, `erlang RATE PHASES`,
348 * `erlang_mean_order MEAN PHASES`, `hyperexp P RATE1 RATE2`, `ph ALPHA T`,
349 * `aph ALPHA T`, `coxian RATES PROBS`, `map D0 D1`, `mmpp2 L0 L1 S0 S1`,
350 * `mmap D0 D1 D11 ... D1K`, `bmap D0 D1 ... DB`, `mph ALPHA S EXITS`,
351 * `immediate now` and `disabled`. Matrices are JSON. Nullopt for any other
352 * declaration.
353 */
354template <class Numeric>
355std::optional<lang::Distrib<double>> markovian_distribution(const std::string& dist,
356 const std::vector<std::string>& args,
357 Numeric numeric) {
358 const std::size_t n = args.size();
359 if (dist == "exp" && n == 1) return lang::Distrib<double>::exp_rate(numeric(args[0]));
360 if (dist == "erlang" && n == 2) return lang::Distrib<double>(Erlang(numeric(args[0]), to_count(args[1], "Erlang order")));
361 if (dist == "erlang_mean_order" && n == 2)
362 return lang::erlang_fit_mean_order(numeric(args[0]), to_count(args[1], "Erlang order"));
363 if (dist == "hyperexp" && n == 3)
364 return lang::Distrib<double>(HyperExp(numeric(args[0]), numeric(args[1]), numeric(args[2])));
365 if (dist == "ph" && n == 2) return lang::Distrib<double>(PH(vector_arg(args[0]), matrix_arg(args[1])));
366 if (dist == "aph" && n == 2) return lang::Distrib<double>(APH(vector_arg(args[0]), matrix_arg(args[1])));
367 if (dist == "coxian" && n == 2) return lang::Distrib<double>(Coxian(vector_arg(args[0]), vector_arg(args[1])));
368 if (dist == "map" && n == 2) return lang::Distrib<double>(MAP(matrix_arg(args[0]), matrix_arg(args[1])));
369 if (dist == "mmpp2" && n == 4) {
370 const double l0 = numeric(args[0]), l1 = numeric(args[1]), s0 = numeric(args[2]), s1 = numeric(args[3]);
371 const Matrix<double> D0{{-l0 - s0, s0}, {s1, -l1 - s1}};
372 const Matrix<double> D1{{l0, 0.0}, {0.0, l1}};
375 return d;
376 }
377 if (dist == "mmap" && n >= 3) {
378 std::vector<Matrix<double>> marks;
379 for (std::size_t k = 2; k < n; ++k) marks.push_back(matrix_arg(args[k]));
382 return d;
383 }
384 if (dist == "bmap" && n >= 2) {
385 std::vector<Matrix<double>> blocks;
386 for (const std::string& a : args) blocks.push_back(matrix_arg(a));
389 return d;
390 }
391 if (dist == "mph" && n == 3) {
392 const Matrix<double> e = matrix_arg(args[2]);
393 std::vector<std::vector<double>> exits;
394 for (std::size_t r = 0; r < e.rows(); ++r) {
395 std::vector<double> row;
396 for (std::size_t c = 0; c < e.cols(); ++c) row.push_back(e(r, c));
397 exits.push_back(row);
398 }
401 return d;
402 }
403 if (dist == "immediate" && n == 1 && args[0] == "now") return lang::Distrib<double>::immediate();
404 if (dist == "disabled" && n == 0) return lang::Distrib<double>::disabled_dist();
405 return std::nullopt;
406}
407
408/** A network build plus the name maps the environment compiler needs. */
411 std::map<std::string, std::size_t> nodes; ///< name -> 1-based node index
412 std::map<std::string, std::size_t> classes; ///< name -> 1-based class index
413 explicit BuiltNetwork(const std::string& name) : model(name) {}
414};
415
416template <class Map>
417std::size_t lookup(const Map& m, const std::string& name, const char* what) {
418 const auto it = m.find(name);
419 if (it == m.end()) throw value_error(std::string("unknown ") + what + " " + name);
420 return it->second;
421}
422
423/** Mode lookup, keyed by (transition, mode); the message names the pair. */
424template <class Map>
425std::size_t lookup(const Map& m, const std::pair<std::string, std::string>& key, const char* what) {
426 const auto it = m.find(key);
427 if (it == m.end())
428 throw value_error(std::string("unknown ") + what + " ('" + key.first + "', '" + key.second + "')");
429 return it->second;
430}
431
432inline BuiltNetwork build_network_impl(const NetworkSpec& spec, const std::map<std::string, double>& parameters) {
433 std::map<std::string, double> values(parameters);
434 std::set<std::string> declared;
435 auto numeric = [&](const std::string& token) -> double {
436 const auto it = values.find(token);
437 if (it != values.end()) return it->second;
438 if (token.size() > 2 && token.compare(0, 2, "1-") == 0) {
439 const auto jt = values.find(token.substr(2));
440 if (jt != values.end()) return 1.0 - jt->second;
441 }
442 return to_float(token);
443 };
444 BuiltNetwork out(spec.name);
445 qn::Network<double>& model = out.model;
446 std::map<std::string, std::string> node_kind; // name -> declared type word
447 struct Route {
448 std::string c1, c2, n1, n2;
449 double prob;
450 };
451 std::vector<Route> routes;
452 std::vector<std::pair<std::string, std::string>> links;
453 struct Dispatch {
454 std::string node, cls, strategy;
455 };
456 std::vector<Dispatch> dispatches;
457 struct RegionSpec {
458 std::string node;
459 long capacity, class_capacity;
460 };
461 std::vector<RegionSpec> regions;
462 std::map<std::pair<std::string, std::string>, std::size_t> modes;
463 std::size_t max_class = 0;
464 auto node_of = [&](const std::string& n) { return lookup(out.nodes, n, "node"); };
465 auto class_of = [&](const std::string& n) { return lookup(out.classes, n, "class"); };
466
467 for (const Declaration& row : spec.declarations) {
468 const std::size_t line = row.first;
469 const std::vector<std::string>& w = row.second;
470 try {
471 const std::string& kind = w[0];
472 if (kind == "param" && w.size() == 3) {
473 if (declared.count(w[1])) throw value_error("duplicate parameter");
474 declared.insert(w[1]);
475 const double v = to_float(w[2]);
476 values.emplace(w[1], v); // setdefault: a caller's value wins
477 } else if (kind == "node" && w.size() >= 3) {
478 const std::string& name = w[1];
479 const std::string& typ = w[2];
480 const std::vector<std::string> options(w.begin() + 3, w.end());
481 if (out.nodes.count(name)) throw value_error("duplicate node " + name);
482 std::size_t idx = 0;
483 if (typ == "source" && options.empty()) idx = model.add_source(name);
484 else if (typ == "sink" && options.empty()) idx = model.add_sink(name);
485 else if (typ == "delay" && options.empty()) idx = model.add_delay(name);
486 else if (typ == "router" && options.empty()) idx = model.add_router(name);
487 else if (typ == "place" && options.size() <= 1)
488 idx = options.empty() ? model.add_place(name) : model.add_place(name, sched_by_name(options[0]));
489 else if (typ == "transition" && options.empty()) idx = model.add_transition(name);
490 else if (typ == "cache" && options.size() == 3) {
492 par.nitems = to_count(options[0], "cache item count");
493 par.itemcap = std::vector<int>(1, static_cast<int>(to_int(options[1])));
494 par.replacestrat = replacement_by_name(options[2]);
495 idx = model.add_cache(name, par);
496 } else if (typ == "queue" && (options.size() == 1 || options.size() == 2)) {
497 idx = model.add_queue(name, sched_by_name(options[0]));
498 if (options.size() == 2) model.set_number_of_servers(idx, static_cast<double>(to_int(options[1])));
499 } else {
500 throw value_error("invalid node declaration");
501 }
502 out.nodes[name] = idx;
503 node_kind[name] = typ;
504 } else if (kind == "class" && (w.size() == 3 || w.size() == 5)) {
505 const std::string& name = w[1];
506 const std::string& typ = w[2];
507 if (out.classes.count(name)) throw value_error("duplicate class " + name);
508 std::size_t idx = 0;
509 if (typ == "open" && w.size() == 3) idx = model.add_open_class(name);
510 else if (typ == "closed" && w.size() == 5)
511 idx = model.add_closed_class(name, static_cast<double>(to_int(w[3])), node_of(w[4]));
512 else throw value_error("invalid class declaration");
513 out.classes[name] = idx;
514 if (idx > max_class) max_class = idx;
515 } else if ((kind == "arrival" || kind == "service") && w.size() >= 5) {
516 const std::string& dist = w[3];
517 const std::vector<std::string> args(w.begin() + 4, w.end());
519 const std::optional<lang::Distrib<double>> md = markovian_distribution(dist, args, to_float);
520 if (md) {
521 d = *md;
522 } else if (dist == "prior_gaussian" && args.size() == 5) {
523 const double lo = to_float(args[0]), hi = to_float(args[1]);
524 const std::size_t count = to_count(args[2], "prior grid size");
525 const double mean = to_float(args[3]), sd = to_float(args[4]);
526 const std::vector<double> rates = linspace(lo, hi, count);
527 std::vector<double> probs(rates.size());
528 double total = 0.0;
529 for (std::size_t i = 0; i < rates.size(); ++i) {
530 const double z = (rates[i] - mean) / sd;
531 probs[i] = std::exp(-0.5 * z * z);
532 total += probs[i];
533 }
534 std::vector<lang::Distrib<double>> alts;
535 for (std::size_t i = 0; i < rates.size(); ++i) {
536 probs[i] /= total;
537 alts.push_back(lang::Distrib<double>::exp_rate(rates[i]));
538 }
539 d = lang::prior_discrete(alts, probs);
540 } else if (dist == "replayer_aph" && args.size() == 1) {
541 d = replayer_fit_aph(trace_path(args[0]));
542 } else if (dist == "replayer" && args.size() == 1) {
543 d = Replayer(trace_path(args[0]));
544 } else {
545 throw value_error("unsupported distribution");
546 }
547 const std::size_t node = node_of(w[1]), cls = class_of(w[2]);
548 if (kind == "arrival") {
549 if (node_kind[w[1]] != "source")
550 throw value_error("'" + node_kind[w[1]] + "' node " + w[1] + " has no set_arrival");
551 model.set_arrival(node, cls, d);
552 } else {
553 model.set_service(node, cls, d);
554 }
555 } else if (kind == "route" && w.size() == 6) {
556 routes.push_back(Route{w[1], w[2], w[3], w[4], numeric(w[5])});
557 } else if (kind == "completes" && w.size() == 3) {
558 if (w[2] != "true" && w[2] != "false") throw value_error("completes requires true or false");
559 model.set_class_completes(class_of(w[1]), w[2] == "true");
560 } else if (kind == "cache_read_zipf" && w.size() == 5) {
561 const std::size_t node = node_of(w[1]), cls = class_of(w[2]);
562 model.set_cache_read(node, cls,
563 lang::Distrib<double>::zipf(to_float(w[3]), to_count(w[4], "Zipf item count")));
564 } else if (kind == "cache_read_discrete" && w.size() > 3) {
565 std::vector<double> p;
566 double total = 0.0;
567 for (std::size_t k = 3; k < w.size(); ++k) {
568 p.push_back(to_float(w[k]));
569 total += p.back();
570 }
571 for (double& v : p) v /= total;
572 const std::size_t node = node_of(w[1]), cls = class_of(w[2]);
573 model.set_cache_read(node, cls, lang::Distrib<double>::discrete_sampler(p, std::vector<double>()));
574 } else if ((kind == "cache_hit" || kind == "cache_miss") && w.size() == 4) {
575 const std::size_t node = node_of(w[1]), r = class_of(w[2]), s = class_of(w[3]);
576 if (kind == "cache_hit") model.set_cache_hit_class(node, r, s);
577 else model.set_cache_miss_class(node, r, s);
578 } else if (kind == "cache_retrieval" && w.size() == 5) {
579 model.set_retrieval_system(node_of(w[1]), class_of(w[2]), class_of(w[3]), node_of(w[4]));
580 } else if (kind == "mode" && (w.size() == 4 || w.size() == 5)) {
581 const std::string& timing = w[3];
582 const std::size_t node = node_of(w[1]);
583 const std::size_t mode = model.add_mode(node, w[2]);
584 modes[std::make_pair(w[1], w[2])] = mode;
585 const std::vector<std::string> margs(w.begin() + 4, w.end());
586 const std::optional<lang::Distrib<double>> md =
587 timing != "immediate" ? markovian_distribution(timing, margs, to_float)
588 : std::optional<lang::Distrib<double>>();
589 if (timing == "immediate" && w.size() == 4)
591 else if (md)
592 model.set_mode_distribution(node, mode, *md);
593 else throw value_error("invalid mode timing");
594 } else if ((kind == "enable" || kind == "inhibit" || kind == "fire") && w.size() == 6) {
595 const std::size_t node = node_of(w[1]);
596 const std::size_t mode = lookup(modes, std::make_pair(w[1], w[2]), "mode");
597 const std::size_t cls = class_of(w[3]), place = node_of(w[4]);
598 const double value = static_cast<double>(to_int(w[5]));
599 if (kind == "enable") model.set_enabling_conditions(node, mode, cls, place, value);
600 else if (kind == "inhibit") model.set_inhibiting_conditions(node, mode, cls, place, value);
601 else model.set_firing_outcome(node, mode, cls, place, value);
602 } else if (kind == "weight" && w.size() == 4) {
603 const std::size_t node = node_of(w[1]);
604 model.set_firing_weight(node, lookup(modes, std::make_pair(w[1], w[2]), "mode"), to_float(w[3]));
605 } else if (kind == "state" && w.size() >= 3) {
606 std::vector<double> tokens;
607 for (std::size_t k = 2; k < w.size(); ++k) tokens.push_back(static_cast<double>(to_int(w[k])));
608 const std::size_t node = node_of(w[1]);
609 if (node_kind[w[1]] != "place")
610 unsupported("state", "line " + std::to_string(line) + ": state " + w[1] +
611 ": only a place's initial marking is carried; the initial state of a '" +
612 node_kind[w[1]] + "' node has no builder counterpart in this port "
613 "(set_state_prior would also replace the state space)");
614 model.set_initial_marking(node, tokens);
615 } else if (kind == "link" && w.size() == 3) {
616 links.push_back(std::make_pair(w[1], w[2]));
617 } else if (kind == "dispatch" && w.size() == 4) {
618 dispatches.push_back(Dispatch{w[1], w[2], w[3]});
619 } else if (kind == "region" && w.size() == 4) {
620 regions.push_back(RegionSpec{w[1], to_int(w[2]), to_int(w[3])});
621 } else {
622 throw value_error("unknown or invalid declaration '" + kind + "'");
623 }
624 } catch (const UnsupportedError&) {
625 throw;
626 } catch (const Error& e) {
627 throw value_error("line " + std::to_string(line) + ": " + e.what());
628 }
629 }
630 std::vector<std::string> unknown;
631 for (const auto& kv : parameters)
632 if (!declared.count(kv.first)) unknown.push_back(kv.first);
633 if (!unknown.empty()) {
634 std::string msg = "unknown parameters: [";
635 for (std::size_t k = 0; k < unknown.size(); ++k) msg += (k ? ", '" : "'") + unknown[k] + "'";
636 throw value_error(msg + "]");
637 }
639 for (const Route& r : routes) {
640 if (!(0.0 <= r.prob && r.prob <= 1.0)) throw value_error("routing probability must be in [0, 1]");
641 routing.set(class_of(r.c1), class_of(r.c2), node_of(r.n1), node_of(r.n2), r.prob);
642 }
643 if (!routes.empty() && !links.empty()) throw value_error("route and link declarations cannot be mixed");
644 if (!routes.empty()) model.link(routing);
645 if (!links.empty()) {
646 // `add_link` records connectivity only, and a node with no explicit
647 // strategy splits uniformly over its links for every class: the
648 // RAND strategy over a connection-only matrix.
650 std::set<std::size_t> origins;
651 for (const auto& l : links) {
652 const std::size_t a = node_of(l.first), b = node_of(l.second);
653 origins.insert(a);
654 for (const auto& c : out.classes) conn.set(c.second, c.second, a, b, 1.0);
655 }
656 for (std::size_t a : origins)
657 for (const auto& c : out.classes) model.set_routing(a, c.second, lang::RoutingStrategy::RAND);
658 model.link(conn);
659 }
660 for (const Dispatch& d : dispatches)
661 model.set_routing(node_of(d.node), class_of(d.cls), routing_by_name(d.strategy));
662 for (const RegionSpec& rg : regions) {
663 std::vector<double> class_max(max_class, -1.0);
664 std::vector<lang::DropStrategy> rule(max_class, lang::DropStrategy::WAITQ);
665 for (const auto& c : out.classes) {
666 class_max[c.second - 1] = static_cast<double>(rg.class_capacity);
667 rule[c.second - 1] = lang::DropStrategy::DROP;
668 }
669 model.add_region(std::vector<std::size_t>(1, node_of(rg.node)), class_max,
670 static_cast<double>(rg.capacity), rule);
671 }
672 // LAL admits Markovian specifications only (LINE:unsupported:NonMarkovian)
673 check_network(model.raw_struct());
674 return out;
675}
676
677} // namespace decl_detail
678
679/** `parse_network(text)`: the header `network NAME` and the declarations after it. */
680inline NetworkSpec parse_network(const std::string& text) {
681 const std::vector<Declaration> rows = decl_detail::split_rows(text);
682 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] != "network")
683 throw value_error("Expected network NAME as first declaration");
684 NetworkSpec spec;
685 spec.name = rows[0].second[1];
686 spec.declarations.assign(rows.begin() + 1, rows.end());
687 return spec;
688}
689
690/**
691 * `build_network(spec, parameters)`: the native network the declarations
692 * describe. `parameters` overrides `param` defaults; naming a parameter the
693 * spec does not declare is an error.
694 */
696 const std::map<std::string, double>& parameters = {}) {
697 return decl_detail::build_network_impl(spec, parameters).model;
698}
699
700/**
701 * A layered model built by `build_layered`. `LqnBuilder` carries no name, so
702 * the name rides beside it and is stamped on the `LqnModel` it hands out.
703 */
705 std::string name;
707
708 /** The raw model with its name, as `LayeredNetwork` would hold it. */
711 m.name = name;
712 return m;
713 }
714 /** `getStruct()`. */
716};
717
718/** `build_layered(text)`: processors, tasks, entries, activities and their calls. */
719inline LayeredModel build_layered(const std::string& text) {
720 const std::vector<Declaration> rows = decl_detail::split_rows(text);
721 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] != "layered")
722 throw value_error("expected layered NAME");
723 LayeredModel out;
724 out.name = rows[0].second[1];
726 std::map<std::string, std::string> objects; // name -> processor|task|entry|activity
727 auto require = [&](const std::string& n, const char* kind) {
728 const auto it = objects.find(n);
729 if (it == objects.end()) throw value_error("'" + n + "'");
730 if (it->second != kind)
731 throw value_error("'" + n + "' is a " + it->second + ", not a " + kind);
732 };
733 for (std::size_t k = 1; k < rows.size(); ++k) {
734 const std::size_t line = rows[k].first;
735 const std::vector<std::string>& w = rows[k].second;
736 try {
737 if (w[0] == "processor" && w.size() == 4) {
738 const long mult = decl_detail::to_int(w[2]);
739 b.processor(w[1], static_cast<double>(mult), decl_detail::sched_by_name(w[3]));
740 objects[w[1]] = "processor";
741 } else if (w[0] == "task" && w.size() == 5) {
742 const double mult = decl_detail::to_float(w[2]);
744 require(w[4], "processor");
745 b.task(w[1], mult, s, w[4]);
746 objects[w[1]] = "task";
747 } else if (w[0] == "think" && w.size() == 3) {
748 require(w[1], "task");
750 } else if (w[0] == "entry" && w.size() == 3) {
751 require(w[2], "task");
752 b.entry(w[1], w[2]);
753 objects[w[1]] = "entry";
754 } else if (w[0] == "activity" && w.size() == 4) {
756 require(w[2], "task");
757 b.activity(w[1], d, w[2]);
758 objects[w[1]] = "activity";
759 } else if (w[0] == "bind" && w.size() == 3) {
760 require(w[1], "activity");
761 require(w[2], "entry");
762 b.bound_to(w[1], w[2]);
763 } else if (w[0] == "call" && w.size() == 4) {
764 require(w[1], "activity");
765 require(w[2], "entry");
766 b.sync_call(w[1], w[2], decl_detail::to_float(w[3]));
767 } else if (w[0] == "reply" && w.size() == 3) {
768 require(w[1], "activity");
769 require(w[2], "entry");
770 b.replies_to(w[1], w[2]);
771 } else {
772 throw value_error("unknown or invalid declaration");
773 }
774 } catch (const UnsupportedError&) {
775 throw;
776 } catch (const Error& e) {
777 throw value_error("line " + std::to_string(line) + ": " + e.what());
778 }
779 }
780 check_layered(out.get_struct(), out.name);
781 return out;
782}
783
784/**
785 * `build_environment(text, base)`: one stage per `stage NAME CATEGORY NODE
786 * CLASS RATE`, each a fresh build of the `base` network text with the service
787 * of CLASS at NODE replaced by Exp(RATE), and `switch FROM TO RATE` for the
788 * exponential stage transitions.
789 */
790inline env::Environment<double> build_environment(const std::string& text, const std::string& base) {
791 const std::vector<Declaration> rows = decl_detail::split_rows(text);
792 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] != "environment")
793 throw value_error("expected environment NAME");
794 std::size_t nstages = 0;
795 for (std::size_t k = 1; k < rows.size(); ++k)
796 if (rows[k].second[0] == "stage") ++nstages;
797 env::Environment<double> e(rows[0].second[1], nstages);
798 std::map<std::string, std::size_t> by_name;
799 for (std::size_t k = 1; k < rows.size(); ++k) {
800 const std::size_t line = rows[k].first;
801 const std::vector<std::string>& w = rows[k].second;
802 try {
803 if (w[0] == "stage" && w.size() == 6) {
804 if (by_name.count(w[1])) throw value_error("duplicate stage");
806 const std::size_t node = decl_detail::lookup(stage.nodes, w[3], "node");
807 const std::size_t cls = decl_detail::lookup(stage.classes, w[4], "class");
809 const std::size_t idx = by_name.size();
810 by_name[w[1]] = idx;
811 e.set_stage(idx, w[1], w[2], stage.model.get_struct());
812 } else if (w[0] == "switch" && w.size() == 4) {
813 const std::size_t from = decl_detail::lookup(by_name, w[1], "stage");
814 const std::size_t to = decl_detail::lookup(by_name, w[2], "stage");
816 } else {
817 throw value_error("invalid declaration");
818 }
819 } catch (const UnsupportedError&) {
820 throw;
821 } catch (const Error& ex) {
822 throw value_error("line " + std::to_string(line) + ": " + ex.what());
823 }
824 }
826 return e;
827}
828
829} // namespace lal
830} // namespace line
831
832#endif // LINE_LANG_LAL_NETWORK_DECL_H
Base error for the multiprecision C++ port.
Definition error.h:73
Malformed or inconsistent input (dimensions, negative populations, ...): LINE:input:<kind>.
Definition error.h:103
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
A refusal: the feature, method or analysis is not covered: LINE:unsupported:<kind>.
Definition error.h:117
UnsupportedError(const std::string &what)
Definition error.h:119
void set_stage(std::size_t e, const std::string &nm, const std::string &type, const qn::NetworkStruct< T > &model)
addStage: name the stage and give it its network.
void add_transition(std::size_t e, std::size_t h, const lang::Distrib< T > &d, const ResetMarginal &reset=ResetMarginal())
addTransition: enable e -> h with a distribution and a reset policy.
void bound_to(const std::string &act, const std::string &entry_name)
Bind an activity to an entry: it is the entry's first activity.
std::size_t activity(const std::string &name, const Distrib< T > &hostdem, const std::string &on_task)
Add an activity on a task, with its host demand.
std::size_t processor(const std::string &name, double mult, SchedStrategy sched, double repl=1.0)
Add a processor.
Definition lqn_builder.h:49
void replies_to(const std::string &act, const std::string &entry_name)
Mark an activity as the one that replies to an entry.
void sync_call(const std::string &act, const std::string &dest_entry, const T &mean)
A synchronous call from an activity to an entry of another task.
void think_time(const std::string &task_name, const Distrib< T > &d)
Set a task's think time.
Definition lqn_builder.h:87
const LqnModel< T > & model() const
std::size_t entry(const std::string &name, const std::string &on_task)
Add an entry on a task.
std::size_t task(const std::string &name, double mult, SchedStrategy sched, const std::string &on_processor, double repl=1.0)
Add a task on a processor.
Definition lqn_builder.h:66
A queueing network under construction.
std::size_t add_source(const std::string &nm)
The external arrival station.
void set_enabling_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setEnablingConditions(mode, class, place, tokens): how many class-r tokens the mode needs ...
std::size_t add_open_class(const std::string &nm, int prio=0)
An open class.
void set_cache_read(std::size_t cache_node, std::size_t r, const std::vector< T > &pmf)
Cache.setRead(jobclass, popularity): class r (1-based) reads the cache, drawing items from the pmf pm...
void set_mode_timing(std::size_t node, std::size_t mode, lang::TimingStrategy ts)
Transition.setTimingStrategy(mode, strategy): TIMED or IMMEDIATE.
void set_firing_weight(std::size_t node, std::size_t mode, const T &w)
Transition.setFiringWeights(mode, weight): the share among tied modes.
void set_cache_miss_class(std::size_t cache_node, std::size_t r, std::size_t m)
Cache.setMissClass(jobclass, missclass): a class-r read that misses leaves as class m.
std::size_t add_delay(const std::string &nm)
An infinite-server station (a Delay, MATLAB's Delay / DelayStation).
RoutingMatrix< T > init_routing_matrix() const
An empty routing matrix, MATLAB's model.initRoutingMatrix.
void set_mode_distribution(std::size_t node, std::size_t mode, const Distrib< T > &d)
Transition.setDistribution(mode, dist): the mode's firing law.
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_inhibiting_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setInhibitingConditions(mode, class, place, tokens): the class-r count at place that BLOCK...
void set_number_of_servers(std::size_t node, double n)
queue.setNumberOfServers(n).
void set_class_completes(std::size_t cls, bool flag)
jobclass.completes = flag: whether a passage through the reference station counts as a completion.
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).
std::size_t add_cache(const std::string &nm, const CacheParam< T > &par)
A Cache node with its item population, list capacities and popularity.
std::size_t add_mode(std::size_t node, const std::string &nm)
Transition.addMode(name): a new firing mode, returning its 1-based index.
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.
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().
std::size_t add_place(const std::string &nm)
A Place: an SPN token container.
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
void set_cache_hit_class(std::size_t cache_node, std::size_t r, std::size_t h)
Cache.setHitClass(jobclass, hitclass): a class-r read that hits leaves as class h.
void set_retrieval_system(std::size_t cache_node, std::size_t read_class, std::size_t miss_class, const std::vector< std::size_t > &queue_nodes)
Cache.setRetrievalSystem(readClass, missClass, queues): a delayed-hit cache whose misses are fetched ...
void link(const RoutingMatrix< T > &Pm)
model.link(P): install the routing.
void set_service(std::size_t node, std::size_t cls, const Distrib< T > &d)
station.setService(class, dist).
void set_firing_outcome(std::size_t node, std::size_t mode, std::size_t cls, std::size_t dest, const T &tokens)
Transition.setFiringOutcome(mode, class, node, tokens): the class-r tokens the firing deposits.
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_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.
The routing matrix a model script fills in, MATLAB's P cell array.
void set(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
LINE Agent Language (LAL): the finite-agent model record, its validation, the joint-state event kerne...
The moment fitters the reference distributions carry as STATIC FACTORIES: Erlang.fitMeanAndOrder,...
The distributions a user names, spelled as their Python twins.
A random environment: a port of matlab/src/lang/Environment.m, restricted to what SolverENV reads out...
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Build a layered queueing network in code, as the MATLAB constructors do.
.lqnx -> LqnStruct, a port of matlab/src/lang/layered/@LayeredNetwork/parseXML.m followed by ....
LINE Agent Language (LAL): the Markovian admission check.
void unsupported(const std::string &kind, const std::string &what)
The refusal of a construct this port does not carry: LINE:unsupported:LAL_<kind>.
lang::ReplacementStrategy replacement_by_name(const std::string &name)
getattr(ReplacementStrategy, name).
std::filesystem::path repo_root()
The LINE repository root, the base a relative trace path falls back to: $LINE_ROOT when set,...
nlohmann::json json_arg(const std::string &token)
A vector or matrix argument written as JSON, e.g.
Matrix< double > matrix_arg(const std::string &token)
std::optional< lang::Distrib< double > > markovian_distribution(const std::string &dist, const std::vector< std::string > &args, Numeric numeric)
Build one of the Markovian laws LAL admits from a declaration (markovian_distribution): exp RATE,...
std::vector< double > vector_arg(const std::string &token)
lang::SchedStrategy sched_by_name(const std::string &name)
getattr(SchedStrategy, name) over the strategies this port enumerates.
BuiltNetwork build_network_impl(const NetworkSpec &spec, const std::map< std::string, double > &parameters)
std::size_t to_count(const std::string &s, const std::string &what)
A nonnegative count, int(token) then checked for a sign.
lang::Distrib< double > replayer_fit_aph(const std::string &path)
Replayer(path).fit_aph(): the population mean and variance and the bias-corrected sample skewness (sc...
lang::RoutingStrategy routing_by_name(const std::string &name)
getattr(RoutingStrategy, name).
double to_float(const std::string &s)
Python float(token): the whole word must be a number (inf and nan included).
std::string trace_path(const std::string &name)
_trace_path: as given, else relative to the repository root; then made absolute.
std::vector< std::string > shell_words(const std::string &line)
shlex.split(line, comments=True): POSIX words with '...', "..." and backslash escapes,...
std::size_t lookup(const Map &m, const std::string &name, const char *what)
long to_int(const std::string &s)
Python int(token): an optionally signed run of decimal digits.
std::vector< double > linspace(double lo, double hi, std::size_t count)
numpy.linspace(lo, hi, count), endpoint included and pinned.
std::vector< Declaration > split_rows(const std::string &text)
The nonblank lines of text, numbered from 1 as str.splitlines() numbers them.
Definition ag.h:49
void check_network(const qn::NetworkStruct< double > &sn, const std::string &where=std::string())
Refuse a network holding any non-Markovian specification (check_network).
Definition markov.h:146
NetworkSpec parse_network(const std::string &text)
parse_network(text): the header network NAME and the declarations after it.
env::Environment< double > build_environment(const std::string &text, const std::string &base)
build_environment(text, base): one stage per stage NAME CATEGORY NODE CLASS RATE, each a fresh build ...
void check_environment(const env::Environment< double > &e)
Refuse an Environment with a non-Markovian holding law or stage model (check_environment).
Definition markov.h:257
void check_layered(const lqn::LqnStruct< double > &lsn, const std::string &name)
Refuse a LayeredNetwork with a non-Markovian demand, think time, setup or arrival (check_layered).
Definition markov.h:242
InputError value_error(const std::string &what)
LINE:input:Unspecified, the C++ spelling of the Python ValueError raised throughout LAL.
Definition core.h:85
LayeredModel build_layered(const std::string &text)
build_layered(text): processors, tasks, entries, activities and their calls.
qn::Network< double > build_network(const NetworkSpec &spec, const std::map< std::string, double > &parameters={})
build_network(spec, parameters): the native network the declarations describe.
std::pair< std::size_t, std::vector< std::string > > Declaration
One declaration: its 1-based source line and its shell words.
Distrib< T > aph_fit_central(const T &mean, const T &var, const T &skew)
APH.fitCentral(MEAN, VAR, SKEW): the three central moments converted to raw ones and matched by a can...
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
@ IMMEDIATE
fires with zero delay, resolved by weight and priority
Definition lang_types.h:384
Distrib< T > erlang_fit_mean_order(const T &mean, std::size_t k)
Erlang.fitMeanAndOrder(MEAN, k): k phases, each of rate k / MEAN.
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
Definition lang_types.h:430
@ SDR
Krzesinski (1987) product-form state-dependent routing.
Definition lang_types.h:439
Distrib< T > prior_discrete(const std::vector< Distrib< T > > &alternatives, const std::vector< T > &probabilities)
Prior(distributions, probabilities): the discrete form.
Definition prior.h:110
const char * sched_to_text(SchedStrategy s)
Definition lang_types.h:248
void dist_refresh_moments(Distrib< T > &d)
Fill in the first two moments of a distribution given by its matrices.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
Definition lang_types.h:419
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
Definition lang_types.h:424
@ CLIMB
move up one position on a hit (transposition rule)
Definition lang_types.h:425
@ QLRU
q-LRU: LRU with probabilistic admission on a miss
Definition lang_types.h:426
@ LRU
least recently used
Definition lang_types.h:423
@ FIFO
first in, first out
Definition lang_types.h:421
LqnStruct< T > lqn_finalize(const LqnModel< T > &m)
Port of @LayeredNetwork/getStruct.m: flatten the model into its struct.
Definition lqn_reader.h:501
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
Prior: parameter uncertainty as a weighted set of alternative models.
ErrorKind(std::string n)
Definition error.h:39
A layered model built by build_layered.
lqn::LqnModel< double > model() const
The raw model with its name, as LayeredNetwork would hold it.
lqn::LqnStruct< double > get_struct() const
getStruct().
lqn::LqnBuilder< double > builder
NetworkSpec: the network name and the declarations after the header line.
std::vector< Declaration > declarations
A network build plus the name maps the environment compiler needs.
BuiltNetwork(const std::string &name)
std::map< std::string, std::size_t > nodes
name -> 1-based node index
std::map< std::string, std::size_t > classes
name -> 1-based class index
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 exp_rate(const T &r)
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 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 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 immediate()
The point mass at zero.
static Distrib exp_mean(const T &m)
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 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 intermediate model, and the second stage that flattens it.
Definition lqn_reader.h:411
std::string name
LayeredNetwork.getName(); empty when unnamed.
Definition lqn_reader.h:413
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
std::vector< int > itemcap
lang::ReplacementStrategy replacestrat