5#ifndef LINE_SOLVERS_MAM_SOLVER_MAM_RETRIAL_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_RETRIAL_H
160namespace retrial_detail {
165 const typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator it =
168 for (std::size_t r = 0; r < it->second.retrial_proc.size(); ++r)
169 if (!it->second.retrial_proc[r].disabled)
return true;
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))
190 std::string(
"SolverMAM: the ") + role +
" process of class '" + L.
classes[r - 1].name +
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");
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 '" +
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 "
215inline double retrial_block_width(std::size_t V, std::size_t M,
int N) {
216 double d = 0.0, term = 1.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);
220 if (d > 1e12)
return 1e12;
222 return static_cast<double>(V) * d;
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()
235 : std::numeric_limits<double>::min();
236 return static_cast<double>(r.truncLevel) * top / denom;
256 info.
why =
"the BMAP/PH/N/N retrial solver requires an open queueing model";
260 info.
why =
"the BMAP/PH/N/N retrial solver supports a single class only";
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);
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)";
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) {
291 info.
why =
"no RETRIAL drop strategy is configured on a bufferless queue";
298 typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator rp =
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) {
306 info.
why =
"The retrial station has no retrial delay; configure one with setRetrial or setOrbit.";
311 info.
why =
"the BMAP/PH/N/N retrial solver requires an exponential retrial delay; "
312 "use SolverLDES for a non-exponential one";
315 if (c < rp->second.max_attempts.size() && rp->second.max_attempts[c] > 0) {
317 info.
why =
"the BMAP/PH/N/N retrial solver supports only unlimited retrial attempts; "
318 "use SolverLDES for a finite cap";
323 if (c < rst.orbit_impatience.size() && !rst.orbit_impatience[c].disabled &&
326 info.
why =
"the BMAP/PH/N/N retrial solver requires an exponential orbit impatience; "
327 "use SolverLDES for a non-exponential one";
335 info.
why =
"BMAP/PH/N/N retrial solver does not model non-persistent customers "
336 "(setOrbitPersistence); use SolverCTMC or SolverSSA.";
341 info.
why =
"BMAP/PH/N/N retrial solver does not model orbital search "
342 "(setOrbitalSearch); use SolverCTMC or SolverSSA.";
349 info.
alpha = rmean > 0.0 ? 1.0 / rmean
350 : (c < rp->second.retrial_rate.size()
354 for (std::size_t i = 1; i <= L.
nstations; ++i)
355 if (L.
stations[i - 1].nodetype == qn::NodeType::Source) {
360 info.
why =
"no Source node found";
365 if (!std::isfinite(ns) || ns < 1.0) {
366 info.
why =
"the retrial station must have a finite, positive server count";
369 info.
nservers =
static_cast<int>(ns);
376 info.
why =
"Invalid arrival process at source.";
381 info.
why =
"Invalid service process at queue.";
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];
396 if (rfcr <=
static_cast<double>(info.
nservers) - 1.0)
397 info.
R =
static_cast<long>(rfcr);
423 if (info.
ok)
return std::string();
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'";
461 "SolverMAM: no valid impatience configuration was detected (retrial or reneging): " +
466 retrial_detail::assert_markovian(L, src, r,
"arrival");
467 retrial_detail::assert_markovian(L, q, r,
"service");
471 if (L.
droprule[q - 1][r - 1] == DropStrategy::RETRIAL_WITH_LIMIT)
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");
484 std::vector<Matrix<T> > D;
491 const std::vector<T> beta =
map_pie(svc);
503 const typename std::map<std::size_t, qn::RetrialParam<T> >::const_iterator rit =
509 "SolverMAM: station '" + L.
stations[q - 1].name +
"' bounds the retrial count at " +
511 " attempts. The BMAP/PH/N/N generator has no per-job attempt counter in its state "
512 "descriptor. Use SolverCTMC or SolverSSA");
515 if (ret.
order() != 1)
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));
531 "SolverMAM: the retrial station '" + L.
stations[q - 1].name +
532 "' has no exponential retrial delay; configure one with setRetrial or setOrbit.");
534 const T gamma = zero;
538 const double blockw =
539 retrial_detail::retrial_block_width(arv.order(), svc.
order(), info.
nservers);
540 if (blockw > cfg.max_block)
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");
551 const std::vector<long> Rv(1, info.
R);
555 qopt.
maxDim = cfg.max_dim;
560 if (cfg.orbit_maxlevel == 0) {
564 while (retrial_detail::orbit_trunc_error(res) > cfg.orbit_tailtol) {
566 if (
static_cast<double>(next + 1) * blockw > cfg.max_dim)
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");
589 out.
C.assign(K, zero);
590 out.
X.assign(K, zero);
597 out.
R(q - 1, r - 1) = T(out.
Q(q - 1, r - 1) / res.
throughput);
604 out.
C[r - 1] = out.
R(q - 1, r - 1);
NumericError(const std::string &what)
UnsupportedError(const std::string &what)
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.
const char * process_to_text(ProcessType p)
The MATLAB ProcessType name, as sn.procid prints it.
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).
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.
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....
The options SolverMAM reads.
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).
std::size_t order() const
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
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 utilization
N_server / N.
T throughput
N_server / b1.
T N_server
mean number of busy servers