LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
33
#include "
line/api/mc/dtmc_stochcomp.h
"
34
#include "
line/lang/qn/network_struct.h
"
35
#include "
line/num/number.h
"
36
37
namespace
line
{
38
namespace
api
{
39
40
/** What sn_rt_stations returns: the complemented routing and the station visits. */
41
template
<
class
T>
42
struct
SnRtStations
{
43
Matrix<T>
rtst
;
///< (nstations*nclasses) square, STATION-major rows
44
Matrix<T>
Vst
;
///< (nstations x nclasses), cellsum(sn.visits) by station
45
};
46
47
template
<
class
T>
48
SnRtStations<T>
sn_rt_stations
(
const
qn::NetworkStruct<T>
&
sn
) {
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();
51
SnRtStations<T>
out;
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
line::Matrix
Definition
matrix.h:56
line::Matrix::Matrix
Matrix()
Definition
matrix.h:58
line::qn::NetworkStruct
A network plus its refreshed NetworkStruct.
Definition
network_struct.h:838
dtmc_stochcomp.h
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
line::api
Definition
infer_fmlps.h:69
line::api::sn_rt_stations
SnRtStations< T > sn_rt_stations(const qn::NetworkStruct< T > &sn)
Definition
sn_rt_stations.h:48
line::mc::dtmc_stochcomp
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....
Definition
dtmc_stochcomp.h:49
line::sn
Definition
sn_gd_balance.h:42
line
Definition
aoi_dist2ph.h:52
network_struct.h
A queueing network and its refreshed NetworkStruct.
number.h
Number-type abstraction for the templated API port.
line::api::SnRtStations
What sn_rt_stations returns: the complemented routing and the station visits.
Definition
sn_rt_stations.h:42
line::api::SnRtStations::rtst
Matrix< T > rtst
(nstations*nclasses) square, STATION-major rows
Definition
sn_rt_stations.h:43
line::api::SnRtStations::Vst
Matrix< T > Vst
(nstations x nclasses), cellsum(sn.visits) by station
Definition
sn_rt_stations.h:44
line::num_traits
Definition
number.h:111
include
line
api
sn
sn_rt_stations.h
Generated by
1.18.0