LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
avg_table.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_AVG_TABLE_H
6#define LINE_SOLVERS_AVG_TABLE_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * @ingroup line_public
12 * The result tables a solver returns.
13 *
14 * `AvgTable` is what Python's `getAvgTable()` returns and what this port spells
15 * `avg_table()`: one row per (station, class) that carries a metric, plus the
16 * per-class system columns `getAvgSysTable()` reports. The columns are the
17 * reference's own -- QLen, Util, RespT, ResidT, ArvR, Tput -- and a
18 * (station, class) pair with no row is a zero, not a gap.
19 *
20 * THESE TYPES CARRY NO SOLVER MACHINERY ON PURPOSE. The solver templates are a
21 * heavy instantiation, so this header stays free of them and every example,
22 * test and CLI translation unit can name a result without paying for the stack
23 * that produced it; `line/solvers/solver.h` declares the solvers themselves and
24 * their bodies are compiled once into `line_mp_api`.
25 */
26
27#include <cstddef>
28#include <iosfwd>
29#include <string>
30#include <vector>
31
32namespace line {
33
34class JobClass;
35class Node;
36
37/** `getAvgTable`, one row per (station, class) that carries a metric. */
38struct AvgTable {
39 std::vector<std::string> Station, JobClass;
40 std::vector<double> QLen, Util, RespT, ResidT, ArvR, Tput;
41 /** `getAvgSysTable`: system response time and throughput, per class. */
42 std::vector<std::string> SysClass;
43 std::vector<double> SysRespT, SysTput;
44 std::string solver, method;
45 int iter = 0;
46 bool has_lognormconst = false;
47 double lognormconst = 0.0;
48 /** `getAvgCacheTable`'s ListCost column; empty on a model without item sizes. */
49 std::vector<double> ListCost;
50 /** The reference's own warning text, empty when it did not warn. */
51 std::string warning;
52 /**
53 * Confidence half-widths of the six metric columns, row for row; EMPTY unless
54 * `SolverOptions::confint` asked for them and the engine reports them (JMT, LDES).
55 */
56 std::vector<double> QLenCI, UtilCI, RespTCI, ResidTCI, ArvRCI, TputCI;
57 /** Whether the half-width columns are filled. */
58 bool has_ci() const { return !QLenCI.empty(); }
59
60 /** One cell of the table, by station and class NAME; NaN when absent. */
61 double get(const std::string& column, const std::string& station,
62 const std::string& jobclass) const;
63 /** A complete metric column. */
64 std::vector<double> column(const std::string& column) const;
65
66 /** Rows whose station or class has `name`, MATLAB's one-argument `filterBy`. */
67 AvgTable filter_by(const std::string& name) const;
68 /** Rows at one station for one class, MATLAB's two-argument `filterBy`. */
69 AvgTable filter_by(const std::string& station, const std::string& jobclass) const;
70 AvgTable filter_by(const Node& node) const;
71 AvgTable filter_by(const ::line::JobClass& jobclass) const;
72 AvgTable filter_by(const Node& node, const ::line::JobClass& jobclass) const;
73 AvgTable filter_by(const ::line::JobClass& jobclass, const Node& node) const;
74
75 /** MATLAB-compatible filtering aliases, preserving C++ snake-case naming. */
76 AvgTable get(const Node& node) const;
77 AvgTable get(const ::line::JobClass& jobclass) const;
78 AvgTable get(const Node& node, const ::line::JobClass& jobclass) const;
79 AvgTable get(const ::line::JobClass& jobclass, const Node& node) const;
80 AvgTable tget(const Node& node) const;
81 AvgTable tget(const ::line::JobClass& jobclass) const;
82 AvgTable tget(const Node& node, const ::line::JobClass& jobclass) const;
83 AvgTable tget(const ::line::JobClass& jobclass, const Node& node) const;
84
85 /** Direct object indexing: `table(queue, jobs)`. */
86 AvgTable operator()(const Node& node) const;
87 AvgTable operator()(const ::line::JobClass& jobclass) const;
88 AvgTable operator()(const Node& node, const ::line::JobClass& jobclass) const;
89 AvgTable operator()(const ::line::JobClass& jobclass, const Node& node) const;
90
91 /** Print the labelled station-class table. */
92 void print(std::ostream& out) const;
93 void print() const;
94 /** The number of rows the table carries. */
95 std::size_t size() const { return Station.size(); }
96 bool empty() const { return Station.empty(); }
97};
98
99std::ostream& operator<<(std::ostream& out, const AvgTable& table);
100
101/**
102 * `getAvgQLenTable()`, `getAvgUtilTable()`, `getAvgRespTTable()`, `getAvgTputTable()`: the Station and
103 * JobClass columns of `getAvgTable` with ONE metric column, row for row, as `getAvgMetricTable.m` builds them.
104 */
106 std::vector<std::string> Station, JobClass;
107 /** The metric's values, aligned with the rows; `metric` names the column (QLen, Util, RespT, Tput). */
108 std::vector<double> Value;
109 std::string metric;
110 std::size_t size() const { return Station.size(); }
111 bool empty() const { return Station.empty(); }
112};
113
114/** The one-metric view of `table`, keeping every row of it. */
115inline AvgMetricTable avg_metric_view(const AvgTable& table, const std::string& metric) {
117 v.Station = table.Station;
118 v.JobClass = table.JobClass;
119 v.Value = table.column(metric);
120 v.metric = metric;
121 return v;
122}
123
124/**
125 * `getAvgSysTable()`: one row per CHAIN, the cycle time and the completing throughput at
126 * the chain's reference station, as `@NetworkSolver/getAvgSysTable.m` reports them.
127 */
129 std::vector<std::string> Chain, JobClasses;
130 std::vector<double> SysRespT, SysTput;
131 /** Print the chain table. */
132 void print(std::ostream& out) const;
133 void print() const;
134 std::size_t size() const { return Chain.size(); }
135 bool empty() const { return Chain.empty(); }
136};
137
138std::ostream& operator<<(std::ostream& out, const AvgSysTable& table);
139
140/**
141 * `getAvgChainTable`: the station table aggregated by CHAIN, one row per (station, chain),
142 * row-major over (station, chain) and with no row filter, as `@NetworkSolver/getAvgChainTable.m`.
143 */
145 std::vector<std::string> Station, Chain, JobClasses;
146 std::vector<double> QLen, Util, RespT, ResidT, ArvR, Tput;
147 /** Print the station-chain table. */
148 void print(std::ostream& out) const;
149 void print() const;
150 std::size_t size() const { return Station.size(); }
151 bool empty() const { return Station.empty(); }
152};
153
154std::ostream& operator<<(std::ostream& out, const AvgChainTable& table);
155
156/**
157 * `getAvgFJTable()`: one row per (Fork/Join pair, class) with a nonzero metric, the fork-join SECTION
158 * metrics of `fjFixedPoint.m` (MVA, NC, Fluid), JMT and LDES. FJRespT is the time from the Fork to the
159 * matching Join, FJTput the throughput through the pair, FJQLen the jobs inside it. Empty on a model
160 * without a Fork/Join pair and for a solver that does not compute them.
161 */
163 std::vector<std::string> Fork, Join, JobClass;
164 std::vector<double> FJQLen, FJRespT, FJTput;
165 /** Print the labelled pair-class table. */
166 void print(std::ostream& out) const;
167 void print() const;
168 std::size_t size() const { return Fork.size(); }
169 bool empty() const { return Fork.empty(); }
170};
171
172std::ostream& operator<<(std::ostream& out, const AvgFJTable& table);
173
174/** `SolverBA(model, method).getBoundsTable()`. */
176 std::vector<std::string> Station, JobClass;
177 std::vector<double> Qlower, Qupper, Tlower, Tupper;
178 std::string method;
179};
180
181/** One response-time CDF curve: `F` the CDF value, `t` the time it is reached. */
182struct CdfCurve {
183 std::vector<double> F, t;
184};
185
186/**
187 * `getSymbolicSolution`: the stationary law as a function of the rate symbols.
188 *
189 * The entries are expression strings, not numbers, and are NOT comparable with
190 * another codebase's by text: the symbol numbering x1..xE follows event
191 * enumeration order and the printed normal form depends on the engine version.
192 * Substitute rates and compare numbers instead.
193 */
195 std::vector<std::string> pi; ///< stationary probability of each state
196 std::vector<std::string> num; ///< numerator of each entry over `den`
197 std::string den = "1"; ///< common denominator of the vector
198 std::vector<std::string> symbols; ///< x1..xE, empty where an event has no positive rate
199 std::vector<double> rate0; ///< nominal value of each symbol
200 std::string engine; ///< backend that answered, e.g. "sage"
201};
202
203/** `getTranAvg`: the transient mean queue length per (station, class). */
204struct TranAvg {
205 std::vector<double> t; ///< the time axis
206 std::vector<std::vector<double> > QNt; ///< [step][station*class]
207 std::vector<std::string> label; ///< the (station, class) of each column
208};
209
210/**
211 * `sampleSysAggr` / `sampleAggr`: ONE simulated trajectory, not a mean.
212 *
213 * It has the shape of a `TranAvg` and is deliberately a type of its own,
214 * because the two must never be read for each other: `TranAvg` is E[N](t)
215 * estimated over independent runs, this is a single sample path, and averaging
216 * a column of `state` over `t` is a time average rather than an ensemble one.
217 */
219 std::vector<double> t; ///< event times, ascending
220 std::vector<std::vector<double> > state; ///< [step][column]
221 std::vector<std::string> label; ///< what each column counts
222};
223
224} // namespace line
225
226#endif // LINE_SOLVERS_AVG_TABLE_H
A job class: the index it was given, and the model that owns it.
Definition nodes.h:385
A node of the model: the index it was given, and the model that owns it.
Definition nodes.h:59
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
std::ostream & operator<<(std::ostream &out, const AvgTable &table)
AvgMetricTable avg_metric_view(const AvgTable &table, const std::string &metric)
The one-metric view of table, keeping every row of it.
Definition avg_table.h:115
getAvgChainTable: the station table aggregated by CHAIN, one row per (station, chain),...
Definition avg_table.h:144
std::vector< double > QLen
Definition avg_table.h:146
std::vector< double > ArvR
Definition avg_table.h:146
std::vector< double > RespT
Definition avg_table.h:146
bool empty() const
Definition avg_table.h:151
std::vector< double > Util
Definition avg_table.h:146
std::vector< double > ResidT
Definition avg_table.h:146
std::size_t size() const
Definition avg_table.h:150
void print(std::ostream &out) const
Print the station-chain table.
std::vector< std::string > Chain
Definition avg_table.h:145
std::vector< std::string > JobClasses
Definition avg_table.h:145
std::vector< std::string > Station
Definition avg_table.h:145
std::vector< double > Tput
Definition avg_table.h:146
getAvgFJTable(): one row per (Fork/Join pair, class) with a nonzero metric, the fork-join SECTION met...
Definition avg_table.h:162
std::vector< std::string > Fork
Definition avg_table.h:163
std::size_t size() const
Definition avg_table.h:168
void print(std::ostream &out) const
Print the labelled pair-class table.
std::vector< double > FJTput
Definition avg_table.h:164
std::vector< std::string > JobClass
Definition avg_table.h:163
std::vector< double > FJRespT
Definition avg_table.h:164
std::vector< double > FJQLen
Definition avg_table.h:164
std::vector< std::string > Join
Definition avg_table.h:163
bool empty() const
Definition avg_table.h:169
getAvgQLenTable(), getAvgUtilTable(), getAvgRespTTable(), getAvgTputTable(): the Station and JobClass...
Definition avg_table.h:105
std::size_t size() const
Definition avg_table.h:110
std::vector< double > Value
The metric's values, aligned with the rows; metric names the column (QLen, Util, RespT,...
Definition avg_table.h:108
std::vector< std::string > JobClass
Definition avg_table.h:106
std::string metric
Definition avg_table.h:109
std::vector< std::string > Station
Definition avg_table.h:106
bool empty() const
Definition avg_table.h:111
getAvgSysTable(): one row per CHAIN, the cycle time and the completing throughput at the chain's refe...
Definition avg_table.h:128
std::vector< double > SysRespT
Definition avg_table.h:130
bool empty() const
Definition avg_table.h:135
std::size_t size() const
Definition avg_table.h:134
void print(std::ostream &out) const
Print the chain table.
std::vector< std::string > JobClasses
Definition avg_table.h:129
std::vector< double > SysTput
Definition avg_table.h:130
std::vector< std::string > Chain
Definition avg_table.h:129
getAvgTable, one row per (station, class) that carries a metric.
Definition avg_table.h:38
std::vector< double > ArvR
Definition avg_table.h:40
std::vector< double > TputCI
Definition avg_table.h:56
std::vector< double > UtilCI
Definition avg_table.h:56
std::vector< double > Tput
Definition avg_table.h:40
std::vector< double > ResidT
Definition avg_table.h:40
std::vector< double > RespT
Definition avg_table.h:40
std::size_t size() const
The number of rows the table carries.
Definition avg_table.h:95
double lognormconst
Definition avg_table.h:47
std::vector< double > Util
Definition avg_table.h:40
void print() const
std::vector< std::string > Station
Definition avg_table.h:39
std::vector< double > column(const std::string &column) const
A complete metric column.
std::vector< double > SysTput
Definition avg_table.h:43
bool has_ci() const
Whether the half-width columns are filled.
Definition avg_table.h:58
std::vector< double > ResidTCI
Definition avg_table.h:56
bool empty() const
Definition avg_table.h:96
std::vector< std::string > JobClass
Definition avg_table.h:39
std::string warning
The reference's own warning text, empty when it did not warn.
Definition avg_table.h:51
double get(const std::string &column, const std::string &station, const std::string &jobclass) const
One cell of the table, by station and class NAME; NaN when absent.
std::string solver
Definition avg_table.h:44
std::vector< double > QLenCI
Confidence half-widths of the six metric columns, row for row; EMPTY unless SolverOptions::confint as...
Definition avg_table.h:56
AvgTable tget(const Node &node) const
AvgTable filter_by(const std::string &name) const
Rows whose station or class has name, MATLAB's one-argument filterBy.
std::vector< double > RespTCI
Definition avg_table.h:56
std::string method
Definition avg_table.h:44
std::vector< double > ArvRCI
Definition avg_table.h:56
AvgTable operator()(const Node &node) const
Direct object indexing: table(queue, jobs).
bool has_lognormconst
Definition avg_table.h:46
std::vector< double > ListCost
getAvgCacheTable's ListCost column; empty on a model without item sizes.
Definition avg_table.h:49
std::vector< double > SysRespT
Definition avg_table.h:43
std::vector< std::string > SysClass
getAvgSysTable: system response time and throughput, per class.
Definition avg_table.h:42
std::vector< double > QLen
Definition avg_table.h:40
SolverBA(model, method).getBoundsTable().
Definition avg_table.h:175
std::vector< double > Tlower
Definition avg_table.h:177
std::string method
Definition avg_table.h:178
std::vector< double > Qupper
Definition avg_table.h:177
std::vector< std::string > Station
Definition avg_table.h:176
std::vector< double > Qlower
Definition avg_table.h:177
std::vector< std::string > JobClass
Definition avg_table.h:176
std::vector< double > Tupper
Definition avg_table.h:177
One response-time CDF curve: F the CDF value, t the time it is reached.
Definition avg_table.h:182
std::vector< double > F
Definition avg_table.h:183
std::vector< double > t
Definition avg_table.h:183
sampleSysAggr / sampleAggr: ONE simulated trajectory, not a mean.
Definition avg_table.h:218
std::vector< std::vector< double > > state
[step][column]
Definition avg_table.h:220
std::vector< std::string > label
what each column counts
Definition avg_table.h:221
std::vector< double > t
event times, ascending
Definition avg_table.h:219
getSymbolicSolution: the stationary law as a function of the rate symbols.
Definition avg_table.h:194
std::vector< double > rate0
nominal value of each symbol
Definition avg_table.h:199
std::string den
common denominator of the vector
Definition avg_table.h:197
std::vector< std::string > pi
stationary probability of each state
Definition avg_table.h:195
std::vector< std::string > symbols
x1..xE, empty where an event has no positive rate
Definition avg_table.h:198
std::string engine
backend that answered, e.g. "sage"
Definition avg_table.h:200
std::vector< std::string > num
numerator of each entry over den
Definition avg_table.h:196
getTranAvg: the transient mean queue length per (station, class).
Definition avg_table.h:204
std::vector< std::string > label
the (station, class) of each column
Definition avg_table.h:207
std::vector< std::vector< double > > QNt
[step][station*class]
Definition avg_table.h:206
std::vector< double > t
the time axis
Definition avg_table.h:205