LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_mam_censor.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_SOLVERS_MAM_SOLVER_MAM_CENSOR_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_CENSOR_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `solver_mam_censor.m`: the 'censor' method of SolverMAM. The network
12 * CTMC is read as a system of connected level-dependent QBDs and solved by the
13 * successive censoring algorithm of Baer, Al Hanbali, Boucherie and van Ommeren
14 * (Ann. Oper. Res. 310:389-410, 2022), `mam::ldqbd_censor`.
15 *
16 * THE CHAIN. The generator and state space are those SolverCTMC builds, so open
17 * classes are truncated at `MamOptions::cutoff` exactly as there (0, the MAM
18 * default, is the reference's Inf, which SolverCTMC resolves to its state
19 * budget), and the metrics are SolverCTMC's own extraction: only the stationary
20 * solve is replaced, through the `CtmcStationaryHook` argument of
21 * `ctmc::solver_ctmc_analyzer`.
22 *
23 * THE LEVEL is the total job count at one station, the LEVEL STATION:
24 * `MamOptions::censor_level` (a station name) or `censor_level_index` (a 1-based
25 * station index), or by default each station in decreasing order of the range
26 * of its job count until one works. The PHASE of a state is its local state at
27 * the level station.
28 *
29 * THE SETS are the classes of a partition keyed by the local states of a subset
30 * of the other stateful nodes. Every subset is a candidate, in nchoosek order
31 * from the empty key (a single set, plain linear level reduction, which applies
32 * whenever every transition moves the level station by at most one job) up to
33 * all of them. Set ids are the ranks of the sorted unique key rows, as MATLAB's
34 * `unique(...,'rows')` numbers them. Among the candidates that admit an order
35 * the one with the least estimated work is solved; inside a set the levels
36 * present are renumbered by rank. Partitions into more than 64 sets, or into
37 * singletons, are skipped.
38 *
39 * THE ORDER is built greedily on the sparsity pattern: at each step a set is
40 * censored whose fill keeps every remaining set block tridiagonal by level, the
41 * one with the least fill (ties to the lowest set id). The update is
42 * nonnegative, so the structural verdict is `ldqbd_censor`'s numeric one.
43 *
44 * A reducible chain is solved on its recurrent class when it has exactly one;
45 * with several the answer depends on the initial state and the method refuses
46 * (`LINE:unsupported:Structure`).
47 */
48
49#include <algorithm>
50#include <cmath>
51#include <cstddef>
52#include <limits>
53#include <map>
54#include <optional>
55#include <set>
56#include <string>
57#include <utility>
58#include <vector>
59
63#include "line/lang/qn/state.h"
64#include "line/num/number.h"
68#include "line/util/error.h"
69#include "line/util/matrix.h"
70
71namespace line {
72namespace mam {
73
74/** What `solver_mam_censor.m` reports in INFO, all indices 1-based. */
76 std::size_t level_station = 0; ///< the level station
77 std::vector<std::size_t> key_nodes; ///< stateful node indices of the set key
78 std::size_t nsets = 0; ///< number of sets
79 std::vector<std::size_t> order; ///< the censoring order of the sets
80 std::vector<std::vector<std::size_t>> phases; ///< phases[j][l], set order[j]
81 double cost = std::numeric_limits<double>::infinity(); ///< estimated work
82 std::size_t ncandidates = 0; ///< candidate partitions ordered
83 std::size_t nstates = 0; ///< states of the chain handed in
84};
85
86/** The metrics of the 'censor' method and its INFO. */
87template <class T>
92
93namespace censor_detail {
94
95/** The partition cap of `mam_censor_solve` (MAXSETS). */
96static const std::size_t kMaxSets = 64;
97
98/** Sparsity pattern with both adjacency directions, diagonal entries allowed. */
99struct Pattern {
100 std::vector<std::set<std::size_t>> out, in;
101 explicit Pattern(std::size_t n) : out(n), in(n) {}
102 void add(std::size_t i, std::size_t j) {
103 out[i].insert(j);
104 in[j].insert(i);
105 }
106 bool has(std::size_t i, std::size_t j) const { return out[i].count(j) > 0; }
107 /** P(i,:) = false and P(:,i) = false. */
108 void clear_node(std::size_t i) {
109 const std::vector<std::size_t> o(out[i].begin(), out[i].end());
110 for (std::size_t j : o) in[j].erase(i);
111 out[i].clear();
112 const std::vector<std::size_t> n(in[i].begin(), in[i].end());
113 for (std::size_t j : n) out[j].erase(i);
114 in[i].clear();
115 }
116};
117
118inline double cube_sum(const std::vector<std::size_t>& p) {
119 double s = 0.0;
120 for (std::size_t x : p) {
121 const double d = static_cast<double>(x);
122 s += d * d * d;
123 }
124 return s;
125}
126
127inline bool level_gap(const std::vector<std::size_t>& setid, const std::vector<std::size_t>& lvl,
128 std::size_t a, std::size_t b) {
129 if (setid[a] != setid[b]) return false;
130 const std::size_t d = lvl[a] > lvl[b] ? lvl[a] - lvl[b] : lvl[b] - lvl[a];
131 return d > 1;
132}
133
134/**
135 * Port of `censor_fill`: the pattern of P_Bk * (paths inside k) * P_kB over the
136 * alive states outside set k, and the number of columns of B that P_kB touches.
137 * F(b,c) holds when b enters some state i of k and a path inside k leads from i
138 * to a state of k with an edge to c. Returned as (b,c) pairs, rows ascending.
139 */
140inline std::vector<std::pair<std::size_t, std::size_t>> censor_fill(
141 const Pattern& P, const std::vector<std::size_t>& kix, std::size_t k,
142 const std::vector<std::size_t>& setid, const std::vector<bool>& alive, std::size_t& ncols,
143 std::size_t& nrows_into) {
144 // direct targets of each state of k outside k; every state with an edge is
145 // alive, since a censored set has its rows and columns cleared
146 std::map<std::size_t, std::vector<std::size_t>> direct;
147 std::set<std::size_t> cols;
148 for (std::size_t i : kix) {
149 std::vector<std::size_t>& d = direct[i];
150 for (std::size_t j : P.out[i])
151 if (alive[j] && setid[j] != k) {
152 d.push_back(j);
153 cols.insert(j);
154 }
155 }
156 ncols = cols.size();
157 std::set<std::size_t> rows;
158 for (std::size_t i : kix)
159 for (std::size_t b : P.in[i])
160 if (alive[b] && setid[b] != k) rows.insert(b);
161 nrows_into = rows.size();
162 std::vector<std::pair<std::size_t, std::size_t>> F;
163 if (cols.empty()) return F;
164 // X after its closure: the B columns reachable from each state of k
165 std::map<std::size_t, std::set<std::size_t>> X;
166 for (std::size_t i : kix) {
167 std::set<std::size_t>& xi = X[i];
168 std::set<std::size_t> seen;
169 std::vector<std::size_t> stack(1, i);
170 seen.insert(i);
171 while (!stack.empty()) {
172 const std::size_t u = stack.back();
173 stack.pop_back();
174 const std::vector<std::size_t>& du = direct[u];
175 xi.insert(du.begin(), du.end());
176 for (std::size_t v : P.out[u])
177 if (setid[v] == k && alive[v] && seen.insert(v).second) stack.push_back(v);
178 }
179 }
180 for (std::size_t b : rows) {
181 std::set<std::size_t> fr;
182 for (std::size_t i : P.out[b])
183 if (setid[i] == k && alive[i]) {
184 const std::set<std::size_t>& xi = X[i];
185 fr.insert(xi.begin(), xi.end());
186 }
187 for (std::size_t c : fr) F.emplace_back(b, c);
188 }
189 return F;
190}
191
192/**
193 * Port of `censor_order`: the greedy structural elimination order of the S
194 * sets (0-based ids) and its estimated work, or an empty order and Inf.
195 */
196inline std::vector<std::size_t> censor_order(Pattern P, const std::vector<std::size_t>& setid,
197 const std::vector<std::size_t>& lvl, std::size_t S,
198 const std::vector<std::vector<std::size_t>>& pcnt,
199 double& cost) {
200 const std::size_t nr = setid.size();
201 cost = std::numeric_limits<double>::infinity();
202 // every set must start block tridiagonal by level
203 for (std::size_t i = 0; i < nr; ++i)
204 for (std::size_t j : P.out[i])
205 if (level_gap(setid, lvl, i, j)) return std::vector<std::size_t>();
206 std::vector<std::vector<std::size_t>> members(S);
207 for (std::size_t i = 0; i < nr; ++i) members[setid[i]].push_back(i);
208 std::vector<bool> alive(nr, true);
209 std::vector<std::size_t> remaining(S), ord;
210 for (std::size_t s = 0; s < S; ++s) remaining[s] = s;
211 double total = 0.0;
212 for (std::size_t step = 0; step + 1 < S; ++step) {
213 bool found = false;
214 std::size_t best = 0, bestFill = std::numeric_limits<std::size_t>::max();
215 double bestWork = 0.0;
216 std::vector<std::pair<std::size_t, std::size_t>> bestF;
217 for (std::size_t k : remaining) {
218 const std::vector<std::size_t>& kix = members[k];
219 std::size_t ncols = 0, nrows = 0;
220 const std::vector<std::pair<std::size_t, std::size_t>> F =
221 censor_fill(P, kix, k, setid, alive, ncols, nrows);
222 bool ok = true;
223 for (const std::pair<std::size_t, std::size_t>& e : F)
224 if (level_gap(setid, lvl, e.first, e.second)) {
225 ok = false;
226 break;
227 }
228 if (!ok) continue;
229 std::size_t nf = 0;
230 for (const std::pair<std::size_t, std::size_t>& e : F)
231 if (!P.has(e.first, e.second)) ++nf;
232 if (!found || nf < bestFill) {
233 found = true;
234 best = k;
235 bestFill = nf;
236 bestF = F;
237 const std::size_t pmax = *std::max_element(pcnt[k].begin(), pcnt[k].end());
238 bestWork = cube_sum(pcnt[k]) + static_cast<double>(kix.size()) *
239 static_cast<double>(ncols) *
240 static_cast<double>(pmax + nrows);
241 }
242 }
243 if (!found) return std::vector<std::size_t>();
244 total += bestWork;
245 for (const std::pair<std::size_t, std::size_t>& e : bestF) P.add(e.first, e.second);
246 for (std::size_t i : members[best]) {
247 P.clear_node(i);
248 alive[i] = false;
249 }
250 ord.push_back(best);
251 remaining.erase(std::find(remaining.begin(), remaining.end(), best));
252 }
253 ord.push_back(remaining.front());
254 total += cube_sum(pcnt[remaining.front()]);
255 cost = total;
256 return ord;
257}
258
259/** Port of `censor_level_station`: the 0-based level station the options name. */
260template <class T>
262 const std::size_t M = sn.nstations;
263 if (!opt.censor_level.empty() && opt.censor_level_index.has_value())
264 throw InputError(ErrorKind{"Argument"},
265 "SolverMAM: options.config.censor_level must be a station name or "
266 "index, not both");
267 if (!opt.censor_level.empty()) {
268 for (std::size_t i = 0; i < M; ++i)
269 if (sn.stations[i].name == opt.censor_level) return i;
270 throw InputError(ErrorKind{"Argument"},
271 "SolverMAM: options.config.censor_level names no station: " +
272 opt.censor_level);
273 }
274 const double v = *opt.censor_level_index;
275 if (std::isfinite(v) && v >= 1.0 && v <= static_cast<double>(M) && v == std::round(v))
276 return static_cast<std::size_t>(v) - 1;
277 throw InputError(ErrorKind{"Argument"},
278 "SolverMAM: options.config.censor_level must be a station name or index");
279}
280
281/** Port of `mam_censor_solve`: the stationary vector over the rows of Q. */
282template <class T>
283std::vector<T> mam_censor_solve(const Matrix<T>& Q, const std::vector<qn::NetState<T>>& SS,
284 const Matrix<T>& SSa, const qn::NetworkStruct<T>& sn,
285 const MamOptions& opt, MamCensorInfo& info) {
286 const T zero = num_traits<T>::from_int(0);
287 const T one = num_traits<T>::from_int(1);
288 const std::size_t n = Q.rows();
289 info = MamCensorInfo();
290 info.nstates = n;
291
292 // SIZE: the level blocks are dense, and the permuted chain is densified
293 // below, so the method stops at options.config.censor_states_max states of
294 // the generated chain, the same bound in every codebase (mam_censor_solve).
295 const std::size_t states_max = opt.censor_states_max == 0 ? 10000 : opt.censor_states_max;
296 if (n > states_max)
297 throw UnsupportedError(ErrorKind{"StateSpace"},
298 "SolverMAM: the censor method solves chains of at most "
299 "options.config.censor_states_max = " + std::to_string(states_max) +
300 " states, and this one has " + std::to_string(n) +
301 ". Raise the cap, lower options.cutoff, or use SolverCTMC.");
302
303 // recurrent class
304 Matrix<T> A(n, n, zero);
305 for (std::size_t i = 0; i < n; ++i)
306 for (std::size_t j = 0; j < n; ++j)
307 if (i != j && num_traits<T>::to_double(Q(i, j)) > 0) A(i, j) = one;
308 const mc::SccResult scc = mc::stronglyconncomp(A);
309 std::size_t nrec = 0;
310 for (bool b : scc.recurrent)
311 if (b) ++nrec;
312 if (nrec != 1)
313 throw UnsupportedError(ErrorKind{"Structure"},
314 "SolverMAM: the censor method needs a chain with one recurrent class; this one has " +
315 std::to_string(nrec) +
316 ", so its stationary distribution depends on the initial state");
317 std::vector<std::size_t> keep;
318 for (std::size_t i = 0; i < n; ++i)
319 if (scc.recurrent[scc.scc[i] - 1]) keep.push_back(i);
320 const std::size_t nr = keep.size();
321 Matrix<T> Qr(nr, nr, zero);
322 for (std::size_t a = 0; a < nr; ++a)
323 for (std::size_t b = 0; b < nr; ++b) Qr(a, b) = Q(keep[a], keep[b]);
324
325 // job count of each station in each state; SSa holds per-class counts by
326 // station, column (ist-1)*K + k
327 const std::size_t K = sn.nclasses, M = sn.nstations;
328 std::vector<std::vector<double>> cnt(M, std::vector<double>(nr, 0.0));
329 for (std::size_t ist = 0; ist < M; ++ist)
330 for (std::size_t s = 0; s < nr; ++s) {
331 double c = 0.0;
332 for (std::size_t k = 0; k < K; ++k)
333 c += num_traits<T>::to_double(SSa(keep[s], ist * K + k));
334 cnt[ist][s] = c;
335 }
336
337 // candidate level stations (0-based)
338 std::vector<std::size_t> cand;
339 if (!opt.censor_level.empty() || opt.censor_level_index.has_value()) {
340 cand.push_back(censor_level_station(sn, opt));
341 } else {
342 std::vector<double> rng(M, 0.0);
343 for (std::size_t ist = 0; ist < M; ++ist)
344 if (nr > 0)
345 rng[ist] = *std::max_element(cnt[ist].begin(), cnt[ist].end()) -
346 *std::min_element(cnt[ist].begin(), cnt[ist].end());
347 // a Source holds Inf jobs in every state: no level, range 0. Inf-Inf is
348 // NaN, and a NaN breaks the strict weak order the sort below needs.
349 for (double &r : rng)
350 if (!std::isfinite(r)) r = 0.0;
351 std::vector<std::size_t> idx(M);
352 for (std::size_t i = 0; i < M; ++i) idx[i] = i;
353 std::stable_sort(idx.begin(), idx.end(),
354 [&rng](std::size_t a, std::size_t b) { return rng[a] > rng[b]; });
355 for (std::size_t i : idx)
356 if (rng[i] > 0) cand.push_back(i);
357 if (cand.empty()) cand.push_back(0);
358 }
359
360 Pattern P0(nr);
361 std::vector<std::pair<std::size_t, std::size_t>> edges;
362 for (std::size_t i = 0; i < nr; ++i)
363 for (std::size_t j = 0; j < nr; ++j)
364 if (i != j && !(Qr(i, j) == zero)) {
365 P0.add(i, j);
366 edges.emplace_back(i, j);
367 }
368
369 const std::size_t nstateful = sn.stateful_nodes.size();
370 struct Best {
371 double cost = std::numeric_limits<double>::infinity();
372 std::size_t L = 0, S = 0;
373 std::vector<std::size_t> keyNodes, setid, lvl, ord;
374 } best;
375 std::size_t ncand = 0;
376 for (std::size_t L : cand) {
377 const std::vector<double>& lev = cnt[L];
378 // a single set needs every transition to move the level by at most one
379 bool far = false;
380 for (const std::pair<std::size_t, std::size_t>& e : edges)
381 if (std::fabs(lev[e.first] - lev[e.second]) > 1.0) {
382 far = true;
383 break;
384 }
385 if (far) continue;
386 const std::size_t lsf = sn.stateful_of_station(L + 1);
387 std::vector<std::size_t> others;
388 for (std::size_t isf = 1; isf <= nstateful; ++isf)
389 if (isf != lsf) others.push_back(isf);
390 const std::size_t no = others.size();
391 for (std::size_t sz = 0; sz <= no; ++sz) {
392 // combinations of `others` of size sz in nchoosek (lexicographic) order
393 std::vector<std::size_t> c(sz);
394 for (std::size_t q = 0; q < sz; ++q) c[q] = q;
395 while (true) {
396 std::vector<std::size_t> keyNodes(sz);
397 for (std::size_t q = 0; q < sz; ++q) keyNodes[q] = others[c[q]];
398
399 std::vector<std::size_t> setid(nr, 0);
400 std::size_t S = 1;
401 if (!keyNodes.empty()) {
402 std::vector<std::vector<std::vector<double>>> rows(nr);
403 std::map<std::vector<std::vector<double>>, std::size_t> uniq;
404 for (std::size_t s = 0; s < nr; ++s) {
405 rows[s].reserve(sz);
406 for (std::size_t isf : keyNodes) {
407 const std::vector<T>& loc = SS[keep[s]].local[isf - 1];
408 std::vector<double> d(loc.size());
409 for (std::size_t t = 0; t < loc.size(); ++t)
410 d[t] = num_traits<T>::to_double(loc[t]);
411 rows[s].push_back(d);
412 }
413 uniq.emplace(rows[s], 0);
414 }
415 std::size_t rank = 0;
416 for (auto& kv : uniq) kv.second = rank++;
417 for (std::size_t s = 0; s < nr; ++s) setid[s] = uniq[rows[s]];
418 S = uniq.size();
419 }
420 if (!(S > kMaxSets || (S > 1 && S == nr))) {
421 std::vector<std::size_t> lvl(nr, 0);
422 std::vector<std::vector<std::size_t>> pcnt(S);
423 std::vector<std::vector<std::size_t>> members(S);
424 for (std::size_t s = 0; s < nr; ++s) members[setid[s]].push_back(s);
425 for (std::size_t q = 0; q < S; ++q) {
426 std::vector<double> u;
427 for (std::size_t s : members[q]) u.push_back(lev[s]);
428 std::sort(u.begin(), u.end());
429 u.erase(std::unique(u.begin(), u.end()), u.end());
430 pcnt[q].assign(u.size(), 0);
431 for (std::size_t s : members[q]) {
432 lvl[s] = static_cast<std::size_t>(
433 std::lower_bound(u.begin(), u.end(), lev[s]) - u.begin()) + 1;
434 ++pcnt[q][lvl[s] - 1];
435 }
436 }
437 double lb = 0.0;
438 for (const std::vector<std::size_t>& p : pcnt) lb += cube_sum(p);
439 if (lb < best.cost) {
440 double cost = 0.0;
441 const std::vector<std::size_t> ord =
442 censor_order(P0, setid, lvl, S, pcnt, cost);
443 ++ncand;
444 if (!ord.empty() && cost < best.cost) {
445 best.cost = cost;
446 best.L = L;
447 best.keyNodes = keyNodes;
448 best.setid = setid;
449 best.lvl = lvl;
450 best.S = S;
451 best.ord = ord;
452 }
453 }
454 }
455 // next combination
456 if (sz == 0) break;
457 std::size_t q = sz;
458 while (q > 0 && c[q - 1] == no - sz + (q - 1)) --q;
459 if (q == 0) break;
460 ++c[q - 1];
461 for (std::size_t t = q; t < sz; ++t) c[t] = c[t - 1] + 1;
462 }
463 }
464 }
465 if (!std::isfinite(best.cost))
466 throw UnsupportedError(ErrorKind{"Structure"},
467 "SolverMAM: the censor method found no level station whose job count changes by at "
468 "most one job per transition; the chain is not a system of connected LDQBDs in any "
469 "station's queue length");
470
471 // permute to (set, level, phase) and solve
472 const std::size_t S = best.S;
473 std::vector<std::size_t> perm;
474 perm.reserve(nr);
475 std::vector<std::vector<std::size_t>> phases(S);
476 for (std::size_t j = 0; j < S; ++j) {
477 std::vector<std::size_t> ix;
478 for (std::size_t s = 0; s < nr; ++s)
479 if (best.setid[s] == best.ord[j]) ix.push_back(s);
480 std::stable_sort(ix.begin(), ix.end(), [&best](std::size_t a, std::size_t b) {
481 return best.lvl[a] < best.lvl[b];
482 });
483 std::size_t lmax = 0;
484 for (std::size_t s : ix) lmax = std::max(lmax, best.lvl[s]);
485 phases[j].assign(lmax, 0);
486 for (std::size_t s : ix) {
487 ++phases[j][best.lvl[s] - 1];
488 perm.push_back(s);
489 }
490 }
491 Matrix<T> Qp(nr, nr, zero);
492 for (std::size_t a = 0; a < nr; ++a)
493 for (std::size_t b = 0; b < nr; ++b) Qp(a, b) = Qr(perm[a], perm[b]);
494 const LdqbdCensorResult<T> res = ldqbd_censor(Qp, phases);
495 std::vector<T> pi(n, zero);
496 for (std::size_t a = 0; a < nr; ++a) pi[keep[perm[a]]] = res.pi[a];
497
498 info.level_station = best.L + 1;
499 info.key_nodes = best.keyNodes;
500 info.nsets = S;
501 info.order.resize(S);
502 for (std::size_t j = 0; j < S; ++j) info.order[j] = best.ord[j] + 1;
503 info.phases = phases;
504 info.cost = best.cost;
505 info.ncandidates = ncand;
506 return pi;
507}
508
509} // namespace censor_detail
510
511/**
512 * Port of `solver_mam_censor.m`. `L` is the struct the MAM runner hands the
513 * dispatch (non-Markovian laws already converted with preserveDet false, the
514 * reference's default for this method).
515 */
516template <class T>
519 copt.method = "default";
520 copt.cutoff = opt.cutoff == 0 ? std::numeric_limits<double>::infinity()
521 : static_cast<double>(opt.cutoff);
522 copt.nonmkv = opt.nonmkv;
523 copt.nonmkv_order = opt.nonmkv_order;
525 MamCensorInfo& info = out.info;
526 const ctmc::CtmcStationaryHook<T> stat =
527 [&opt, &info](const Matrix<T>& Q, const std::vector<qn::NetState<T>>& SS,
528 const Matrix<T>& SSa, const qn::NetworkStruct<T>& snx) {
529 return censor_detail::mam_censor_solve(Q, SS, SSa, snx, opt, info);
530 };
531 const ctmc::CtmcSolution<T> d = ctmc::solver_ctmc_analyzer(L, copt, stat);
532 out.sol.Q = d.avg.QN;
533 out.sol.U = d.avg.UN;
534 out.sol.R = d.avg.RN;
535 out.sol.Tp = d.avg.TN;
536 out.sol.C = d.avg.CN;
537 out.sol.X = d.avg.XN;
538 out.sol.method = "censor";
539 out.sol.iter = 1;
540 return out;
541}
542
543} // namespace mam
544} // namespace line
545
546#endif // LINE_SOLVERS_MAM_SOLVER_MAM_CENSOR_H
InputError(const std::string &what)
Definition error.h:105
std::size_t rows() const
Definition matrix.h:89
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
The exception types the port throws.
Stationary distribution of a chain of connected LDQBDs by successive censoring.
The option and result types SolverMAM shares with its analyzers.
Dense matrix and non-owning view.
The option and result types every MVA analyzer shares.
CtmcSolution< T > solver_ctmc_analyzer(const NetworkStruct< T > &sn_in, const CtmcOptions &opt, const CtmcStationaryHook< T > &stationary=CtmcStationaryHook< T >())
Port of solver_ctmc_analyzer.m plus the fork-join wrapper of @@SolverCTMC/runAnalyzer....
std::function< std::vector< T >( const Matrix< T > &Q, const std::vector< NetState< T > > &space, const Matrix< T > &space_aggr, const NetworkStruct< T > &sn)> CtmcStationaryHook
A caller-supplied STATIONARY SOLVER, the optional third argument of solver_ctmc_analyzer....
std::size_t censor_level_station(const qn::NetworkStruct< T > &sn, const MamOptions &opt)
Port of censor_level_station: the 0-based level station the options name.
bool level_gap(const std::vector< std::size_t > &setid, const std::vector< std::size_t > &lvl, std::size_t a, std::size_t b)
std::vector< std::size_t > censor_order(Pattern P, const std::vector< std::size_t > &setid, const std::vector< std::size_t > &lvl, std::size_t S, const std::vector< std::vector< std::size_t > > &pcnt, double &cost)
Port of censor_order: the greedy structural elimination order of the S sets (0-based ids) and its est...
std::vector< std::pair< std::size_t, std::size_t > > censor_fill(const Pattern &P, const std::vector< std::size_t > &kix, std::size_t k, const std::vector< std::size_t > &setid, const std::vector< bool > &alive, std::size_t &ncols, std::size_t &nrows_into)
Port of censor_fill: the pattern of P_Bk * (paths inside k) * P_kB over the alive states outside set ...
static const std::size_t kMaxSets
The partition cap of mam_censor_solve (MAXSETS).
double cube_sum(const std::vector< std::size_t > &p)
std::vector< T > mam_censor_solve(const Matrix< T > &Q, const std::vector< qn::NetState< T > > &SS, const Matrix< T > &SSa, const qn::NetworkStruct< T > &sn, const MamOptions &opt, MamCensorInfo &info)
Port of mam_censor_solve: the stationary vector over the rows of Q.
MamCensorResult< T > solver_mam_censor(const qn::NetworkStruct< T > &L, const MamOptions &opt)
Port of solver_mam_censor.m.
LdqbdCensorResult< T > ldqbd_censor(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &phases, double tol=1e-10)
Stationary distribution of a chain of connected LDQBDs (ldqbd_censor.m).
SccResult stronglyconncomp(const Matrix< T > &A)
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Port of solver_ctmc_analyzer.m and the parts of @@SolverCTMC/runAnalyzer.m that surround one solve: t...
Port of the MATLAB +State package: the encoding that turns a station's state row into marginal job co...
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
The SolverCTMC knobs this port honours.
std::size_t nonmkv_order
options.config.nonmkvorder: the phase budget sn_nonmarkov_toph spends on a non-Markovian service law.
double cutoff
< 0 = not given
std::string nonmkv
options.config.nonmkv: 'bernstein' (default) runs sn_nonmarkov_toph, 'none' skips it; any other name ...
Everything one CTMC solve produces.
Stationary distribution of a chain of connected LDQBDs.
std::vector< T > pi
in the ordering of Q
What solver_mam_censor.m reports in INFO, all indices 1-based.
std::vector< std::size_t > key_nodes
stateful node indices of the set key
std::size_t ncandidates
candidate partitions ordered
double cost
estimated work
std::size_t nsets
number of sets
std::vector< std::size_t > order
the censoring order of the sets
std::size_t level_station
the level station
std::vector< std::vector< std::size_t > > phases
phases[j][l], set order[j]
std::size_t nstates
states of the chain handed in
The metrics of the 'censor' method and its INFO.
mva::MvaSolution< T > sol
The options SolverMAM reads.
Definition mam_types.h:30
Sparsity pattern with both adjacency directions, diagonal entries allowed.
std::vector< std::set< std::size_t > > in
void add(std::size_t i, std::size_t j)
bool has(std::size_t i, std::size_t j) const
std::vector< std::set< std::size_t > > out
void clear_node(std::size_t i)
P(i,:) = false and P(:,i) = false.
std::vector< bool > recurrent
recurrent[c-1] is true when component c has no edge leaving it.
std::vector< std::size_t > scc
Component index of each state, 1-based as in MATLAB (0 is never used).
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:97
One network state: the per-stateful-node local rows it is composed of.
Definition state.h:3022