LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solvers.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_SOLVERS_H
6#define LINE_LANG_LAL_SOLVERS_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * LINE Agent Language (LAL): SolverCTMC and SolverSSA on a finite
12 * composition (the `_lal_composition` arms of Python's SolverCTMC and
13 * SolverSSA).
14 *
15 * Python dispatches on the model type inside the network solvers; the C++
16 * network solvers take a NetworkStruct, so the LAL arms are separate classes
17 * here, `line::lal::SolverCTMC` and `line::lal::SolverSSA`, with the same
18 * method names, option names, refusals and cache rule. A result is recomputed
19 * whenever the composition signature, its truncation flag or the options
20 * change.
21 */
22
23#include <cctype>
24#include <cmath>
25#include <functional>
26#include <limits>
27#include <optional>
28#include <set>
29#include <sstream>
30#include <string>
31#include <utility>
32#include <vector>
33
35#include "line/lang/lal/ctmc.h"
36#include "line/lang/lal/ssa.h"
39#include "line/util/expm.h"
40
41namespace line {
42namespace lal {
43
44/** Solve a composition by exact finite CTMC (`lal.ctmc.solve_composition(model)`). */
45inline Result solve_composition(const Composition& model, std::size_t max_states = 0,
46 std::size_t max_dense_bytes = kDefaultMaxDenseBytes) {
47 const Model snapshot = model.model();
48 return solve_composition(snapshot, max_states, max_dense_bytes);
49}
50
51namespace detail {
52
53inline std::string lower(std::string s) {
54 for (char& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
55 return s;
56}
57
58inline std::string strip_prefix(const std::string& s, const std::string& p) {
59 return s.compare(0, p.size(), p) == 0 ? s.substr(p.size()) : s;
60}
61
62inline std::string network_metric_refusal(const std::string& caller) {
63 return caller + " requires queueing-network station and class metrics; "
64 "a general LAL composition provides state and action tables instead.";
65}
66
67} // namespace detail
68
69/** Options of the LAL arm of SolverCTMC. */
71 std::string method = "default";
72 std::size_t ctmc_max_states = 3000000; ///< hard cap on enumerated global states
73 std::optional<std::pair<double, double>> timespan; ///< refused when set
74 std::optional<std::vector<double>> init_sol; ///< refused when set
75 nlohmann::json config = nlohmann::json::object(); ///< refused when nonempty
76
77 std::string key() const {
78 return detail::lower(method) + "|" + std::to_string(ctmc_max_states) + "|" +
79 (timespan ? detail::repr_double(timespan->first) + "," + detail::repr_double(timespan->second) : "None") + "|" +
80 (init_sol ? std::to_string(init_sol->size()) : "None") + "|" + config.dump();
81 }
82};
83
84/**
85 * Exact finite CTMC enumeration or MDD aggregation of a composition.
86 * Methods: `default`/`exact` (explicit CTMC; `default` falls back to `mdd` on a
87 * state-space limit when MDD supports the model) and `mdd`.
88 */
90 public:
91 /**
92 * The solver REFERENCES `model`, as Python's re-reads `self.model` on every
93 * query: a later edit (an added agent or sync, hide, setReward) changes the
94 * signature and the next query re-solves. `model` must outlive the solver,
95 * so a temporary is refused at compile time.
96 */
98 : options(std::move(options)), model_(&model) {}
100
102
103 static bool supports(const Composition&) { return true; }
104
105 std::pair<bool, std::optional<std::string>> supportsModelMethod(const std::string& method) const {
106 const std::string m = detail::lower(method);
107 if (m == "default" || m == "exact") return {true, std::nullopt};
108 if (m == "mdd") {
109 const Model snapshot = model_->model();
110 const std::set<std::string> features = model_features(snapshot);
111 if (!features.empty())
112 return {false, std::string("LAL MDD supports timed hand-declared agents only; the composition uses ") +
113 detail::join_sorted(features) + " actions."};
114 if (!snapshot.min_syncs.empty())
115 return {false, std::string("LAL MDD does not support minimum-rate synchronization.")};
116 for (const AgentRecord& a : snapshot.agents)
117 if (a.initial_distribution) {
118 std::size_t nz = 0;
119 for (double p : *a.initial_distribution)
120 if (p != 0) ++nz;
121 if (nz != 1) return {false, std::string("LAL MDD requires deterministic initial states.")};
122 }
123 return {true, std::nullopt};
124 }
125 return {false, std::string("LAL compositions support exact finite CTMC enumeration and restricted MDD aggregation.")};
126 }
127
129 std::string method = detail::lower(options.method);
130 auto ok = supportsModelMethod(method);
131 if (!ok.first) throw UnsupportedError(ErrorKind("Method"), *ok.second);
132 if (options.timespan || options.init_sol || !options.config.empty())
133 throw UnsupportedError(ErrorKind("Option"),
134 "LAL SolverCTMC does not support timespan, init_sol or config options; "
135 "use the composition initial distribution and getTranProbSys(t).");
136 const Model snapshot = model_->model();
137 const bool truncated = model_->source_truncated;
138 std::optional<std::string> fallback_reason;
139 std::optional<Result> solved;
140 if (method != "mdd") {
141 try {
142 solved = solve_(snapshot);
143 } catch (const UnsupportedError& exc) {
144 if (method != "default" || exc.id() != "LINE:unsupported:StateSpace") throw;
145 if (!supportsModelMethod("mdd").first) throw;
146 fallback_reason = exc.what();
147 method = "mdd";
148 }
149 }
150 result_ = State();
151 if (method == "mdd") {
152 MddSolution mdd = solve_mdd(snapshot, std::min<std::size_t>(options.ctmc_max_states, 100000));
153 const bool exact = mdd.mcd.no_aggregation && !truncated;
154 mdd.table.attrs.method = "mdd";
155 mdd.table.attrs.exact = exact;
156 mdd.table.attrs.truncated = truncated;
157 mdd.table.attrs.fallback_reason = fallback_reason;
158 mdd.table.attrs.extra["approximation"] =
159 exact ? nlohmann::json(nullptr) : nlohmann::json("MDD level aggregation");
160 result_.state_table = mdd.table;
161 result_.method = "mdd";
162 result_.exact = exact;
163 result_.truncated = truncated;
164 result_.mdd = std::move(mdd.mcd);
165 } else {
166 Result& r = *solved;
167 for (TableAttrs* a : {&r.state_table.attrs, &r.action_table.attrs}) {
168 a->method = "ctmc";
169 a->exact = !truncated;
170 a->truncated = truncated;
171 }
172 result_.state_table = r.state_table;
173 result_.action_table = r.action_table;
174 result_.rewards = r.rewards;
175 result_.discrete = has_discrete(snapshot);
176 result_.pi = r.probabilities;
177 result_.space = r.states;
178 result_.compiled = std::move(r.compiled);
179 result_.method = "ctmc";
180 result_.exact = !truncated;
181 result_.truncated = truncated;
182 }
183 signature_ = key_();
184 return *this;
185 }
186
187 void reset() { signature_.reset(); }
188
189 StateTable getAvgTable() { return ensure_().state_table; }
190
192 const State& r = ensure_();
193 if (r.method == "mdd")
194 throw UnsupportedError(ErrorKind("Metric"), "LAL MDD does not yet calculate action throughputs.");
195 return *r.action_table;
196 }
199
200 /**
201 * Throughput of one LAL action (`getAvgAct`): named by label, by
202 * `agent.action("x")`, by `composition.action(...)` or by
203 * `ActionSpec::key(node, EventType[, class])`; an open class or a trailing
204 * `[*]` sums the family.
205 */
206 double getAvgAct(const ActionSpec& action) { return act_value(*model_, getActTable(), action); }
207 double getAvgAct(const std::string& node, lang::EventType event,
208 const std::optional<std::string>& jobclass = std::nullopt,
209 const std::optional<std::string>& mode = std::nullopt) {
210 return getAvgAct(ActionSpec::key(node, event, jobclass, mode));
211 }
212 double getAvgAct(std::size_t node, lang::EventType event, std::size_t jobclass = 0) {
213 return getAvgAct(ActionSpec::key(node, event, jobclass));
214 }
215 /** Throughputs of several actions, each named as in `getAvgAct`. */
216 std::vector<double> getActAvg(const std::vector<ActionSpec>& actions) {
217 std::vector<double> out;
218 for (const ActionSpec& a : actions) out.push_back(getAvgAct(a));
219 return out;
220 }
221 double get_avg_act(const ActionSpec& action) { return getAvgAct(action); }
222 std::vector<double> get_act_avg(const std::vector<ActionSpec>& actions) { return getActAvg(actions); }
223
224 /** The rewards declared with `Composition::setReward`, on the stationary law: `(R, names)`. */
225 std::pair<std::vector<double>, std::vector<std::string>> getAvgReward() {
226 const State& r = ensure_();
227 if (r.method == "mdd") throw UnsupportedError(ErrorKind("Metric"), "LAL MDD does not evaluate rewards.");
228 std::pair<std::vector<double>, std::vector<std::string>> out;
229 for (const auto& kv : r.rewards) {
230 out.first.push_back(kv.second);
231 out.second.push_back(kv.first);
232 }
233 return out;
234 }
235
236 /** Joint stationary distribution in `getStateSpace` order (MATLAB getProbSys). */
237 std::vector<double> getProbSys() {
238 const State& r = ensure_();
239 if (r.method == "mdd")
240 throw UnsupportedError(ErrorKind("Metric"),
241 "MDD aggregation does not return a joint stationary distribution.");
242 return r.pi;
243 }
244
246 const State& r = ensure_();
247 if (r.method == "mdd")
248 throw UnsupportedError(ErrorKind("Metric"), "MDD aggregation does not construct a joint generator.");
249 return r.compiled->generator;
250 }
251
252 /** The generator and the event filters, in `getEventLabels` order. */
253 std::pair<Matrix<double>, std::vector<Matrix<double>>> getGenerator() {
254 const Matrix<double> q = getInfGen();
255 return {q, ensure_().compiled->events};
256 }
257
258 std::vector<std::string> getEventLabels() {
259 const State& r = ensure_();
260 if (r.method == "mdd") throw UnsupportedError(ErrorKind("Metric"), "LAL MDD does not expose event filters.");
261 return r.compiled->labels;
262 }
263
264 /**
265 * Joint state names, one row per state and one column per agent, plus the
266 * per-agent columns (Python returns the object array and its column slices).
267 */
268 std::pair<std::vector<std::vector<std::string>>, std::vector<std::vector<std::string>>> getStateSpace() {
269 const State& r = ensure_();
270 if (r.method == "mdd")
271 throw UnsupportedError(ErrorKind("Metric"), "MDD aggregation does not return the joint state space.");
272 std::vector<std::vector<std::string>> space;
273 for (std::size_t i = 0; i < r.space.size(); ++i) space.push_back(r.compiled->state_names(i));
274 std::vector<std::vector<std::string>> local(r.compiled->agent_names.size());
275 for (const auto& row : space)
276 for (std::size_t a = 0; a < row.size(); ++a) local[a].push_back(row[a]);
277 return {space, local};
278 }
279
280 /** Transient joint distribution `pi0 exp(Q t)`. */
281 std::vector<double> getTranProbSys(double t) {
282 if (!std::isfinite(t) || t < 0)
283 throw InputError(ErrorKind("Argument"), "t must be finite and nonnegative.");
284 const State& r = ensure_();
285 if (r.method == "mdd")
286 throw UnsupportedError(ErrorKind("Metric"), "LAL MDD does not provide transient probabilities.");
287 if (r.discrete) {
288 // a MarkovChain part: the generator is P - I, and t counts steps
289 if (std::fabs(t - std::round(t)) > 1e-12)
290 throw InputError(ErrorKind("Argument"),
291 "a discrete-time composition advances one step per unit of time, so getTranProbSys "
292 "requires a nonnegative integer number of steps.");
293 const Matrix<double>& Q = r.compiled->generator;
294 std::vector<double> p = r.compiled->initial_distribution;
295 const long steps = static_cast<long>(std::llround(t));
296 for (long k = 0; k < steps; ++k) {
297 std::vector<double> next(p.size(), 0.0);
298 for (std::size_t i = 0; i < p.size(); ++i) {
299 if (p[i] == 0) continue;
300 for (std::size_t j = 0; j < p.size(); ++j) next[j] += p[i] * (Q(i, j) + (i == j ? 1.0 : 0.0));
301 }
302 p.swap(next);
303 }
304 return p;
305 }
306 Matrix<double> qt = r.compiled->generator;
307 for (std::size_t k = 0; k < qt.size(); ++k) qt[k] *= t;
308 const Matrix<double> e = expm(qt);
309 const std::vector<double>& p0 = r.compiled->initial_distribution;
310 std::vector<double> out(p0.size(), 0.0);
311 for (std::size_t i = 0; i < p0.size(); ++i)
312 for (std::size_t j = 0; j < p0.size(); ++j) out[j] += p0[i] * e(i, j);
313 return out;
314 }
315
316 /** MDD aggregation details (Python's `_result.mdd`); throws unless the method run was mdd. */
318 const State& r = ensure_();
319 if (r.method != "mdd") throw UnsupportedError(ErrorKind("Metric"), "No MDD aggregation was run.");
320 return *r.mdd;
321 }
322
323 std::string getResultMethod() { return ensure_().method; }
324
325 void getAvg() const { throw UnsupportedError(ErrorKind("Metric"), detail::network_metric_refusal("getAvg")); }
326 void getAvgQLen() const {
327 throw UnsupportedError(ErrorKind("Metric"), detail::network_metric_refusal("getAvgQLen"));
328 }
329
330 /** Test seam: replaces the explicit CTMC call (Python tests monkeypatch it). */
331 std::function<Result(const Model&, std::size_t)> ctmc_backend;
332
333 private:
334 struct State {
335 std::string method;
336 bool exact = false;
337 bool truncated = false;
338 StateTable state_table;
339 std::optional<ActionTable> action_table;
340 std::vector<double> pi;
341 std::vector<std::vector<std::size_t>> space;
342 std::optional<Compiled> compiled;
343 std::optional<mdd::MddMcdResult<double>> mdd;
344 std::vector<std::pair<std::string, double>> rewards;
345 bool discrete = false;
346 };
347
348 const Composition* model_;
349 State result_;
350 std::optional<std::string> signature_;
351
352 Result solve_(const Model& snapshot) {
353 if (ctmc_backend) return ctmc_backend(snapshot, options.ctmc_max_states);
354 return solve_composition(snapshot, options.ctmc_max_states);
355 }
356 std::string key_() const {
357 return signature(model_->model()) + (model_->source_truncated ? "|T|" : "|F|") + options.key();
358 }
359 const State& ensure_() {
360 if (!signature_ || *signature_ != key_()) runAnalyzer();
361 return result_;
362 }
363};
364
365/** Options of the LAL arm of SolverSSA. */
367 std::string method = "default";
368 long samples = 10000; ///< deprecated alias of events
369 std::optional<long> events; ///< event budget; overrides samples
370 unsigned long long seed = 0;
371 std::optional<double> warmupfrac;
372 std::pair<double, double> timespan{0.0, std::numeric_limits<double>::infinity()};
373 nlohmann::json config = nlohmann::json::object();
374 std::optional<double> timestep;
375 bool record_events = false;
376 bool record_syspath = false;
377 double timeout = std::numeric_limits<double>::infinity();
378 double cutoff = std::numeric_limits<double>::infinity();
379
380 std::string key() const {
381 std::ostringstream os;
382 os << detail::lower(method) << '|' << samples << '|' << (events ? std::to_string(*events) : "None") << '|'
383 << seed << '|' << (warmupfrac ? detail::repr_double(*warmupfrac) : "None") << '|' << detail::repr_double(timespan.first)
384 << ',' << detail::repr_double(timespan.second) << '|' << config.dump() << '|'
385 << (timestep ? detail::repr_double(*timestep) : "None") << '|' << record_events << record_syspath << '|'
386 << detail::repr_double(timeout) << '|' << detail::repr_double(cutoff);
387 return os.str();
388 }
389};
390
391/** Serial Gillespie (`serial`, `ssa`, `default`) and next-reaction (`nrm`) simulation of a composition. */
393 public:
394 /** References `model`, which must outlive the solver (see SolverCTMC). */
396 : options(std::move(options)), model_(&model) {}
398
400
401 static bool supports(const Composition&) { return true; }
402
403 /**
404 * `listValidMethods`: SolverSSA.m answers this solver's row of the method
405 * registry (doc/line-methods.json) whatever the model, a Composition
406 * included; `supportsModelMethod` then says which of them a composition
407 * takes (serial, ssa, default and nrm).
408 */
409 static std::vector<std::string> listValidMethods() { return ::line::method_registry::methods("SSA"); }
410 static std::vector<std::string> list_valid_methods() { return listValidMethods(); }
411
412 std::pair<bool, std::optional<std::string>> supportsModelMethod(const std::string& method) const {
413 const std::string m = detail::strip_prefix(detail::lower(method), "ssa.");
414 const Model snapshot = model_->model();
415 if (has_discrete(snapshot))
416 return {false, std::string("SolverSSA simulates continuous time; a discrete-time composition (MarkovChain) "
417 "has no holding times to sample.")};
418 if (m == "nrm") {
419 const std::set<std::string> features = model_features(snapshot);
420 if (!features.empty())
421 return {false, "the next-reaction method supports timed hand-declared agents only; the composition "
422 "uses " + detail::join_sorted(features) + " actions (use serial)."};
423 }
424 if (m == "default" || m == "serial" || m == "ssa" || m == "nrm") return {true, std::nullopt};
425 return {false, std::string("LAL compositions support serial SSA and NRM only.")};
426 }
427
430 if (!ok.first) throw UnsupportedError(ErrorKind("Method"), *ok.second);
431 if (options.timespan.first != 0.0 || !std::isinf(options.timespan.second) || !options.config.empty() ||
433 !std::isinf(options.cutoff))
434 throw UnsupportedError(ErrorKind("Option"),
435 "LAL SSA does not yet support finite timespan, config, timestep, "
436 "path recording, timeout or cutoff options.");
437 const Model snapshot = model_->model();
438 const double warmupfrac = options.warmupfrac ? *options.warmupfrac : 0.0;
439 const long count = options.events ? *options.events : options.samples;
440 const std::string m = detail::strip_prefix(detail::lower(options.method), "ssa.");
441 SSAResult r = simulate(snapshot, count, options.seed, warmupfrac, m == "nrm" ? "nrm" : "ssa");
442 const bool truncated = model_->source_truncated;
443 for (TableAttrs* a : {&r.state_table.attrs, &r.action_table.attrs}) {
444 a->method = r.method;
445 a->exact = false;
446 a->truncated = truncated;
447 a->extra["statistical"] = true;
448 a->extra["seed"] = options.seed;
449 a->extra["events"] = r.events;
450 a->extra["duration"] = r.duration;
451 a->extra["absorbed"] = r.absorbed;
452 a->extra["warmupfrac"] = warmupfrac;
453 }
454 result_ = std::move(r);
455 signature_ = key_();
456 return *this;
457 }
458
459 void reset() { signature_.reset(); }
460 StateTable getAvgTable() { return ensure_().state_table; }
461 ActionTable getActTable() { return ensure_().action_table; }
464 const SSAResult& getResult() { return ensure_(); }
465 /**
466 * `getAvgTard()`, inherited by the reference from NetworkSolver: mean class
467 * tardiness against the JobClass deadlines, as {Tard, SysTard}. It solves
468 * first when no result is held (`getAvgTard.m` calls `getAvg`) and returns
469 * what the result carries. A composition declares no JobClass and no
470 * deadline, so no LAL result carries a tardiness and both matrices are
471 * empty, as the reference returns `[]` for them.
472 */
473 std::vector<Matrix<double>> getAvgTard() {
474 ensure_();
475 return {Matrix<double>(), Matrix<double>()};
476 }
477 std::vector<Matrix<double>> get_avg_tard() { return getAvgTard(); }
478
479 /** Throughput estimate of one LAL action (named as in SolverCTMC::getAvgAct). */
480 double getAvgAct(const ActionSpec& action) { return act_value(*model_, getActTable(), action); }
481 double getAvgAct(const std::string& node, lang::EventType event,
482 const std::optional<std::string>& jobclass = std::nullopt,
483 const std::optional<std::string>& mode = std::nullopt) {
484 return getAvgAct(ActionSpec::key(node, event, jobclass, mode));
485 }
486 double getAvgAct(std::size_t node, lang::EventType event, std::size_t jobclass = 0) {
487 return getAvgAct(ActionSpec::key(node, event, jobclass));
488 }
489 /** Throughput estimates of several actions, each named as in `getAvgAct`. */
490 std::vector<double> getActAvg(const std::vector<ActionSpec>& actions) {
491 std::vector<double> out;
492 for (const ActionSpec& a : actions) out.push_back(getAvgAct(a));
493 return out;
494 }
495
496 /** Estimates of the rewards declared with `Composition::setReward`: `(R, names)`. */
497 std::pair<std::vector<double>, std::vector<std::string>> getAvgReward() {
498 const SSAResult& r = ensure_();
499 std::pair<std::vector<double>, std::vector<std::string>> out;
500 for (const auto& kv : r.rewards) {
501 out.first.push_back(kv.second);
502 out.second.push_back(kv.first);
503 }
504 return out;
505 }
506
507 /**
508 * `getTotalSimulatedTime`: the measured horizon of the LAL SSA run, the
509 * time its state and action estimates are averaged over (after warm-up);
510 * +inf when the run was absorbed, as the tables' `duration` attribute
511 * reads. The network counterpart is `SsaSolution::simulated_time`.
512 */
513 double getTotalSimulatedTime() { return ensure_().duration; }
514 /**
515 * `getSampleCount`: the measured events of the LAL SSA run (after
516 * warm-up), the tables' `events` attribute. The network counterpart is
517 * `SsaSolution::samples`.
518 */
519 long getSampleCount() { return ensure_().events; }
520
521 void getAvg() const {
522 throw UnsupportedError(ErrorKind("Metric"), "getAvg requires queueing-network station and class metrics; "
523 "use the LAL state and action tables.");
524 }
525 void sample() const {
526 throw UnsupportedError(ErrorKind("Analysis"), "LAL SSA sample paths are not yet exposed.");
527 }
528
529 private:
530 const Composition* model_;
531 SSAResult result_;
532 std::optional<std::string> signature_;
533
534 std::string key_() const {
535 return signature(model_->model()) + (model_->source_truncated ? "|T|" : "|F|") + options.key();
536 }
537 const SSAResult& ensure_() {
538 if (!signature_ || *signature_ != key_()) runAnalyzer();
539 return result_;
540 }
541};
542
543} // namespace lal
544} // namespace line
545
546#endif // LINE_LANG_LAL_SOLVERS_H
LINE Agent Language (LAL): programmatic construction of finite agents and their composition,...
const std::string & id() const noexcept
The full identifier, e.g.
Definition error.h:78
InputError(const std::string &what)
Definition error.h:105
std::size_t size() const
Definition matrix.h:91
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
A collection of agents and embedded LINE models with atomic synchronisations (Composition).
Definition builder.h:655
Model model(const std::vector< Sync > *syncs=nullptr, const std::vector< ExtSync > *ext_syncs=nullptr) const
The current model snapshot (_model).
Definition builder.h:906
SolverCTMC & runAnalyzer()
Definition solvers.h:128
CTMCOptions options
Definition solvers.h:101
SolverCTMC(const Composition &model, CTMCOptions options=CTMCOptions())
The solver REFERENCES model, as Python's re-reads self.model on every query: a later edit (an added a...
Definition solvers.h:97
StateTable getAvgTable()
Definition solvers.h:189
double getAvgAct(const std::string &node, lang::EventType event, const std::optional< std::string > &jobclass=std::nullopt, const std::optional< std::string > &mode=std::nullopt)
Definition solvers.h:207
std::vector< std::string > getEventLabels()
Definition solvers.h:258
static bool supports(const Composition &)
Definition solvers.h:103
ActionTable getActTable()
Definition solvers.h:191
void getAvgQLen() const
Definition solvers.h:326
std::pair< std::vector< double >, std::vector< std::string > > getAvgReward()
The rewards declared with Composition::setReward, on the stationary law: (R, names).
Definition solvers.h:225
std::function< Result(const Model &, std::size_t)> ctmc_backend
Test seam: replaces the explicit CTMC call (Python tests monkeypatch it).
Definition solvers.h:331
std::pair< Matrix< double >, std::vector< Matrix< double > > > getGenerator()
The generator and the event filters, in getEventLabels order.
Definition solvers.h:253
ActionTable getActionTable()
Definition solvers.h:198
std::vector< double > getActAvg(const std::vector< ActionSpec > &actions)
Throughputs of several actions, each named as in getAvgAct.
Definition solvers.h:216
SolverCTMC(const Composition &&, CTMCOptions=CTMCOptions())=delete
std::pair< bool, std::optional< std::string > > supportsModelMethod(const std::string &method) const
Definition solvers.h:105
double get_avg_act(const ActionSpec &action)
Definition solvers.h:221
void getAvg() const
Definition solvers.h:325
std::vector< double > getProbSys()
Joint stationary distribution in getStateSpace order (MATLAB getProbSys).
Definition solvers.h:237
double getAvgAct(const ActionSpec &action)
Throughput of one LAL action (getAvgAct): named by label, by agent.action("x"), by composition....
Definition solvers.h:206
std::vector< double > get_act_avg(const std::vector< ActionSpec > &actions)
Definition solvers.h:222
Matrix< double > getInfGen()
Definition solvers.h:245
std::pair< std::vector< std::vector< std::string > >, std::vector< std::vector< std::string > > > getStateSpace()
Joint state names, one row per state and one column per agent, plus the per-agent columns (Python ret...
Definition solvers.h:268
std::vector< double > getTranProbSys(double t)
Transient joint distribution pi0 exp(Q t).
Definition solvers.h:281
ActionTable getActT()
Definition solvers.h:197
double getAvgAct(std::size_t node, lang::EventType event, std::size_t jobclass=0)
Definition solvers.h:212
const mdd::MddMcdResult< double > & getMDDResult()
MDD aggregation details (Python's _result.mdd); throws unless the method run was mdd.
Definition solvers.h:317
std::string getResultMethod()
Definition solvers.h:323
void sample() const
Definition solvers.h:525
std::vector< Matrix< double > > getAvgTard()
getAvgTard(), inherited by the reference from NetworkSolver: mean class tardiness against the JobClas...
Definition solvers.h:473
double getAvgAct(std::size_t node, lang::EventType event, std::size_t jobclass=0)
Definition solvers.h:486
static std::vector< std::string > list_valid_methods()
Definition solvers.h:410
static std::vector< std::string > listValidMethods()
listValidMethods: SolverSSA.m answers this solver's row of the method registry (doc/line-methods....
Definition solvers.h:409
StateTable getAvgTable()
Definition solvers.h:460
std::vector< Matrix< double > > get_avg_tard()
Definition solvers.h:477
ActionTable getActTable()
Definition solvers.h:461
const SSAResult & getResult()
Definition solvers.h:464
void getAvg() const
Definition solvers.h:521
static bool supports(const Composition &)
Definition solvers.h:401
double getAvgAct(const std::string &node, lang::EventType event, const std::optional< std::string > &jobclass=std::nullopt, const std::optional< std::string > &mode=std::nullopt)
Definition solvers.h:481
SSAOptions options
Definition solvers.h:399
std::pair< std::vector< double >, std::vector< std::string > > getAvgReward()
Estimates of the rewards declared with Composition::setReward: (R, names).
Definition solvers.h:497
std::vector< double > getActAvg(const std::vector< ActionSpec > &actions)
Throughput estimates of several actions, each named as in getAvgAct.
Definition solvers.h:490
SolverSSA(const Composition &model, SSAOptions options=SSAOptions())
References model, which must outlive the solver (see SolverCTMC).
Definition solvers.h:395
SolverSSA(const Composition &&, SSAOptions=SSAOptions())=delete
SolverSSA & runAnalyzer()
Definition solvers.h:428
ActionTable getActionTable()
Definition solvers.h:463
double getTotalSimulatedTime()
getTotalSimulatedTime: the measured horizon of the LAL SSA run, the time its state and action estimat...
Definition solvers.h:513
long getSampleCount()
getSampleCount: the measured events of the LAL SSA run (after warm-up), the tables' events attribute.
Definition solvers.h:519
std::pair< bool, std::optional< std::string > > supportsModelMethod(const std::string &method) const
Definition solvers.h:412
double getAvgAct(const ActionSpec &action)
Throughput estimate of one LAL action (named as in SolverCTMC::getAvgAct).
Definition solvers.h:480
ActionTable getActT()
Definition solvers.h:462
LINE Agent Language (LAL): the result tables every LAL solver returns, the exact finite CTMC analysis...
Matrix exponential by scaling and squaring with a diagonal Pade approximant.
The method names of each solver, in listing order.
Definition ag.h:49
std::string signature(const Model &m)
A deterministic text signature of a model snapshot (Python's repr(model)), used by the solvers to cac...
Definition core.h:472
SSAResult simulate(const Model &snapshot, long events, unsigned long long seed, double warmupfrac=0.0, const std::string &method="ssa")
Simulate event races without constructing the joint state space (simulate).
Definition ssa.h:213
bool has_discrete(const Model &model)
True when any agent of the model is discrete-time.
Definition core.h:543
MddSolution solve_mdd(const Model &snapshot, std::size_t max_states=100000)
MDD aggregation for finite active/passive compositions (solve_mdd).
Definition ctmc.h:366
ActionTable action_table(const Compiled &compiled, const std::vector< double > &probs, const Model *snapshot=nullptr)
Labelled event throughputs probs @ rowsum(event), hidden labels left out.
Definition ctmc.h:238
Result solve_composition(const Model &snapshot, std::size_t max_states=0, std::size_t max_dense_bytes=kDefaultMaxDenseBytes)
Solve a finite composition, respecting its initial state if reducible (solve_composition).
Definition ctmc.h:260
std::set< std::string > model_features(const Model &model)
Features of a model that only the extended kernel interprets (model_features).
Definition core.h:525
static const std::size_t kDefaultMaxDenseBytes
Default dense-storage budget of the CTMC path: 256 MiB.
Definition ctmc.h:114
EventType
The events a state can undergo, with the values of MATLAB EventType.
Definition lang_types.h:116
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Matrix< T > expm(const Matrix< T > &A)
Matrix exponential exp(A).
Definition expm.h:141
LINE Agent Language (LAL): on-demand Gillespie simulation of a finite composition (lal/ssa....
ErrorKind(std::string n)
Definition error.h:39
TableAttrs attrs
Definition ctmc.h:81
The immutable agent record (core.Agent).
Definition core.h:284
std::optional< std::vector< double > > initial_distribution
Definition core.h:289
Options of the LAL arm of SolverCTMC.
Definition solvers.h:70
std::string key() const
Definition solvers.h:77
std::optional< std::vector< double > > init_sol
refused when set
Definition solvers.h:74
nlohmann::json config
refused when nonempty
Definition solvers.h:75
std::string method
Definition solvers.h:71
std::optional< std::pair< double, double > > timespan
refused when set
Definition solvers.h:73
std::size_t ctmc_max_states
hard cap on enumerated global states
Definition solvers.h:72
The output of solve_mdd: the marginal table and the MCD aggregation.
Definition ctmc.h:356
A composition snapshot (core.Model): agents in declaration order plus synchronisations.
Definition core.h:310
std::vector< MinSync > min_syncs
Definition core.h:313
std::vector< AgentRecord > agents
Definition core.h:311
The result container shared by the LAL solver paths (LALCTMCResult, the AG decomposition results,...
Definition ctmc.h:96
std::vector< double > probabilities
joint probabilities (CTMC)
Definition ctmc.h:106
std::optional< Compiled > compiled
Definition ctmc.h:107
ActionTable action_table
Definition ctmc.h:104
std::vector< std::vector< std::size_t > > states
joint states (CTMC)
Definition ctmc.h:105
StateTable state_table
Definition ctmc.h:103
std::vector< std::pair< std::string, double > > rewards
Stationary expectations of the rewards declared with Composition::setReward, in order.
Definition ctmc.h:110
Options of the LAL arm of SolverSSA.
Definition solvers.h:366
std::string method
Definition solvers.h:367
unsigned long long seed
Definition solvers.h:370
long samples
deprecated alias of events
Definition solvers.h:368
std::optional< long > events
event budget; overrides samples
Definition solvers.h:369
std::string key() const
Definition solvers.h:380
nlohmann::json config
Definition solvers.h:373
std::optional< double > warmupfrac
Definition solvers.h:371
std::pair< double, double > timespan
Definition solvers.h:372
std::optional< double > timestep
Definition solvers.h:374
The SSA result (LALSSAResult).
Definition ssa.h:36
ActionTable action_table
Definition ssa.h:38
StateTable state_table
Definition ssa.h:37
double duration
measured time; +inf when absorbed
Definition ssa.h:40
long events
measured events (after warm-up)
Definition ssa.h:39
std::vector< std::pair< std::string, double > > rewards
Estimates of the rewards declared with Composition::setReward, in order.
Definition ssa.h:44
std::string method
Definition ssa.h:42
TableAttrs attrs
Definition ctmc.h:69
The attrs of a LAL result table.
Definition ctmc.h:46
Result of the Miner-Ciardo-Donatelli level aggregation.
Definition mdd_types.h:229