LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_mam_retrial.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_SOLVERS_MAM_SOLVER_MAM_RETRIAL_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_RETRIAL_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `solver_mam_retrial.m`, the customer-impatience analyzer of SolverMAM.
12 *
13 * The reference file carries TWO analyzers behind one name, and tries them in
14 * this order:
15 *
16 * 1. RENEGING, a MAP/M/s+G queue whose waiting jobs abandon after a generally
17 * distributed patience (Gursoy, Mehr and Akar). Solved as a multi-regime
18 * Markov fluid queue; ported in solver_mam_reneging.h on mfq_multiregime.
19 * 2. RETRIAL, the BMAP/PH/N/N bufferless orbit queue with flexible retrials
20 * admission control (Dudin et al., Mathematics 2025, 13(9), 1434). Solved
21 * by `qsys_bmapphnn_retrial`, which IS ported (api/qsys).
22 *
23 * BOTH ROUTES ARE REACHABLE, IN THE REFERENCE'S ORDER. The reneging gate
24 * (`mam_reneging_detect`) reads `stations[i].impatience` and
25 * `stations[i].patience`, the C++ counterparts of `sn.impatienceClass` and
26 * `sn.patienceProc`, and is tried first; a queue with a waiting line whose jobs
27 * abandon is never handed to the orbit generator below.
28 *
29 * WHAT THE ORBIT IS. A retrial station has no waiting room: the buffer equals
30 * the server count. A job that finds every server busy joins an ORBIT and
31 * re-attempts at rate alpha per orbiting job; a completion does NOT promote
32 * from the orbit. That is why the queue length reported here is
33 * `L_orbit + N_server` and not the marginal of an ordered buffer.
34 *
35 * THE TRUNCATION IS THE ANSWER'S ACCURACY, AND IT IS ITERATED HERE. The orbit
36 * is unbounded, so `qsys_bmapphnn_retrial` truncates it; the reference does not
37 * accept the first truncation but doubles the level until the relative tail
38 * contribution `truncLevel * mass(top level) / L_orbit` falls under
39 * `TailTolerance`. The ported engine implements ONE solve at a given level and
40 * returns `truncLevel`, `topLevelMass` and `L_orbit`, which is exactly the
41 * triple that refinement test needs, so the loop lives here rather than being
42 * dropped. Without it a model is answered at the reference's FIXED default
43 * level, whose formula depends on neither alpha nor gamma -- the two parameters
44 * that actually govern the tail decay -- and the error is silent.
45 *
46 * WHERE THIS IS STRICTER THAN THE REFERENCE, and why each is the honest outcome:
47 *
48 * - A NON-CONVERGED TRUNCATION IS AN ERROR, NOT A WARNING. When doubling hits
49 * the dimension cap before reaching the tolerance, `solver_mam_retrial.m`
50 * emits `line_warning` and returns the underestimate. The C++ port has no
51 * warning channel, so the same situation would return a number with nothing
52 * attached to it; it refuses instead, and names `orbit_maxlevel` as the way
53 * to ask for that number deliberately.
54 * - A NON-PHASE-TYPE SERVICE IS REFUSED, NOT APPROXIMATED. The reference's
55 * `warnIfApproximated` lets a Det, Replayer, Uniform, Gamma, Pareto, Weibull
56 * or Lognormal service through under an Erlang fit of matching mean and SCV,
57 * and says so in a warning. Everything but Det is already gated out by
58 * `runner_detail::check_processes`; Det reaches here, and `dist_to_map` would
59 * silently give it a 20-phase Erlang -- which is not only a different model
60 * but blows the per-level block up by C(n + 19, 19) states per busy server.
61 * - A BOUNDED RETRY COUNT IS REFUSED. `RetrialParam::max_attempts` and
62 * `DropStrategy::RETRIAL_WITH_LIMIT` say a job gives up after k failed
63 * retries. The generator has no attempt counter in its state descriptor, so
64 * there is no level at which that job could be told apart from a persistent
65 * one.
66 *
67 * WHAT THE C++ MODEL LAYER CANNOT SAY, so what is pinned at its reference
68 * default rather than read: the orbit abandonment rate gamma (`sn.orbitImpatience`,
69 * default 0), the batch rejection probability p (`sn.batchRejectProb`, default
70 * 0), the finite orbit `sn.orbitMaxJobs`, the CONSTANT retrial policy
71 * (`sn.retrialPolicy`; the ported engine is LINEAR-only, which is the
72 * reference's own default), and the admission threshold R, which the reference
73 * lowers below N-1 only from a Finite Capacity Region and `NetworkStruct` has no
74 * region field. Each is stated here so that a later model-layer addition has a
75 * list of what to wire, and none of them is invented from a capacity heuristic.
76 *
77 * REFERENCE DEFECTS in solver_mam_retrial.m and qsys_bmapphnn_retrial.m:
78 *
79 * 1. `Tolerance` IS PARSED AND NEVER USED. `solver_mam_retrial.m` reads
80 * `options.tol`, defaults it to 1e-10 and forwards it as 'Tolerance';
81 * `qsys_bmapphnn_retrial.m` assigns it on line 83 and no later line reads
82 * it. The single dense solve behind the generator is direct, so there is no
83 * iteration for it to terminate. Not propagated: `MamOptions::tol` is
84 * likewise not forwarded here, and the comment records why rather than
85 * leaving a caller to wonder why lowering the tolerance changes nothing.
86 * 2. (FIXED in the reference) THE DEFAULT RETRIAL RATE WAS A MAGIC 0.1. A
87 * station carrying only a RETRIAL drop rule and no retrial process used to
88 * run with `alpha = 0.1`; `qsys_is_retrial.m` now refuses it and
89 * `retInfo.alpha` is `sn.retrialMu`, so `mam_retrial_detect` does the same.
90 * 3. `extractPHParams` NORMALIZES A BAD beta INSTEAD OF REPORTING IT. When the
91 * entry vector recovered from D1 does not sum to one it is rescaled, and
92 * when it sums to zero it is replaced by the uniform vector. Both hide a
93 * malformed service representation. Not reproduced: `map_pie` is the
94 * codebase's own embedded entry vector and is exact for any Markovian pair,
95 * and a pair that is not Markovian is refused above by name.
96 *
97 * ARITHMETIC. The generator is a rational expression in its inputs and the
98 * stationary law is one linear solve, so nothing here needs a transcendental
99 * function and this analyzer carries no `has_transcendental` gate -- unlike
100 * `solver_mam_basic`, whose station solves run tolerance-terminated Riccati
101 * iterations. `qsys_bmapphnn_retrial` documents the same property, and the
102 * exact instantiation returns the stationary law of the truncated chain
103 * exactly.
104 */
105
106#include <algorithm>
107#include <cmath>
108#include <cstddef>
109#include <limits>
110#include <map>
111#include <string>
112#include <vector>
113
121#include "line/util/error.h"
122#include "line/util/matrix.h"
123
124namespace line {
125namespace mam {
126
127/**
128 * The knobs `solver_mam_retrial.m` reads from `options.config` and from model
129 * fields the C++ `NetworkStruct` does not carry.
130 *
131 * Kept as a separate argument rather than added to `MamOptions`, so that the
132 * options every MAM analyzer shares do not grow a field only one of them reads.
133 * The defaults are the reference's.
134 */
136 /** `options.config.orbit_maxlevel`; 0 asks for the adaptive refinement. */
137 std::size_t orbit_maxlevel = 0;
138 /** `options.config.orbit_tailtol`, the relative orbit-truncation target. */
139 double orbit_tailtol = 1e-6;
140 /** `'MaxDim'`: the largest generator dimension the refinement may reach. */
141 double max_dim = 2e5;
142 /** `'MaxBlockSize'`: the largest per-level block V*d that may be assembled. */
143 double max_block = 5e3;
144};
145
146/** What `qsys_is_retrial.m` returns: the station it found, or why it found none. */
148 bool ok = false;
149 std::size_t station = 0; ///< 1-based station index of the retrial queue
150 std::size_t source = 0; ///< 1-based station index of the Source
151 std::size_t cls = 1; ///< 1-based class index; the reference is single-class
152 int nservers = 0; ///< N
153 long R = 0; ///< admission threshold, N-1 unless an FCR lowers it
154 double alpha = 0.0; ///< `retInfo.alpha` = sn.retrialMu of the retrial station (no default)
155 double gamma = 0.0; ///< `retInfo.gamma`: orbit impatience default
156 double p = 0.0; ///< `retInfo.p`: batch rejection probability default
157 std::string why; ///< the reference's `errorMsg`, empty when ok
158};
159
160namespace retrial_detail {
161
162/** Does any class at this station declare a retrial process? */
163template <class T>
164bool has_retrial_proc(const qn::NetworkStruct<T>& L, std::size_t ist) {
165 const typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator it =
166 L.retrialparam.find(ist);
167 if (it == L.retrialparam.end()) return false;
168 for (std::size_t r = 0; r < it->second.retrial_proc.size(); ++r)
169 if (!it->second.retrial_proc[r].disabled) return true;
170 return false;
171}
172
173/**
174 * The reference's `assertMarkovian`, as a refusal naming the station and the
175 * class. A process that is not a (D0, D1) pair as declared has no place in a
176 * matrix-analytic generator, and the C++ layer would hand it over as an Erlang
177 * of matching moments instead of reporting it.
178 */
179template <class T>
180void assert_markovian(const qn::NetworkStruct<T>& L, std::size_t ist, std::size_t r,
181 const char* role) {
182 const lang::Distrib<T>& d = L.service[ist - 1][r - 1];
183 if (L.disabled[ist - 1][r - 1] || d.disabled)
184 throw UnsupportedError(ErrorKind{"Retrial"}, std::string("SolverMAM: the ") + role + " process of class '" +
185 L.classes[r - 1].name + "' at station '" + L.stations[ist - 1].name +
186 "' is disabled; the matrix-analytic retrial solver has no state for "
187 "a class that does not visit its own station");
188 if (!basic_detail::is_markovian_type(d.type))
189 throw UnsupportedError(ErrorKind{"Distribution"},
190 std::string("SolverMAM: the ") + role + " process of class '" + L.classes[r - 1].name +
191 "' at station '" + L.stations[ist - 1].name + "' is " + lang::process_to_text(d.type) +
192 ", which has no Markovian (D0,D1) representation. The reference replaces it by an "
193 "Erlang of matching mean and squared coefficient of variation and warns that the "
194 "answer is approximate; this port refuses instead, because the substitute is a "
195 "different model under the same method name. Use SolverCTMC, SolverSSA or SolverLDES");
196 const Map<T> m = lang::dist_to_map(d);
197 if (!basic_detail::is_markovian_map(m))
198 throw UnsupportedError(ErrorKind{"Model"}, std::string("SolverMAM: the ") + role + " process of class '" +
199 L.classes[r - 1].name + "' at station '" +
200 L.stations[ist - 1].name +
201 "' has a (D0,D1) pair that is not a Markovian generator (a negative "
202 "off-diagonal, a negative arrival entry, or rows that do not sum to "
203 "zero)");
204}
205
206/**
207 * The per-level block width V*d of the generator, where d counts the multisets
208 * of service phases over the busy servers.
209 *
210 * Computed BEFORE the first solve, because the engine assembles one dense
211 * (truncLevel + 1) * V*d square matrix and an oversized block has to be
212 * reported rather than attempted. In double throughout: the binomials overflow
213 * an integer long before they reach a block size anyone would wait for.
214 */
215inline double retrial_block_width(std::size_t V, std::size_t M, int N) {
216 double d = 0.0, term = 1.0; // term = C(n + M - 1, M - 1), starting at n = 0
217 for (int n = 0; n <= N; ++n) {
218 if (n > 0) term *= static_cast<double>(n + static_cast<int>(M) - 1) / static_cast<double>(n);
219 d += term;
220 if (d > 1e12) return 1e12; // already past any usable cap; stop growing
221 }
222 return static_cast<double>(V) * d;
223}
224
225/**
226 * `orbitTruncationError`: the relative contribution the truncated tail would
227 * add to the mean orbit length, which the mass sitting at the top level bounds.
228 */
229template <class T>
230double orbit_trunc_error(const qsys::BmapPhNnRetrialResult<T>& r) {
231 const double lorbit = num_traits<T>::to_double(r.L_orbit);
232 const double top = num_traits<T>::to_double(r.topLevelMass);
233 const double denom = lorbit > std::numeric_limits<double>::min()
234 ? lorbit
235 : std::numeric_limits<double>::min();
236 return static_cast<double>(r.truncLevel) * top / denom;
237}
238
239} // namespace retrial_detail
240
241/**
242 * Port of `qsys_is_retrial.m`, plus the reneging gate of `solver_mam_retrial.m`.
243 *
244 * Returns rather than throws, because `solver_mam_analyzer.m` uses it as the
245 * 2c/2d branch predicate and only errors once every branch has declined. The
246 * rejection reason travels in `why` so the dispatch can quote it.
247 */
248template <class T>
250 using lang::DropStrategy;
251 MamRetrialInfo info;
252
253 // A mixed model has a closed chain whose population the orbit generator has
254 // no level for, so the predicate must be "every class open", not "any".
255 if (!L.is_open_model()) {
256 info.why = "the BMAP/PH/N/N retrial solver requires an open queueing model";
257 return info;
258 }
259 if (L.nclasses != 1) {
260 info.why = "the BMAP/PH/N/N retrial solver supports a single class only";
261 return info;
262 }
263 info.cls = 1;
264
265 // A retrial station is one that DECLARES an orbit, or one that is
266 // bufferless: capacity equal to the server count leaves no waiting line, so
267 // a blocked job has nowhere to go but an orbit.
268 std::vector<std::size_t> bufferless;
269 for (std::size_t i = 1; i <= L.nstations; ++i) {
270 if (L.stations[i - 1].nodetype != qn::NodeType::Queue) continue;
271 const double cap = L.cap[i - 1];
272 const bool isbufferless = std::isfinite(cap) && cap == L.stations[i - 1].nservers;
273 if (retrial_detail::has_retrial_proc(L, i) || isbufferless) bufferless.push_back(i);
274 }
275 if (bufferless.empty()) {
276 info.why = "no retrial queue found (declare one with setRetrial, or give a station a "
277 "capacity equal to its server count)";
278 return info;
279 }
280
281 for (std::size_t i : bufferless) {
282 for (std::size_t r = 0; r < L.nclasses; ++r)
283 if (L.droprule[i - 1][r] == DropStrategy::RETRIAL ||
284 L.droprule[i - 1][r] == DropStrategy::RETRIAL_WITH_LIMIT) {
285 info.station = i;
286 break;
287 }
288 if (info.station != 0) break;
289 }
290 if (info.station == 0) {
291 info.why = "no RETRIAL drop strategy is configured on a bufferless queue";
292 return info;
293 }
294 // The BMAP/PH/N/N analysis of Dudin et al. takes an EXPONENTIAL retrial
295 // delay and orbit abandonment (one rate each) and an unlimited number of
296 // attempts; anything else is a different model, not an approximation of it.
297 {
298 typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator rp =
299 L.retrialparam.find(info.station);
300 const std::size_t c = info.cls - 1;
301 if (rp == L.retrialparam.end() || c >= rp->second.retrial_proc.size() ||
302 rp->second.retrial_proc[c].disabled) {
303 // A RETRIAL drop rule without a retrial delay used to run with a hidden
304 // rate of 0.1; the rate is part of the model, so ask for it instead.
305 info.station = 0;
306 info.why = "The retrial station has no retrial delay; configure one with setRetrial or setOrbit.";
307 return info;
308 } else {
309 if (rp->second.retrial_proc[c].type != lang::ProcessType::EXP) {
310 info.station = 0;
311 info.why = "the BMAP/PH/N/N retrial solver requires an exponential retrial delay; "
312 "use SolverLDES for a non-exponential one";
313 return info;
314 }
315 if (c < rp->second.max_attempts.size() && rp->second.max_attempts[c] > 0) {
316 info.station = 0;
317 info.why = "the BMAP/PH/N/N retrial solver supports only unlimited retrial attempts; "
318 "use SolverLDES for a finite cap";
319 return info;
320 }
321 }
322 const auto& rst = L.stations[info.station - 1];
323 if (c < rst.orbit_impatience.size() && !rst.orbit_impatience[c].disabled &&
324 rst.orbit_impatience[c].type != lang::ProcessType::EXP) {
325 info.station = 0;
326 info.why = "the BMAP/PH/N/N retrial solver requires an exponential orbit impatience; "
327 "use SolverLDES for a non-exponential one";
328 return info;
329 }
330 // Non-persistent customers and orbital search are not part of the Dudin et
331 // al. model (the orbit impatience gamma is its only exit from the orbit).
332 if (num_traits<T>::to_double(rst.orbit_join_of(c)) < 1.0 ||
333 num_traits<T>::to_double(rst.orbit_persist_of(c)) < 1.0) {
334 info.station = 0;
335 info.why = "BMAP/PH/N/N retrial solver does not model non-persistent customers "
336 "(setOrbitPersistence); use SolverCTMC or SolverSSA.";
337 return info;
338 }
339 if (num_traits<T>::to_double(rst.orbit_search_of(c)) > 0.0) {
340 info.station = 0;
341 info.why = "BMAP/PH/N/N retrial solver does not model orbital search "
342 "(setOrbitalSearch); use SolverCTMC or SolverSSA.";
343 return info;
344 }
345 // Retrial rate alpha of the exponential retrial delay (sn.retrialMu),
346 // checked present above: no placeholder default.
347 const lang::Distrib<T>& rd = rp->second.retrial_proc[c];
348 const double rmean = num_traits<T>::to_double(rd.mean);
349 info.alpha = rmean > 0.0 ? 1.0 / rmean
350 : (c < rp->second.retrial_rate.size()
351 ? num_traits<T>::to_double(rp->second.retrial_rate[c]) : 0.0);
352 }
353
354 for (std::size_t i = 1; i <= L.nstations; ++i)
355 if (L.stations[i - 1].nodetype == qn::NodeType::Source) {
356 info.source = i;
357 break;
358 }
359 if (info.source == 0) {
360 info.why = "no Source node found";
361 return info;
362 }
363
364 const double ns = L.stations[info.station - 1].nservers;
365 if (!std::isfinite(ns) || ns < 1.0) {
366 info.why = "the retrial station must have a finite, positive server count";
367 return info;
368 }
369 info.nservers = static_cast<int>(ns);
370
371 // Validate the arrival and service processes: the reference requires a
372 // representation {alpha, A} / {D0, D1} of length >= 2 at both ends, and a
373 // disabled process is stored as a 1 x 1 NaN, which fails that test.
374 if (L.disabled[info.source - 1][info.cls - 1] ||
375 L.service[info.source - 1][info.cls - 1].disabled) {
376 info.why = "Invalid arrival process at source.";
377 return info;
378 }
379 if (L.disabled[info.station - 1][info.cls - 1] ||
380 L.service[info.station - 1][info.cls - 1].disabled) {
381 info.why = "Invalid service process at queue.";
382 return info;
383 }
384
385 // Admission threshold: N-1 (no admission control) unless a Finite Capacity
386 // Region holding this station carries a global cap at or below N-1. The
387 // last column of the region's cap matrix is the station's global bound.
388 info.R = static_cast<long>(info.nservers) - 1;
389 for (std::size_t f = 0; f < L.regions.size(); ++f) {
390 const std::vector<std::vector<double> >& cap = L.regions[f].cap;
391 if (cap.size() < info.station) continue;
392 const std::vector<double>& row = cap[info.station - 1];
393 if (row.empty()) continue;
394 const double rfcr = row[row.size() - 1];
395 if (rfcr > 0.0) {
396 if (rfcr <= static_cast<double>(info.nservers) - 1.0)
397 info.R = static_cast<long>(rfcr);
398 break;
399 }
400 }
401 info.ok = true;
402 return info;
403}
404
405/**
406 * The 'retrial' method's applicability as one sentence; empty when applicable.
407 *
408 * A "MUST BE PRESENT" RULE, which is why it cannot live in a feature set: a
409 * FeatureSet says "I accept this construct", so it can refuse a model for HAVING
410 * something and never for LACKING it. This analyzer needs the BMAP/PH/N/N
411 * bufferless retrial topology to work on, and a model without one is not a
412 * smaller retrial model, it is a different one.
413 *
414 * ONE PREDICATE, THREE CALLERS: `mam_dispatch`'s 'retrial' arm raises it,
415 * `runner_detail::check_model_method` raises it ahead of the dispatch, and
416 * `autosolver::auto_family_refusal` returns it through
417 * `mam_model_method_refusal`, so the method the report offers and the method
418 * that runs are the same set.
419 */
420template <class T>
422 const MamRetrialInfo info = mam_retrial_detect(L);
423 if (info.ok) return std::string();
424 // mam_retrial_applicable.m: the MAP/M/s+G reneging shape makes the method
425 // applicable as well. It is a SHAPE, not a presence, so a patience on a
426 // two-queue model is still refused.
428 if (ren.ok) return std::string();
430 return "SolverMAM: the 'retrial' method needs a BMAP/PH/N/N bufferless retrial topology "
431 "or a MAP/M/s+G reneging shape (one Source, one FCFS Queue with exponential "
432 "service, one open class, a patience distribution); this model has neither. " +
433 ren.why + " Use method 'default'";
434 return "SolverMAM: the 'retrial' method needs a BMAP/PH/N/N bufferless retrial topology; "
435 "this model declares no orbit (" + info.why + "). Use method 'default'";
436}
437
438/**
439 * Port of `solver_mam_retrial.m`.
440 *
441 * @param L the refreshed struct, with non-Markovian processes already gated
442 * out by the runner
443 * @param opt the MAM options; only `mapmsg_quantization` (reneging route) is read,
444 * none reaches the orbit engine, see defect 1
445 * @param cfg the orbit truncation controls
446 */
447template <class T>
449 const MamRetrialConfig& cfg = MamRetrialConfig()) {
450 using lang::DropStrategy;
451 // see defect 1: the reference forwards options.tol to the orbit engine and nothing reads it
452 const T zero = num_traits<T>::from_int(0);
453
454 // Route 1, reneging, is tried first, as solver_mam_retrial.m does.
456 if (ren.ok) return solver_mam_reneging(L, opt, ren);
457
458 const MamRetrialInfo info = mam_retrial_detect(L);
459 if (!info.ok)
460 throw UnsupportedError(ErrorKind{"Reneging"},
461 "SolverMAM: no valid impatience configuration was detected (retrial or reneging): " +
462 (mam_declares_reneging(L) ? ren.why : info.why));
463
464 const std::size_t q = info.station, src = info.source, r = info.cls;
465
466 retrial_detail::assert_markovian(L, src, r, "arrival");
467 retrial_detail::assert_markovian(L, q, r, "service");
468
469 // A bounded retry count is a per-job attribute; the orbit level counts jobs
470 // and nothing else, so a job on its last attempt is indistinguishable there.
471 if (L.droprule[q - 1][r - 1] == DropStrategy::RETRIAL_WITH_LIMIT)
472 throw UnsupportedError(ErrorKind{"Retrial"},
473 "SolverMAM: station '" + L.stations[q - 1].name +
474 "' declares DropStrategy.RETRIAL_WITH_LIMIT. The BMAP/PH/N/N generator indexes its "
475 "levels by the orbit population alone and has no per-job attempt counter, so a job "
476 "about to give up cannot be told from a persistent one. Use SolverCTMC or SolverSSA");
477
478 // ---- the arrival BMAP ---------------------------------------------------
479 // A genuine BATCH arrival would give D = {D0, D1, ..., DK}; lang::Distrib
480 // holds a single (D0, D1) pair, so every model the C++ layer can build is
481 // the K = 1 case. The engine takes the general list, so nothing is lost
482 // here beyond the batch models the model layer cannot express.
483 const Map<T> arv = lang::dist_to_map(L.service[src - 1][r - 1]);
484 std::vector<Matrix<T> > D;
485 D.push_back(arv.D0);
486 D.push_back(arv.D1);
487
488 // ---- the PH service -----------------------------------------------------
489 const Map<T> svc = lang::dist_to_map(L.service[q - 1][r - 1]);
490 const Matrix<T> S = svc.D0;
491 const std::vector<T> beta = map_pie(svc);
492
493 // ---- the orbit parameters ----------------------------------------------
494 // The retrial process is an inter-retry TIME, and the generator carries a
495 // single scalar rate per orbiting job, so only a one-phase process can be
496 // read. The reference takes -D0(1,1) whatever the order is, which for a
497 // multi-phase process is the exit rate of its FIRST phase and not the mean
498 // retry rate of anything.
499 // Retrial rate alpha: mam_retrial_detect reads it from sn.retrialMu and refuses
500 // a station without an exponential retrial delay, so there is no default
501 // (defect 2 no longer applies: the 0.1 placeholder was removed).
502 T alpha = num_traits<T>::from_double(info.alpha);
503 const typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator rit =
504 L.retrialparam.find(q);
505 if (rit != L.retrialparam.end()) {
506 const qn::RetrialParam<T>& rp = rit->second;
507 if (rp.max_attempts.size() >= r && rp.max_attempts[r - 1] > 0)
508 throw UnsupportedError(ErrorKind{"Retrial"},
509 "SolverMAM: station '" + L.stations[q - 1].name + "' bounds the retrial count at " +
510 std::to_string(rp.max_attempts[r - 1]) +
511 " attempts. The BMAP/PH/N/N generator has no per-job attempt counter in its state "
512 "descriptor. Use SolverCTMC or SolverSSA");
513 if (rp.retrial_proc.size() >= r && !rp.retrial_proc[r - 1].disabled) {
514 const Map<T> ret = lang::dist_to_map(rp.retrial_proc[r - 1]);
515 if (ret.order() != 1)
516 throw UnsupportedError(ErrorKind{"Retrial"},
517 "SolverMAM: the retrial process of class '" + L.classes[r - 1].name +
518 "' at station '" + L.stations[q - 1].name + "' has " +
519 std::to_string(ret.order()) +
520 " phases. The generator retries each orbiting job at a single scalar rate, so "
521 "only an exponential inter-retry time can be represented; the reference reads "
522 "-D0(1,1) regardless, which is the exit rate of the first phase and not the "
523 "retry rate of the process");
524 alpha = T(zero - ret.D0(0, 0));
525 } else if (rp.retrial_rate.size() >= r && rp.retrial_rate[r - 1] > zero) {
526 alpha = rp.retrial_rate[r - 1];
527 }
528 }
529 if (!(alpha > zero) || !std::isfinite(num_traits<T>::to_double(alpha)))
530 throw UnsupportedError(ErrorKind{"Retrial"},
531 "SolverMAM: the retrial station '" + L.stations[q - 1].name +
532 "' has no exponential retrial delay; configure one with setRetrial or setOrbit.");
533
534 const T gamma = zero; // sn.orbitImpatience, absent from NetworkStruct
535 const T p = zero; // sn.batchRejectProb, absent from NetworkStruct
536
537 // ---- the truncation, and the refinement the engine leaves to its caller --
538 const double blockw =
539 retrial_detail::retrial_block_width(arv.order(), svc.order(), info.nservers);
540 if (blockw > cfg.max_block)
541 throw UnsupportedError(ErrorKind{"StateSpace"},
542 "SolverMAM: the per-level block of the retrial generator at station '" +
543 L.stations[q - 1].name + "' is " + std::to_string(static_cast<long long>(blockw)) +
544 " states wide, past the " + std::to_string(static_cast<long long>(cfg.max_block)) +
545 "-state cap: the service has " + std::to_string(svc.order()) +
546 " phases and the station " + std::to_string(info.nservers) +
547 " servers, and the busy servers' phase multisets grow as C(n + phases - 1, phases - 1). "
548 "Fit the service with fewer phases, reduce the server count, or raise "
549 "MamRetrialConfig::max_block if the memory cost is acceptable");
550
551 const std::vector<long> Rv(1, info.R);
553 qopt.maxLevel = cfg.orbit_maxlevel;
554 qopt.tailTolerance = cfg.orbit_tailtol;
555 qopt.maxDim = cfg.max_dim;
556 qopt.maxBlockSize = cfg.max_block;
558 qsys::qsys_bmapphnn_retrial(D, beta, S, info.nservers, alpha, gamma, p, Rv, qopt);
559
560 if (cfg.orbit_maxlevel == 0) {
561 // The reference doubles the level until the tail contribution is under
562 // TailTolerance. `blockw` is the per-level width, so (level + 1) * blockw
563 // is the dimension the next solve would assemble.
564 while (retrial_detail::orbit_trunc_error(res) > cfg.orbit_tailtol) {
565 const std::size_t next = 2 * res.truncLevel;
566 if (static_cast<double>(next + 1) * blockw > cfg.max_dim)
567 throw NumericError(ErrorKind{"NonConvergence"},
568 "SolverMAM: the orbit truncation of station '" + L.stations[q - 1].name +
569 "' did not reach the requested accuracy: the tail still contributes " +
570 std::to_string(retrial_detail::orbit_trunc_error(res)) + " of the mean orbit "
571 "length at level " + std::to_string(res.truncLevel) +
572 ", against a target of " + std::to_string(cfg.orbit_tailtol) +
573 ", and doubling would pass the dimension cap. The orbit measures would be "
574 "underestimated, which the reference reports as a warning and this port has no "
575 "channel for. Raise MamRetrialConfig::max_dim, or set "
576 "MamRetrialConfig::orbit_maxlevel to accept a fixed truncation");
577 qopt.maxLevel = next;
578 res = qsys::qsys_bmapphnn_retrial(D, beta, S, info.nservers, alpha, gamma, p, Rv, qopt);
579 }
580 }
581
582 // ---- the LINE metric tuple ---------------------------------------------
584 const std::size_t M = L.nstations, K = L.nclasses;
585 out.Q = Matrix<T>(M, K, zero);
586 out.U = Matrix<T>(M, K, zero);
587 out.R = Matrix<T>(M, K, zero);
588 out.Tp = Matrix<T>(M, K, zero);
589 out.C.assign(K, zero);
590 out.X.assign(K, zero);
591
592 // The orbit is part of the station: a job waiting to retry has not left it.
593 out.Q(q - 1, r - 1) = T(res.L_orbit + res.N_server);
594 out.U(q - 1, r - 1) = res.utilization;
595 out.Tp(q - 1, r - 1) = res.throughput;
596 if (res.throughput > zero)
597 out.R(q - 1, r - 1) = T(out.Q(q - 1, r - 1) / res.throughput);
598 // else the reference writes Inf, and the NaN sweep at the end of
599 // mam_dispatch zeroes every non-finite entry before any caller sees it; a
600 // zero written here is the same value by a route that also holds at
601 // T = Rational, which has no infinity to write.
602
603 out.X[r - 1] = res.throughput;
604 out.C[r - 1] = out.R(q - 1, r - 1);
605 // The reference's `totiter` for this analyzer is the truncation level that
606 // produced the answer, not an iteration count.
607 out.iter = static_cast<int>(res.truncLevel);
608 return out;
609}
610
611} // namespace mam
612} // namespace line
613
614#endif // LINE_SOLVERS_MAM_SOLVER_MAM_RETRIAL_H
NumericError(const std::string &what)
Definition error.h:112
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
std::vector< std::vector< Distrib< T > > > service
service[i][r], 0-based station and class; a disabled entry marks a pair never visited.
std::vector< std::vector< bool > > disabled
std::map< std::size_t, RetrialParam< T > > retrialparam
Retrial parameters, keyed by 1-based STATION index.
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
bool is_open_model() const
sn_is_open_model: EVERY class is open, which is not has_open_classes.
std::vector< std::vector< DropStrategy > > droprule
std::vector< Region > regions
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The exception types the port throws.
The option and result types SolverMAM shares with its analyzers.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
Definition lang_types.h:465
const char * process_to_text(ProcessType p)
The MATLAB ProcessType name, as sn.procid prints it.
Definition lang_types.h:655
bool mam_declares_reneging(const qn::NetworkStruct< T > &L)
True when some station-class pair declares RENEGING, with or without a patience law this analyzer can...
MamRenegingInfo mam_reneging_detect(const qn::NetworkStruct< T > &L)
Port of mam_reneging_applicable.m: is this the MAP/M/s+G shape?
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
Definition map_moment.h:89
MamRetrialInfo mam_retrial_detect(const qn::NetworkStruct< T > &L)
Port of qsys_is_retrial.m, plus the reneging gate of solver_mam_retrial.m.
mva::MvaSolution< T > solver_mam_retrial(const qn::NetworkStruct< T > &L, const MamOptions &opt, const MamRetrialConfig &cfg=MamRetrialConfig())
Port of solver_mam_retrial.m.
mva::MvaSolution< T > solver_mam_reneging(const qn::NetworkStruct< T > &L, const MamOptions &opt, const MamRenegingInfo &info)
The reneging route of solver_mam_retrial.m.
std::string mam_retrial_refusal(const qn::NetworkStruct< T > &L)
The 'retrial' method's applicability as one sentence; empty when applicable.
BmapPhNnRetrialResult< T > qsys_bmapphnn_retrial(const std::vector< Matrix< T > > &D, const std::vector< T > &beta, const Matrix< T > &S, int N, const T &alpha, const T &gamma, const T &p, const std::vector< long > &R, const BmapPhNnRetrialOptions &opt)
The BMAP/PH/N/N bufferless retrial queue.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
The BMAP/PH/N/N bufferless retrial queue with flexible retrial admission control.
Port of solver_mam_basic.m, the dec.source analyzer and the default algorithm of SolverMAM.
The reneging route of solver_mam_retrial.m: the MAP/M/s+G queue whose waiting jobs abandon after a ge...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
The options SolverMAM reads.
Definition mam_types.h:30
What mam_reneging_applicable.m returns: the station it found, or why it found none.
std::string why
the reference's errorMsg, empty when ok
The knobs solver_mam_retrial.m reads from options.config and from model fields the C++ NetworkStruct ...
double max_dim
'MaxDim': the largest generator dimension the refinement may reach.
double orbit_tailtol
options.config.orbit_tailtol, the relative orbit-truncation target.
std::size_t orbit_maxlevel
options.config.orbit_maxlevel; 0 asks for the adaptive refinement.
double max_block
'MaxBlockSize': the largest per-level block V*d that may be assembled.
What qsys_is_retrial.m returns: the station it found, or why it found none.
std::string why
the reference's errorMsg, empty when ok
std::size_t station
1-based station index of the retrial queue
double alpha
retInfo.alpha = sn.retrialMu of the retrial station (no default)
std::size_t cls
1-based class index; the reference is single-class
long R
admission threshold, N-1 unless an FCR lowers it
double p
retInfo.p: batch rejection probability default
double gamma
retInfo.gamma: orbit impatience default
std::size_t source
1-based station index of the Source
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Matrix< T > D0
Definition map_moment.h:54
std::size_t order() const
Definition map_moment.h:57
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:97
std::vector< T > X
Definition mva_types.h:99
std::vector< T > C
Definition mva_types.h:99
The parameters of a retrial station: MATLAB sn.retrialProc and friends.
std::vector< int > max_attempts
0 = unbounded
std::vector< T > retrial_rate
mu_r, the per-class orbit retry rate
std::vector< lang::Distrib< T > > retrial_proc
retrial_proc[r] is the class-r retrial process; empty = not a retrial class.
Options of qsys_bmapphnn_retrial (the name-value pairs of the .m file).
std::size_t maxLevel
Fixed orbit truncation level ('MaxLevel'); 0 selects the reference's adaptive choice,...
double maxDim
'MaxDim': cap on the total generator dimension of the refinement.
double tailTolerance
'TailTolerance': relative orbit-truncation error target.
double maxBlockSize
'MaxBlockSize': cap on the per-level block size V*d; exceeding it is an error.
Result of qsys_bmapphnn_retrial.
T L_orbit
mean number of customers in orbit
std::size_t truncLevel
truncation level used
T N_server
mean number of busy servers