LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
ctmc.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_CTMC_H
6#define LINE_LANG_LAL_CTMC_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * LINE Agent Language (LAL): the result tables every LAL solver returns, the
12 * exact finite CTMC analysis (`lal/ctmc.py`, `solve_composition`) and the MDD
13 * aggregation (`lal/mdd.py`, `solve_mdd`).
14 *
15 * The CTMC path is explicit enumeration, not a product form. The reachable
16 * state space is split into closed classes whose weights are the absorption
17 * probabilities from the declared initial distribution, so a reducible chain
18 * is solved from its initial state rather than refused.
19 *
20 * Python's pandas tables with `attrs` become `StateTable` / `ActionTable`
21 * (rows plus `TableAttrs`); Python diagnostic dicts become nlohmann::json.
22 */
23
24#include <algorithm>
25#include <functional>
26#include <map>
27#include <set>
28#include <optional>
29#include <string>
30#include <vector>
31
32#include "json.hpp"
34#include "line/api/mdd/mdd.h"
38#include "line/lang/lal/core.h"
40#include "line/util/lu.h"
41
42namespace line {
43namespace lal {
44
45/** The `attrs` of a LAL result table. */
46struct TableAttrs {
47 std::string method;
48 std::optional<bool> exact;
49 bool truncated = false;
50 std::optional<std::string> fallback_reason;
51 nlohmann::json extra = nlohmann::json::object(); ///< remaining Python attrs
52};
53
54/** One row of a state table: `Agent, State, Probability`. */
55struct StateRow {
56 std::string agent;
57 std::string state;
58 double probability = 0.0;
59};
60
61/** One row of an action table: `Action, Throughput`. */
62struct ActionRow {
63 std::string action;
64 double throughput = 0.0;
65};
66
67struct StateTable {
68 std::vector<StateRow> rows;
70 std::size_t size() const { return rows.size(); }
71 /** Probability of one agent state; throws when absent. */
72 double probability(const std::string& agent, const std::string& state) const {
73 for (const StateRow& r : rows)
74 if (r.agent == agent && r.state == state) return r.probability;
75 throw value_error("No state row " + agent + "." + state);
76 }
77};
78
80 std::vector<ActionRow> rows;
82 std::size_t size() const { return rows.size(); }
83 /** Throughput of one action label; throws when absent. */
84 double throughput(const std::string& action) const {
85 for (const ActionRow& r : rows)
86 if (r.action == action) return r.throughput;
87 throw value_error("No action row " + action);
88 }
89};
90
91/**
92 * The result container shared by the LAL solver paths (`LALCTMCResult`,
93 * the AG decomposition results, SSA). Fields a path does not produce stay at
94 * their defaults.
95 */
96struct Result {
97 std::string method = "ctmc";
98 bool exact = false;
99 bool truncated = false;
100 std::optional<std::string> fallback_reason;
101 bool converged = true;
102 int iterations = 0;
105 std::vector<std::vector<std::size_t>> states; ///< joint states (CTMC)
106 std::vector<double> probabilities; ///< joint probabilities (CTMC)
107 std::optional<Compiled> compiled;
108 nlohmann::json diagnostics = nlohmann::json::object();
109 /** Stationary expectations of the rewards declared with `Composition::setReward`, in order. */
110 std::vector<std::pair<std::string, double>> rewards;
111};
112
113/** Default dense-storage budget of the CTMC path: 256 MiB. */
114static const std::size_t kDefaultMaxDenseBytes = 256u * 1024u * 1024u;
115
116namespace detail {
117
118/** Strongly connected components (iterative Tarjan) of a directed graph given by adjacency lists. */
119inline std::vector<int> strong_components(const std::vector<std::vector<std::size_t>>& adj, int& count) {
120 const std::size_t n = adj.size();
121 std::vector<int> index(n, -1), low(n, 0), comp(n, -1);
122 std::vector<char> on(n, 0);
123 std::vector<std::size_t> stack;
124 int next = 0;
125 count = 0;
126 for (std::size_t s = 0; s < n; ++s) {
127 if (index[s] != -1) continue;
128 std::vector<std::pair<std::size_t, std::size_t>> call{{s, 0}};
129 index[s] = low[s] = next++;
130 stack.push_back(s);
131 on[s] = 1;
132 while (!call.empty()) {
133 const std::size_t v = call.back().first;
134 std::size_t& it = call.back().second;
135 if (it < adj[v].size()) {
136 const std::size_t w = adj[v][it++];
137 if (index[w] == -1) {
138 index[w] = low[w] = next++;
139 stack.push_back(w);
140 on[w] = 1;
141 call.push_back({w, 0});
142 } else if (on[w]) {
143 low[v] = std::min(low[v], index[w]);
144 }
145 } else {
146 if (low[v] == index[v]) {
147 while (true) {
148 const std::size_t w = stack.back();
149 stack.pop_back();
150 on[w] = 0;
151 comp[w] = count;
152 if (w == v) break;
153 }
154 ++count;
155 }
156 call.pop_back();
157 if (!call.empty()) {
158 const std::size_t u = call.back().first;
159 low[u] = std::min(low[u], low[v]);
160 }
161 }
162 }
163 }
164 return comp;
165}
166
167inline Matrix<double> submatrix(const Matrix<double>& q, const std::vector<std::size_t>& r,
168 const std::vector<std::size_t>& c) {
169 Matrix<double> out(r.size(), c.size(), 0.0);
170 for (std::size_t i = 0; i < r.size(); ++i)
171 for (std::size_t j = 0; j < c.size(); ++j) out(i, j) = q(r[i], c[j]);
172 return out;
173}
174
175} // namespace detail
176
177/**
178 * Marginal state probabilities of every agent (`agent_state_rows`): one row
179 * per local state of a hand agent; an embedded LINE model contributes one
180 * agent per stateful node, whose state is the node's row of LINE's state
181 * space, plus the stage agent of an embedded Environment.
182 */
183inline StateTable agent_state_rows(const Model& snapshot, const std::vector<std::vector<std::size_t>>& states,
184 const std::vector<double>& probs) {
185 StateTable t;
186 for (std::size_t a = 0; a < snapshot.agents.size(); ++a) {
187 const AgentRecord& agent = snapshot.agents[a];
188 if (!agent.embedded) {
189 std::vector<double> m(agent.states.size(), 0.0);
190 for (std::size_t i = 0; i < states.size(); ++i) m[states[i][a]] += probs[i];
191 for (std::size_t s = 0; s < agent.states.size(); ++s) t.rows.push_back({agent.name, agent.states[s], m[s]});
192 continue;
193 }
194 EmbeddedPart& emb = *agent.embedded;
195 const std::string prefix = emb.prefix().empty() ? std::string() : emb.prefix() + ".";
196 if (emb.has_stages()) {
197 std::map<std::size_t, double> marg;
198 for (std::size_t i = 0; i < states.size(); ++i) marg[emb.stage_of(states[i][a])] += probs[i];
199 const std::vector<std::string> names = emb.stage_names();
200 for (const auto& kv : marg)
201 t.rows.push_back({prefix + "Env", kv.first < names.size() ? names[kv.first] : std::to_string(kv.first),
202 kv.second});
203 }
204 for (const auto& node : emb.node_states()) {
205 std::vector<std::string> order;
206 std::map<std::string, double> marg;
207 for (std::size_t i = 0; i < states.size(); ++i) {
208 const std::string label = emb.node_state_label(states[i][a], node.second);
209 if (!marg.count(label)) order.push_back(label);
210 marg[label] += probs[i];
211 }
212 for (const std::string& label : order) t.rows.push_back({prefix + node.first, label, marg[label]});
213 }
214 }
215 return t;
216}
217
218/** Agent-state marginals of a joint probability vector, in the Python row order. */
219inline StateTable marginal_table(const Model& snapshot, const Compiled& compiled, const std::vector<double>& probs) {
220 return agent_state_rows(snapshot, compiled.states, probs);
221}
222
223/** Stationary expectation of every declared reward (`reward_values`). */
224inline std::vector<std::pair<std::string, double>> reward_values(const Model& snapshot,
225 const std::vector<std::vector<std::size_t>>& states,
226 const std::vector<double>& probs) {
227 std::vector<std::pair<std::string, double>> out;
228 for (const auto& r : snapshot.rewards) {
229 double v = 0.0;
230 for (std::size_t i = 0; i < states.size(); ++i)
231 if (probs[i] != 0) v += probs[i] * r.second(StateView(snapshot, states[i]));
232 out.push_back(std::make_pair(r.first, v));
233 }
234 return out;
235}
236
237/** Labelled event throughputs `probs @ rowsum(event)`, hidden labels left out. */
238inline ActionTable action_table(const Compiled& compiled, const std::vector<double>& probs,
239 const Model* snapshot = nullptr) {
240 ActionTable t;
241 for (std::size_t k = 0; k < compiled.labels.size(); ++k) {
242 if (snapshot && is_hidden(*snapshot, compiled.labels[k])) continue;
243 double x = 0.0;
244 const Matrix<double>& E = compiled.events[k];
245 for (std::size_t i = 0; i < E.rows(); ++i) {
246 double s = 0.0;
247 for (std::size_t j = 0; j < E.cols(); ++j) s += E(i, j);
248 x += probs[i] * s;
249 }
250 t.rows.push_back({compiled.labels[k], x});
251 }
252 return t;
253}
254
255/**
256 * Solve a finite composition, respecting its initial state if reducible
257 * (`solve_composition`). `max_states = 0` leaves only the dense-storage bound.
258 * A resource limit becomes `LINE:unsupported:StateSpace`.
259 */
260inline Result solve_composition(const Model& snapshot, std::size_t max_states = 0,
261 std::size_t max_dense_bytes = kDefaultMaxDenseBytes) {
262 Compiled compiled;
263 try {
265 o.reachable_only = true;
266 o.max_states = max_states;
267 o.max_dense_bytes = max_dense_bytes;
268 compiled = compile_model(snapshot, o);
269 } catch (const StateSpaceLimitError& exc) {
270 throw UnsupportedError(ErrorKind("StateSpace"), std::string("LAL CTMC: ") + exc.what() + ".");
271 }
272 const Matrix<double>& q = compiled.generator;
273 const std::size_t N = compiled.states.size();
274 std::set<std::size_t> seen;
275 for (std::size_t i = 0; i < N; ++i)
276 if (compiled.initial_distribution[i] > 0) seen.insert(i);
277 std::vector<std::size_t> pending(seen.begin(), seen.end());
278 for (std::size_t p = 0; p < pending.size(); ++p) {
279 const std::size_t i = pending[p];
280 for (std::size_t j = 0; j < N; ++j)
281 if (q(i, j) > 0 && !seen.count(j)) {
282 seen.insert(j);
283 pending.push_back(j);
284 }
285 }
286 const std::vector<std::size_t> reachable(seen.begin(), seen.end());
287 const std::size_t R = reachable.size();
288 Matrix<double> qr = detail::submatrix(q, reachable, reachable);
289 std::vector<std::vector<std::size_t>> adj(R);
290 for (std::size_t i = 0; i < R; ++i)
291 for (std::size_t j = 0; j < R; ++j)
292 if (i != j && qr(i, j) != 0) adj[i].push_back(j);
293 int count = 0;
294 const std::vector<int> labels = detail::strong_components(adj, count);
295 // Python numbers SCCs in scipy's order; the closed classes are kept in
296 // ascending order of their smallest member, which is what fixes the
297 // (order-independent) result.
298 std::vector<std::vector<std::size_t>> members(static_cast<std::size_t>(count));
299 for (std::size_t i = 0; i < R; ++i) members[static_cast<std::size_t>(labels[i])].push_back(i);
300 std::vector<std::vector<std::size_t>> closed;
301 for (const auto& m : members) {
302 bool out = false;
303 for (std::size_t i : m)
304 for (std::size_t j : adj[i])
305 if (labels[j] != labels[i] && qr(i, j) > 0) out = true;
306 if (!out) closed.push_back(m);
307 }
308 std::sort(closed.begin(), closed.end());
309 std::vector<char> recurrent(R, 0);
310 for (const auto& m : closed)
311 for (std::size_t i : m) recurrent[i] = 1;
312 std::vector<std::size_t> transient;
313 for (std::size_t i = 0; i < R; ++i)
314 if (!recurrent[i]) transient.push_back(i);
315 std::vector<double> w0(R);
316 for (std::size_t i = 0; i < R; ++i) w0[i] = compiled.initial_distribution[reachable[i]];
318 std::vector<std::size_t> piv;
319 if (!transient.empty()) {
320 lu = detail::submatrix(qr, transient, transient);
321 for (std::size_t k = 0; k < lu.size(); ++k) lu[k] = -lu[k];
322 piv = lu_factor(lu);
323 }
324 std::vector<double> probs(N, 0.0);
325 for (const auto& m : closed) {
326 double weight = 0.0;
327 for (std::size_t i : m) weight += w0[i];
328 if (!transient.empty()) {
329 std::vector<double> flow(transient.size(), 0.0);
330 for (std::size_t t = 0; t < transient.size(); ++t)
331 for (std::size_t i : m) flow[t] += qr(transient[t], i);
332 lu_solve(lu, piv, flow);
333 for (std::size_t t = 0; t < transient.size(); ++t) weight += w0[transient[t]] * flow[t];
334 }
335 std::vector<std::size_t> rec;
336 for (std::size_t i : m) rec.push_back(reachable[i]);
337 const std::vector<double> pc = mc::ctmc_solve(detail::submatrix(q, rec, rec));
338 for (std::size_t k = 0; k < rec.size(); ++k) probs[rec[k]] = weight * pc[k];
339 }
340 Result r;
341 r.method = "ctmc";
342 r.states = compiled.states;
343 r.probabilities = probs;
344 r.state_table = agent_state_rows(snapshot, compiled.states, probs);
345 r.action_table = action_table(compiled, probs, &snapshot);
346 r.rewards = reward_values(snapshot, compiled.states, probs);
347 // a discrete-time part: throughputs are per-step frequencies
348 if (has_discrete(snapshot)) r.action_table.attrs.extra["time"] = "discrete";
349 r.state_table.attrs.method = "ctmc";
350 r.action_table.attrs.method = "ctmc";
351 r.compiled = std::move(compiled);
352 return r;
353}
354
355/** The output of `solve_mdd`: the marginal table and the MCD aggregation. */
360
361/**
362 * MDD aggregation for finite active/passive compositions (`solve_mdd`). Exact
363 * explicit-frontier reachability, an irreducibility check over the stored
364 * edges, then the Miner-Ciardo-Donatelli level aggregation.
365 */
366inline MddSolution solve_mdd(const Model& snapshot, std::size_t max_states = 100000) {
367 validate_model(snapshot);
368 if (!snapshot.min_syncs.empty())
369 throw UnsupportedError(ErrorKind("Synchronization"), "MDD has no descriptor for minimum-rate synchronization.");
370 const std::vector<AgentRecord>& agents = snapshot.agents;
371 const std::size_t K = agents.size();
372 std::vector<int> init(K);
373 for (std::size_t i = 0; i < K; ++i) {
374 const AgentRecord& a = agents[i];
375 if (a.initial_distribution) {
376 std::size_t nz = 0, first = 0;
377 for (std::size_t s = 0; s < a.initial_distribution->size(); ++s)
378 if ((*a.initial_distribution)[s] != 0) {
379 if (nz == 0) first = s;
380 ++nz;
381 }
382 if (nz != 1) throw UnsupportedError(ErrorKind("Initial"), "LAL MDD requires deterministic initial states.");
383 init[i] = static_cast<int>(first);
384 } else {
385 init[i] = static_cast<int>(a.state_index(a.initial));
386 }
387 }
388 std::map<Endpoint, std::vector<Endpoint>> sync;
389 for (const Sync& s : snapshot.syncs) sync[s.active] = s.passive;
390 struct DenseEvent {
391 std::vector<std::size_t> lev;
392 std::vector<Matrix<double>> W;
393 std::string label;
394 };
395 std::vector<DenseEvent> events;
396 for (std::size_t i = 0; i < K; ++i) {
397 const AgentRecord& agent = agents[i];
398 std::vector<std::string> actions;
399 for (const Transition& t : agent.transitions)
400 if (t.role == Role::Active && std::find(actions.begin(), actions.end(), t.action) == actions.end())
401 actions.push_back(t.action);
402 for (const std::string& action : actions) {
403 const std::size_t n = agent.states.size();
404 Matrix<double> active(n, n, 0.0);
405 for (const Transition& t : agent.transitions)
406 if (t.role == Role::Active && t.action == action)
407 active(agent.state_index(t.source), agent.state_index(t.target)) += t.value;
408 DenseEvent ev;
409 ev.lev.push_back(i);
410 ev.W.push_back(active);
411 ev.label = agent.name + "." + action;
412 auto it = sync.find(Endpoint(agent.name, action));
413 if (it != sync.end()) {
414 for (const Endpoint& p : it->second) {
415 const std::size_t j = snapshot.index_of(p.first);
416 const AgentRecord& other = agents[j];
417 const std::size_t m = other.states.size();
418 Matrix<double> block(m, m, 0.0);
419 for (const Transition& t : other.transitions)
420 if (t.role == Role::Passive && t.action == p.second)
421 block(other.state_index(t.source), other.state_index(t.target)) += t.value;
422 for (std::size_t r = 0; r < m; ++r) {
423 double s = 0.0;
424 for (std::size_t c = 0; c < m; ++c) s += block(r, c);
425 for (std::size_t c = 0; c < m; ++c) block(r, c) = s > 0 ? block(r, c) / s : 0.0;
426 }
427 ev.lev.push_back(j);
428 ev.W.push_back(block);
429 }
430 }
431 events.push_back(std::move(ev));
432 }
433 }
434 if (events.empty()) throw UnsupportedError(ErrorKind("Structure"), "LAL MDD requires at least one active event.");
435
436 std::size_t expanded = 0;
437 auto successors = [&](const std::vector<int>& state, bool check) -> std::vector<std::vector<int>> {
438 if (check) {
439 ++expanded;
440 if (expanded > max_states)
441 throw UnsupportedError(ErrorKind("StateSpace"),
442 "LAL MDD reachability exceeds " + std::to_string(max_states) + " states.");
443 }
444 std::set<std::vector<int>> result;
445 for (const DenseEvent& ev : events) {
446 std::vector<std::vector<int>> local;
447 bool empty = false;
448 for (std::size_t t = 0; t < ev.lev.size(); ++t) {
449 std::vector<int> nz;
450 const Matrix<double>& b = ev.W[t];
451 const std::size_t row = static_cast<std::size_t>(state[ev.lev[t]]);
452 for (std::size_t c = 0; c < b.cols(); ++c)
453 if (b(row, c) > 0) nz.push_back(static_cast<int>(c));
454 if (nz.empty()) empty = true;
455 local.push_back(nz);
456 }
457 if (empty) continue;
458 std::vector<std::size_t> idx(local.size(), 0);
459 while (true) {
460 std::vector<int> target = state;
461 for (std::size_t t = 0; t < local.size(); ++t) target[ev.lev[t]] = local[t][idx[t]];
462 result.insert(target);
463 std::size_t d = local.size();
464 bool done = false;
465 while (true) {
466 if (d == 0) {
467 done = true;
468 break;
469 }
470 --d;
471 if (++idx[d] < local[d].size()) break;
472 idx[d] = 0;
473 }
474 if (done) break;
475 }
476 }
477 return std::vector<std::vector<int>>(result.begin(), result.end());
478 };
479 std::vector<int> domain(K);
480 for (std::size_t i = 0; i < K; ++i) domain[i] = static_cast<int>(agents[i].states.size());
481 const mdd::MDD diagram =
482 mdd::mdd_reachset(domain, init, [&](const std::vector<int>& s) { return successors(s, true); });
483 const std::vector<std::vector<int>> states = diagram.enumerate();
484 std::map<std::vector<int>, std::size_t> lookup;
485 for (std::size_t i = 0; i < states.size(); ++i) lookup[states[i]] = i;
486 std::vector<std::vector<std::size_t>> adj(states.size());
487 std::size_t edges = 0;
488 for (std::size_t i = 0; i < states.size(); ++i)
489 for (const std::vector<int>& target : successors(states[i], false)) {
490 adj[i].push_back(lookup.at(target));
491 if (++edges > 1000000)
492 throw UnsupportedError(ErrorKind("StateSpace"), "LAL MDD irreducibility check exceeds 1000000 edges.");
493 }
494 int ncomp = 0;
495 detail::strong_components(adj, ncomp);
496 if (ncomp != 1)
497 throw UnsupportedError(ErrorKind("ReducibleCTMC"), "LAL MDD currently requires an irreducible reachable chain.");
499 desc.K = K;
500 desc.domain = domain;
501 desc.init = init;
502 for (const DenseEvent& ev : events) {
504 e.a = ev.lev.front();
505 e.b = ev.lev.back();
506 e.lev = ev.lev;
507 for (const Matrix<double>& w : ev.W) {
509 for (std::size_t r = 0; r < w.rows(); ++r)
510 for (std::size_t c = 0; c < w.cols(); ++c) b.add(r, c, w(r, c));
511 e.W.push_back(b.build());
512 }
513 desc.events.push_back(std::move(e));
514 }
515 MddSolution out;
516 out.mcd = mdd::mdd_mcd(diagram.to_struct(), desc);
517 for (std::size_t i = 0; i < K; ++i) {
518 const std::size_t k = K - 1 - i;
519 std::vector<double> marginal(agents[i].states.size(), 0.0);
520 for (std::size_t r = 0; r < out.mcd.Mrows[k].size(); ++r)
521 marginal[static_cast<std::size_t>(out.mcd.Mrows[k][r].second)] += out.mcd.pik[k][r];
522 for (std::size_t j = 0; j < agents[i].states.size(); ++j)
523 out.table.rows.push_back({agents[i].name, agents[i].states[j], marginal[j]});
524 }
525 return out;
526}
527
528} // namespace lal
529} // namespace line
530
531#endif // LINE_LANG_LAL_CTMC_H
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
bool empty() const
Definition matrix.h:92
UnsupportedError(const std::string &what)
Definition error.h:119
An embedded LINE model seen by the LAL core (Python's EmbeddedNetwork / EmbeddedEnvironment duck type...
Definition core.h:197
virtual const std::string & prefix() const =0
The embedding prefix, empty when none was given.
virtual std::vector< std::pair< std::string, std::size_t > > node_states()=0
[(node name, isf)] of the stateful node agents (isf is 1-based).
virtual std::size_t stage_of(std::size_t)
The stage of global state s (Environment only).
Definition core.h:240
virtual bool has_stages()
True for an embedded Environment, whose stage is an agent of its own.
Definition core.h:238
virtual std::string node_state_label(std::size_t s, std::size_t isf)=0
The state row of stateful node isf in global state s, as [v1 v2 ...].
virtual std::vector< std::string > stage_names()
The stage names (Environment only).
Definition core.h:242
Raised when finite-state compilation exceeds a configured resource limit.
Definition core.h:79
StateView(const Model &model, const std::vector< std::size_t > &state)
Definition core.h:347
The diagram: insert / member / index / enumerate / cardinality.
Definition mdd.h:97
MddStruct to_struct() const
Export the diagram as plain arrays for downstream algorithms.
Definition mdd.h:181
std::vector< std::vector< int > > enumerate() const
All stored states as rows, in index() order.
Definition mdd.h:172
Incremental triplet builder; duplicate entries are accumulated.
Definition mdd_types.h:75
Builder & add(std::size_t i, std::size_t j, const T &value)
Accumulate value into entry (i,j).
Definition mdd_types.h:80
MddLocalMatrix< T > build() const
Definition mdd_types.h:93
LINE Agent Language (LAL): the finite-agent model record, its validation, the joint-state event kerne...
Steady-state distribution of a continuous-time Markov chain.
LU factorization with partial pivoting, templated on the number type.
Quasi-reduced ordered Multi-valued Decision Diagram.
Miner-Ciardo-Donatelli approximate stationary analysis.
Reachability set generation into a decision diagram.
The rate side of the decision-diagram domain: local matrices, events, the Kronecker descriptor,...
Definition ag.h:49
std::pair< std::string, std::string > Endpoint
(agent, action).
Definition core.h:139
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
std::vector< std::pair< std::string, double > > reward_values(const Model &snapshot, const std::vector< std::vector< std::size_t > > &states, const std::vector< double > &probs)
Stationary expectation of every declared reward (reward_values).
Definition ctmc.h:224
Compiled compile_model(const Model &model, const CompileOptions &opt=CompileOptions())
Compile the Cartesian (or, with reachable_only, the reachable) finite state space and its event matri...
Definition core.h:1262
StateTable agent_state_rows(const Model &snapshot, const std::vector< std::vector< std::size_t > > &states, const std::vector< double > &probs)
Marginal state probabilities of every agent (agent_state_rows): one row per local state of a hand age...
Definition ctmc.h:183
InputError value_error(const std::string &what)
LINE:input:Unspecified, the C++ spelling of the Python ValueError raised throughout LAL.
Definition core.h:85
void validate_model(const Model &model, bool allow_unbounded=false)
Validate the common agent model used by both frontends (validate_model).
Definition core.h:550
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
StateTable marginal_table(const Model &snapshot, const Compiled &compiled, const std::vector< double > &probs)
Agent-state marginals of a joint probability vector, in the Python row order.
Definition ctmc.h:219
static const std::size_t kDefaultMaxDenseBytes
Default dense-storage budget of the CTMC path: 256 MiB.
Definition ctmc.h:114
std::vector< T > ctmc_solve(const Matrix< T > &Qin, const std::string &linsolver=std::string())
Steady-state distribution of a continuous-time Markov chain.
Definition ctmc_solve.h:133
MDD mdd_reachset(const std::vector< int > &domain, const std::vector< int > &init, const MddNextState &nextfun)
Generate and store the reachability set into a quasi-reduced ordered MDD.
MddMcdResult< T > mdd_mcd(const MddStruct &mdds, const MddDescriptor< T > &desc, const MddMcdOptions &options=MddMcdOptions())
Approximate stationary measures by decision-diagram-guided aggregation.
Definition mdd_mcd.h:384
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
void lu_solve(const Matrix< T > &LU, const std::vector< std::size_t > &piv, std::vector< T > &b)
Solve LUx = Pb in place on b, using the factors from lu_factor.
Definition lu.h:94
std::vector< std::size_t > lu_factor(Matrix< T > &A)
In-place LU of A (n x n).
Definition lu.h:48
ErrorKind(std::string n)
Definition error.h:39
One row of an action table: Action, Throughput.
Definition ctmc.h:62
double throughput
Definition ctmc.h:64
std::string action
Definition ctmc.h:63
std::vector< ActionRow > rows
Definition ctmc.h:80
double throughput(const std::string &action) const
Throughput of one action label; throws when absent.
Definition ctmc.h:84
TableAttrs attrs
Definition ctmc.h:81
std::size_t size() const
Definition ctmc.h:82
The immutable agent record (core.Agent).
Definition core.h:284
std::string name
Definition core.h:285
std::optional< std::vector< double > > initial_distribution
Definition core.h:289
std::string initial
Definition core.h:287
std::vector< Transition > transitions
Definition core.h:288
std::vector< std::string > states
Definition core.h:286
std::size_t state_index(const std::string &s) const
Zero-based index of a local state, or npos.
Definition core.h:302
std::shared_ptr< EmbeddedPart > embedded
An embedded LINE model, whose states are global state indices; null for a hand agent.
Definition core.h:294
Options of compile_model.
Definition core.h:1114
std::size_t max_dense_bytes
Definition core.h:1117
std::size_t max_states
Definition core.h:1116
The compiled finite CTMC (core.Compiled).
Definition core.h:396
std::vector< std::string > labels
event labels, in order
Definition core.h:400
std::vector< double > initial_distribution
Definition core.h:402
std::vector< Matrix< double > > events
one rate matrix per label
Definition core.h:401
std::vector< std::vector< std::size_t > > states
joint states as local indices
Definition core.h:397
Matrix< double > generator
Definition core.h:399
The output of solve_mdd: the marginal table and the MCD aggregation.
Definition ctmc.h:356
StateTable table
Definition ctmc.h:357
mdd::MddMcdResult< double > mcd
Definition ctmc.h:358
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< std::pair< std::string, RewardFn > > rewards
declared state rewards, in order
Definition core.h:316
std::vector< Sync > syncs
Definition core.h:312
std::size_t index_of(const std::string &name) const
Definition core.h:318
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
std::string method
Definition ctmc.h:97
bool truncated
Definition ctmc.h:99
nlohmann::json diagnostics
Definition ctmc.h:108
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::optional< std::string > fallback_reason
Definition ctmc.h:100
std::vector< std::pair< std::string, double > > rewards
Stationary expectations of the rewards declared with Composition::setReward, in order.
Definition ctmc.h:110
One row of a state table: Agent, State, Probability.
Definition ctmc.h:55
std::string agent
Definition ctmc.h:56
std::string state
Definition ctmc.h:57
double probability
Definition ctmc.h:58
double probability(const std::string &agent, const std::string &state) const
Probability of one agent state; throws when absent.
Definition ctmc.h:72
std::size_t size() const
Definition ctmc.h:70
TableAttrs attrs
Definition ctmc.h:69
std::vector< StateRow > rows
Definition ctmc.h:68
An ordinary synchronisation: one active endpoint, hand passives and injected node arrivals.
Definition core.h:250
Endpoint active
Definition core.h:251
std::vector< Endpoint > passive
Definition core.h:252
The attrs of a LAL result table.
Definition ctmc.h:46
std::string method
Definition ctmc.h:47
nlohmann::json extra
remaining Python attrs
Definition ctmc.h:51
std::optional< std::string > fallback_reason
Definition ctmc.h:50
std::optional< bool > exact
Definition ctmc.h:48
One labelled local transition source --(action, value)--> target.
Definition core.h:111
std::string target
Definition core.h:116
std::string source
Definition core.h:112
std::string action
Definition core.h:113
Kronecker rate descriptor of a structured model, the input of mdd_mcd.
Definition mdd_types.h:165
std::vector< int > domain
Local domain per level.
Definition mdd_types.h:171
std::vector< int > init
Initial local index per level.
Definition mdd_types.h:189
std::vector< MddEvent< T > > events
The events of the descriptor.
Definition mdd_types.h:193
std::size_t K
Number of levels, i.e.
Definition mdd_types.h:167
One event of the Kronecker rate descriptor.
Definition mdd_types.h:124
std::size_t b
Station (or mode) the event arrives at, 0-based; equals a for an internal event.
Definition mdd_types.h:128
std::size_t a
Station (or transition node) the event departs from, 0-based.
Definition mdd_types.h:126
std::vector< MddLocalMatrix< T > > W
Local matrices at the levels named by lev.
Definition mdd_types.h:132
std::vector< std::size_t > lev
Levels the event touches, as 0-based level indices, aligned with W.
Definition mdd_types.h:130
Result of the Miner-Ciardo-Donatelli level aggregation.
Definition mdd_types.h:229
std::vector< std::vector< T > > pik
pik[k] is the level-k stationary vector over M_k, in paper orientation.
Definition mdd_types.h:237
std::vector< std::vector< std::pair< int, int > > > Mrows
Mrows[k][r] = {node id, local value} of row r of M_k.
Definition mdd_types.h:239