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 * Whether the solve stopped early on `SolverOptions::timeout`, read from the
54 * budget's TRIPPED latch (line/util/line_timeout.h); the metrics are then the
55 * interim solution. Reset by every solve.
56 */
57 bool timed_out = false;
58 /**
59 * Confidence half-widths of the six metric columns, row for row; EMPTY unless
60 * `SolverOptions::confint` asked for them and the engine reports them (JMT, LDES).
61 */
62 std::vector<double> QLenCI, UtilCI, RespTCI, ResidTCI, ArvRCI, TputCI;
63 /** Whether the half-width columns are filled. */
64 bool has_ci() const { return !QLenCI.empty(); }
65
66 /** One cell of the table, by station and class NAME; NaN when absent. */
67 double get(const std::string& column, const std::string& station,
68 const std::string& jobclass) const;
69 /** A complete metric column. */
70 std::vector<double> column(const std::string& column) const;
71
72 /** Rows whose station or class has `name`, MATLAB's one-argument `filterBy`. */
73 AvgTable filter_by(const std::string& name) const;
74 /** Rows at one station for one class, MATLAB's two-argument `filterBy`. */
75 AvgTable filter_by(const std::string& station, const std::string& jobclass) const;
76 AvgTable filter_by(const Node& node) const;
77 AvgTable filter_by(const ::line::JobClass& jobclass) const;
78 AvgTable filter_by(const Node& node, const ::line::JobClass& jobclass) const;
79 AvgTable filter_by(const ::line::JobClass& jobclass, const Node& node) const;
80
81 /** MATLAB-compatible filtering aliases, preserving C++ snake-case naming. */
82 AvgTable get(const Node& node) const;
83 AvgTable get(const ::line::JobClass& jobclass) const;
84 AvgTable get(const Node& node, const ::line::JobClass& jobclass) const;
85 AvgTable get(const ::line::JobClass& jobclass, const Node& node) const;
86 AvgTable tget(const Node& node) const;
87 AvgTable tget(const ::line::JobClass& jobclass) const;
88 AvgTable tget(const Node& node, const ::line::JobClass& jobclass) const;
89 AvgTable tget(const ::line::JobClass& jobclass, const Node& node) const;
90
91 /** Direct object indexing: `table(queue, jobs)`. */
92 AvgTable operator()(const Node& node) const;
93 AvgTable operator()(const ::line::JobClass& jobclass) const;
94 AvgTable operator()(const Node& node, const ::line::JobClass& jobclass) const;
95 AvgTable operator()(const ::line::JobClass& jobclass, const Node& node) const;
96
97 /** Print the labelled station-class table. */
98 void print(std::ostream& out) const;
99 void print() const;
100 /** The number of rows the table carries. */
101 std::size_t size() const { return Station.size(); }
102 bool empty() const { return Station.empty(); }
103};
104
105std::ostream& operator<<(std::ostream& out, const AvgTable& table);
106
107/**
108 * `getAvgQLenTable()`, `getAvgUtilTable()`, `getAvgRespTTable()`, `getAvgTputTable()`: the Station and
109 * JobClass columns of `getAvgTable` with ONE metric column, row for row, as `getAvgMetricTable.m` builds them.
110 */
112 std::vector<std::string> Station, JobClass;
113 /** The metric's values, aligned with the rows; `metric` names the column (QLen, Util, RespT, Tput). */
114 std::vector<double> Value;
115 std::string metric;
116 std::size_t size() const { return Station.size(); }
117 bool empty() const { return Station.empty(); }
118};
119
120/** The one-metric view of `table`, keeping every row of it. */
121inline AvgMetricTable avg_metric_view(const AvgTable& table, const std::string& metric) {
123 v.Station = table.Station;
124 v.JobClass = table.JobClass;
125 v.Value = table.column(metric);
126 v.metric = metric;
127 return v;
128}
129
130/**
131 * `getAvgSysTable()`: one row per CHAIN, the cycle time and the completing throughput at
132 * the chain's reference station, as `@NetworkSolver/getAvgSysTable.m` reports them.
133 */
135 std::vector<std::string> Chain, JobClasses;
136 std::vector<double> SysRespT, SysTput;
137 /** Print the chain table. */
138 void print(std::ostream& out) const;
139 void print() const;
140 std::size_t size() const { return Chain.size(); }
141 bool empty() const { return Chain.empty(); }
142};
143
144std::ostream& operator<<(std::ostream& out, const AvgSysTable& table);
145
146/**
147 * `getAvgChainTable`: the station table aggregated by CHAIN, one row per (station, chain),
148 * row-major over (station, chain) and with no row filter, as `@NetworkSolver/getAvgChainTable.m`.
149 */
151 std::vector<std::string> Station, Chain, JobClasses;
152 std::vector<double> QLen, Util, RespT, ResidT, ArvR, Tput;
153 /** Print the station-chain table. */
154 void print(std::ostream& out) const;
155 void print() const;
156 std::size_t size() const { return Station.size(); }
157 bool empty() const { return Station.empty(); }
158};
159
160std::ostream& operator<<(std::ostream& out, const AvgChainTable& table);
161
162/**
163 * `getAvgFJTable()`: one row per (Fork/Join pair, class) with a nonzero metric, the fork-join SECTION
164 * metrics of `fjFixedPoint.m` (MVA, NC, Fluid), JMT and LDES. FJRespT is the time from the Fork to the
165 * matching Join, FJTput the throughput through the pair, FJQLen the jobs inside it. Empty on a model
166 * without a Fork/Join pair and for a solver that does not compute them.
167 */
169 std::vector<std::string> Fork, Join, JobClass;
170 std::vector<double> FJQLen, FJRespT, FJTput;
171 /** Print the labelled pair-class table. */
172 void print(std::ostream& out) const;
173 void print() const;
174 std::size_t size() const { return Fork.size(); }
175 bool empty() const { return Fork.empty(); }
176};
177
178std::ostream& operator<<(std::ostream& out, const AvgFJTable& table);
179
180/**
181 * `SolverNC.getAvgLinkTable()`: the per-link measures of a loss network (an open model whose single
182 * Delay sits in one DROP finite capacity region), one row per link j and class r with A(j,r) > 0.
183 * Each row of the admission rule A n <= C is a link (GlobalMaxJobs, GlobalMaxMemory,
184 * ClassMaxJobs:<class>, Constraint<k>). Capacity is C_j, Demand A(j,r), Occupancy the mean busy
185 * units of link j over all classes, LinkBlocking the probability that link j alone lacks room for a
186 * class-r job, RouteLoss the probability that the region drops a class-r job. Computed by
187 * `lossn_links` with the method of the last run. Empty on any other model.
188 */
190 std::vector<std::string> Link, JobClass;
192 /** Print the labelled link-class table. */
193 void print(std::ostream& out) const;
194 void print() const;
195 std::size_t size() const { return Link.size(); }
196 bool empty() const { return Link.empty(); }
197};
198
199std::ostream& operator<<(std::ostream& out, const AvgLinkTable& table);
200
201/** `SolverBA(model, method).getBoundsTable()`. */
203 std::vector<std::string> Station, JobClass;
204 std::vector<double> Qlower, Qupper, Tlower, Tupper;
205 std::string method;
206};
207
208/** One response-time CDF curve: `F` the CDF value, `t` the time it is reached. */
209struct CdfCurve {
210 std::vector<double> F, t;
211};
212
213/**
214 * `getSymbolicSolution`: the stationary law as a function of the rate symbols.
215 *
216 * The entries are expression strings, not numbers, and are NOT comparable with
217 * another codebase's by text: the symbol numbering x1..xE follows event
218 * enumeration order and the printed normal form depends on the engine version.
219 * Substitute rates and compare numbers instead.
220 */
222 std::vector<std::string> pi; ///< stationary probability of each state
223 std::vector<std::string> num; ///< numerator of each entry over `den`
224 std::string den = "1"; ///< common denominator of the vector
225 std::vector<std::string> symbols; ///< x1..xE, empty where an event has no positive rate
226 std::vector<double> rate0; ///< nominal value of each symbol
227 std::string engine; ///< backend that answered, e.g. "sage"
228};
229
230/** `getTranAvg`: the transient mean queue length per (station, class). */
231struct TranAvg {
232 std::vector<double> t; ///< the time axis
233 std::vector<std::vector<double> > QNt; ///< [step][station*class]
234 std::vector<std::string> label; ///< the (station, class) of each column
235};
236
237/**
238 * `sampleSysAggr` / `sampleAggr`: ONE simulated trajectory, not a mean.
239 *
240 * It has the shape of a `TranAvg` and is deliberately a type of its own,
241 * because the two must never be read for each other: `TranAvg` is E[N](t)
242 * estimated over independent runs, this is a single sample path, and averaging
243 * a column of `state` over `t` is a time average rather than an ensemble one.
244 */
246 std::vector<double> t; ///< event times, ascending
247 std::vector<std::vector<double> > state; ///< [step][column]
248 std::vector<std::string> label; ///< what each column counts
249 /**
250 * The events of the path, one row each, [time, node, type, class, jobId,
251 * phase]: node and class 1-based, type an `EventType` value (ARV 1, DEP 2,
252 * PHASE 3, START 15, PREEMPT 16, DROP 17), jobId -1 when untracked, phase
253 * 1-based with 0 = none. Several events can share one step, so this is not
254 * one row per step. Filled by SolverLDES; empty from SolverJMT, whose log
255 * carries no events.
256 */
257 std::vector<std::vector<double> > event;
258 /** The 1-based node each column of `state` belongs to (SolverLDES only). */
259 std::vector<std::size_t> column_node;
260 /** Per-class counts (true) or LINE State rows (false, SolverLDES `sample`/`sample_sys`). */
261 bool aggregate = true;
262};
263
264} // namespace line
265
266#endif // LINE_SOLVERS_AVG_TABLE_H
A job class: the index it was given, and the model that owns it.
Definition nodes.h:404
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:51
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:121
getAvgChainTable: the station table aggregated by CHAIN, one row per (station, chain),...
Definition avg_table.h:150
std::vector< double > QLen
Definition avg_table.h:152
std::vector< double > ArvR
Definition avg_table.h:152
std::vector< double > RespT
Definition avg_table.h:152
bool empty() const
Definition avg_table.h:157
std::vector< double > Util
Definition avg_table.h:152
std::vector< double > ResidT
Definition avg_table.h:152
std::size_t size() const
Definition avg_table.h:156
void print(std::ostream &out) const
Print the station-chain table.
std::vector< std::string > Chain
Definition avg_table.h:151
std::vector< std::string > JobClasses
Definition avg_table.h:151
std::vector< std::string > Station
Definition avg_table.h:151
std::vector< double > Tput
Definition avg_table.h:152
getAvgFJTable(): one row per (Fork/Join pair, class) with a nonzero metric, the fork-join SECTION met...
Definition avg_table.h:168
std::vector< std::string > Fork
Definition avg_table.h:169
std::size_t size() const
Definition avg_table.h:174
void print(std::ostream &out) const
Print the labelled pair-class table.
std::vector< double > FJTput
Definition avg_table.h:170
std::vector< std::string > JobClass
Definition avg_table.h:169
std::vector< double > FJRespT
Definition avg_table.h:170
std::vector< double > FJQLen
Definition avg_table.h:170
std::vector< std::string > Join
Definition avg_table.h:169
bool empty() const
Definition avg_table.h:175
SolverNC.getAvgLinkTable(): the per-link measures of a loss network (an open model whose single Delay...
Definition avg_table.h:189
std::vector< double > LinkBlocking
Definition avg_table.h:191
std::vector< double > Capacity
Definition avg_table.h:191
void print(std::ostream &out) const
Print the labelled link-class table.
std::vector< double > Occupancy
Definition avg_table.h:191
std::size_t size() const
Definition avg_table.h:195
std::vector< std::string > JobClass
Definition avg_table.h:190
bool empty() const
Definition avg_table.h:196
std::vector< std::string > Link
Definition avg_table.h:190
std::vector< double > Demand
Definition avg_table.h:191
std::vector< double > RouteLoss
Definition avg_table.h:191
getAvgQLenTable(), getAvgUtilTable(), getAvgRespTTable(), getAvgTputTable(): the Station and JobClass...
Definition avg_table.h:111
std::size_t size() const
Definition avg_table.h:116
std::vector< double > Value
The metric's values, aligned with the rows; metric names the column (QLen, Util, RespT,...
Definition avg_table.h:114
std::vector< std::string > JobClass
Definition avg_table.h:112
std::string metric
Definition avg_table.h:115
std::vector< std::string > Station
Definition avg_table.h:112
bool empty() const
Definition avg_table.h:117
getAvgSysTable(): one row per CHAIN, the cycle time and the completing throughput at the chain's refe...
Definition avg_table.h:134
std::vector< double > SysRespT
Definition avg_table.h:136
bool empty() const
Definition avg_table.h:141
std::size_t size() const
Definition avg_table.h:140
void print(std::ostream &out) const
Print the chain table.
std::vector< std::string > JobClasses
Definition avg_table.h:135
std::vector< double > SysTput
Definition avg_table.h:136
std::vector< std::string > Chain
Definition avg_table.h:135
getAvgTable, one row per (station, class) that carries a metric.
Definition avg_table.h:38
std::vector< double > ArvR
Definition avg_table.h:40
bool timed_out
Whether the solve stopped early on SolverOptions::timeout, read from the budget's TRIPPED latch (line...
Definition avg_table.h:57
std::vector< double > TputCI
Definition avg_table.h:62
std::vector< double > UtilCI
Definition avg_table.h:62
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:101
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:64
std::vector< double > ResidTCI
Definition avg_table.h:62
bool empty() const
Definition avg_table.h:102
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:62
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:62
std::string method
Definition avg_table.h:44
std::vector< double > ArvRCI
Definition avg_table.h:62
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:202
std::vector< double > Tlower
Definition avg_table.h:204
std::string method
Definition avg_table.h:205
std::vector< double > Qupper
Definition avg_table.h:204
std::vector< std::string > Station
Definition avg_table.h:203
std::vector< double > Qlower
Definition avg_table.h:204
std::vector< std::string > JobClass
Definition avg_table.h:203
std::vector< double > Tupper
Definition avg_table.h:204
One response-time CDF curve: F the CDF value, t the time it is reached.
Definition avg_table.h:209
std::vector< double > F
Definition avg_table.h:210
std::vector< double > t
Definition avg_table.h:210
sampleSysAggr / sampleAggr: ONE simulated trajectory, not a mean.
Definition avg_table.h:245
std::vector< std::vector< double > > state
[step][column]
Definition avg_table.h:247
std::vector< std::string > label
what each column counts
Definition avg_table.h:248
std::vector< double > t
event times, ascending
Definition avg_table.h:246
bool aggregate
Per-class counts (true) or LINE State rows (false, SolverLDES sample/sample_sys).
Definition avg_table.h:261
std::vector< std::size_t > column_node
The 1-based node each column of state belongs to (SolverLDES only).
Definition avg_table.h:259
std::vector< std::vector< double > > event
The events of the path, one row each, [time, node, type, class, jobId, phase]: node and class 1-based...
Definition avg_table.h:257
getSymbolicSolution: the stationary law as a function of the rate symbols.
Definition avg_table.h:221
std::vector< double > rate0
nominal value of each symbol
Definition avg_table.h:226
std::string den
common denominator of the vector
Definition avg_table.h:224
std::vector< std::string > pi
stationary probability of each state
Definition avg_table.h:222
std::vector< std::string > symbols
x1..xE, empty where an event has no positive rate
Definition avg_table.h:225
std::string engine
backend that answered, e.g. "sage"
Definition avg_table.h:227
std::vector< std::string > num
numerator of each entry over den
Definition avg_table.h:223
getTranAvg: the transient mean queue length per (station, class).
Definition avg_table.h:231
std::vector< std::string > label
the (station, class) of each column
Definition avg_table.h:234
std::vector< std::vector< double > > QNt
[step][station*class]
Definition avg_table.h:233
std::vector< double > t
the time axis
Definition avg_table.h:232