LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fluid_runner.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_FLUID_FLUID_RUNNER_H
6#define LINE_SOLVERS_FLUID_FLUID_RUNNER_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * The fluid solver's outermost entry point: `@@SolverFLD/runAnalyzer.m`'s method
12 * resolution over `solver_fluid_analyzer.m`'s dispatch.
13 *
14 * WHY THIS IS A SEPARATE HEADER AND NOT ANOTHER BRANCH IN `fluid_dispatch`.
15 * Three of the reference's branches are ports that sit ABOVE `solver_fluid.h`
16 * and include it -- `solver_fluid_closing.m` (fluid_closing.h),
17 * `solver_fld_cacheqn_analyzer.m` (fluid_cacheqn.h) and
18 * `@@SolverFLD/exportODEs.m` (fluid_export_odes.h). A dispatcher inside
19 * `solver_fluid.h` therefore cannot call them without a cyclic include, and
20 * lowering them into it would put three unrelated solvers in one file. The
21 * routing goes here instead, in the one place that may include all four, which
22 * is also the pattern the CTMC, MAM, MVA, NC and SSA runners follow.
23 *
24 * WHAT `fluid_dispatch` STILL REFUSES, and why that is not a duplicate gate.
25 * It cannot see the cache analyzer, so a Cache model reaching it directly is
26 * refused BY NAME rather than solved by the wrong method; the refusal names
27 * this header as the entry point that does route it. Both are true statements
28 * about the function that carries them.
29 *
30 * THE CORRECTION IS APPLIED ONCE, HERE. `solver_fluid_analyzer.m` runs its
31 * utilization and response-time correction after the method switch and on every
32 * branch alike, and the per-method functions it calls return the uncorrected
33 * table for exactly that reason. `solver_fluid` is itself that switch plus the
34 * correction, so the branches routed around it are corrected here and the ones
35 * routed through it are not corrected twice.
36 */
37
38#include <cstddef>
39#include <limits>
40#include <cmath>
41#include <algorithm>
42#include <vector>
43#include <exception>
44#include <string>
45
66#include "line/util/error.h"
68
69namespace line {
70namespace fluid {
71
72/**
73 * Port of `SolverFLD.listValidMethods`.
74 *
75 * Every method the dispatch below accepts, INCLUDING the `fld.`-qualified
76 * spelling of each: the reference's own dispatch took `fld.tbi`, `fld.dae`
77 * and six more while its list named none of them, and native python listed the
78 * whole set, so the three lists disagreed. `aoi` (the MFQ age-of-information
79 * reading) is an alias of `mfq`.
80 */
81inline std::vector<std::string> fluid_list_valid_methods() {
82 // the names and their order are this solver's row of the method registry (doc/line-methods.json)
83 return ::line::method_registry::methods("FLD");
84}
85
86/** Port of `runAnalyzerChecks`' method gate: an unlisted method is refused. */
87inline void fluid_check_method(const std::string& method) {
88 const std::vector<std::string> valid = fluid_list_valid_methods();
89 if (std::find(valid.begin(), valid.end(), method) != valid.end()) return;
90 throw UnsupportedError(ErrorKind{"Method"}, "SolverFLD: the '" + method + "' method is unsupported by this solver");
91}
92
93
94namespace detail {
95
96/** `sn.nodetype == NodeType.Cache`, which is what selects `rmf`. */
97template <class T>
98bool fluid_has_cache(const qn::NetworkStruct<T>& sn) {
99 for (const qn::NodeDef& nd : sn.nodes)
100 if (nd.nodetype == qn::NodeType::Cache) return true;
101 return false;
102}
103
104/** A DPS station, which the matrix method cannot express. */
105template <class T>
106bool fluid_has_dps(const qn::NetworkStruct<T>& sn) {
107 for (const auto& st : sn.stations)
108 if (st.sched == lang::SchedStrategy::DPS) return true;
109 return false;
110}
111
112/**
113 * The method name without its `fld.` prefix, which names the same method.
114 *
115 * `aoi` is folded onto `mfq` here for the same reason: it names the MFQ
116 * branch's age-of-information reading rather than a method of its own, which
117 * is how native python spells it and how
118 * `@@SolverFLD/getAvgAoI` reaches it (it requires method='mfq').
119 */
120inline std::string fluid_unqualify(const std::string& method) {
121 std::string m = method;
122 if (m.size() > 4 && m.compare(0, 4, "fld.") == 0) m = m.substr(4);
123 if (m == "aoi") return "mfq";
124 return m;
125}
126
127/**
128 * Port of `fluid_minnormal_applicable.m`: whether the moment closure can answer
129 * this model, which is what `default` consults before preferring it.
130 *
131 * THE TEST IS STATIC. It inspects the model and the options, never the solution,
132 * so a feature the model DECLARES is decided here and only here. The one
133 * condition that cannot be static is a NON-HYPERBOLIC fixed point (balanced
134 * bottlenecks, a saturated multiclass station, an overloaded open station): it
135 * exists only once the mean is solved, `fluid_lyapunov` raises
136 * FluidNonHyperbolicError on it, and the runner switches `minnormal` -- resolved
137 * or requested -- to a first-order method on that exception alone, since the
138 * closure has no stationary covariance either way and the mean is still
139 * available.
140 *
141 * Every condition below mirrors a refusal that `fluid_moment_terms` or
142 * `solver_fluid_moments` would otherwise raise, so this function and those
143 * refusals must move together.
144 */
145template <class T>
146bool fluid_minnormal_applicable(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
147 std::string& reason) {
148 const std::size_t M = sn.nstations, K = sn.nclasses;
149 const FluidLayout L = fluid_layout(sn);
150
151 // Open and mixed models are supported: the covariance projects the EXT source
152 // pool out. What it cannot take is a NON-POISSON arrival stream, whose source
153 // coordinates track the phase of a single arrival process, not a population.
154 for (std::size_t i = 0; i < M; ++i) {
155 if (sn.stations[i].sched != lang::SchedStrategy::EXT) continue;
156 for (std::size_t r = 0; r < K; ++r)
157 if (L.kic[i][r] > 1) {
158 reason = "class " + std::to_string(r + 1) + " has a " +
159 std::to_string(L.kic[i][r]) + "-phase (non-Poisson) arrival process";
160 return false;
161 }
162 }
163 // A cache model is answered through the decomposition analyzer, with the
164 // closure in its network step, so cache nodes no longer decline the method.
165 // What still declines is a replacement strategy with no drift-based fluid
166 // model, mirroring the runtime gate in `fluid_cacheqn_gate`: LRU, HLRU,
167 // CLIMB and QLRU are answered by a characteristic-time fixed point, which is
168 // not a fluid method and has no covariance.
169 for (std::size_t nd = 0; nd < sn.nodes.size(); ++nd) {
170 if (sn.nodes[nd].nodetype != qn::NodeType::Cache) continue;
171 const std::size_t key = nd + 1; // nodeparam is keyed 1-based
172 if (sn.nodeparam.count(key) == 0) {
173 reason = "a cache uses a replacement strategy with no drift-based fluid model";
174 return false;
175 }
176 const lang::ReplacementStrategy rs = sn.nodeparam.at(key).replacestrat;
179 reason = "a cache uses a replacement strategy with no drift-based fluid model";
180 return false;
181 }
182 }
183 // The disciplines with a branch in `ode_rates_closing_factors`; anything else
184 // falls through to g = x, i.e. an infinite server.
185 for (std::size_t i = 0; i < M; ++i) {
186 const lang::SchedStrategy s = sn.stations[i].sched;
187 const bool ok = s == lang::SchedStrategy::INF || s == lang::SchedStrategy::EXT ||
190 if (!ok) {
191 reason = "station " + std::to_string(i + 1) + " uses " + lang::sched_to_text(s) +
192 ", which has no fluid drift branch";
193 return false;
194 }
195 }
196 // The Lyapunov solve is cubic in the phase-resolved state, so the same cap
197 // `solver_fluid_moments` enforces decides selection rather than being hit
198 // later.
199 if (L.nstates > opt.moment_maxstate) {
200 reason = "the phase-resolved state has " + std::to_string(L.nstates) +
201 " coordinates, above the moment_maxstate limit of " +
202 std::to_string(opt.moment_maxstate);
203 return false;
204 }
205 // The moment methods need an autonomous drift.
206 // `fluid_minnormal_applicable.m:99`: a time-varying rate multiplier makes the
207 // drift non-autonomous, so there is no stationary covariance to solve for and
208 // `default` must resolve to a first-order method instead.
209 if (fluid_has_time_varying_rates(opt)) {
210 reason = "a rate schedule (nhpp_sched / rate_traj / rate_sched) makes the drift "
211 "time-varying";
212 return false;
213 }
214 reason.clear();
215 return true;
216}
217
218/**
219 * Port of `fluid_dae_applicable.m`: whether the differential-algebraic route can
220 * answer this model, which is what the fallback ladder consults before trying
221 * `dae` on a declined `minnormal`.
222 *
223 * WHY THIS EXISTS SEPARATELY FROM `fluid_minnormal_applicable`. The two methods
224 * state the SAME closure and differ only in how the coupled equations are
225 * discharged, so a model `minnormal` accepts is almost always one `dae` accepts
226 * too. Almost: `dae` carries a finite-difference Jacobian over the whole unknown
227 * vector rather than one Lyapunov solve, so its state cap is lower; it closes on
228 * the per-station variance only, so DPS and GPS are out; and it has no
229 * decomposition route, so a cache model is out. Those three are exactly the
230 * difference set, and naming them here keeps the ladder from entering a rung
231 * that would refuse the model a moment later.
232 *
233 * The test is STATIC, for the same reason the min-normal one is. The one
234 * condition that cannot be static is the NON-HYPERBOLIC fixed point the ladder
235 * exists to route around -- it exists only once the mean is solved -- and `dae`
236 * fails on it loudly, which is what moves the ladder to its last rung.
237 *
238 * Every condition below mirrors a refusal `solver_fluid_dae` would otherwise
239 * raise, so this function and those refusals must move together.
240 */
241template <class T>
242bool fluid_dae_applicable(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
243 std::string& reason,
244 const FluidDaeOptions& dopt_in = FluidDaeOptions()) {
245 const FluidDaeOptions dopt = fluid_dae_options(opt, dopt_in);
246 const std::size_t M = sn.nstations;
247 const FluidLayout L = fluid_layout(sn);
248
249 // A cache model is a DECOMPOSITION, and `dae` has no arm for it: `minnormal`
250 // on a cache model routes through `solver_fld_cacheqn_analyzer` with the
251 // closure in its network step, while this route would read the cache nodes as
252 // ordinary stations -- a decomposition has no single drift for the algebraic
253 // constraint to attach to.
254 if (fluid_has_cache(sn)) {
255 reason = "a cache model is answered by the decomposition analyzer, which has no dae route";
256 return false;
257 }
258 // The DPS and GPS shares close on the covariance BETWEEN station coordinates,
259 // not on the station total, so their closure state is a matrix block rather
260 // than the scalar the Newton vector carries. Mirrors the `solver_fluid_dae`
261 // refusal.
262 for (std::size_t i = 0; i < M; ++i) {
263 const lang::SchedStrategy s = sn.stations[i].sched;
265 reason = "station " + std::to_string(i + 1) + " uses " + lang::sched_to_text(s) +
266 ", whose share closes on the covariance between its class coordinates "
267 "rather than on the station variance";
268 return false;
269 }
270 }
271 // The simultaneous solve is quartic overall, against the cubic of one Lyapunov
272 // solve, so its crossover is lower than the 200 `minnormal` permits and it
273 // carries its own cap. Same count the min-normal test forms, so the two limits
274 // are read on the same scale.
275 if (L.nstates > dopt.maxstate) {
276 reason = "the phase-resolved state has " + std::to_string(L.nstates) +
277 " coordinates, above the dae_maxstate limit of " +
278 std::to_string(dopt.maxstate);
279 return false;
280 }
281 reason.clear();
282 return true;
283}
284
285/**
286 * Port of `fluid_resolve_default_method.m`: what `default` stands for on THIS
287 * model.
288 *
289 * Preference order: `rmf` for a cache model, then `minnormal` wherever
290 * `fluid_minnormal_applicable` accepts the model, then the historical choice of
291 * `closing` for DPS and `matrix` otherwise. The second-order closure dominates
292 * the first-order methods on every family measured against the exact CTMC and is
293 * the only method that can represent GPS at all, so it is preferred wherever it
294 * applies.
295 *
296 * THIS RUNS BEFORE THE FEATURE GATE, NOT INSIDE THE DISPATCH SWITCH. The gate
297 * validates `fluid_feature_set(method)`, and `default` is not `minnormal`, so
298 * resolving later would let the gate reject a GPS model that the resolved method
299 * supports. Keeping the decision in one function is what stops the gate and the
300 * dispatch from disagreeing.
301 */
302template <class T>
303std::string fluid_resolve_method(const qn::NetworkStruct<T>& sn, const std::string& method,
304 const FluidOptions& opt, std::string& reason) {
305 const std::string m = fluid_unqualify(method);
306 reason.clear();
307 // `rmf` and `refined` are public aliases. Cache models select the
308 // cache/network RMF decomposition; all other models select `ddpp`, the
309 // refined mean field of the matrix drift. The min-normal hybrid that
310 // `refined` used to name is `mnrefined`.
311 if (m == "rmf" || m == "refined") {
312 if (fluid_has_cache(sn)) {
313 reason = "the model has cache nodes";
314 return "rmf";
315 }
316 reason = "the model has no cache nodes";
317 return "ddpp";
318 }
319 // `mfq` (and `aoi`, folded onto it above) RESOLVES TO `matrix` off the shape
320 // `fluid_mfq_admits` accepts, as in `SolverFLD.resolveMethod`: the
321 // analyzer's documented fallback, stated before the gate so the gate checks
322 // and the result names the method that answers.
323 if (m == "mfq") {
324 const FluidMfqAdmits adm = fluid_mfq_admits(sn);
325 if (!adm.ok) {
326 reason = adm.reason;
327 return "matrix";
328 }
329 return m;
330 }
331 if (m != "default") return m;
332 if (fluid_has_cache(sn)) {
333 reason = "the model has cache nodes";
334 return "rmf";
335 }
336 // A BINDING BUFFER OR A CAPACITY REGION ALSO HAS ONE FLUID ROUTE, for the
337 // same reason a Petri net does: nothing else in the fluid tree reads the cap,
338 // the per-class cap or the region limit, so every other method integrates the
339 // capped station as an unbounded one -- which is why
340 // `fluid_check_finite_capacity` refuses them. Resolving `default` to one of
341 // those turned a model this solver CAN answer into an error whose advice was
342 // to type the very method the resolution should have picked. The capacity
343 // test is the gate's own (`binding_capacity_reason`), so the two cannot
344 // disagree, and where the DAE route declines the fall-through leaves the
345 // refusal to the gate, which names the blocking feature.
346 if (!sn.regions.empty() || qn::has_binding_capacity(sn)) {
347 std::string dae_why;
348 if (fluid_dae_applicable(sn, opt, dae_why)) {
349 reason = sn.regions.empty() ? "the model has a binding finite buffer"
350 : "the model has a finite capacity region";
351 return "dae";
352 }
353 }
354 if (fluid_minnormal_applicable(sn, opt, reason)) return "minnormal";
355 return fluid_has_dps(sn) ? "closing" : "matrix";
356}
357
358/** The same, for a caller with no interest in why `minnormal` was declined. */
359template <class T>
360std::string fluid_resolve_method(const qn::NetworkStruct<T>& sn, const std::string& method,
361 const FluidOptions& opt = FluidOptions()) {
362 std::string reason;
363 return fluid_resolve_method(sn, method, opt, reason);
364}
365
366/**
367 * The feature envelope of METHOD on this model: `qn::fluid_feature_set` of the
368 * name the public aliases resolve to. `fluid_feature_set` is model-free, so it
369 * reads `rmf` as the cache decomposition; on a cache-free model `rmf` and
370 * `refined` run as `ddpp` and must carry ddpp's envelope (no Fork, closed
371 * only). Port of the alias step in JAR `SolverFluid.getMethodFeatureSet` and
372 * Python `SolverFLD.getMethodFeatureSet`.
373 */
374template <class T>
375qn::FeatureSet fluid_method_feature_set(const qn::NetworkStruct<T>& sn, const std::string& method) {
376 const std::string m = fluid_unqualify(method);
377 if (m == "rmf" || m == "refined") return qn::fluid_feature_set(fluid_has_cache(sn) ? "rmf" : "ddpp");
378 return qn::fluid_feature_set(method);
379}
380
381/**
382 * `@@SolverFLD/runAnalyzer.m:169-175`: limited load dependence is honoured only by
383 * the closing family, whose drift multiplies the scheduling share by alpha(n_i).
384 *
385 * The C++ featset DOES emit LoadDependence from the model (unlike MATLAB's
386 * getUsedLangFeatures, which is why the reference has to refuse here explicitly),
387 * so this is the same refusal reached one step earlier -- kept as its own check
388 * because `solver_fluid` is callable without the gate.
389 */
390template <class T>
391void fluid_check_load_dependence(const qn::NetworkStruct<T>& sn, const std::string& m) {
392 if (m == "closing" || m == "minnormal" || m == "mnrefined" || m == "dae") return;
393 for (std::size_t i = 0; i < sn.stations.size(); ++i)
394 for (std::size_t k = 0; k < sn.stations[i].lldscaling.size(); ++k)
395 if (std::fabs(num_traits<T>::to_double(sn.stations[i].lldscaling[k]) - 1.0) >
397 throw UnsupportedError(ErrorKind{"LoadDependence"},
398 "solver_fluid_run_analyzer: this model uses load dependence (setLoadDependence), which "
399 "the '" +
400 m +
401 "' method does not evaluate. Use method 'closing' for the mean-field answer, or "
402 "'minnormal'/'mnrefined' for the moment-closure correction");
403}
404
405/**
406 * Can `m` run the fluid fork-join fixed point on this model?
407 *
408 * A fork-join model is not integrated as one drift: `fj_fork_join_transform`
409 * replaces the fork by auxiliary OPEN classes arriving at a Source it adds,
410 * CLOSED MODEL OR NOT (ModelAdapter.mmt in the reference), and the answer is
411 * the fixed point of solving that mixed model repeatedly. A method refused on a
412 * mixed network is therefore refused here by name, on ANY fork model: `softmin`
413 * and `statedep` have no EXT branch, `mnrefined` and `tbi` are closed-only, and
414 * on an OPEN model the DAE form has no unknowns for the auxiliary classes.
415 * Mirrors `fluid_forkjoin_admits.m`. This predicate used to name only the dae
416 * rule, so mnrefined, statedep and tbi ran the closed fork-join and answered
417 * with 53-59% error against the exact CTMC where the reference refuses.
418 *
419 * ASKED AS A PREDICATE so that a REPORT can reach the rule too: Fork and
420 * OpenClass are both declared names, so a feature set cannot state a rule that
421 * is their CONJUNCTION.
422 *
423 * @param sn the refreshed struct of the model
424 * @param m the resolved method name
425 * @return an empty string when the method may run the fixed point here
426 */
427template <class T>
428std::string fluid_forkjoin_supports(const qn::NetworkStruct<T>& sn, const std::string& method) {
429 if (!sn.has_fork()) return std::string();
430 const std::string m = fluid_unqualify(method);
431 if (m == "softmin" || m == "statedep")
432 return "solver_fluid_run_analyzer: the " + m + " method has no route through the fork-join "
433 "fixed point: the transform hands the inner solve a mixed network with a Source, "
434 "and its ODE has no branch for one (it refuses open models). Use method 'closing'";
435 if (m == "mnrefined")
436 return "solver_fluid_run_analyzer: the mnrefined method has no route through the fork-join "
437 "fixed point: the transform hands the inner solve a mixed network, and mnrefined is "
438 "a closed-model method. Use method 'minnormal', the same closure without the 1/N term";
439 if (m == "tbi")
440 return "solver_fluid_run_analyzer: the tbi method has no route through the fork-join fixed "
441 "point: the transform hands the inner solve a mixed network with a Source, and tbi "
442 "refuses open classes. Use method 'closing'";
443 if (m != "dae") return std::string();
444 bool any_open = false;
445 for (std::size_t r = 0; r < sn.classes.size(); ++r)
446 if (!std::isfinite(sn.classes[r].population)) any_open = true;
447 if (!any_open) return std::string();
448 return "solver_fluid_run_analyzer: the dae method has no route through the fork-join fixed "
449 "point on an OPEN model: the transform hands the inner solve a mixed network whose "
450 "auxiliary open classes the DAE form carries no unknowns for. Use method 'minnormal', "
451 "which is the same closure and does run that fixed point";
452}
453
454/**
455 * `@@SolverFLD/runAnalyzer.m:159-183`: the two limits of the DAE route that the
456 * feature gate cannot express, refused before the Newton solve so the message
457 * names the model feature rather than surfacing from inside it.
458 *
459 * A CACHE MODEL is a decomposition, not one system: the caches are solved in
460 * isolation and the network with them relabeled as class switches, so there is
461 * no single drift for the constraint to be attached to. `minnormal` and `rmf`
462 * reach `solver_fld_cacheqn_analyzer`, which carries the closure inside its
463 * network step; no such route exists for the DAE form. Cache IS declared in the
464 * fluid featset -- for those two methods -- so the gate passes it and this is
465 * the only place the distinction can be drawn.
466 *
467 * DPS and GPS are NOT repeated here: the per-method featset already unsets both
468 * for `dae` (solver_feature_sets.h), so the gate refuses them one step earlier
469 * and by feature name, which is the finer message of the two.
470 */
471template <class T>
472void fluid_check_dae(const qn::NetworkStruct<T>& sn, const std::string& m) {
473 if (m != "dae") return;
474 if (fluid_has_cache(sn))
475 throw UnsupportedError(ErrorKind{"Cache"},
476 "solver_fluid_run_analyzer: the dae method does not support caching stations: a cache model is "
477 "solved by decomposition, so it has no single drift to constrain. Use "
478 "method 'minnormal' for the same closure, or 'rmf'");
479 const std::string fj = fluid_forkjoin_supports(sn, m);
480 if (!fj.empty()) throw UnsupportedError(ErrorKind{"Fork"}, fj);
481}
482
483/**
484 * The structural finite-buffer gate `@@SolverFLD/runAnalyzer.m` applies, which
485 * this port did not carry: nothing in the fluid tree reads `sn.cap` or
486 * `sn.classcap`, so a capped station was integrated as an unbounded one and the
487 * table reported more jobs in the buffer than the buffer holds.
488 *
489 * `dae` carries the buffer as an algebraic constraint on the drift, and `mol` is
490 * stated for the Mt/G/s/0 LOSS system, where the server count IS the buffer: for
491 * those two a finite capacity is the model rather than something ignored. Every
492 * other method keeps the guard. There is no feature-registry name for plain
493 * capacity, hence the structural test -- `SolverMVA`, `SolverNC` and `SolverAG`
494 * gate the same way, through the same `check_binding_capacity`.
495 *
496 * `m` is the RESOLVED method, as the reference's gate receives it.
497 */
498template <class T>
499void fluid_check_finite_capacity(const qn::NetworkStruct<T>& sn, const std::string& m) {
500 if (m == "dae" || m == "fld.dae" || m == "mol" || m == "fld.mol") return;
501 // The AoI arm of `mfq` is stated for the capacity-1/2 queue, so there the cap is the model (`fluid_method_refusal.m`).
502 if ((m == "mfq" || m == "fld.mfq" || m == "aoi" || m == "fld.aoi") && aoi_is_aoi(sn).ok) return;
503 qn::check_binding_capacity("SolverFLD", sn);
504}
505
506} // namespace detail
507
508/**
509 * Port of `@@SolverFLD/runAnalyzer.m`: resolve the method, route to the function
510 * the reference routes to, correct once.
511 *
512 * This is what a host should call. `solver_fluid` remains the port of
513 * `solver_fluid_analyzer.m` alone and stays reachable for a caller that wants
514 * one named method and no model-dependent resolution.
515 *
516 * `sn_out`, when given, receives `result.solverSpecific.sn`: the struct the
517 * returned table was integrated on, which the FCFS refit may have re-fitted to
518 * a different phase count. Anything that reads `FluidSolution::xvec` afterwards
519 * must be handed THAT struct, because the vector is laid out by its phases.
520 *
521 * `refreshed_out`, when given, receives the cache decomposition's own struct:
522 * the base one with the cache self-switch renormalized at the CONVERGED hit and
523 * miss split. It is DELIBERATELY NOT `sn_out`: that one is the inner, relabeled
524 * struct the ODE ran on and it lays out `xvec`, whereas this one is the caller's
525 * own topology carrying a solved quantity. Left untouched on every model with no
526 * cache, and on the cache branches that report no split.
527 *
528 * `cache_out`, when given, receives the SAME split as a `CacheMetrics`, which is
529 * the form every other solver states it in (`mva::AvgResult::cache`). The
530 * refreshed struct alone is not enough for a caller: a host that solves through
531 * the CLI reads the hit and miss fractions back onto its own Cache node from
532 * that block, and MATLAB's `CPPLINE.restoreCacheResults` CLEARS the node when it
533 * is absent -- which is how `-s fluid` came to report link()'s offered 1/2-1/2
534 * on cache_replc_rr for a split it had converged to 0.5623/0.4377.
535 */
536template <class T>
537FluidSolution solver_fluid_run_analyzer(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
538 qn::NetworkStruct<T>* sn_out = nullptr,
539 qn::NetworkStruct<T>* refreshed_out = nullptr,
540 solvers::CacheMetrics<T>* cache_out = nullptr,
541 const qn::NetworkStruct<T>* gate_sn = nullptr);
542
543namespace detail {
544
545/**
546 * `@@SolverFLD/fldDispatch.m`: one inner solve of the fixed point, as an
547 * `mva::MvaSolution`.
548 *
549 * The driver is `mva::fj_fixed_point`, the one MVA and NC drive; it speaks
550 * MvaSolution, so the fluid table is carried into that shape here rather than
551 * a second fork-join loop being written for the fluid solver. Nothing else is
552 * fluid-specific: the transform emits Source, Delay, Queue, Router and
553 * ClassSwitch, all of which the drift already carries.
554 */
555template <class T>
556mva::MvaSolution<T> fluid_as_mva_solution(const FluidSolution& f) {
557 mva::MvaSolution<T> s;
558 const std::size_t M = f.QN.rows(), K = f.QN.cols();
559 const T zero = num_traits<T>::from_int(0);
560 s.Q = Matrix<T>(M, K, zero);
561 s.U = Matrix<T>(M, K, zero);
562 s.R = Matrix<T>(M, K, zero);
563 s.Tp = Matrix<T>(M, K, zero);
564 for (std::size_t i = 0; i < M; ++i)
565 for (std::size_t k = 0; k < K; ++k) {
566 s.Q(i, k) = num_traits<T>::from_double(f.QN(i, k));
567 s.U(i, k) = num_traits<T>::from_double(f.UN(i, k));
568 s.R(i, k) = num_traits<T>::from_double(f.RN(i, k));
569 s.Tp(i, k) = num_traits<T>::from_double(f.TN(i, k));
570 }
571 s.C.reserve(f.CN.size());
572 for (double v : f.CN) s.C.push_back(num_traits<T>::from_double(v));
573 s.X.reserve(f.XN.size());
574 for (double v : f.XN) s.X.push_back(num_traits<T>::from_double(v));
575 s.method = f.method;
576 s.iter = static_cast<int>(f.iters);
577 // The fluid solver produces no normalizing constant; the reference leaves it
578 // at zero rather than fabricating one.
579 s.lG = 0.0;
580 return s;
581}
582
583/** The merged fork-join table, back in the fluid solver's own result shape. */
584template <class T>
585FluidSolution fluid_from_mva_solution(const mva::MvaSolution<T>& s, const std::string& method) {
586 FluidSolution f;
587 const std::size_t M = s.Q.rows(), K = s.Q.cols();
588 f.QN = Matrix<double>(M, K, 0.0);
589 f.UN = Matrix<double>(M, K, 0.0);
590 f.RN = Matrix<double>(M, K, 0.0);
591 f.TN = Matrix<double>(M, K, 0.0);
592 for (std::size_t i = 0; i < M; ++i)
593 for (std::size_t k = 0; k < K; ++k) {
594 f.QN(i, k) = num_traits<T>::to_double(s.Q(i, k));
595 f.UN(i, k) = num_traits<T>::to_double(s.U(i, k));
596 f.RN(i, k) = num_traits<T>::to_double(s.R(i, k));
597 f.TN(i, k) = num_traits<T>::to_double(s.Tp(i, k));
598 }
599 f.CN.reserve(s.C.size());
600 for (const T& v : s.C) f.CN.push_back(num_traits<T>::to_double(v));
601 f.XN.reserve(s.X.size());
602 for (const T& v : s.X) f.XN.push_back(num_traits<T>::to_double(v));
603 f.iters = static_cast<std::size_t>(s.iter < 0 ? 0 : s.iter);
604 f.method = method;
605 return f;
606}
607
608/** The leading `M` station rows of a metric matrix. */
609inline Matrix<double> fluid_leading_rows(const Matrix<double>& m, std::size_t M) {
610 if (m.rows() <= M) return m;
611 Matrix<double> out(M, m.cols(), 0.0);
612 for (std::size_t i = 0; i < M; ++i)
613 for (std::size_t k = 0; k < m.cols(); ++k) out(i, k) = m(i, k);
614 return out;
615}
616
617/** `solver_fluid_run_analyzer` without the overload marking; defined below it. */
618template <class T>
619FluidSolution solver_fluid_run_analyzer_core(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
620 qn::NetworkStruct<T>* sn_out,
621 qn::NetworkStruct<T>* refreshed_out,
622 solvers::CacheMetrics<T>* cache_out,
623 const qn::NetworkStruct<T>* gate_sn);
624
625/**
626 * The fork-join arm of `solver_fluid_run_analyzer`.
627 *
628 * Only the steady-state means are produced. The transient tables are indexed by
629 * the ORIGINAL stations and classes, whereas each pass integrates a DIFFERENT
630 * transformed network, so a trajectory read off the last pass would not be the
631 * trajectory of the model the caller built; `xvec` is left empty for the same
632 * reason, which is what makes the passage-time and transient entry points
633 * decline a fork-join model rather than answer it from the wrong state.
634 */
635template <class T>
636FluidSolution fluid_fork_join_run(const qn::NetworkStruct<T>& sn, const FluidOptions& opt) {
637 mva::FjMmt<T> tr = mva::fj_fork_join_transform(sn, opt.fork_join);
638 std::vector<T> lam(tr.V.classes.size() + 1,
639 num_traits<T>::from_double(lang::GlobalConstants::FineTol));
640 mva::MvaOptions mopt;
641 mopt.method = opt.method;
642 mopt.tol = opt.tol;
643 // FluidOptions.iter_tol = 0 means "run the PASS loop to iter_max", but the
644 // fork-join loop tests it as fjFixedPoint.m does, where 0 can never pass the
645 // mixed abs/rel test: every fork-join run then exhausted iter_max (BUG-100).
646 // The sentinel therefore maps to the reference's SolverOptions iter_tol.
647 mopt.iter_tol = opt.iter_tol > 0.0 ? opt.iter_tol : 1e-4;
648 mopt.iter_max = opt.iter_max;
649 mopt.fork_join = opt.fork_join;
650 mopt.base_has_fork = true;
651 FluidOptions inner = opt;
652 std::string fjw;
653 const mva::MvaSolution<T> merged =
654 mva::fj_fixed_point(sn, tr, lam, mopt, [&inner](qn::NetworkStruct<T>& V) {
655 // The UNMARKED core, as the reference's inner solve is fldDispatch:
656 // fluid_mark_overloaded runs at the end of runAnalyzer only, which
657 // the fork-join branch returns before. Marking here turned a
658 // saturated auxiliary class's RespT into +inf, the branch times
659 // then dropped out of fj_ordstat_exp and its quorum exceeded n.
660 return fluid_as_mva_solution<T>(
661 solver_fluid_run_analyzer_core<T>(V, inner, nullptr, nullptr, nullptr, nullptr));
662 }, &fjw);
663 FluidSolution out = fluid_from_mva_solution<T>(merged, opt.method);
664 out.warning = fjw;
665 out.fj = solvers::fj_metrics_to_double(merged.fj); // fork-join section metrics
666 // The driver drops the auxiliary CLASS columns but not the transform's own
667 // STATION row: it appends a Source to carry the auxiliary arrivals, and the
668 // base stations are the prefix of that list. `solver_mva_run_analyzer` trims it in
669 // `filter_metric` against the base struct; this entry point returns the
670 // table directly, so it trims here.
671 out.QN = detail::fluid_leading_rows(out.QN, sn.nstations);
672 out.UN = detail::fluid_leading_rows(out.UN, sn.nstations);
673 out.RN = detail::fluid_leading_rows(out.RN, sn.nstations);
674 out.TN = detail::fluid_leading_rows(out.TN, sn.nstations);
675 // getAvgHandles.m disables the Util handle at a Join: the transform serves it
676 // as an infinite server, whose utilization would restate its queue length.
677 // The MVA arm applies that through filter_metric; this path returns the
678 // table directly, so it applies it here (BUG-100: Join Util read 3.43).
679 for (std::size_t i = 0; i < sn.nstations && i < out.UN.rows(); ++i)
680 if (sn.stations[i].nodetype == qn::NodeType::Join)
681 for (std::size_t k = 0; k < out.UN.cols(); ++k) out.UN(i, k) = 0.0;
682 return out;
683}
684
685} // namespace detail
686
687namespace detail {
688
689/** Whether the model holds a Transition node, i.e. is a stochastic Petri net. */
690template <class T>
691inline bool fluid_is_petri_net(const qn::NetworkStruct<T>& sn) {
692 for (std::size_t i = 0; i < sn.nodes.size(); ++i)
693 if (sn.nodes[i].nodetype == lang::NodeType::Transition) return true;
694 return false;
695}
696
697/**
698 * The 'dae' method's Petri arm.
699 *
700 * 'dae' is the ONLY fluid method that can carry a net: the P-invariants, the
701 * firing flow of an immediate transition and a bounded place are all EQUATIONS,
702 * and the other methods have nowhere to put them. A method named explicitly is
703 * therefore checked rather than silently redirected, so a caller who asked for
704 * 'closing' on a net is told why it cannot answer.
705 */
706template <class T>
707inline FluidSolution fluid_petri_run(const qn::NetworkStruct<T>& sn, const FluidOptions& opt) {
708 const std::string m = (opt.method.rfind("fld.", 0) == 0) ? opt.method.substr(4) : opt.method;
709 if (!(m == "default" || m == "dae"))
710 throw UnsupportedError(ErrorKind{"Place"},
711 "SolverFluid: method '" + opt.method +
712 "' cannot solve a Petri net: its conserved quantities are P-invariants rather than "
713 "chain populations, an immediate transition is an algebraic FLOW rather than an "
714 "event with a rate, and a bounded place is a linear inequality on the marking. Only "
715 "'dae' states those as equations; every other fluid method builds its drift from the "
716 "station/class/phase encoding, where a Place contributes no coordinate at all, and "
717 "would integrate the net as an empty model and report zeros without a warning");
718 petri::PetriOptions po;
719 if (opt.dae_maxstate > 0) po.dae_maxstate = opt.dae_maxstate;
720 po.fluid_boundary = opt.fluid_boundary;
721 const petri::PetriSolution ps = petri::solver_fluid_petri(sn, po);
722 FluidSolution out;
723 out.QN = ps.QN;
724 out.UN = ps.UN;
725 out.RN = ps.RN;
726 out.TN = ps.TN;
727 out.xvec = ps.x;
728 out.iters = ps.iters;
729 out.method = "dae";
730 const std::size_t M = ps.QN.rows(), K = ps.QN.cols();
731 out.CN.assign(K, 0.0);
732 out.XN.assign(K, 0.0);
733 for (std::size_t k = 0; k < K; ++k) {
734 double q = 0.0, x = 0.0;
735 for (std::size_t i = 0; i < M; ++i) {
736 q += ps.QN(i, k);
737 x = std::max(x, ps.TN(i, k));
738 }
739 out.XN[k] = x;
740 out.CN[k] = (x > 1e-14) ? q / x : 0.0;
741 }
742 // The marking covariance of the linear noise approximation: the second
743 // moment no other solver of a Petri net in LINE returns.
744 out.has_moments = true;
745 out.moments.Sigma = ps.Sigma;
746 out.moments.QVar = ps.QVar;
747 out.moments.QStd = ps.QStd;
748 return out;
749}
750
751/**
752 * The 'dae' method's Petri arm of `getTranAvg`: the transient DAE of `solver_fluid_petri` over [0, horizon],
753 * read at RODAS's own steps plus a uniform grid of `points` instants (MATLAB reports the steps of ode15s).
754 *
755 * ONLY 'dae' HAS A PETRI TRANSIENT. MATLAB's getTranAvg replaces every other method, 'default' included, by
756 * 'closing', whose feature gate refuses the Place; the same refusal is raised here, by name.
757 */
758template <class T>
759inline std::vector<FluidTranPoint> fluid_petri_transient(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
760 std::size_t points) {
761 const std::string m = (opt.method.rfind("fld.", 0) == 0) ? opt.method.substr(4) : opt.method;
762 if (m != "dae")
763 throw UnsupportedError(ErrorKind{"Place"},
764 "SolverFluid: getTranAvg integrates the first-order 'closing' drift for method '" + opt.method +
765 "', which has no coordinate for a Place, so a Petri net has no transient under it. Use method "
766 "'dae', which integrates the net's own differential-algebraic system");
767 petri::PetriOptions po;
768 if (opt.dae_maxstate > 0) po.dae_maxstate = opt.dae_maxstate;
769 if (opt.dae_maxcov > 0) po.dae_maxcov = opt.dae_maxcov;
770 po.fluid_boundary = opt.fluid_boundary;
771 po.timespan_end = fluid_default_horizon(sn, opt);
772 const std::size_t np = std::max<std::size_t>(points, 2);
773 for (std::size_t j = 1; j < np; ++j)
774 po.tranpoints.push_back(po.timespan_end * static_cast<double>(j) / static_cast<double>(np - 1));
775 const petri::PetriSolution ps = petri::solver_fluid_petri(sn, po);
776 const petri::PetriTerms terms = petri::petri_build_terms(sn);
777 const std::size_t M = ps.QN.rows(), K = ps.QN.cols(), nt = ps.t.size();
778 const bool withvar = ps.Sigmat.size() == nt && nt > 0;
779 std::vector<FluidTranPoint> traj(nt);
780 for (std::size_t a = 0; a < nt; ++a) {
781 FluidTranPoint& p = traj[a];
782 // t(1) = 0 is moved to FineTol as on every other fluid route
783 p.t = (a == 0 && ps.t[a] == 0.0) ? petri::petri_fine_tol() : ps.t[a];
784 p.QN = Matrix<double>(M, K, 0.0);
785 p.UN = Matrix<double>(M, K, 0.0);
786 p.TN = Matrix<double>(M, K, 0.0);
787 for (std::size_t i = 0; i < M; ++i)
788 for (std::size_t k = 0; k < K; ++k) {
789 p.QN(i, k) = ps.QNt[i][k][a];
790 p.UN(i, k) = ps.UNt[i][k][a];
791 p.TN(i, k) = ps.TNt[i][k][a];
792 }
793 if (!withvar) continue;
794 // the integrated marking covariance, read per station-class as the steady-state QVar is
795 p.QVar = Matrix<double>(M, K, 0.0);
796 for (std::size_t ci = 0; ci < terms.cov_idx.size(); ++ci) {
797 const std::size_t s = terms.cov_idx[ci];
798 const double v = std::max(0.0, ps.Sigmat[a](ci, ci));
799 if (s < terms.nm && terms.coord_station[s] >= 0 && static_cast<std::size_t>(terms.coord_station[s]) < M)
800 p.QVar(static_cast<std::size_t>(terms.coord_station[s]), terms.coord_class[s]) = v;
801 for (std::size_t q = 0; q < terms.nf; ++q)
802 if (terms.fluid_slot[q] == s && terms.fluid_station[q] >= 0 && K > 0)
803 p.QVar(static_cast<std::size_t>(terms.fluid_station[q]), 0) = v;
804 }
805 }
806 return traj;
807}
808
809/**
810 * Report an overloaded open station as non-stationary. Twin of
811 * `matlab/src/solvers/FLD/fluid_mark_overloaded.m`.
812 *
813 * A steady-state fluid solve integrates the drift to a finite horizon. At an
814 * open station whose offered load exceeds its capacity there is no fixed point
815 * to reach: the queue grows for as long as the integration runs, so the value at
816 * the end of the horizon is a property of the horizon and of the ODE solver's
817 * step control, not of the model. The four codebases used to report four
818 * different horizons as the mean.
819 *
820 * The test is the solve's own flow balance, read after the fact: a finite-server
821 * station that is saturated (total utilization within CoarseTol of 1) and at
822 * which an OPEN class departs more slowly than it arrives is not stationary.
823 * Such an entry gets QLen = RespT = +inf, the marker SolverMVA and SolverNC use
824 * for an unstable open station, and the system response time of its chain
825 * follows. Util and Tput (the saturated departure rate) do not depend on the
826 * horizon and stay as computed. Reading the balance rather than the traffic
827 * equations is deliberate: a station downstream of a saturated one is fed at the
828 * saturated station's departure rate, and may well be stable.
829 */
830template <class T>
831void fluid_mark_overloaded(const qn::NetworkStruct<T>& sn, FluidSolution& out) {
832 const std::size_t M = sn.nstations, K = sn.nclasses;
833 if (out.QN.rows() != M || out.QN.cols() != K) return;
834 if (out.UN.rows() != M || out.UN.cols() != K) return;
835 if (out.TN.rows() != M || out.TN.cols() != K) return;
836 if (sn.stations.size() < M) return;
837 const T zero = num_traits<T>::from_int(0);
838 Matrix<T> TN(M, K, zero);
839 for (std::size_t i = 0; i < M; ++i)
840 for (std::size_t k = 0; k < K; ++k) {
841 const double v = out.TN(i, k);
842 TN(i, k) = std::isfinite(v) ? num_traits<T>::from_double(v) : zero;
843 }
844 const Matrix<T> AN = mva::sn_get_arvr_from_tput(sn, TN);
845 if (AN.rows() != M || AN.cols() != K) return;
846 const std::vector<double> njobs = sn.njobs();
847 const double tol = 1e-3; // GlobalConstants.CoarseTol
848 const double inf = std::numeric_limits<double>::infinity();
849 for (std::size_t i = 0; i < M; ++i) {
850 if (sn.stations[i].nodetype == qn::NodeType::Source) continue;
851 if (!std::isfinite(sn.stations[i].nservers)) continue;
852 double usum = 0.0;
853 for (std::size_t k = 0; k < K; ++k)
854 if (!std::isnan(out.UN(i, k))) usum += out.UN(i, k);
855 if (usum < 1.0 - tol) continue;
856 for (std::size_t k = 0; k < K; ++k) {
857 if (k >= njobs.size() || std::isfinite(njobs[k])) continue;
858 const double a = num_traits<T>::to_double(AN(i, k));
859 if (!(a > 0.0) || !(out.TN(i, k) < a * (1.0 - tol))) continue;
860 out.QN(i, k) = inf;
861 if (out.RN.rows() == M && out.RN.cols() == K) out.RN(i, k) = inf;
862 if (out.CN.size() == K) {
863 out.CN[k] = inf;
864 } else {
865 for (std::size_t c = 0; c < sn.inchain.size() && c < out.CN.size(); ++c) {
866 bool in = false;
867 for (std::size_t q : sn.inchain[c])
868 if (q == k + 1) in = true;
869 if (in) {
870 out.CN[c] = inf;
871 break;
872 }
873 }
874 }
875 }
876 }
877}
878
879} // namespace detail
880
881template <class T>
883 qn::NetworkStruct<T>* sn_out,
884 qn::NetworkStruct<T>* refreshed_out,
885 solvers::CacheMetrics<T>* cache_out,
886 const qn::NetworkStruct<T>* gate_sn) {
887 FluidSolution out =
888 detail::solver_fluid_run_analyzer_core(sn, opt, sn_out, refreshed_out, cache_out, gate_sn);
889 // Only a steady-state request is marked: a finite timespan asks for the
890 // state at that time, which is what it gets.
891 // A fork-join model is not marked either: `@@SolverFLD/runAnalyzer.m`
892 // returns from its fork-join branch before the fluid_mark_overloaded call.
893 // Nor are the single-station closed forms (ggisgi, ggingi, tvms, mtginf,
894 // mol): runAnalyzer.m returns from their branch before the call as well.
895 static const char* const kQsysForms[] = {"ggisgi", "fld.ggisgi", "ggingi", "fld.ggingi",
896 "tvms", "fld.tvms", "mtginf", "fld.mtginf",
897 "mol", "fld.mol"};
898 bool qsys_form = false;
899 for (const char* q : kQsysForms)
900 if (opt.method == q) qsys_form = true;
901 if (!std::isfinite(opt.timespan_end) && !sn.has_fork() && !qsys_form)
902 detail::fluid_mark_overloaded(sn, out);
903 return out;
904}
905
906template <class T>
907FluidSolution detail::solver_fluid_run_analyzer_core(const qn::NetworkStruct<T>& sn, const FluidOptions& opt,
908 qn::NetworkStruct<T>* sn_out,
909 qn::NetworkStruct<T>* refreshed_out,
910 solvers::CacheMetrics<T>* cache_out,
911 const qn::NetworkStruct<T>* gate_sn) {
912 // `@@SolverFLD/runAnalyzer.m:17-21` converts the non-Markovian laws to
913 // phase-type BEFORE anything else, with phfit forced to 'ph'. `solver_fluid`
914 // does it for the methods that go through it, but the default resolution
915 // below routes minnormal, refined, closing and dae AROUND `solver_fluid`, and
916 // those drifts read a Det, Uniform or Gamma law as having no phases at all:
917 // gallery_detm1, gallery_um1 and gg1_exp_det returned an all-zero table
918 // where the reference answers. The converted struct is solved with the
919 // conversion switched off, so it is done exactly once.
920 //
921 // THE FEATURE GATE STILL READS THE STRUCT AS DECLARED (`gate_sn`), as the
922 // reference's runAnalyzerChecks reads the MODEL: the featset names Det and
923 // Uniform, not the PH they are fitted by, so gating the converted struct
924 // would refuse every model this conversion exists to admit.
925 if constexpr (num_traits<T>::has_transcendental) {
926 if (api::nonmkv_enabled(opt.nonmkv) && api::sn_has_nonmarkov(sn, false)) {
927 qn::NetworkStruct<T> converted = sn;
929 no.order = opt.nonmkv_order;
931 api::sn_nonmarkov_toph(converted, no);
932 FluidOptions oc = opt;
933 oc.nonmkv = "none";
934 return solver_fluid_run_analyzer(converted, oc, sn_out, refreshed_out, cache_out,
935 &sn);
936 }
937 }
938 std::string why;
939 if (sn_out) *sn_out = sn;
940 // a non-Markovian reneging patience is refused by name for every method
941 {
942 const std::string patWhy = api::sn_patience_refusal(sn);
943 if (!patWhy.empty()) throw UnsupportedError(ErrorKind{"Structure"}, "SolverFLD: " + patWhy);
944 }
945 // A MODEL HOLDING ANY Transition NODE IS A DIFFERENT FORMALISM and goes to a
946 // dedicated runner rather than through the queueing dispatch. The queueing
947 // path rewrites UN from sn.rates (NaN at a Place) and RN from the station
948 // scheduling, and would overwrite the Petri conventions the Petri route
949 // reports -- a place's utilization IS its token count, and its throughput is
950 // the token departure rate, not a service completion rate. The branch is
951 // taken before the feature gate, which is written about queueing stations.
952 if (detail::fluid_is_petri_net(sn)) return detail::fluid_petri_run(sn, opt);
953 // runAnalyzerChecks' METHOD gate, before the feature gate and before the
954 // resolution, exactly as the reference orders them: an unknown name is
955 // reported as unknown rather than as whatever the feature gate finds.
956 fluid_check_method(opt.method);
957 const std::string m = detail::fluid_resolve_method(sn, opt.method, opt, why);
958 // runAnalyzerChecks' universal feature gate, on the RESOLVED method. Only
959 // the runner is gated: `solver_fluid` stays the ungated port of
960 // solver_fluid_analyzer.m for a caller that wants one named method.
961 qn::feature_gate("SolverFluid", qn::fluid_feature_set(m), gate_sn ? *gate_sn : sn);
962 detail::fluid_check_load_dependence(sn, m);
963 detail::fluid_check_dae(sn, m);
964 detail::fluid_check_finite_capacity(sn, m);
965 // Fork-join: the same fixed point MVA and NC drive, with a fluid inner
966 // solve. Taken after the gate so an unsupported feature is still named by
967 // its own message rather than by a failure inside the transformed model.
968 if (sn.has_fork()) {
969 // LINE:unsupported:Structure, as the reference raises it (runAnalyzer)
970 const std::string fj = detail::fluid_forkjoin_supports(sn, m);
971 if (!fj.empty()) throw UnsupportedError(ErrorKind{"Structure"}, fj);
972 FluidOptions fo = opt;
973 fo.method = m;
974 return detail::fluid_fork_join_run(sn, fo);
975 }
976 FluidOptions o = opt;
977 o.method = m;
978
979 // The reference's FCFS non-exponential refit loop, on the branches that are
980 // routed AROUND `solver_fluid` (which runs it itself). `solve` is the same
981 // per-method function the branch used for its first integration, so the
982 // sweeps stay on one drift; the loop is a no-op for a method the reference
983 // does not refit and for a model with no FCFS station.
984 const auto closing_solve = [](const qn::NetworkStruct<T>& s, const FluidOptions& op) {
985 return solver_fluid_closing(s, op);
986 };
987 const auto moments_solve = [](const qn::NetworkStruct<T>& s, const FluidOptions& op) {
988 return solver_fluid_moments(s, op);
989 };
990 const auto dae_solve = [](const qn::NetworkStruct<T>& s, const FluidOptions& op) {
991 return solver_fluid_dae(s, op);
992 };
993
994 FluidSolution out;
995 if (m == "rmf" || (m == "minnormal" && detail::fluid_has_cache(sn))) {
996 // A cache model is a DECOMPOSITION, not one ODE: the caches are solved
997 // in isolation and the network with them relabeled as class switches.
998 // "minnormal" takes the same route, with the closure inside `netfun`.
999 // The analyzer's refreshed struct is CARRIED, not dropped: the split it
1000 // converged on is what every visit-weighted quantity downstream needs.
1002 out = cq.sol;
1003 if (refreshed_out) *refreshed_out = cq.refreshed;
1004 if (cache_out) *cache_out = solvers::cache_metrics_of_matrix(sn, cq.hitprob, cq.missprob);
1005 } else if (m == "closing" || m == "statedep" || m == "softmin" || m == "tbi") {
1006 out = detail::fluid_fcfs_nonexp_refit(sn, o, solver_fluid_closing(sn, o), closing_solve,
1007 sn_out);
1008 } else if (m == "minnormal" || m == "mnrefined") {
1009 // A non-hyperbolic fixed point cannot be seen before the mean is solved,
1010 // so it cannot be declined in advance.
1011 //
1012 // THE LADDER HAS TWO RUNGS, AND THE FIRST ONE KEEPS THE CLOSURE. Most of
1013 // these failures are not a property of the model at all:
1014 // `solver_fluid_moments` must start its alternation at sigma2 = 0, where
1015 // min(n,c) has no derivative, so a saturated or balanced model's
1016 // first-order fixed point lands on the kink, sits on a continuum of
1017 // equilibria, and the Jacobian there is neutral. `solver_fluid_dae` seeds
1018 // the variance POSITIVE and never adopts sigma2 = 0 as an iterate, so the
1019 // smoothed E[min(X,c)] breaks the degeneracy and the fixed point is
1020 // isolated and hyperbolic -- it answers the same closure, with a
1021 // covariance, where the alternation cannot. Dropping straight to first
1022 // order is not merely a lost second moment: on a balanced two-station PS
1023 // cycle at N=10 it returns [9 1] against the exact [5 5], because a
1024 // first-order method has no reason to prefer one point of the continuum
1025 // over another.
1026 //
1027 // The second rung is the first-order method, taken when `dae` declines the
1028 // model in advance (`fluid_dae_applicable`) or fails on the same error,
1029 // which is the genuinely non-hyperbolic case: an unstable open station has
1030 // no stationary distribution to approximate under any closure. Fall back
1031 // whether the closure was RESOLVED from `default` or REQUESTED outright:
1032 // it has no stationary covariance either way, so refusing an explicit
1033 // request would only deny the caller the mean that is still available.
1034 try {
1035 out = detail::fluid_fcfs_nonexp_refit(sn, o, solver_fluid_moments(sn, o),
1036 moments_solve, sn_out);
1037 } catch (const FluidNonHyperbolicError&) {
1038 std::string dae_reason;
1039 bool solved = false;
1040 if (detail::fluid_dae_applicable(sn, o, dae_reason)) {
1041 FluidOptions daeopt = o;
1042 daeopt.method = "dae";
1043 try {
1044 out = detail::fluid_fcfs_nonexp_refit(sn, daeopt, solver_fluid_dae(sn, daeopt),
1045 dae_solve, sn_out);
1046 o = daeopt;
1047 solved = true;
1048 } catch (const FluidNonHyperbolicError&) {
1049 // genuinely neutral or unstable: the last rung answers it
1050 }
1051 }
1052 if (!solved) {
1053 o.method = detail::fluid_has_dps(sn) ? "closing" : "matrix";
1054 qn::feature_gate("SolverFluid", qn::fluid_feature_set(o.method), sn);
1055 detail::fluid_check_load_dependence(sn, o.method);
1056 detail::fluid_check_finite_capacity(sn, o.method);
1057 // `solver_fluid` is the analyzer, refit included, so the matrix arm
1058 // is complete; the closing arm is routed around it and runs the loop
1059 // here.
1060 if (o.method != "closing") return solver_fluid(sn, o, sn_out);
1061 out = detail::fluid_fcfs_nonexp_refit(sn, o, solver_fluid_closing(sn, o),
1062 closing_solve, sn_out);
1063 detail::fluid_analyzer_correct(sn, out.QN, out.UN, out.RN, out.TN);
1064 detail::fluid_snap_all(out.QN, out.UN, out.RN, out.TN);
1065 return out;
1066 }
1067 }
1068 } else if (m == "dae") {
1069 // The same closure `minnormal` computes, stated and solved as ONE
1070 // differential-algebraic system: population conservation is an equation
1071 // rather than a consequence of the drift, and a region cap is an
1072 // algebraic inequality beside it. The constraint rows supply exactly the
1073 // rank the drift Jacobian is missing along the conserved directions, so
1074 // the Lyapunov step that fails in the branch above is rarely what this
1075 // route meets.
1076 //
1077 // WHEN IT DOES, THE FIRST-ORDER RUNG IS TAKEN ONLY IF THE GATE ADMITS
1078 // IT (2026-11-10, as the reference's runAnalyzer does for every method).
1079 // Once a capacity or a REGION is present the first-order methods would
1080 // return the unconstrained population, which is a different model, not
1081 // a coarser answer to this one: the gates below refuse them there, and
1082 // the Lyapunov refusal is then rethrown as it stood. An unstable open
1083 // station with no cap is the other case, and the mean is still
1084 // available for it.
1085 try {
1086 out = detail::fluid_fcfs_nonexp_refit(sn, o, solver_fluid_dae(sn, o), dae_solve,
1087 sn_out);
1088 } catch (const FluidNonHyperbolicError&) {
1089 const std::exception_ptr declined = std::current_exception();
1090 const std::string fb = detail::fluid_has_dps(sn) ? "closing" : "matrix";
1091 try {
1092 qn::feature_gate("SolverFluid", qn::fluid_feature_set(fb), sn);
1093 detail::fluid_check_load_dependence(sn, fb);
1094 detail::fluid_check_finite_capacity(sn, fb);
1095 } catch (const std::exception&) {
1096 std::rethrow_exception(declined);
1097 }
1098 o.method = fb;
1099 if (o.method != "closing") return solver_fluid(sn, o, sn_out);
1100 out = detail::fluid_fcfs_nonexp_refit(sn, o, solver_fluid_closing(sn, o),
1101 closing_solve, sn_out);
1102 detail::fluid_analyzer_correct(sn, out.QN, out.UN, out.RN, out.TN);
1103 detail::fluid_snap_all(out.QN, out.UN, out.RN, out.TN);
1104 return out;
1105 }
1106 } else if (m == "ddpp") {
1107 // The refined mean-field expansion about a smooth hyperbolic fixed
1108 // point (solver_fluid_ddpp.m). It is not refit (the FCFS stations it
1109 // admits are exponential) and has no fallback: a kink or an unstable
1110 // point is its refusal, as in the reference's runAnalyzer.
1111 out = solver_fluid_ddpp(sn, o);
1112 } else if (m == "kp") {
1113 out = solver_fluid_kp(sn, o);
1114 } else if (detail::fluid_qsys_handles(m)) {
1115 // The single-station fluid limits are closed forms, not integrations of
1116 // the network drift: they take the whole model in one call, so they are
1117 // returned unmodified -- neither the FCFS refit nor the analyzer
1118 // correction below applies to a closed form.
1119 return solver_fluid_qsys(sn, o);
1120 } else {
1121 // `solver_fluid` is the switch, the refit AND the correction, so its
1122 // branches are complete already.
1123 return solver_fluid(sn, o, sn_out);
1124 }
1125 detail::fluid_analyzer_correct(sn, out.QN, out.UN, out.RN, out.TN);
1126 detail::fluid_snap_all(out.QN, out.UN, out.RN, out.TN);
1127 // A SOURCE REPORTS NO QUEUE, UTILIZATION OR RESPONSE TIME. The DAE state
1128 // carries an EXT pool coordinate -- a lost arrival is returned to it -- and
1129 // `fluid_dae_metrics` reads every class block, as `solver_fluid_dae.m` does,
1130 // so the pool mass arrives here as the Source's QN. The reference never
1131 // shows it: the Source's QLen/Util/RespT handles are disabled and getAvg
1132 // reports 0. On gallery_mm1k (cap 3) the pool holds 0.2 and this table
1133 // showed Source QLen 0.2, Util 0.2, RespT 0.25 against the reference's 0.
1134 // The throughput row is the arrival rate and stays.
1135 for (std::size_t i = 0; i < out.QN.rows() && i < sn.stations.size(); ++i) {
1136 if (sn.stations[i].nodetype != qn::NodeType::Source) continue;
1137 for (std::size_t k = 0; k < out.QN.cols(); ++k) {
1138 out.QN(i, k) = 0.0;
1139 out.UN(i, k) = 0.0;
1140 out.RN(i, k) = 0.0;
1141 }
1142 }
1143 return out;
1144}
1145
1146/**
1147 * `-a tran` / `@@SolverFLD/getTranAvg` with the method HONOURED, which is the
1148 * one place the reference does not force `closing`.
1149 *
1150 * `solver_fluid_tran_avg` integrates the first-order closing drift whatever
1151 * `opt.method` says, and that IS the reference's rule for every steady-state
1152 * device -- matrix, pnorm, softmin and the rest have no trajectory of their own,
1153 * so the reference substitutes one and warns. `dae` is the exception
1154 * (`getTranAvg.m:155-166`): it integrates the closure itself, with conservation
1155 * as an algebraic equation, so substituting the first-order drift for it would
1156 * hand back a DIFFERENT method's trajectory under this method's name.
1157 *
1158 * Every other method keeps the byte-identical path it had, gate included -- this
1159 * routes, it does not re-gate.
1160 */
1161template <class T>
1162std::vector<FluidTranPoint> solver_fluid_run_transient(const qn::NetworkStruct<T>& sn,
1163 const FluidOptions& opt,
1164 std::size_t points = 101) {
1165 // a Petri net has its own transient DAE, and no other method's trajectory
1166 if (detail::fluid_is_petri_net(sn)) return detail::fluid_petri_transient(sn, opt, points);
1167 // The single-station fluid limits produce their OWN trajectory over the
1168 // horizon -- that is what they are -- so substituting the first-order
1169 // closing drift for them would answer a different model with a
1170 // time-averaged rate.
1171 if (detail::fluid_qsys_handles(detail::fluid_unqualify(opt.method))) {
1172 FluidOptions o = opt;
1173 o.method = detail::fluid_unqualify(opt.method);
1174 qn::feature_gate("SolverFluid", qn::fluid_feature_set(o.method), sn);
1175 std::vector<FluidTranPoint> traj;
1176 solver_fluid_qsys(sn, o, &traj);
1177 return traj;
1178 }
1179 if (detail::fluid_unqualify(opt.method) != "dae")
1180 return solver_fluid_tran_avg(sn, opt, points);
1181 qn::feature_gate("SolverFluid", qn::fluid_feature_set("dae"), sn);
1182 detail::fluid_check_dae(sn, std::string("dae"));
1184}
1185
1186/**
1187 * Port of `@@SolverFLD/getCdfRespT`: the response-time law of every (station,
1188 * class) pair, read off the marked-fluid trajectory started from the steady
1189 * state.
1190 *
1191 * THE SOLVE COMES FIRST AND IS NOT THE CALLER'S. The reference clears its
1192 * cached result, re-runs `getAvg` to fill `odeStateVec`, and hands the passage
1193 * time BOTH that vector and `result.solverSpecific.sn` -- the struct the FCFS
1194 * refit may have re-fitted -- because the vector is laid out by the phase counts
1195 * of that struct and not of the model's. Bundling the two here is what keeps a
1196 * caller from pairing a state vector with the wrong struct, which would be a
1197 * length error at best and a law of the wrong model at worst.
1198 *
1199 * A Source has no response time and is left empty, as is a pair whose class the
1200 * station does not serve; an empty entry is an ABSENT law, never a degenerate
1201 * one.
1202 */
1203template <class T>
1204std::vector<std::vector<FluidPassage> > solver_fluid_cdf_respt(const qn::NetworkStruct<T>& sn,
1205 const FluidOptions& opt,
1206 std::size_t points = 201) {
1209 if (r.xvec.empty())
1210 throw UnsupportedError(ErrorKind{"Analysis"},
1211 "solver_fluid_cdf_respt: the '" + r.method +
1212 "' method reports no fluid state vector to mark a job in, so it has no passage time; "
1213 "use 'closing', 'matrix' or a moment closure");
1214 std::vector<std::vector<FluidPassage> > RD(
1215 snr.nstations, std::vector<FluidPassage>(snr.nclasses));
1216 for (std::size_t i = 0; i < snr.nstations; ++i) {
1217 if (snr.stations[i].nodetype == qn::NodeType::Source) continue;
1218 for (std::size_t c = 0; c < snr.nclasses; ++c) {
1219 if (snr.disabled[i][c]) continue;
1220 RD[i][c] = fluid_passage_time(snr, r.xvec, i + 1, c + 1, opt.tol, points, r.closure);
1221 }
1222 }
1223 return RD;
1224}
1225
1226/**
1227 * Port of `@@SolverFLD/exportODEs.m`, which hands `options.method` to
1228 * `solver_fluid_symodes` UNRESOLVED: `default` exports the `matrix` system, as
1229 * in MATLAB and Python, even where the runner would integrate `minnormal`,
1230 * which has no symbolic form. The resolution is consulted only to refuse `rmf`.
1231 *
1232 * `rmf` has no single exported drift -- the cache decomposition rewrites the
1233 * routing between passes, so there is one fluid system per sweep and none of
1234 * them is "the" model's -- and is refused by name rather than exported at the
1235 * routing of whichever sweep happened to be last.
1236 */
1237template <class T>
1239 const std::string& notation = "scalar",
1240 const std::string& model_name = "model") {
1241 const std::string m = detail::fluid_resolve_method(sn, opt.method);
1242 if (m == "rmf")
1243 throw UnsupportedError(ErrorKind{"Cache"},
1244 "solver_fluid_export_odes: a Cache model is solved by alternating a cache drift with a "
1245 "queueing drift whose routing is rewritten at every sweep, so it has no one ODE system "
1246 "to export; export the model without its Cache node, or read the sweeps through "
1247 "solver_fld_cacheqn_tran");
1248 return fluid_export_odes(sn, opt, notation, model_name);
1249}
1250
1251} // namespace fluid
1252} // namespace line
1253
1254#endif // LINE_SOLVERS_FLUID_FLUID_RUNNER_H
What a solver observed about the Cache nodes of a model.
UnsupportedError(const std::string &what)
Definition error.h:119
Raised when the moment closure cannot serve this model: the linearization at the fixed point is not h...
A network plus its refreshed NetworkStruct.
std::vector< std::vector< bool > > disabled
std::vector< Station< T > > stations
stations[k-1] is the k-th station
The exception types the port throws.
The fork-join fixed point that drives one inner MVA solve.
The Heidelberger-Trivedi fork-join transform, options.config.fork_join='ht'.
The INTEGRATED caching-queueing network under the fluid solver: ports of solver_fld_cacheqn_analyzer....
Port of solver_fluid_initsol.m, and of the entry point of solver_fluid_closing.m that consumes it.
The min-normal closure as a DIFFERENTIAL-ALGEBRAIC system: solver_fluid_dae.m.
Refined mean-field (O(1/N)) steady state of the matrix fluid drift, method = "ddpp" (alias fld....
@@SolverFLD/exportODEs.m: the fluid ODE system as a standalone LaTeX document, in a form meant to be ...
Port of solver_fluid_kp.m: the fluid AND diffusion limits of the (MAP_t/Ph_t/inf)^N network of Y.
The second-order fluid methods: fluid_moment_terms.m, fluid_lyapunov.m, fluid_drift_jacobian....
The one exception the fluid fallback ladder catches.
Response-time distribution by tagged fluid: a port of solver_fluid_passage_time.m,...
Fluid analysis of a stochastic Petri net: one simultaneous algebraic solve per active set.
Port of matlab/src/solvers/FLD/solver_fluid_qsys_analyzer.m: the single-station fluid limits.
Port of ode_eliminate_immediate.m, eliminate_immediate_matrix.m and ode_solve_stiff....
The method names of each solver, in listing order.
bool sn_has_nonmarkov(const qn::NetworkStruct< T > &sn, bool preserve_det=false)
Whether any law in the struct would be replaced, so a caller can skip copying the struct when there i...
bool nonmkv_enabled(const std::string &method)
Resolve options.config.nonmkv to NonmarkovOptions::enabled.
std::string sn_patience_refusal(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
Port of sn_patience_refusal.m: the by-name refusal of a reneging patience that is not a Markovian law...
@ Ph
Bernstein density fit: a genuine phase-type, shape-carrying.
void sn_nonmarkov_toph(qn::NetworkStruct< T > &sn, const NonmarkovOptions &opts=NonmarkovOptions())
Replace every non-Markovian service and firing law by a Markovian surrogate.
PetriTerms petri_build_terms(const qn::NetworkStruct< T > &sn)
Assemble the drift terms of a net.
double petri_fine_tol()
GlobalConstants.FineTol, the reference's own "effectively zero".
PetriSolution solver_fluid_petri(const qn::NetworkStruct< T > &sn, const PetriOptions &opt=PetriOptions())
Fluid analysis of a stochastic Petri net.
FluidCacheqnSolution< T > solver_fld_cacheqn_analyzer(const qn::NetworkStruct< T > &sn, const FluidOptions &opt)
Port of solver_fld_cacheqn_analyzer.m.
void fluid_check_method(const std::string &method)
Port of runAnalyzerChecks' method gate: an unlisted method is refused.
double fluid_default_horizon(const qn::NetworkStruct< T > &sn, const FluidOptions &opt)
The horizon a transient runs to when the caller gives none.
FluidMfqAdmits fluid_mfq_admits(const qn::NetworkStruct< T > &sn)
Port of fluid_mfq_admits.m.
FluidSolution solver_fluid_kp(const qn::NetworkStruct< T > &sn, const FluidOptions &opt)
Port of solver_fluid_kp.m: the steady table at the horizon.
Definition fluid_kp.h:1055
FluidLayout fluid_layout(const qn::NetworkStruct< T > &sn)
Port of the layout half of solver_fluid_odes.m.
Definition fluid_odes.h:282
FluidSolution solver_fluid_dae(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, const FluidDaeOptions &dopt_in=FluidDaeOptions())
solver_fluid_dae.m: the min-normal closure solved as one system.
Definition fluid_dae.h:2153
FluidSolution solver_fluid_closing(const qn::NetworkStruct< T > &sn, const FluidOptions &opt)
Port of solver_fluid_closing.m: the closing family's entry point.
std::vector< std::string > fluid_list_valid_methods()
Port of SolverFLD.listValidMethods.
AoiTopology aoi_is_aoi(const qn::NetworkStruct< T > &sn)
Port of aoi_is_aoi.m.
Definition fluid_aoi.h:106
std::string solver_fluid_export_odes(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, const std::string &notation="scalar", const std::string &model_name="model")
Port of @@SolverFLD/exportODEs.m, which hands options.method to solver_fluid_symodes UNRESOLVED: defa...
FluidDaeOptions fluid_dae_options(const FluidOptions &opt, const FluidDaeOptions &dopt)
The controls the DAE route actually reads: the struct a caller pinned, with whatever options....
Definition fluid_dae.h:903
FluidSolution solver_fluid_run_analyzer(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, qn::NetworkStruct< T > *sn_out=nullptr, qn::NetworkStruct< T > *refreshed_out=nullptr, solvers::CacheMetrics< T > *cache_out=nullptr, const qn::NetworkStruct< T > *gate_sn=nullptr)
Port of @@SolverFLD/runAnalyzer.m: resolve the method, route to the function the reference routes to,...
FluidSolution solver_fluid(const qn::NetworkStruct< T > &sn_in, const FluidOptions &opt, qn::NetworkStruct< T > *sn_out=nullptr)
Port of solver_fluid_analyzer.m: dispatch on the method, refit the non-exponential FCFS stations the ...
FluidSolution solver_fluid_qsys(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, std::vector< FluidTranPoint > *traj=nullptr)
Solve a single-station model with one of the closed-form fluid limits.
Definition fluid_qsys.h:165
std::vector< FluidTranPoint > solver_fluid_tran_avg(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, std::size_t points=101)
getTranAvg on the first-order closing drift, over that horizon.
FluidPassage fluid_passage_time(const qn::NetworkStruct< T > &sn, const std::vector< double > &x_steady, std::size_t ist, std::size_t cls, double tol=1e-4, std::size_t points=201, const FluidClosure &closure=FluidClosure())
Response-time CDF at station ist for class cls, both 1-based.
FluidSolution solver_fluid_moments(const qn::NetworkStruct< T > &sn, const FluidOptions &opt)
Port of solver_fluid_moments.m: the second-order fluid analysis backing minnormal and mnrefined.
FluidSolution solver_fluid_ddpp(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, FluidDdppReport *report=nullptr, bool probe=false)
Port of solver_fluid_ddpp.m.
Definition fluid_ddpp.h:299
std::vector< std::vector< FluidPassage > > solver_fluid_cdf_respt(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, std::size_t points=201)
Port of @@SolverFLD/getCdfRespT: the response-time law of every (station, class) pair,...
std::string fluid_export_odes(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, const std::string &notation="scalar", const std::string &model_name="model")
Render the fluid ODE system of sn as a LaTeX document.
std::vector< FluidTranPoint > solver_fluid_run_transient(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, std::size_t points=101)
-a tran / @@SolverFLD/getTranAvg with the method HONOURED, which is the one place the reference does ...
std::vector< FluidTranPoint > solver_fluid_dae_transient(const qn::NetworkStruct< T > &sn, const FluidOptions &opt, double t_end, std::size_t points=101, const std::vector< double > &out_grid=std::vector< double >(), const FluidDaeOptions &dopt_in=FluidDaeOptions())
@@SolverFLD/getTranAvg for the DAE route: the metrics ALONG the trajectory.
Definition fluid_dae.h:2611
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
const char * sched_to_text(SchedStrategy s)
Definition lang_types.h:248
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
Definition lang_types.h:419
@ FIFO
first in, first out
Definition lang_types.h:421
bool in(const std::string &s, std::initializer_list< const char * > set)
FjMmt< T > fj_fork_join_transform(const qn::NetworkStruct< T > &L, const std::string &method)
options.config.fork_join -> the transform it names.
Definition fj_ht.h:389
MvaSolution< T > fj_fixed_point(const qn::NetworkStruct< T > &L, FjMmt< T > &tr, std::vector< T > &lam, const MvaOptions &opt, InnerSolve inner, std::string *warning=nullptr)
Drive the fork-join fixed point of a transformed model to convergence.
Definition fj_driver.h:512
Matrix< T > sn_get_arvr_from_tput(const qn::NetworkStruct< T > &L, const Matrix< T > &TN)
Port of sn_get_arvr_from_tput: the arrival rate each station sees, from the throughputs and the class...
FeatureSet fluid_feature_set(const std::string &method)
void check_binding_capacity(const std::string &solver, const NetworkStruct< T > &sn)
NetworkSolver.checkBindingCapacity (NetworkSolver.m:1172-1228): the shared structural gate for finite...
bool has_binding_capacity(const NetworkStruct< T > &sn)
getUsedLangFeatures: the features the MODEL uses.
void feature_gate(const std::string &solver, const FeatureSet &declared, const NetworkStruct< T > &sn, const std::string &requested_method="", const std::string &resolved_method="")
runAnalyzerChecks: refuse a model the solver does not declare, by name.
CacheMetrics< T > cache_metrics_of_matrix(const qn::NetworkStruct< T > &sn, const Matrix< T > &hitprob, const Matrix< T > &missprob)
The same, for the integrated caching-queueing branch, whose hit and miss probabilities are (ncaches x...
FjMetrics< double > fj_metrics_to_double(const FjMetrics< T > &in)
The same metrics in double precision, for the facade and the CLI.
Definition fj_metrics.h:90
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/api/sn/sn_patience_handles.m.
The DECLARED side of the gate: one feature set per solver.
SolverFluid: the closing method, a port of solver_fluid.m, solver_fluid_iteration....
The SolverMVA class surface: @@SolverMVA/runAnalyzer.m and the gates around it.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
options.config.nonmkv and friends.
std::size_t order
nonmkvorder, the phase budget
PhFit phfit
which surrogate family
What the steady analyzer returns: the fluid metrics plus the converged split.
Controls, defaulting to SolverOptions('Fluid') in the reference.
What the analyzer returns, in the same shape as the MVA solver's result.
std::vector< double > xvec
the converged fluid state
static constexpr double FineTol
Definition lang_types.h:823
static constexpr double Zero
Definition lang_types.h:825
A node of the network.
Every Cache node of the model, in node order; empty on a model with none.