LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
nc_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_NC_NC_TYPES_H
6#define LINE_SOLVERS_NC_NC_TYPES_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Controls and result shape shared by the normalizing-constant analyzers.
12 *
13 * The result is `mva::MvaSolution<T>`, not a type of its own: SolverNC returns
14 * the same [Q,U,R,T,C,X,lG] tuple as SolverMVA, and sharing the struct is what
15 * lets the fork-join fixed point (`fj_driver.h`) drive `nc_dispatch` as its
16 * inner solve without a shim.
17 */
18
19#include <cstddef>
20#include <memory>
21#include <string>
22#include <vector>
23
29#include "line/util/matrix.h"
30
31namespace line {
32namespace nc {
33
34/** Controls, defaulting to `SolverOptions('NC')` in the reference. */
36 std::string method = "default";
37 double tol = 1e-4; ///< options.tol
38 double iter_tol = 1e-4; ///< options.iter_tol, the eta stopping test
39 int iter_max = 1000;
40 /**
41 * `options.config.highvar`. SolverOptions('NC') overrides the global
42 * default and sets this to 'interp', so a non-product-form FCFS station is
43 * rescaled by the WSC 2020 interpolation and the analyzer iterates. Setting
44 * it to 'default' makes the outer loop run exactly once.
45 */
46 std::string highvar = "interp";
47 /**
48 * `options.config.fork_join`: which fork-join arm the shared fixed point
49 * takes on a model with a Fork. `default`/`mmt`/`fjt` is the MMT transform,
50 * `ht`/`heidelberger-trivedi` the Heidelberger-Trivedi one. See
51 * `MvaOptions::fork_join`; the driver is the same function for both solvers.
52 */
53 std::string fork_join = "default";
54 /**
55 * `options.config.multiserver`: how a finite multiserver station is
56 * represented. `default` keeps the historical dispatch (Seidmann on
57 * `default`, the exact mu(n)=min(n,c) lattice on `exact`/`is`/`panald`,
58 * and the lattice on the 2-station Delay+multiserver shape); `seidmann`
59 * forces Seidmann everywhere, `exact`/`lld` forces the lattice everywhere
60 * it is admissible. The SolverMVA values this solver has no counterpart for
61 * (`softmin`, `conway`, `krzesinski`, `suri`, `erlang`) fall back to
62 * `default` rather than throwing: one options object is commonly reused
63 * across solvers. See `MvaOptions::multiserver`.
64 */
65 std::string multiserver = "default";
66 std::size_t samples = 100000; ///< options.samples, read by the estimators
67 unsigned long seed = 23000; ///< options.seed, read by the estimators
68 /**
69 * `options.config.aghq_nodes`: nodes per simplex direction of the adaptive
70 * Gauss-Hermite rule. q = 1 reproduces pfqn_le; the rule costs q^(M-1)
71 * evaluations, so the default stays small.
72 */
73 std::size_t aghq_nodes = 3;
74 /**
75 * `options.config.mcmc_batches`: the non-overlapping batches the
76 * Chen-O'Cinneide estimator splits its run into for the batch-means
77 * confidence intervals. 30 is Schmeiser (1982), the count used in the
78 * tables of the paper.
79 */
80 std::size_t mcmc_batches = 30;
81 /**
82 * `options.config.mcmc_burnin`: the warm-up fraction that estimator
83 * discards before it starts accumulating. The paper discards none and
84 * ignores the initialization bias.
85 */
86 double mcmc_burnin = 0.1;
87 /**
88 * `options.config.algorithm` for `getCdfRespT`: 'exact' selects
89 * `pfqn_stdf`, 'rd' the heuristic `pfqn_stdf_heur`. The reference defaults
90 * this field into the options struct when it is absent.
91 */
92 std::string cdf_algorithm = "exact";
93 /** `options.config.mem_tol` / `mem_maxiter`, read by the MEM fixed point. */
94 double mem_tol = 1e-6;
95 long mem_maxiter = 1000;
96 /**
97 * Whether the model this solve came from has a Fork, which the model handed
98 * to the analyzer no longer does. Same role as `MvaOptions::base_has_fork`.
99 */
100 bool base_has_fork = false;
101 /**
102 * `options.config.slotted`. Runs the solve on a discrete time scale, the
103 * same switch SolverLDES uses. It routes to `solver_nc_dt` and REFUSES a
104 * model outside the discrete-time product form rather than falling back to
105 * the continuous-time analyzers: the continuous-time answer to a slotted
106 * question is a different number, not a worse one.
107 */
108 bool slotted = false;
109 /**
110 * `options.config.timescale`: "auto", "discrete" or "continuous". NC reads
111 * "auto" as continuous; "discrete" means the same as `slotted`. Both are
112 * read through `solvers::slotted_request`, shared with MAM and LDES.
113 */
114 std::string timescale = "auto";
115 /**
116 * `options.config.slotlength`, the slot length in model time units: the
117 * lattice unit, never a rescale. The product form needs the unit slot.
118 */
119 double slotlength = 1.0;
120};
121
122/**
123 * True when the caller asked for the discrete-time route (`slotted` or
124 * timescale "discrete"). Never inferred from the model: a Geometric service
125 * time is an ordinary continuous-time model unless the caller declares the slot
126 * lattice, so NC reads timescale "auto" as continuous.
127 */
128inline bool nc_is_slotted(const NcSolverOptions& opt) {
129 return solvers::slotted_request(opt.timescale, opt.slotted, opt.slotlength).discrete();
130}
131
132/** The `[Q,U,R,T,C,X,lG]` of the reference, plus the algorithm that ran. */
133template <class T>
136 std::string actualmethod;
137 Matrix<T> STeff; ///< the service times of the last pass, MATLAB's STeff
138 /**
139 * Set only by the integrated cacheqn branch: the converged struct whose
140 * routing carries the ACTUAL hit/miss probabilities, from which the runner
141 * derives ArvR and ResidT. Empty for every other model. Same role as
142 * `mva::DispatchResult::refreshed_struct`.
143 */
144 std::shared_ptr<qn::NetworkStruct<T>> refreshed_struct;
145 /**
146 * The reference's warning text, verbatim, empty when it did not warn. Same
147 * role as `mva::AvgResult::warning`, which `solver_nc_run_analyzer` copies it into:
148 * a statement about HOW the numbers were produced. The cache branch uses it
149 * for the two cost-cap conditions -- a promotion path the caps block, and a
150 * method that has no cost-capped counterpart and was switched -- because the
151 * port has no `line_warning` channel and a FLAG no caller reads is the same
152 * as saying nothing.
153 */
154 std::string warning;
155 /**
156 * (h) mean storage cost held by each cache list, K_j = sum_i sigma_i pi_ij.
157 * EMPTY for every model without item sizes, which is every model but a cache
158 * carrying `sn.nodeparam.itemsize` (ton21cache Sec. IX).
159 */
160 std::vector<T> listcost;
161 /**
162 * What the cache branches observed, EMPTY on a model with no Cache node.
163 *
164 * It rides here rather than being recomputed by the caller because the
165 * analyzers already have it and throwing it away would mean solving the
166 * cache twice to answer `getAvgCacheTable` -- and the second solve, being a
167 * different call, would be free to disagree with the first.
168 */
170 /**
171 * Set only by the `cftp` / `cftp.approx` route (`solver_nc_cftp.h`), EMPTY
172 * for every other method: the sampled states one draw per row (cftpSamples),
173 * the per-draw coalescence horizon or mixing steps (cftpHorizon), the
174 * distinct sampled states (space / spaceAggr) and the empirical probability
175 * of each (the sampled pi).
176 */
178 std::vector<long> cftp_horizon;
179 std::vector<std::vector<int>> cftp_space;
180 std::vector<T> cftp_prob;
181 /**
182 * Set only by the loss-network analyzer (`solver_nc_lossn.h`), EMPTY for
183 * every other model: the inputs `getAvgLinkTable` re-solves with the same
184 * method, MATLAB's `self.result.LossN`.
185 */
187};
188
189} // namespace nc
190} // namespace line
191
192#endif // LINE_SOLVERS_NC_NC_TYPES_H
What a solver observed about the Cache nodes of a model.
The inputs of a loss network solved by SolverNC, kept beside the result.
Dense matrix and non-owning view.
The option and result types every MVA analyzer shares.
bool nc_is_slotted(const NcSolverOptions &opt)
True when the caller asked for the discrete-time route (slotted or timescale "discrete").
Definition nc_types.h:128
SlottedRequest slotted_request(std::string timescale, bool slotted, double slotlength)
Resolves timescale (empty reads as "auto"), slotted and slotlength as they come from options....
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
Port of matlab/src/solvers/line_slotted_request.m: the one reading of the discrete-time switch shared...
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:97
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:134
solvers::LossnInfo lossn
Set only by the loss-network analyzer (solver_nc_lossn.h), EMPTY for every other model: the inputs ge...
Definition nc_types.h:186
std::vector< T > listcost
(h) mean storage cost held by each cache list, K_j = sum_i sigma_i pi_ij.
Definition nc_types.h:160
std::vector< std::vector< int > > cftp_space
Definition nc_types.h:179
mva::MvaSolution< T > sol
Definition nc_types.h:135
Matrix< T > STeff
the service times of the last pass, MATLAB's STeff
Definition nc_types.h:137
std::string warning
The reference's warning text, verbatim, empty when it did not warn.
Definition nc_types.h:154
std::shared_ptr< qn::NetworkStruct< T > > refreshed_struct
Set only by the integrated cacheqn branch: the converged struct whose routing carries the ACTUAL hit/...
Definition nc_types.h:144
std::vector< T > cftp_prob
Definition nc_types.h:180
solvers::CacheMetrics< T > cache
What the cache branches observed, EMPTY on a model with no Cache node.
Definition nc_types.h:169
std::string actualmethod
Definition nc_types.h:136
Matrix< int > cftp_states
Set only by the cftp / cftp.approx route (solver_nc_cftp.h), EMPTY for every other method: the sample...
Definition nc_types.h:177
std::vector< long > cftp_horizon
Definition nc_types.h:178
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:35
double mem_tol
options.config.mem_tol / mem_maxiter, read by the MEM fixed point.
Definition nc_types.h:94
double slotlength
options.config.slotlength, the slot length in model time units: the lattice unit, never a rescale.
Definition nc_types.h:119
std::string multiserver
options.config.multiserver: how a finite multiserver station is represented.
Definition nc_types.h:65
bool base_has_fork
Whether the model this solve came from has a Fork, which the model handed to the analyzer no longer d...
Definition nc_types.h:100
std::size_t mcmc_batches
options.config.mcmc_batches: the non-overlapping batches the Chen-O'Cinneide estimator splits its run...
Definition nc_types.h:80
std::string fork_join
options.config.fork_join: which fork-join arm the shared fixed point takes on a model with a Fork.
Definition nc_types.h:53
double tol
options.tol
Definition nc_types.h:37
std::size_t aghq_nodes
options.config.aghq_nodes: nodes per simplex direction of the adaptive Gauss-Hermite rule.
Definition nc_types.h:73
std::size_t samples
options.samples, read by the estimators
Definition nc_types.h:66
std::string highvar
options.config.highvar.
Definition nc_types.h:46
std::string timescale
options.config.timescale: "auto", "discrete" or "continuous".
Definition nc_types.h:114
unsigned long seed
options.seed, read by the estimators
Definition nc_types.h:67
double mcmc_burnin
options.config.mcmc_burnin: the warm-up fraction that estimator discards before it starts accumulatin...
Definition nc_types.h:86
bool slotted
options.config.slotted.
Definition nc_types.h:108
std::string cdf_algorithm
options.config.algorithm for getCdfRespT: 'exact' selects pfqn_stdf, 'rd' the heuristic pfqn_stdf_heu...
Definition nc_types.h:92
double iter_tol
options.iter_tol, the eta stopping test
Definition nc_types.h:38
Every Cache node of the model, in node order; empty on a model with none.
self.result.LossN.
Definition lossn_info.h:39