LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver.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_SOLVER_H
6#define LINE_SOLVERS_SOLVER_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * @ingroup line_public
12 * The solver API a user writes, spelled as its Python twin.
13 *
14 * SolverMVA s(model, "lin");
15 * AvgTable t = s.avg_table();
16 *
17 * against Python's
18 *
19 * s = MVA(model, method='lin')
20 * t = s.avg_table()
21 *
22 * NAMING. A multi-word getter drops the `get_` prefix (`avg_table`,
23 * `tran_avg`, `cdf_respt`), because `line_solver/_aliasing.py` resolves exactly
24 * that spelling onto Python's own `getAvgTable`/`getTranAvg`/`getCdfRespT`; a
25 * SINGLE-word getter keeps it (`get_name`), because that same module
26 * deliberately refuses to expand a bare lowercase word and Python has no
27 * `name()`. So every name here is a name that also resolves in Python.
28 *
29 * IT IS A FACADE, NOT A SOLVER. Every method forwards to the runner the CLI
30 * calls, so a program written against this header and `line-cli` on the same
31 * model answer with the same numbers.
32 *
33 * THESE CLASSES ARE `double`-ONLY AND NOT TEMPLATES, deliberately. The solver
34 * templates are a heavy instantiation and the multiprecision arithmetic has no
35 * Python counterpart, so the bodies are compiled ONCE into `line_mp_api` and a
36 * translation unit including this header pays for none of it. Reach for
37 * `line::mva::solver_mva_run_analyzer` and its siblings directly when you want
38 * another arithmetic.
39 */
40
41#include <cstddef>
42#include <functional>
43#include <string>
44#include <vector>
45
52#include "line/util/matrix.h"
53
54namespace line {
55
56/** `Network` as a user names it: the `double` model, Python's `Network`. */
58/** `model.init_routing_matrix()`'s type, Python's `RoutingMatrix`. */
60
61/** `getAvgChain()`: the station x chain matrices, `@NetworkSolver/getAvgChain.m`'s outputs. */
62struct AvgChain {
64};
65
66/**
67 * One CTMC state as a state-set predicate sees it, the reference's `RewardState`:
68 * the AGGREGATE row of `state_space_aggr()`, per-(station, class) job counts in
69 * `(ist-1)*K + k` order. A Place is a station, so its count is its marking.
70 */
71class StateView {
72 public:
73 StateView(const std::vector<double>& row, const qn::NetworkStruct<double>& sn)
74 : row_(&row), sn_(&sn) {}
75 /** `s.at(node).total()`: jobs of every class at a station node; a handle converts. */
76 double total(std::size_t node) const;
77 /** `s.at(node, cls)`: jobs of class `cls` (1-based; a handle converts) at a station node. */
78 double at(std::size_t node, std::size_t cls) const;
79 /** The aggregate row itself. */
80 const std::vector<double>& row() const { return *row_; }
81
82 private:
83 std::size_t column(std::size_t node, std::size_t cls) const;
84 const std::vector<double>* row_;
86};
87
88/**
89 * A STATE SET named by a predicate, the reference's function-handle form,
90 * e.g. `[&](const StateView& s) { return s.total(queue1) >= 5; }`. An empty
91 * predicate names the empty set.
92 */
93typedef std::function<bool(const StateView&)> StatePredicate;
94
95/** `getCdfFirstPassT(A, B, C, tset)`: the curve, the reach probabilities and the resolved sets. */
97 std::vector<double> t; ///< the grid: the caller's, else 1000 points to the horizon
98 std::vector<double> F; ///< F(t), DEFECTIVE under a taboo set
99 std::vector<double> f; ///< the density at t
100 double reachprob = 0.0; ///< probability of entering B (before C)
101 double tabooprob = 0.0; ///< probability of entering C before B
102 std::vector<std::size_t> source; ///< 0-based state rows of A; empty = conditional stationary
103 std::vector<std::size_t> target; ///< 0-based state rows of B
104 std::vector<std::size_t> taboo; ///< 0-based state rows of C minus B
105};
106
107/** `getFirstPassTMoments(A, B, nmax, C)`: `[m, mall, p]` with the resolved sets. */
109 std::vector<double> m; ///< moments 1..nmax from A (conditional on B before C)
110 Matrix<double> mall; ///< (nstates x nmax), one row per starting state
111 std::vector<double> p; ///< (nstates) probability of entering B before C
112 std::vector<std::size_t> source; ///< 0-based state rows of A; empty = conditional stationary
113 std::vector<std::size_t> target; ///< 0-based state rows of B
114 std::vector<std::size_t> taboo; ///< 0-based state rows of C minus B
115};
116
117/**
118 * The shared surface of every solver, Python's `NetworkSolver`.
119 *
120 * The solve is performed on first demand and cached, which is what
121 * `hasResults`/`is_solved` reports; `reset()` discards it.
122 */
124 public:
125 virtual ~NetworkSolver() {}
126
127 /** `getName()`: the solver's own name, e.g. "MVA". */
128 const std::string& get_name() const { return name_; }
129 /** The options this solver was built with. */
130 const SolverOptions& options() const { return opts_; }
131 /** The model this solver was built on. */
132 Network& model() const { return *model_; }
133
134 /** `getAvgTable()`: the average table, solving on first demand. */
135 const AvgTable& avg_table();
136 /** `getAvgSysTable()`: per-chain system response time and throughput of the same solve. */
138 /** `getAvgQLenTable()`: `avg_table()`'s Station, JobClass and QLen columns. */
140 /** `getAvgUtilTable()`: `avg_table()`'s Station, JobClass and Util columns. */
142 /** `getAvgRespTTable()`: `avg_table()`'s Station, JobClass and RespT columns. */
144 /** `getAvgTputTable()`: `avg_table()`'s Station, JobClass and Tput columns. */
146
147 /** `getAvgSysRespT()`: the per-chain system response time column of `avg_sys_table`. */
148 std::vector<double> avg_sys_respt() { return avg_sys_table().SysRespT; }
149 /** `getAvgSysTput()`: the per-chain system throughput column of `avg_sys_table`. */
150 std::vector<double> avg_sys_tput() { return avg_sys_table().SysTput; }
151
152 /** `getAvgChain()`: the station table of the same solve aggregated by chain, (nstations x nchains). */
154 /** `getAvgQLenChain()` and its siblings: one matrix of `avg_chain()` each. */
161 /** `getAvgChainTable()`: `avg_chain()` as a labelled table, one row per (station, chain). */
163 /** `runAnalyzer()`: force the solve, returning the table it produced. */
164 const AvgTable& run_analyzer() { return avg_table(); }
165 /** `listValidMethods()`: the methods this solver advertises on this model. */
166 std::vector<std::string> list_valid_methods() const;
167 /** `isSolved()` / `hasResults()`: whether a solve has been performed. */
168 bool is_solved() const { return solved_; }
169 /** `reset()`: discard the cached solve. */
170 void reset() {
171 solved_ = false;
172 table_ = AvgTable();
175 }
176 /** `getMethodUsed()`: the method the solve actually resolved to. */
177 std::string method_used();
178
179 /**
180 * What the same solve observed at each Cache node, the data behind `getAvgCacheTable()` and
181 * `getAvgItemTable()`. A Cache is not a station, so none of this reaches `avg_table()`.
182 * Empty on a model without a Cache; a field the engine did not compute is an empty vector.
183 */
185 /**
186 * `cache.getHitRatio()` after the solve: the per-class hit probability at the named Cache,
187 * NaN for a class that does not read it. Throws when the solver measured none there.
188 */
189 std::vector<double> hit_ratio(const std::string& cache);
190 std::vector<double> hit_ratio(const Node& cache);
191 /** `cache.getMissRatio()` after the solve, with `hit_ratio`'s conventions. */
192 std::vector<double> miss_ratio(const std::string& cache);
193 std::vector<double> miss_ratio(const Node& cache);
194
195 /**
196 * `getAvgFJ()`: the fork-join section metrics of the same solve, one row per Fork/Join pair
197 * (`fj_sorted_pairs`), one column per class. Empty without a pair, or when the solver computes none.
198 */
200 /** `getAvgFJTable()` (aliases `getAvgFJT`, `fjAvgT`, `aFJT`): the same metrics as a labelled table. */
204
205 protected:
206 NetworkSolver(Network& m, const std::string& name, const SolverOptions& o)
207 : model_(&m), name_(name), opts_(o) {}
208
210 std::string name_;
215 bool solved_ = false;
216};
217
218/**
219 * Every solver takes the model and either a method name or a full option set,
220 * mirroring Python's `SolverX(model, method_or_options=None, **kwargs)`.
221 */
222#define LINE_DECLARE_SOLVER(Cls, tag) \
223 class Cls : public NetworkSolver { \
224 public: \
225 explicit Cls(Network& m, const SolverOptions& o = SolverOptions()) \
226 : NetworkSolver(m, tag, o) {} \
227 Cls(Network& m, const std::string& method) \
228 : NetworkSolver(m, tag, SolverOptions().set_method(method)) {} \
229 }
230
231LINE_DECLARE_SOLVER(SolverMVA, "MVA");
232LINE_DECLARE_SOLVER(SolverNC, "NC");
233LINE_DECLARE_SOLVER(SolverMAM, "MAM");
234LINE_DECLARE_SOLVER(SolverSSA, "SSA");
235
236#undef LINE_DECLARE_SOLVER
237
238/**
239 * `SolverJMT`: the Java Modelling Tools client, which also answers a
240 * transient, a response-time law, a state probability and a trajectory.
241 *
242 * IT IS NOT A BARE `LINE_DECLARE_SOLVER`, and the difference is the point: the
243 * macro exposes averages alone, so a program holding a `SolverJMT` could reach
244 * `getAvgTable` and nothing else while `jmt_logs.h` implemented all four of
245 * these and `line-cli -s jmt` reached none of them either.
246 *
247 * EVERY ONE OF THEM IS READ OFF A LOGGED RUN, so each is a `jsim` answer
248 * whatever `--method` asked for: JMVA computes means from a product form and
249 * logs no trajectory at all.
250 */
251class SolverJMT : public NetworkSolver {
252 public:
253 explicit SolverJMT(Network& m, const SolverOptions& o = SolverOptions())
254 : NetworkSolver(m, "JMT", o) {}
255 SolverJMT(Network& m, const std::string& method)
256 : NetworkSolver(m, "JMT", SolverOptions().set_method(method)) {}
257
258 /** `getCdfRespT()`: the EMPIRICAL response-time CDF per (station, class). */
259 std::vector<std::vector<CdfCurve> > cdf_respt();
260
261 /**
262 * `getTranAvg()`: E[N](t), averaged over `options.config.replications`
263 * (`SolverOptions::replications`, default 10) independent replications
264 * under method `default`; an explicit `jsim` is one run.
265 *
266 * A FINITE HORIZON IS REQUIRED (`options.timespan`): a transient mean over
267 * an unstated horizon is not a quantity, and it is also what makes the
268 * replications' event grids commensurable.
269 */
271
272 /** `getProbAggr(node, state)`: the time the declared state is held for. */
273 double prob_aggr(std::size_t node, const std::vector<double>& state);
274
275 /**
276 * `sampleSysAggr(events)`, or `sampleAggr(node, events)` when `node` is
277 * given: one logged trajectory.
278 *
279 * `events` TRUNCATES, it does not stop the run: JMT's `maxEvents` is
280 * global and cannot be asked for a count at one node, so what comes back is
281 * a prefix of the run the engine produced. Zero returns all of it.
282 */
283 SamplePath sample(std::size_t events = 0, std::size_t node = 0);
284};
285
286/** `SolverCTMC`: the average table plus the chain it was computed from. */
287class SolverCTMC : public NetworkSolver {
288 public:
290 : NetworkSolver(m, "CTMC", o) {}
291 SolverCTMC(Network& m, const std::string& method)
292 : NetworkSolver(m, "CTMC", SolverOptions().set_method(method)) {}
293
294 /** `getStateSpace()`: the aggregate state space, one row per state. */
296 /** `getGenerator()`: the infinitesimal generator over that space. */
298 /** `getProbAggr(node, state)`: the aggregate marginal of one state. */
299 double prob_aggr(std::size_t node, const std::vector<double>& state);
300 /** `getProbStateAggr(node)`: the marginal over every state of one station. */
301 std::vector<double> marg_aggr(std::size_t node);
302 /** `getCdfRespT()`: the response-time CDF per (station, class). */
303 std::vector<std::vector<CdfCurve> > cdf_respt();
304 /**
305 * `getStateSpaceAggr()`: per-(station, class) job counts of every state, in
306 * `(ist-1)*K + k` column order, one row per state of `generator()`.
307 */
309
310 /**
311 * `getCdfFirstPassT(A, B, C, tset)`: the FIRST PASSAGE TIME from the state
312 * set A into the state set B. A set is given as 1-based ROW INDICES into
313 * `state_space()` or as state rows of it; an empty A starts from the
314 * conditional stationary law on the complement of B.
315 *
316 * C is an optional TABOO set: a passage that enters C before B is lost, so
317 * F becomes the DEFECTIVE law Pr{B entered by t, C not before}, tending to
318 * `reachprob`. `tset` replaces the default horizon grid; an infinite entry
319 * returns `reachprob`.
320 */
322 const Matrix<double>& C = Matrix<double>(),
323 const std::vector<double>& tset = std::vector<double>());
324 /** As above, with the sets named by predicates over the aggregate state. */
326 const StatePredicate& C = StatePredicate(),
327 const std::vector<double>& tset = std::vector<double>());
328
329 /**
330 * `getFirstPassTMoments(A, B, nmax, C)`: moments of order 1..nmax of the same
331 * passage, exact by one linear solve per order. With a taboo set C they are
332 * CONDITIONAL on entering B before C, and `mall` is NaN where B cannot be
333 * entered first; `p` is the per-state probability of entering B before C.
334 */
336 std::size_t nmax = 3,
337 const Matrix<double>& C = Matrix<double>());
338 /** As above, with the sets named by predicates over the aggregate state. */
340 std::size_t nmax = 3,
341 const StatePredicate& C = StatePredicate());
342
343 /**
344 * `getSymbolicSolution()`: the stationary law over the rate symbols x1..xE.
345 *
346 * The generator itself needs no computer algebra, being linear in the
347 * symbols, but solving pi Q = 0 over the field of rational functions does,
348 * and that is delegated to the backend `options.symbolic` names. Throws
349 * when no backend can be resolved rather than returning a numeric answer
350 * under a symbolic name.
351 */
353
354 /** `CTMC.printInfGen(Q, SS)`: the generator beside the state it belongs to. */
355 static void print_inf_gen(const Matrix<double>& Q, const Matrix<double>& space);
356};
357
358/** `SolverLDES`: the discrete-event simulator, which also answers the empirical response-time law. */
359class SolverLDES : public NetworkSolver {
360 public:
362 : NetworkSolver(m, "LDES", o) {}
363 SolverLDES(Network& m, const std::string& method)
364 : NetworkSolver(m, "LDES", SolverOptions().set_method(method)) {}
365 /** `SolverLDES(model, initSolver)`: warm-started from `aux`'s steady state, see `init_from_solver`. */
367 : NetworkSolver(m, "LDES", o) {
368 init_from_solver(aux);
369 }
370
371 /** `getCdfRespT()`: the EMPIRICAL response-time CDF per (station, class), from the per-job samples. */
372 std::vector<std::vector<CdfCurve> > cdf_respt();
373
374 /**
375 * `initFromSolver(initSolver)`: warm-start from an auxiliary solver's steady state.
376 *
377 * A SolverCTMC gives the mode of its exact aggregate stationary distribution, any other solver
378 * its mean queue lengths rounded to a placement conserving each closed population. The
379 * placement is declared as the MODEL initial state, one row per station under a prior of one,
380 * which LDES starts from as every state-driven solver does, so it changes the model shared
381 * with any other solver. The transient filter is then disabled (tranfilter=fixed,
382 * warmupfrac=0), since the run starts near steady state.
383 */
385
386 /**
387 * `initFromJobs(jobs)`: start from a job-level initial state, one row per job
388 * [station, class, remaining, elapsed, qage, sage, order, id] with 0-based indexes.
389 *
390 * remaining is the work still owed (-1 a fresh draw, -2 the residual given elapsed), qage and
391 * sage the time already spent at the station and in the system, order the rank at the
392 * station (the first ones take the servers), id an optional tag (-1 untagged). The layout is
393 * the one `final_jobs` returns, so `s2.init_from_jobs(s1.final_jobs())` continues a run where
394 * it stopped, residual work included. Held by the solver rather than the model, since only
395 * LDES can honour it; takes precedence over the model state and `init_sol`, and enables
396 * `track_jobs`. Supported at FCFS queues, the PS family and Delays.
397 */
399
400 /**
401 * `getFinalJobs()`: the jobs present at the end of the run, in the `init_from_jobs` layout.
402 * A run made with `track_jobs` is reused; otherwise one is made with it. A transient run
403 * (`timespan_end`) is read at its horizon.
404 */
405 const Matrix<double>& final_jobs();
406 /** The [id, station, class, time] of every departure of a tagged job, from the same run. */
408
409 private:
410 void run_tracked();
411 Matrix<double> final_jobs_;
412 Matrix<double> job_departures_;
413 bool jobs_ready_ = false;
414};
415
416/** `SolverFLD`: the fluid solver, which also answers a transient. */
417class SolverFLD : public NetworkSolver {
418 public:
419 explicit SolverFLD(Network& m, const SolverOptions& o = SolverOptions())
420 : NetworkSolver(m, "FLD", o) {}
421 SolverFLD(Network& m, const std::string& method)
422 : NetworkSolver(m, "FLD", SolverOptions().set_method(method)) {}
423
424 /** `getTranAvg()`: the transient mean queue length per station. */
426 /** `getCdfRespT()`: the response-time CDF per (station, class). */
427 std::vector<std::vector<CdfCurve> > cdf_respt();
428};
429
430/** `SolverBA`: the bounding solver, whose result is a bounds table. */
431class SolverBA : public NetworkSolver {
432 public:
433 explicit SolverBA(Network& m, const SolverOptions& o = SolverOptions())
434 : NetworkSolver(m, "BA", o) {}
435 SolverBA(Network& m, const std::string& method)
436 : NetworkSolver(m, "BA", SolverOptions().set_method(method)) {}
437
438 /** `getBoundsTable()`: the per-class queue-length and throughput bounds. */
440};
441
442/** One row of `SolverAUTO::find_solver`: a (family, method) pair and whether this model can run it. */
444 std::string solver; ///< the method family: "mva", "ctmc", "ldes", ...
445 std::string method; ///< the qualified method name to pass, "mva.exact"
446 bool runnable = false; ///< the model passes this method's own support gate
447 std::string method_class; ///< "exact", "approx", "bound" or "simulation"
448 std::string metrics; ///< the measure groups the family answers, comma-joined
449 std::string reason; ///< why a refused pair was refused, "" when runnable
450};
451
452/**
453 * `SolverAUTO` (aliases `AUTO`, `SolverAuto`, `LINE`): the solver that picks a solver, a port of
454 * `matlab/src/solvers/AUTO/@SolverAUTO` on a flat Network.
455 *
456 * The METHOD is a selection intent (default/auto, heur, exact, sim, fast, accurate, bound), a family
457 * ('nc', 'nc.comom'), or a bare method name the first declaring family resolves ('comom' is
458 * 'nc.comom'). An intent picks a ranking (`chooseSolver`), keyed on the getter asked for, whose order
459 * is a RETRY LIST (`delegate.m`): the chosen solver, then every candidate the model's feature set
460 * admits. A family names its engine and bypasses the ranking.
461 *
462 * WHAT IS DELEGATED. The average family (`avg_table` and every getter built on it: `avg_sys_table`,
463 * `avg_chain*`, `avg_fj*`, the cache ratios), the response-time CDF, the transient mean, the
464 * aggregate state probability, and, through the solver the reference names for each, the CTMC
465 * state space, generator and symbolic solution and the BA bounds. A getter whose ranked solvers
466 * expose no such call in this facade is skipped to the next candidate, never answered by a solver
467 * outside the ranking.
468 *
469 * The selection policy cites nothing of its own (`citations.m` passes no method name), so
470 * `citations()` is empty; each delegate's references are its own solver's.
471 */
472class SolverAUTO : public NetworkSolver {
473 public:
474 explicit SolverAUTO(Network& m, const SolverOptions& o = SolverOptions());
475 SolverAUTO(Network& m, const std::string& method);
476
477 /**
478 * `getSelectedSolverName()`: the facade name ("MVA", "FLD", ...) of the delegate that answered
479 * the last request, or, before any, the one the ranking picks for the mean metrics; "" when
480 * no solver is feasible.
481 */
482 std::string selected_solver_name();
483 /** `getSelectedMethod()`: the method FAMILY of that delegate, lowercase ("mva", "fld"). */
484 std::string selected_method();
485 /** `getCandidateSolverNames()`: the facade names of the feasible candidates, in slot order. */
486 std::vector<std::string> candidate_solver_names() const;
487 /** `chooseSolver(getter)`: the facade name the configured method picks for that getter. */
488 std::string choose_solver(const std::string& getter = "getAvg") const;
489 /** `delegate`'s retry order for that getter, as facade names; the chosen solver comes first. */
490 std::vector<std::string> proposed_solver_names(const std::string& getter = "getAvg") const;
491 /** `isStochastic()`: by the delegate that ran, else whether any candidate is a simulator. */
492 bool is_stochastic();
493 /** `isComposite()`: false, since this facade holds a flat Network. */
494 bool is_composite() const { return false; }
495
496 /** `listAllMethods()`: every method name the constructor accepts, independent of the model. */
497 std::vector<std::string> list_all_methods() const;
498 /** `findSolver(metric, showAll)`: which (family, method) pairs answer `metric` on this model. */
499 std::vector<AutoCandidate> find_solver(const std::string& metric = std::string(),
500 bool show_all = false) const;
501 /** `citations()`: the selection policy's references, none. */
502 std::vector<io::Citation> citations() const { return std::vector<io::Citation>(); }
503
504 /** `getCdfRespT()`, delegated through the 'getCdfRespT' ranking. */
505 std::vector<std::vector<CdfCurve> > cdf_respt();
506 /** `getTranAvg()`, delegated through the 'getTranAvg' ranking. */
508 /** `getProbAggr(node, state)`, delegated through the 'getProbAggr' ranking. */
509 double prob_aggr(std::size_t node, const std::vector<double>& state);
510
511 /** `ctmcSolver()`: the SolverCTMC the generator and state-space calls go to, with these options. */
512 SolverCTMC ctmc_solver() const;
513 /** `fldSolver()`: the SolverFLD the fluid-only calls go to. */
514 SolverFLD fld_solver() const;
515 /** `ncSolver()`: the SolverNC the normalizing-constant calls go to. */
516 SolverNC nc_solver() const;
517 /** `baSolver()`: the SolverBA the bound calls go to, method 'auto' unless a bound method was named. */
518 SolverBA ba_solver() const;
523
524 /** `selectionIntents()`. */
525 static std::vector<std::string> selection_intents();
526 /** `familyNames()`: the method families, in the order a bare method name is looked up. */
527 static std::vector<std::string> family_names();
528 /** `metricGroups()`, `metricGroupOf(name)` and `familyMetrics(family)`. */
529 static std::vector<std::string> metric_groups();
530 static std::string metric_group_of(const std::string& name);
531 static std::vector<std::string> family_metrics(const std::string& family);
532 /**
533 * `getFeatureSet()`: the union of the feature sets of SolverMVA, NC, CTMC, FLD, MAM, SSA, LDES
534 * and JMT, as registry names. AG is deliberately absent, as in the reference.
535 */
536 static std::vector<std::string> feature_set();
537 /** `supports(model)`: whether the model uses only features some family declares. */
538 static bool supports(Network& model);
539
540 private:
541 /** Facade name of the delegate that answered the last delegated request, "" before any. */
542 std::string last_;
543};
544
545// Python's short aliases: `MVA(model)` is `SolverMVA(model)`.
546typedef SolverMVA MVA;
547typedef SolverNC NC;
549typedef SolverSSA SSA;
552typedef SolverMAM MAM;
558typedef SolverBA BA;
559
560} // namespace line
561
562#endif // LINE_SOLVERS_SOLVER_H
The result tables a solver returns.
What a solver observed about the Cache nodes of a model.
The shared surface of every solver, Python's NetworkSolver.
Definition solver.h:123
AvgTable table_
Definition solver.h:212
Matrix< double > avg_respt_chain()
Definition solver.h:157
const SolverOptions & options() const
The options this solver was built with.
Definition solver.h:130
const solvers::CacheMetrics< double > & cache_metrics()
What the same solve observed at each Cache node, the data behind getAvgCacheTable() and getAvgItemTab...
std::vector< double > miss_ratio(const std::string &cache)
cache.getMissRatio() after the solve, with hit_ratio's conventions.
AvgFJTable avg_fj_table()
getAvgFJTable() (aliases getAvgFJT, fjAvgT, aFJT): the same metrics as a labelled table.
const solvers::FjMetrics< double > & avg_fj()
getAvgFJ(): the fork-join section metrics of the same solve, one row per Fork/Join pair (fj_sorted_pa...
solvers::FjMetrics< double > fj_
Definition solver.h:214
const std::string & get_name() const
getName(): the solver's own name, e.g.
Definition solver.h:128
AvgChain avg_chain()
getAvgChain(): the station table of the same solve aggregated by chain, (nstations x nchains).
solvers::CacheMetrics< double > cache_
Definition solver.h:213
AvgMetricTable avg_qlen_table()
getAvgQLenTable(): avg_table()'s Station, JobClass and QLen columns.
Definition solver.h:139
SolverOptions opts_
Definition solver.h:211
std::string method_used()
getMethodUsed(): the method the solve actually resolved to.
AvgSysTable avg_sys_table()
getAvgSysTable(): per-chain system response time and throughput of the same solve.
Matrix< double > avg_residt_chain()
Definition solver.h:158
std::vector< double > avg_sys_tput()
getAvgSysTput(): the per-chain system throughput column of avg_sys_table.
Definition solver.h:150
Matrix< double > avg_qlen_chain()
getAvgQLenChain() and its siblings: one matrix of avg_chain() each.
Definition solver.h:155
const AvgTable & run_analyzer()
runAnalyzer(): force the solve, returning the table it produced.
Definition solver.h:164
AvgMetricTable avg_respt_table()
getAvgRespTTable(): avg_table()'s Station, JobClass and RespT columns.
Definition solver.h:143
AvgMetricTable avg_tput_table()
getAvgTputTable(): avg_table()'s Station, JobClass and Tput columns.
Definition solver.h:145
Network * model_
Definition solver.h:209
std::vector< std::string > list_valid_methods() const
listValidMethods(): the methods this solver advertises on this model.
const AvgTable & avg_table()
getAvgTable(): the average table, solving on first demand.
std::vector< double > hit_ratio(const std::string &cache)
cache.getHitRatio() after the solve: the per-class hit probability at the named Cache,...
virtual ~NetworkSolver()
Definition solver.h:125
AvgMetricTable avg_util_table()
getAvgUtilTable(): avg_table()'s Station, JobClass and Util columns.
Definition solver.h:141
bool is_solved() const
isSolved() / hasResults(): whether a solve has been performed.
Definition solver.h:168
Network & model() const
The model this solver was built on.
Definition solver.h:132
void reset()
reset(): discard the cached solve.
Definition solver.h:170
NetworkSolver(Network &m, const std::string &name, const SolverOptions &o)
Definition solver.h:206
Matrix< double > avg_util_chain()
Definition solver.h:156
AvgFJTable fj_avg_t()
Definition solver.h:203
Matrix< double > avg_arvr_chain()
Definition solver.h:159
Matrix< double > avg_tput_chain()
Definition solver.h:160
AvgChainTable avg_chain_table()
getAvgChainTable(): avg_chain() as a labelled table, one row per (station, chain).
AvgFJTable avg_fjt()
Definition solver.h:202
std::vector< double > avg_sys_respt()
getAvgSysRespT(): the per-chain system response time column of avg_sys_table.
Definition solver.h:148
std::string name_
Definition solver.h:210
A node of the model: the index it was given, and the model that owns it.
Definition nodes.h:59
SolverAUTO (aliases AUTO, SolverAuto, LINE): the solver that picks a solver, a port of matlab/src/sol...
Definition solver.h:472
std::vector< std::string > proposed_solver_names(const std::string &getter="getAvg") const
delegate's retry order for that getter, as facade names; the chosen solver comes first.
static std::vector< std::string > family_names()
familyNames(): the method families, in the order a bare method name is looked up.
std::string choose_solver(const std::string &getter="getAvg") const
chooseSolver(getter): the facade name the configured method picks for that getter.
std::vector< io::Citation > citations() const
citations(): the selection policy's references, none.
Definition solver.h:502
SolverBA ba_solver() const
baSolver(): the SolverBA the bound calls go to, method 'auto' unless a bound method was named.
static std::vector< std::string > metric_groups()
metricGroups(), metricGroupOf(name) and familyMetrics(family).
std::vector< std::string > list_all_methods() const
listAllMethods(): every method name the constructor accepts, independent of the model.
Matrix< double > generator()
Definition solver.h:520
Matrix< double > state_space()
Definition solver.h:519
std::vector< std::vector< CdfCurve > > cdf_respt()
getCdfRespT(), delegated through the 'getCdfRespT' ranking.
static bool supports(Network &model)
supports(model): whether the model uses only features some family declares.
SymbolicSolution symbolic_solution()
Definition solver.h:521
BoundsTable bounds_table()
Definition solver.h:522
std::vector< std::string > candidate_solver_names() const
getCandidateSolverNames(): the facade names of the feasible candidates, in slot order.
SolverNC nc_solver() const
ncSolver(): the SolverNC the normalizing-constant calls go to.
SolverFLD fld_solver() const
fldSolver(): the SolverFLD the fluid-only calls go to.
std::string selected_solver_name()
getSelectedSolverName(): the facade name ("MVA", "FLD", ...) of the delegate that answered the last r...
SolverCTMC ctmc_solver() const
ctmcSolver(): the SolverCTMC the generator and state-space calls go to, with these options.
static std::vector< std::string > family_metrics(const std::string &family)
static std::string metric_group_of(const std::string &name)
static std::vector< std::string > feature_set()
getFeatureSet(): the union of the feature sets of SolverMVA, NC, CTMC, FLD, MAM, SSA,...
std::vector< AutoCandidate > find_solver(const std::string &metric=std::string(), bool show_all=false) const
findSolver(metric, showAll): which (family, method) pairs answer metric on this model.
std::string selected_method()
getSelectedMethod(): the method FAMILY of that delegate, lowercase ("mva", "fld").
bool is_stochastic()
isStochastic(): by the delegate that ran, else whether any candidate is a simulator.
TranAvg tran_avg()
getTranAvg(), delegated through the 'getTranAvg' ranking.
SolverAUTO(Network &m, const SolverOptions &o=SolverOptions())
double prob_aggr(std::size_t node, const std::vector< double > &state)
getProbAggr(node, state), delegated through the 'getProbAggr' ranking.
static std::vector< std::string > selection_intents()
selectionIntents().
bool is_composite() const
isComposite(): false, since this facade holds a flat Network.
Definition solver.h:494
SolverBA: the bounding solver, whose result is a bounds table.
Definition solver.h:431
BoundsTable bounds_table()
getBoundsTable(): the per-class queue-length and throughput bounds.
SolverBA(Network &m, const std::string &method)
Definition solver.h:435
SolverBA(Network &m, const SolverOptions &o=SolverOptions())
Definition solver.h:433
SolverCTMC: the average table plus the chain it was computed from.
Definition solver.h:287
static void print_inf_gen(const Matrix< double > &Q, const Matrix< double > &space)
CTMC.printInfGen(Q, SS): the generator beside the state it belongs to.
Matrix< double > generator()
getGenerator(): the infinitesimal generator over that space.
double prob_aggr(std::size_t node, const std::vector< double > &state)
getProbAggr(node, state): the aggregate marginal of one state.
Matrix< double > state_space()
getStateSpace(): the aggregate state space, one row per state.
FirstPassage cdf_first_passt(const Matrix< double > &A, const Matrix< double > &B, const Matrix< double > &C=Matrix< double >(), const std::vector< double > &tset=std::vector< double >())
getCdfFirstPassT(A, B, C, tset): the FIRST PASSAGE TIME from the state set A into the state set B.
SolverCTMC(Network &m, const SolverOptions &o=SolverOptions())
Definition solver.h:289
SymbolicSolution symbolic_solution()
getSymbolicSolution(): the stationary law over the rate symbols x1..xE.
FirstPassageMoments first_passt_moments(const Matrix< double > &A, const Matrix< double > &B, std::size_t nmax=3, const Matrix< double > &C=Matrix< double >())
getFirstPassTMoments(A, B, nmax, C): moments of order 1..nmax of the same passage,...
std::vector< double > marg_aggr(std::size_t node)
getProbStateAggr(node): the marginal over every state of one station.
std::vector< std::vector< CdfCurve > > cdf_respt()
getCdfRespT(): the response-time CDF per (station, class).
Matrix< double > state_space_aggr()
getStateSpaceAggr(): per-(station, class) job counts of every state, in (ist-1)*K + k column order,...
SolverCTMC(Network &m, const std::string &method)
Definition solver.h:291
SolverFLD: the fluid solver, which also answers a transient.
Definition solver.h:417
SolverFLD(Network &m, const std::string &method)
Definition solver.h:421
std::vector< std::vector< CdfCurve > > cdf_respt()
getCdfRespT(): the response-time CDF per (station, class).
TranAvg tran_avg()
getTranAvg(): the transient mean queue length per station.
SolverFLD(Network &m, const SolverOptions &o=SolverOptions())
Definition solver.h:419
SolverJMT: the Java Modelling Tools client, which also answers a transient, a response-time law,...
Definition solver.h:251
TranAvg tran_avg()
getTranAvg(): E[N](t), averaged over options.config.replications (SolverOptions::replications,...
SolverJMT(Network &m, const SolverOptions &o=SolverOptions())
Definition solver.h:253
SamplePath sample(std::size_t events=0, std::size_t node=0)
sampleSysAggr(events), or sampleAggr(node, events) when node is given: one logged trajectory.
SolverJMT(Network &m, const std::string &method)
Definition solver.h:255
std::vector< std::vector< CdfCurve > > cdf_respt()
getCdfRespT(): the EMPIRICAL response-time CDF per (station, class).
double prob_aggr(std::size_t node, const std::vector< double > &state)
getProbAggr(node, state): the time the declared state is held for.
SolverLDES: the discrete-event simulator, which also answers the empirical response-time law.
Definition solver.h:359
SolverLDES(Network &m, const SolverOptions &o=SolverOptions())
Definition solver.h:361
SolverLDES & init_from_jobs(const Matrix< double > &jobs)
initFromJobs(jobs): start from a job-level initial state, one row per job [station,...
SolverLDES(Network &m, const std::string &method)
Definition solver.h:363
std::vector< std::vector< CdfCurve > > cdf_respt()
getCdfRespT(): the EMPIRICAL response-time CDF per (station, class), from the per-job samples.
const Matrix< double > & job_departures()
The [id, station, class, time] of every departure of a tagged job, from the same run.
const Matrix< double > & final_jobs()
getFinalJobs(): the jobs present at the end of the run, in the init_from_jobs layout.
SolverLDES & init_from_solver(NetworkSolver &aux)
initFromSolver(initSolver): warm-start from an auxiliary solver's steady state.
SolverLDES(Network &m, NetworkSolver &aux, const SolverOptions &o=SolverOptions())
SolverLDES(model, initSolver): warm-started from aux's steady state, see init_from_solver.
Definition solver.h:366
One CTMC state as a state-set predicate sees it, the reference's RewardState: the AGGREGATE row of st...
Definition solver.h:71
double total(std::size_t node) const
s.at(node).total(): jobs of every class at a station node; a handle converts.
const std::vector< double > & row() const
The aggregate row itself.
Definition solver.h:80
double at(std::size_t node, std::size_t cls) const
s.at(node, cls): jobs of class cls (1-based; a handle converts) at a station node.
StateView(const std::vector< double > &row, const qn::NetworkStruct< double > &sn)
Definition solver.h:73
A network plus its refreshed NetworkStruct.
A queueing network under construction.
The routing matrix a model script fills in, MATLAB's P cell array.
Fork-join section metrics: FJQLen, FJRespT and FJTput of every Fork/Join pair.
Bibliographic references for the algorithms a run used.
Dense matrix and non-owning view.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
SolverSSA SSA
Definition solver.h:549
SolverAUTO AUTO
Definition solver.h:555
SolverAUTO SolverAuto
Definition solver.h:556
SolverBA BA
Definition solver.h:558
qn::RoutingMatrix< double > RoutingMatrix
model.init_routing_matrix()'s type, Python's RoutingMatrix.
Definition solver.h:59
SolverMAM MAM
Definition solver.h:552
qn::Network< double > Network
Network as a user names it: the double model, Python's Network.
Definition solver.h:57
SolverFLD FLD
Definition solver.h:550
SolverLDES LDES
Definition solver.h:554
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
SolverAUTO LINE
Definition solver.h:557
SolverNC NC
Definition solver.h:547
SolverFLD SolverFluid
Definition solver.h:551
SolverCTMC CTMC
Definition solver.h:548
std::function< bool(const StateView &)> StatePredicate
A STATE SET named by a predicate, the reference's function-handle form, e.g.
Definition solver.h:93
SolverJMT JMT
Definition solver.h:553
SolverMVA MVA
Definition solver.h:546
LINE_DECLARE_SOLVER(SolverMVA, "MVA")
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
The keyword arguments a solver takes, as one struct.
One row of SolverAUTO::find_solver: a (family, method) pair and whether this model can run it.
Definition solver.h:443
bool runnable
the model passes this method's own support gate
Definition solver.h:446
std::string solver
the method family: "mva", "ctmc", "ldes", ...
Definition solver.h:444
std::string method
the qualified method name to pass, "mva.exact"
Definition solver.h:445
std::string method_class
"exact", "approx", "bound" or "simulation"
Definition solver.h:447
std::string reason
why a refused pair was refused, "" when runnable
Definition solver.h:449
std::string metrics
the measure groups the family answers, comma-joined
Definition solver.h:448
getAvgChainTable: the station table aggregated by CHAIN, one row per (station, chain),...
Definition avg_table.h:144
getAvgChain(): the station x chain matrices, @NetworkSolver/getAvgChain.m's outputs.
Definition solver.h:62
Matrix< double > QN
Definition solver.h:63
Matrix< double > TN
Definition solver.h:63
Matrix< double > RN
Definition solver.h:63
Matrix< double > AN
Definition solver.h:63
Matrix< double > UN
Definition solver.h:63
Matrix< double > WN
Definition solver.h:63
getAvgFJTable(): one row per (Fork/Join pair, class) with a nonzero metric, the fork-join SECTION met...
Definition avg_table.h:162
getAvgQLenTable(), getAvgUtilTable(), getAvgRespTTable(), getAvgTputTable(): the Station and JobClass...
Definition avg_table.h:105
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
std::vector< double > SysTput
Definition avg_table.h:130
getAvgTable, one row per (station, class) that carries a metric.
Definition avg_table.h:38
SolverBA(model, method).getBoundsTable().
Definition avg_table.h:175
getFirstPassTMoments(A, B, nmax, C): [m, mall, p] with the resolved sets.
Definition solver.h:108
Matrix< double > mall
(nstates x nmax), one row per starting state
Definition solver.h:110
std::vector< std::size_t > source
0-based state rows of A; empty = conditional stationary
Definition solver.h:112
std::vector< double > p
(nstates) probability of entering B before C
Definition solver.h:111
std::vector< std::size_t > target
0-based state rows of B
Definition solver.h:113
std::vector< double > m
moments 1..nmax from A (conditional on B before C)
Definition solver.h:109
std::vector< std::size_t > taboo
0-based state rows of C minus B
Definition solver.h:114
getCdfFirstPassT(A, B, C, tset): the curve, the reach probabilities and the resolved sets.
Definition solver.h:96
double tabooprob
probability of entering C before B
Definition solver.h:101
std::vector< std::size_t > taboo
0-based state rows of C minus B
Definition solver.h:104
std::vector< std::size_t > source
0-based state rows of A; empty = conditional stationary
Definition solver.h:102
std::vector< double > t
the grid: the caller's, else 1000 points to the horizon
Definition solver.h:97
double reachprob
probability of entering B (before C)
Definition solver.h:100
std::vector< double > F
F(t), DEFECTIVE under a taboo set.
Definition solver.h:98
std::vector< std::size_t > target
0-based state rows of B
Definition solver.h:103
std::vector< double > f
the density at t
Definition solver.h:99
sampleSysAggr / sampleAggr: ONE simulated trajectory, not a mean.
Definition avg_table.h:218
The knobs a solver reads; a negative or empty field keeps the engine default.
getSymbolicSolution: the stationary law as a function of the rate symbols.
Definition avg_table.h:194
getTranAvg: the transient mean queue length per (station, class).
Definition avg_table.h:204
Every Cache node of the model, in node order; empty on a model with none.
self.result.FJ: one row per Fork/Join pair, one column per class.
Definition fj_metrics.h:43