5#ifndef LINE_LANG_LAL_NETWORK_DECL_H
6#define LINE_LANG_LAL_NETWORK_DECL_H
58using Declaration = std::pair<std::size_t, std::vector<std::string>>;
74 std::vector<std::string> out;
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];
83 if (c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n') {
84 if (in_word) out.push_back(tok);
88 }
else if (c ==
'#') {
89 if (in_word) out.push_back(tok);
91 }
else if (c ==
'\\') {
96 }
else if (c ==
'\'') {
99 }
else if (c ==
'"') {
109 if (c ==
'\'') st = WORD;
115 }
else if (c ==
'\\' && k + 1 <
line.size() && (
line[k + 1] ==
'"' ||
line[k + 1] ==
'\\')) {
117 }
else if (c ==
'\\' && k + 1 >=
line.size()) {
125 if (st == SQ || st == DQ)
throw value_error(
"No closing quotation");
126 if (in_word) out.push_back(tok);
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;
140 const std::string
line = text.substr(start, end - start);
141 std::vector<std::string> words;
145 throw value_error(
"line " + std::to_string(number) +
": " + e.what());
147 if (!words.empty()) rows.push_back(
Declaration(number, words));
149 start = end + ((text[end] ==
'\r' && end + 1 < text.size() && text[end + 1] ==
'\n') ? 2 : 1);
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();
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 +
"'");
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;
175 if (k < j && (s[k] ==
'+' || s[k] ==
'-')) ++k;
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));
184inline std::size_t
to_count(
const std::string& s,
const std::string& what) {
186 if (v < 0)
throw value_error(what +
" must be nonnegative");
187 return static_cast<std::size_t
>(v);
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) {
197 if (t ==
"none")
continue;
198 for (
char& c : t) c =
static_cast<char>(std::toupper(
static_cast<unsigned char>(c)));
205 const auto it = table.find(name);
206 if (it == table.end())
throw value_error(
"unknown scheduling strategy " + 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);
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);
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();
251 namespace fs = std::filesystem;
253 if (!p.is_absolute() && !fs::exists(p)) {
255 if (fs::exists(alt)) p = alt;
257 return fs::weakly_canonical(fs::absolute(p)).string();
266 const Replayer rep(path);
267 const std::vector<double>& x = rep.trace;
268 const double n =
static_cast<double>(x.size());
270 for (
double v : x) mean += v;
272 double m2 = 0.0, m3 = 0.0;
274 const double d = v - mean;
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);
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;
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;
302[[noreturn]]
inline void unsupported(
const std::string& kind,
const std::string& what) {
307inline nlohmann::json
json_arg(
const std::string& token) {
309 const nlohmann::json j = nlohmann::json::parse(token);
310 if (j.is_array())
return j;
311 }
catch (
const std::exception&) {
313 throw value_error(
"expected a JSON vector or matrix, got '" + token +
"'");
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>());
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()) {
332 for (std::size_t c = 0; c < j.size(); ++c) m(0, c) = j[c].get<
double>();
335 const std::size_t cols = j.front().size();
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>();
354template <
class Numeric>
356 const std::vector<std::string>& args,
358 const std::size_t n = args.size();
361 if (dist ==
"erlang_mean_order" && n == 2)
363 if (dist ==
"hyperexp" && n == 3)
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]);
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]));
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));
391 if (dist ==
"mph" && n == 3) {
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);
411 std::map<std::string, std::size_t>
nodes;
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);
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);
428 throw value_error(std::string(
"unknown ") + what +
" ('" + key.first +
"', '" + key.second +
"')");
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;
446 std::map<std::string, std::string> node_kind;
448 std::string c1, c2, n1, n2;
451 std::vector<Route> routes;
452 std::vector<std::pair<std::string, std::string>> links;
454 std::string node, cls, strategy;
456 std::vector<Dispatch> dispatches;
459 long capacity, class_capacity;
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"); };
468 const std::size_t
line = row.first;
469 const std::vector<std::string>& w = row.second;
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]);
476 values.emplace(w[1], v);
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());
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)
489 else if (typ ==
"transition" && options.empty()) idx = model.
add_transition(name);
490 else if (typ ==
"cache" && options.size() == 3) {
493 par.
itemcap = std::vector<int>(1,
static_cast<int>(
to_int(options[1])));
496 }
else if (typ ==
"queue" && (options.size() == 1 || options.size() == 2)) {
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];
509 if (typ ==
"open" && w.size() == 3) idx = model.
add_open_class(name);
510 else if (typ ==
"closed" && w.size() == 5)
512 else throw value_error(
"invalid class declaration");
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());
522 }
else if (dist ==
"prior_gaussian" && args.size() == 5) {
524 const std::size_t count =
to_count(args[2],
"prior grid size");
526 const std::vector<double> rates =
linspace(lo, hi, count);
527 std::vector<double> probs(rates.size());
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);
534 std::vector<lang::Distrib<double>> alts;
535 for (std::size_t i = 0; i < rates.size(); ++i) {
540 }
else if (dist ==
"replayer_aph" && args.size() == 1) {
542 }
else if (dist ==
"replayer" && args.size() == 1) {
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");
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");
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]);
564 }
else if (kind ==
"cache_read_discrete" && w.size() > 3) {
565 std::vector<double> p;
567 for (std::size_t k = 3; k < w.size(); ++k) {
571 for (
double& v : p) v /= total;
572 const std::size_t node = node_of(w[1]), cls = class_of(w[2]);
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]);
578 }
else if (kind ==
"cache_retrieval" && w.size() == 5) {
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 =
588 : std::optional<lang::Distrib<double>>();
589 if (timing ==
"immediate" && w.size() == 4)
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]));
602 }
else if (kind ==
"weight" && w.size() == 4) {
603 const std::size_t node = node_of(w[1]);
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)");
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])});
622 throw value_error(
"unknown or invalid declaration '" + kind +
"'");
626 }
catch (
const Error& e) {
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] +
"'";
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);
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()) {
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);
654 for (
const auto& c : out.
classes) conn.
set(c.second, c.second, a, b, 1.0);
656 for (std::size_t a : origins)
660 for (
const Dispatch& d : dispatches)
662 for (
const RegionSpec& rg : regions) {
663 std::vector<double> class_max(max_class, -1.0);
665 for (
const auto& c : out.
classes) {
666 class_max[c.second - 1] =
static_cast<double>(rg.class_capacity);
669 model.
add_region(std::vector<std::size_t>(1, node_of(rg.node)), class_max,
670 static_cast<double>(rg.capacity), rule);
682 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] !=
"network")
683 throw value_error(
"Expected network NAME as first declaration");
685 spec.
name = rows[0].second[1];
696 const std::map<std::string, double>& parameters = {}) {
721 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] !=
"layered")
724 out.
name = rows[0].second[1];
726 std::map<std::string, std::string> objects;
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);
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;
737 if (w[0] ==
"processor" && w.size() == 4) {
740 objects[w[1]] =
"processor";
741 }
else if (w[0] ==
"task" && w.size() == 5) {
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");
753 objects[w[1]] =
"entry";
754 }
else if (w[0] ==
"activity" && w.size() == 4) {
756 require(w[2],
"task");
758 objects[w[1]] =
"activity";
759 }
else if (w[0] ==
"bind" && w.size() == 3) {
760 require(w[1],
"activity");
761 require(w[2],
"entry");
763 }
else if (w[0] ==
"call" && w.size() == 4) {
764 require(w[1],
"activity");
765 require(w[2],
"entry");
767 }
else if (w[0] ==
"reply" && w.size() == 3) {
768 require(w[1],
"activity");
769 require(w[2],
"entry");
772 throw value_error(
"unknown or invalid declaration");
776 }
catch (
const Error& e) {
792 if (rows.empty() || rows[0].second.size() != 2 || rows[0].second[0] !=
"environment")
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;
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;
803 if (w[0] ==
"stage" && w.size() == 6) {
804 if (by_name.count(w[1]))
throw value_error(
"duplicate stage");
809 const std::size_t idx = by_name.size();
812 }
else if (w[0] ==
"switch" && w.size() == 4) {
821 }
catch (
const Error& ex) {
Base error for the multiprecision C++ port.
A refusal: the feature, method or analysis is not covered: LINE:unsupported:<kind>.
UnsupportedError(const std::string &what)
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.
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.
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.
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 > ¶meters)
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.
void check_network(const qn::NetworkStruct< double > &sn, const std::string &where=std::string())
Refuse a network holding any non-Markovian specification (check_network).
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).
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).
InputError value_error(const std::string &what)
LINE:input:Unspecified, the C++ spelling of the Python ValueError raised throughout LAL.
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 > ¶meters={})
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.
@ IMMEDIATE
fires with zero delay, resolved by weight and priority
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.
@ SDR
Krzesinski (1987) product-form state-dependent routing.
Distrib< T > prior_discrete(const std::vector< Distrib< T > > &alternatives, const std::vector< T > &probabilities)
Prior(distributions, probabilities): the discrete form.
const char * sched_to_text(SchedStrategy s)
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.
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
@ CLIMB
move up one position on a hit (transposition rule)
@ QLRU
q-LRU: LRU with probabilistic admission on a miss
@ FIFO
first in, first out
LqnStruct< T > lqn_finalize(const LqnModel< T > &m)
Port of @LayeredNetwork/getStruct.m: flatten the model into its struct.
Conservation laws of a layered queueing network, enumerated from its structure.
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
Prior: parameter uncertainty as a weighted set of alternative models.
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
qn::Network< double > model
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.
std::string name
LayeredNetwork.getName(); empty when unnamed.
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
std::vector< int > itemcap
lang::ReplacementStrategy replacestrat