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 /** One cell of the table, by station and class NAME; NaN when absent. */
54 double get(const std::string& column, const std::string& station,
55 const std::string& jobclass) const;
56 /** A complete metric column. */
57 std::vector<double> column(const std::string& column) const;
58
59 /** Rows whose station or class has `name`, MATLAB's one-argument `filterBy`. */
60 AvgTable filter_by(const std::string& name) const;
61 /** Rows at one station for one class, MATLAB's two-argument `filterBy`. */
62 AvgTable filter_by(const std::string& station, const std::string& jobclass) const;
63 AvgTable filter_by(const Node& node) const;
64 AvgTable filter_by(const ::line::JobClass& jobclass) const;
65 AvgTable filter_by(const Node& node, const ::line::JobClass& jobclass) const;
66 AvgTable filter_by(const ::line::JobClass& jobclass, const Node& node) const;
67
68 /** MATLAB-compatible filtering aliases, preserving C++ snake-case naming. */
69 AvgTable get(const Node& node) const;
70 AvgTable get(const ::line::JobClass& jobclass) const;
71 AvgTable get(const Node& node, const ::line::JobClass& jobclass) const;
72 AvgTable get(const ::line::JobClass& jobclass, const Node& node) const;
73 AvgTable tget(const Node& node) const;
74 AvgTable tget(const ::line::JobClass& jobclass) const;
75 AvgTable tget(const Node& node, const ::line::JobClass& jobclass) const;
76 AvgTable tget(const ::line::JobClass& jobclass, const Node& node) const;
77
78 /** Direct object indexing: `table(queue, jobs)`. */
79 AvgTable operator()(const Node& node) const;
80 AvgTable operator()(const ::line::JobClass& jobclass) const;
81 AvgTable operator()(const Node& node, const ::line::JobClass& jobclass) const;
82 AvgTable operator()(const ::line::JobClass& jobclass, const Node& node) const;
83
84 /** Print the labelled station-class table. */
85 void print(std::ostream& out) const;
86 void print() const;
87 /** The number of rows the table carries. */
88 std::size_t size() const { return Station.size(); }
89 bool empty() const { return Station.empty(); }
90};
91
92std::ostream& operator<<(std::ostream& out, const AvgTable& table);
93
94/** `SolverBA(model, method).getBoundsTable()`. */
96 std::vector<std::string> Station, JobClass;
97 std::vector<double> Qlower, Qupper, Tlower, Tupper;
98 std::string method;
99};
100
101/** One response-time CDF curve: `F` the CDF value, `t` the time it is reached. */
102struct CdfCurve {
103 std::vector<double> F, t;
104};
105
106/**
107 * `getSymbolicSolution`: the stationary law as a function of the rate symbols.
108 *
109 * The entries are expression strings, not numbers, and are NOT comparable with
110 * another codebase's by text: the symbol numbering x1..xE follows event
111 * enumeration order and the printed normal form depends on the engine version.
112 * Substitute rates and compare numbers instead.
113 */
115 std::vector<std::string> pi; ///< stationary probability of each state
116 std::vector<std::string> num; ///< numerator of each entry over `den`
117 std::string den = "1"; ///< common denominator of the vector
118 std::vector<std::string> symbols; ///< x1..xE, empty where an event has no positive rate
119 std::vector<double> rate0; ///< nominal value of each symbol
120 std::string engine; ///< backend that answered, e.g. "sage"
121};
122
123/** `getTranAvg`: the transient mean queue length per (station, class). */
124struct TranAvg {
125 std::vector<double> t; ///< the time axis
126 std::vector<std::vector<double> > QNt; ///< [step][station*class]
127 std::vector<std::string> label; ///< the (station, class) of each column
128};
129
130/**
131 * `sampleSysAggr` / `sampleAggr`: ONE simulated trajectory, not a mean.
132 *
133 * It has the shape of a `TranAvg` and is deliberately a type of its own,
134 * because the two must never be read for each other: `TranAvg` is E[N](t)
135 * estimated over independent runs, this is a single sample path, and averaging
136 * a column of `state` over `t` is a time average rather than an ensemble one.
137 */
139 std::vector<double> t; ///< event times, ascending
140 std::vector<std::vector<double> > state; ///< [step][column]
141 std::vector<std::string> label; ///< what each column counts
142};
143
144} // namespace line
145
146#endif // LINE_SOLVERS_AVG_TABLE_H
A job class: the index it was given, and the model that owns it.
Definition nodes.h:334
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)
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 > Tput
Definition avg_table.h:40
std::vector< double > ResidT
Definition avg_table.h:40
void print(std::ostream &out) const
Print the labelled station-class table.
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:88
double lognormconst
Definition avg_table.h:47
std::vector< double > Util
Definition avg_table.h:40
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 empty() const
Definition avg_table.h:89
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
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::string method
Definition avg_table.h:44
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:95
std::vector< double > Tlower
Definition avg_table.h:97
std::string method
Definition avg_table.h:98
std::vector< double > Qupper
Definition avg_table.h:97
std::vector< std::string > Station
Definition avg_table.h:96
std::vector< double > Qlower
Definition avg_table.h:97
std::vector< std::string > JobClass
Definition avg_table.h:96
std::vector< double > Tupper
Definition avg_table.h:97
One response-time CDF curve: F the CDF value, t the time it is reached.
Definition avg_table.h:102
std::vector< double > F
Definition avg_table.h:103
std::vector< double > t
Definition avg_table.h:103
sampleSysAggr / sampleAggr: ONE simulated trajectory, not a mean.
Definition avg_table.h:138
std::vector< std::vector< double > > state
[step][column]
Definition avg_table.h:140
std::vector< std::string > label
what each column counts
Definition avg_table.h:141
std::vector< double > t
event times, ascending
Definition avg_table.h:139
getSymbolicSolution: the stationary law as a function of the rate symbols.
Definition avg_table.h:114
std::vector< double > rate0
nominal value of each symbol
Definition avg_table.h:119
std::string den
common denominator of the vector
Definition avg_table.h:117
std::vector< std::string > pi
stationary probability of each state
Definition avg_table.h:115
std::vector< std::string > symbols
x1..xE, empty where an event has no positive rate
Definition avg_table.h:118
std::string engine
backend that answered, e.g. "sage"
Definition avg_table.h:120
std::vector< std::string > num
numerator of each entry over den
Definition avg_table.h:116
getTranAvg: the transient mean queue length per (station, class).
Definition avg_table.h:124
std::vector< std::string > label
the (station, class) of each column
Definition avg_table.h:127
std::vector< std::vector< double > > QNt
[step][station*class]
Definition avg_table.h:126
std::vector< double > t
the time axis
Definition avg_table.h:125