LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sn_rt_stations.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_API_SN_SN_RT_STATIONS_H
6#define LINE_API_SN_SN_RT_STATIONS_H
7
8/**
9 * @file
10 * @ingroup api_sn
11 * Port of matlab/src/api/sn/sn_rt_stations.m.
12 *
13 * `sn.rt` is over STATEFUL nodes, and a Router or a Cache is stateful without
14 * being a station. Callers that need a station-to-station routing matrix must
15 * therefore eliminate the non-station stateful rows, not index around them:
16 * the reference forms the stochastic complement
17 *
18 * rtst = P(A,A) + P(A,B) (I - P(B,B))^-1 P(B,A),
19 *
20 * with A the (station, class) rows in STATION order and B the rest. That is
21 * exactly `dtmc_stochcomp(rt, A)`, which is what this port calls; the explicit
22 * block form is only how the reference spells it.
23 *
24 * `Vst` is `cellsum(sn.visits)` restricted to the same station rows, in the
25 * same order, so the two outputs are index-compatible.
26 *
27 * ARITHMETIC: field. dtmc_stochcomp is a linear solve.
28 */
29
30#include <cstddef>
31#include <vector>
32
35#include "line/num/number.h"
36
37namespace line {
38namespace api {
39
40/** What sn_rt_stations returns: the complemented routing and the station visits. */
41template <class T>
43 Matrix<T> rtst; ///< (nstations*nclasses) square, STATION-major rows
44 Matrix<T> Vst; ///< (nstations x nclasses), cellsum(sn.visits) by station
45};
46
47template <class T>
49 const T zero = num_traits<T>::from_int(0);
50 const std::size_t K = sn.nclasses, M = sn.nstations, S = sn.nof_stateful();
52 std::vector<std::size_t> keep;
53 keep.reserve(M * K);
54 for (std::size_t ist = 0; ist < M; ++ist) {
55 const std::size_t isf = sn.stateful_of_station(ist + 1) - 1;
56 for (std::size_t r = 0; r < K; ++r) keep.push_back(isf * K + r);
57 }
58 if (sn.rt.rows() == S * K) {
59 out.rtst = mc::dtmc_stochcomp(sn.rt, keep);
60 } else {
61 out.rtst = Matrix<T>(M * K, M * K, zero);
62 }
63 out.Vst = Matrix<T>(M, K, zero);
64 for (std::size_t ist = 0; ist < M; ++ist) {
65 const std::size_t isf = sn.stateful_of_station(ist + 1) - 1;
66 for (std::size_t c = 0; c < sn.visits.size(); ++c)
67 for (std::size_t r = 0; r < K; ++r)
68 out.Vst(ist, r) = T(out.Vst(ist, r) + sn.visits[c](isf, r));
69 }
70 return out;
71}
72
73} // namespace api
74} // namespace line
75
76#endif // LINE_API_SN_SN_RT_STATIONS_H
A network plus its refreshed NetworkStruct.
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
SnRtStations< T > sn_rt_stations(const qn::NetworkStruct< T > &sn)
Matrix< T > dtmc_stochcomp(const Matrix< T > &P, const std::vector< std::size_t > &keep)
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
What sn_rt_stations returns: the complemented routing and the station visits.
Matrix< T > rtst
(nstations*nclasses) square, STATION-major rows
Matrix< T > Vst
(nstations x nclasses), cellsum(sn.visits) by station