LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mam_types.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_MAM_MAM_TYPES_H
6#define LINE_SOLVERS_MAM_MAM_TYPES_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * The option and result types SolverMAM shares with its analyzers.
12 *
13 * The solution type IS `mva::MvaSolution<T>`: the MAM analyzers return the same
14 * [Q,U,R,T,C,X] tuple, and `@@NetworkSolver/getAvg` applies the same
15 * solver-independent metric filter afterwards, so reusing it is what keeps the
16 * two runners from drifting apart.
17 */
18
19#include <cstddef>
20#include <limits>
21#include <optional>
22#include <string>
23
25
26namespace line {
27namespace mam {
28
29/** The options SolverMAM reads. Defaults are SolverOptions('MAM'). */
30struct MamOptions {
31 std::string method = "default";
32 double tol = 1e-4;
33 /** SolverOptions('MAM') lowers this from the global 1000 to 100. */
34 int iter_max = 100;
35 /**
36 * `options.config.space_max`: the order budget of the per-station arrival
37 * superposition, handed to mmap_super_safe. `dec.poisson` is exactly this
38 * set to 1, which collapses every stream to marked Poisson.
39 */
40 std::size_t space_max = 128;
41 /**
42 * `options.config.preserveDet`: keep a Det service as Det so the exact
43 * MAP/D/c solver can claim it, instead of Erlang-approximating it.
44 *
45 * EMPTY MEANS NOT GIVEN, which is the whole point of the optional. The
46 * reference defaults the field only when the caller left it unset
47 * (`solver_mam_analyzer.m:43-47`), and the default it picks is
48 * METHOD-DEPENDENT, so a plain `= true` here is not the same thing: it
49 * cannot say "on unless bgchain" and cannot let an explicit request win.
50 */
51 std::optional<bool> preserve_det;
52 /**
53 * `options.config.nonmkvorder`: the phase budget `sn_nonmarkov_toph` spends
54 * replacing a non-Markovian service law. The reference default is 20.
55 */
56 std::size_t nonmkv_order = 20;
57 /**
58 * `options.config.nonmkv`: 'bernstein' (default) runs `sn_nonmarkov_toph`,
59 * 'none' skips it; any other name is refused (`api::nonmkv_enabled`).
60 */
61 std::string nonmkv = "bernstein";
62 /**
63 * `options.config.phfit`: true selects the two-moment concentrated-ME fit
64 * (the reference default), false the Bernstein density fit. MAM consumes a
65 * matrix exponential happily, so the default stands here.
66 */
67 bool phfit_cme = true;
68 /**
69 * `options.config.num_cdf_pts`: how many points the response-time CDF is
70 * evaluated at. The GLOBAL default is 200, not the 100 that
71 * `solver_mam_passage_time.m`'s own fallback names -- the fallback is dead,
72 * because SolverOptions always sets the field. Measured: MATLAB returns 200
73 * rows for a model whose `options.config` was never touched.
74 */
75 std::size_t num_cdf_pts = 200;
76 /**
77 * `options.cutoff`: the level truncation `getProb` / `getProbMarg` use for
78 * an OPEN model, where the queue length is unbounded. 0 selects the
79 * reference's default of 100.
80 */
81 std::size_t cutoff = 0;
82 /**
83 * `options.config.bgstates_max`: the cap on the number of states of the
84 * bgchain background chain, which enumerates the closed-class population
85 * vector and so grows as nchoosek(N+Mc-1,Mc-1) per background class. 0
86 * selects the default of 20000. Exceeding it is a named error, not a silent
87 * degradation.
88 */
89 std::size_t bgstates_max = 0;
90 /**
91 * `options.config.bgaggr`: the number G of AGGREGATE background classes the
92 * bgchain method carries, so the chain has 1 + G classes. G = 1 is the
93 * classic tagged/aggregate pair and the default; G >= R-1 aggregates nothing
94 * and carries every closed chain exactly. 0 selects the default of 1.
95 */
96 std::size_t bgaggr = 0;
97 /**
98 * `options.config.qbdphases_max`: the cap on the phase count of one bgchain
99 * station QBD, the product (arrival order) x (environment states) x (service
100 * phases). 0 selects the default of 500.
101 */
102 std::size_t qbdphases_max = 0;
103 /**
104 * `options.config.fj_accuracy`: the FJ_codes truncation C of the
105 * queue-length DIFFERENCE between the two fork-join branches. Larger is
106 * more accurate and costs (C + 1) m^2 ma in every matrix dimension; the
107 * reference default is 100.
108 */
109 std::size_t fj_accuracy = 100;
110 /**
111 * `options.config.fj_tmode`: which route `computeT.m` takes to the T
112 * matrix, 'NARE' (Riccati, the reference default) or 'Sylvester' (the
113 * fixed-point iteration of Section 5.1).
114 */
115 std::string fj_tmode = "NARE";
116 /**
117 * `options.config.sync_phases`: the synchronous phase expansion of the
118 * 'sync.faster' / 'sync.slower' methods. 0 (the default) solves the
119 * synchronous approximation without expansion; N >= 1 splits a
120 * deterministic service into N phases and tightens both bounds.
121 */
122 std::size_t sync_phases = 0;
123 /**
124 * `options.config.mapmsg_quantization`: the number of regimes the MAP/M/s+G
125 * reneging analyzer quantizes the patience CDF into (solver_mam_reneging.h).
126 * The reference default is 81; fewer than 2 leaves no grid and is refused.
127 */
128 std::size_t mapmsg_quantization = 81;
129 /**
130 * `options.config.ispn_place`: the unbounded level of the 'ispn' method, a
131 * place name or 'place.class' in a multiclass net. Empty (the default) takes
132 * the single level that no non-negative S-invariant covers.
133 */
134 std::string ispn_place;
135 /**
136 * `options.config.ispn_maxlevel`: the largest level window the 'ispn'
137 * method explores before refusing the net. 0 keeps spn_ispn's default, 200.
138 */
139 std::size_t ispn_maxlevel = 0;
140 /**
141 * `options.config.censor_level` given as a STATION NAME: the level station
142 * of the 'censor' method (`solver_mam_censor.h`). Empty means not given.
143 */
144 std::string censor_level;
145 /**
146 * `options.config.censor_level` given as a 1-based STATION INDEX. It is
147 * kept as the number the caller wrote, so a non-integer or out-of-range
148 * value is refused (`LINE:input:Argument`) exactly where the reference
149 * refuses it. At most one of `censor_level` and this may be set; with
150 * neither, every station is tried in decreasing order of its job-count range.
151 */
152 std::optional<double> censor_level_index;
153 /**
154 * `options.config.censor_states_max`: the largest generated CTMC the
155 * 'censor' method solves, since its level blocks are dense. 0 selects the
156 * default of 10000; a larger chain is refused as LINE:unsupported:StateSpace.
157 * Unlike MATLAB, the JAR and Python, the C++ SolverMAM has no worst-case
158 * state-space estimator, so it does not screen the method before the chain
159 * is built.
160 */
161 std::size_t censor_states_max = 0;
162 /**
163 * `options.config.timescale`: "auto", "discrete" or "continuous". "auto"
164 * lets the distributions decide whether the model is slotted; the other two
165 * force the reading and raise when the model does not admit it.
166 */
167 std::string timescale = "auto";
168 /**
169 * `options.config.slotted`: true asks for the discrete time scale, the same
170 * as timescale "discrete" (solvers::slotted_request, shared with NC and LDES).
171 */
172 bool slotted = false;
173 /**
174 * `options.config.slotlength`: the slot in model time units, the lattice
175 * unit d. It never rescales a law: Geometric, DiscreteUniform and DMAP need
176 * 1/d integral, Det(v) needs v/d integral.
177 */
178 double slotlength = 1.0;
179 /**
180 * `options.timespan`: the transient horizon. SolverOptions('MAM') defaults
181 * it to [Inf, Inf], i.e. steady state only, and `runAnalyzer` treats a
182 * finite upper bound as the request for a transient solve.
183 */
184 double timespan_start = 0.0;
185 double timespan_end = std::numeric_limits<double>::infinity();
186
187 /**
188 * `preserve_det` with the reference's method-dependent default applied,
189 * and the ONLY spelling any analyzer should read.
190 *
191 * 'bgchain' builds a phase-type MIXTURE of the open service laws and has
192 * no deterministic-service branch at all, so a Det that survives to it
193 * arrives with no (D0,D1) pair to mix. 'censor' solves the network CTMC,
194 * which carries no deterministic clock either. Both therefore need the Det
195 * FITTED to PH, which is what `solver_mam_analyzer.m:68` says by defaulting
196 * `preserveDet` to `~any(strcmpi(method,{'bgchain','censor'}))`. Every other
197 * method wants the Det preserved so the exact MAP/D/c branch can claim it.
198 *
199 * The method name is compared exactly, not case-insensitively as the
200 * reference's `strcmpi` does, because `check_method` has already refused
201 * anything that is not one of `list_valid_methods`' lowercase names by the
202 * time an analyzer reads this.
203 */
205 return preserve_det.value_or(method != "bgchain" && method != "censor");
206 }
207};
208
209/** What the MAM dispatch returns: the metrics plus the algorithm that ran. */
210template <class T>
213 /** The concrete algorithm, as the reference's `actualmethod`. */
214 std::string actualmethod;
215};
216
217} // namespace mam
218} // namespace line
219
220#endif // LINE_SOLVERS_MAM_MAM_TYPES_H
The option and result types every MVA analyzer shares.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
The options SolverMAM reads.
Definition mam_types.h:30
std::size_t mapmsg_quantization
options.config.mapmsg_quantization: the number of regimes the MAP/M/s+G reneging analyzer quantizes t...
Definition mam_types.h:128
int iter_max
SolverOptions('MAM') lowers this from the global 1000 to 100.
Definition mam_types.h:34
std::string ispn_place
options.config.ispn_place: the unbounded level of the 'ispn' method, a place name or 'place....
Definition mam_types.h:134
std::size_t num_cdf_pts
options.config.num_cdf_pts: how many points the response-time CDF is evaluated at.
Definition mam_types.h:75
double timespan_start
options.timespan: the transient horizon.
Definition mam_types.h:184
std::optional< double > censor_level_index
options.config.censor_level given as a 1-based STATION INDEX.
Definition mam_types.h:152
std::size_t bgstates_max
options.config.bgstates_max: the cap on the number of states of the bgchain background chain,...
Definition mam_types.h:89
std::string timescale
options.config.timescale: "auto", "discrete" or "continuous".
Definition mam_types.h:167
std::size_t bgaggr
options.config.bgaggr: the number G of AGGREGATE background classes the bgchain method carries,...
Definition mam_types.h:96
bool phfit_cme
options.config.phfit: true selects the two-moment concentrated-ME fit (the reference default),...
Definition mam_types.h:67
std::string nonmkv
options.config.nonmkv: 'bernstein' (default) runs sn_nonmarkov_toph, 'none' skips it; any other name ...
Definition mam_types.h:61
std::size_t fj_accuracy
options.config.fj_accuracy: the FJ_codes truncation C of the queue-length DIFFERENCE between the two ...
Definition mam_types.h:109
std::size_t qbdphases_max
options.config.qbdphases_max: the cap on the phase count of one bgchain station QBD,...
Definition mam_types.h:102
std::string method
Definition mam_types.h:31
std::size_t cutoff
options.cutoff: the level truncation getProb / getProbMarg use for an OPEN model, where the queue len...
Definition mam_types.h:81
bool slotted
options.config.slotted: true asks for the discrete time scale, the same as timescale "discrete" (solv...
Definition mam_types.h:172
std::size_t nonmkv_order
options.config.nonmkvorder: the phase budget sn_nonmarkov_toph spends replacing a non-Markovian servi...
Definition mam_types.h:56
std::optional< bool > preserve_det
options.config.preserveDet: keep a Det service as Det so the exact MAP/D/c solver can claim it,...
Definition mam_types.h:51
std::string censor_level
options.config.censor_level given as a STATION NAME: the level station of the 'censor' method (solver...
Definition mam_types.h:144
std::size_t space_max
options.config.space_max: the order budget of the per-station arrival superposition,...
Definition mam_types.h:40
std::string fj_tmode
options.config.fj_tmode: which route computeT.m takes to the T matrix, 'NARE' (Riccati,...
Definition mam_types.h:115
bool preserve_det_resolved() const
preserve_det with the reference's method-dependent default applied, and the ONLY spelling any analyze...
Definition mam_types.h:204
std::size_t sync_phases
options.config.sync_phases: the synchronous phase expansion of the 'sync.faster' / 'sync....
Definition mam_types.h:122
double slotlength
options.config.slotlength: the slot in model time units, the lattice unit d.
Definition mam_types.h:178
std::size_t ispn_maxlevel
options.config.ispn_maxlevel: the largest level window the 'ispn' method explores before refusing the...
Definition mam_types.h:139
std::size_t censor_states_max
options.config.censor_states_max: the largest generated CTMC the 'censor' method solves,...
Definition mam_types.h:161
What the MAM dispatch returns: the metrics plus the algorithm that ran.
Definition mam_types.h:211
std::string actualmethod
The concrete algorithm, as the reference's actualmethod.
Definition mam_types.h:214
mva::MvaSolution< T > sol
Definition mam_types.h:212
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:97