5#ifndef LINE_SOLVERS_MVA_SOLVER_MVA_POLLING_H
6#define LINE_SOLVERS_MVA_SOLVER_MVA_POLLING_H
64std::vector<std::size_t> polling_polled_classes(
const qn::NetworkStruct<T>& L, std::size_t q) {
65 std::vector<std::size_t> polled;
66 for (std::size_t r = 0; r < L.nclasses; ++r) {
67 const double mu = num_traits<T>::to_double(L.rates(q - 1, r));
68 const bool disabled = r < L.service[q - 1].size() && L.service[q - 1][r].disabled;
69 if (!disabled && !std::isnan(mu) && mu > 0.0) polled.push_back(r);
94 if (st.
sched == qn::SchedStrategy::POLLING) any =
true;
96 std::string base = method.empty() ? std::string(
"default") : method;
97 if (base.rfind(
"amva.", 0) == 0) base = base.substr(5);
98 int nsrc = 0, nq = 0, nsnk = 0;
100 if (nd.
nodetype == NodeType::Source) ++nsrc;
101 else if (nd.
nodetype == NodeType::Queue) ++nq;
102 else if (nd.
nodetype == NodeType::Sink) ++nsnk;
104 const bool shape = L.
nof_nodes() == 3 && nsrc == 1 && nq == 1 && nsnk == 1 &&
107 return "SolverMVA serves a POLLING station only as an open multiclass single-station "
108 "system (Source -> Queue -> Sink); use SolverLDES or SolverJMT for this model.";
109 if (base !=
"default" && base !=
"exact")
110 return "the polling analyzer answers 'default' and 'exact' only; the '" + base +
111 "' method has no polling arm";
112 std::size_t src = 0, q = 0;
113 for (std::size_t i = 0; i < L.
nstations; ++i) {
114 if (L.
stations[i].nodetype == NodeType::Source) src = i + 1;
115 if (L.
stations[i].nodetype == NodeType::Queue) q = i + 1;
119 return "the polling analyzer models a single cyclic server; this station has more than one server.";
120 const std::vector<std::size_t> polled = detail::polling_polled_classes(L, q);
122 return "the polling analyzer requires one polling type, declared for every class the station serves.";
124 for (std::size_t r : polled)
126 return "the polling analyzer requires one polling type, declared for every class the station serves.";
128 return "the polling analyzer has no load-dependent polling order (PollingOrder); use "
129 "SolverCTMC, SolverSSA or SolverLDES.";
131 return "the polling analyzer has no time-limited visits (PollingTimer); use SolverCTMC, "
132 "SolverSSA or SolverLDES.";
137 for (std::size_t r : polled)
141 return "the polling-table analyzer requires exhaustive or gated service and Poisson arrivals.";
147 return "the polling analyzer has no formula for G-limited polling with K>1 (only K=1, "
148 "which is 1-limited); use SolverCTMC, SolverSSA or SolverLDES.";
151 return "MVA exact method unavailable for K-limited polling with K>1 (only the "
152 "approximation in method default).";
153 if (base ==
"exact") {
155 for (std::size_t r : polled)
158 return "MVA exact method unavailable for this model.";
173 std::size_t src = 0, q = 0;
174 for (std::size_t i = 0; i < L.
nstations; ++i) {
175 if (L.
stations[i].nodetype == qn::NodeType::Source) src = i + 1;
176 if (L.
stations[i].nodetype == qn::NodeType::Queue) q = i + 1;
178 if (src == 0 || q == 0)
return "";
179 for (std::size_t r : detail::polling_polled_classes(L, q)) {
181 if (std::isfinite(v) && std::fabs(v - 1.0) > 1e-8)
182 return "The MVA polling analyzer assumes Poisson arrivals, but some classes have a "
183 "non-exponential arrival process (SCV ~= 1). The result treats them as Poisson "
184 "with the same rate; use SolverCTMC, SolverSSA or SolverLDES for an accurate "
207 "solver_mva_polling_analyzer: the two-moment polling inputs come from distribution "
208 "SCVs, which need a transcendental T");
218 std::size_t src = 0, q = 0;
219 for (std::size_t i = 0; i < M; ++i) {
220 if (L.
stations[i].nodetype == NodeType::Source) src = i + 1;
221 if (L.
stations[i].nodetype == NodeType::Queue) q = i + 1;
228 std::vector<T> Vq(K, zero);
229 for (std::size_t c = 0; c < L.
nchains; ++c)
230 for (std::size_t r = 0; r < K; ++r) Vq[r] += L.
visits[c](qstateful - 1, r);
232 const std::vector<std::size_t> polled = detail::polling_polled_classes(L, q);
233 const std::size_t nP = polled.size();
235 pm.
lambda.assign(nP, zero);
236 pm.
b.assign(nP, zero);
237 pm.
b2.assign(nP, zero);
238 pm.
r.assign(nP, zero);
239 pm.
delta2.assign(nP, zero);
241 for (std::size_t jj = 0; jj < nP; ++jj) {
242 const std::size_t r = polled[jj];
243 const T mu = L.
rates(q - 1, r);
244 const T lr = L.
rates(src - 1, r);
246 pm.
b[jj] = T(one / mu);
247 pm.
b2[jj] = T(T(one + L.
scv(q - 1, r)) / T(mu * mu));
254 T so_mean = zero, so_var = zero;
258 so_var = T(qst.
switchover[r].scv * so_mean * so_mean);
261 if (!(m > 0.0) || std::isinf(m)) {
263 so_var = T(imm * imm);
277 std::vector<std::size_t> tabjj(Mt);
278 std::vector<T> s_mean(Mt), s_var(Mt);
279 for (std::size_t t = 0; t < Mt; ++t) {
282 while (jj < nP && polled[jj] != cls) ++jj;
285 "solver_mva_polling_analyzer: the polling table lists a class the station does not serve");
298 s_mean[t] = pm.
r[jj];
327 "solver_mva_polling_analyzer: unsupported polling type");
336 out.
C.assign(K, zero);
337 out.
X.assign(K, zero);
338 for (std::size_t jj = 0; jj < nP; ++jj) {
339 const std::size_t r = polled[jj];
340 const T mu = L.
rates(q - 1, r);
341 const T Rr = T(T(Wp[jj] + T(one / mu)) * Vq[r]);
342 out.
R(q - 1, r) = Rr;
347 out.
U(q - 1, r) = T(pm.
lambda[jj] / mu);
348 out.
Q(q - 1, r) = T(pm.
lambda[jj] * Rr);
350 out.
method =
"stationtime";
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t stateful_of_station(std::size_t st) const
std::size_t nof_nodes() const
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< NodeDef > nodes
every node, in creation order
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
double nclosedjobs() const
sn.nclosedjobs: the total population of the closed classes.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The option and result types every MVA analyzer shares.
@ CYCLIC
fixed cyclic order (or the polling table)
PollingType
Polling service disciplines, with the values of MATLAB PollingType.
@ KLIMITED
serve at most K per visit (K in pollingPar)
@ EXHAUSTIVE
serve until the queue empties
@ GATED
serve exactly the jobs present at the polling instant
@ GLIMITED
serve at most K of the jobs present at the polling instant
@ DECREMENTING
serve until the queue is one shorter than at arrival
NodeType
Node kinds, with the values of MATLAB NodeType.
MvaSolution< T > solver_mva_polling_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_polling_analyzer.m.
std::string polling_poisson_warning(const qn::NetworkStruct< T > &L)
The reference's line_warning for method 'default' when a polled class has a non-Poisson arrival proce...
std::string polling_reason(const qn::NetworkStruct< T > &L, const std::string &method)
Why SolverMVA cannot answer a model holding a POLLING station under method, or "" when it can (or the...
std::vector< T > polling_qsys_table(const std::vector< T > &lambda, const std::vector< T > &b, const std::vector< T > &b2, const std::vector< std::size_t > &table, const std::vector< T > &s_mean, const std::vector< T > &s_var, bool gated)
Mean waiting times only; see polling_qsys_table_full.
std::vector< T > polling_qsys_klimited(const PollingMoments< T > &m, std::vector< long > K)
std::vector< T > polling_qsys_decrementing(const PollingMoments< T > &m)
std::vector< T > polling_qsys_exhaustive(const PollingMoments< T > &m)
Exhaustive service: the server empties a queue completely before switching.
std::vector< T > polling_qsys_gated(const PollingMoments< T > &m)
Gated service: only the jobs found at the polling instant are served.
std::vector< T > polling_qsys_1limited(const PollingMoments< T > &m)
1-limited polling: one job served per visit.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Mean waiting times in polling systems: 1-limited and decrementing service, and the pseudo-conservatio...
Mean waiting times of a polling system under exhaustive service.
Approximate mean waiting times of a cyclic k-limited polling system.
Exact mean waiting times of a polling system with a polling table.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
bool is_immediate() const
static constexpr double Immediate
Rate of an Immediate distribution; its mean is 1/Immediate = 1e-8.
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
double lG
log of the normalizing constant, the reference's lG.
Per-queue first two moments of the arrival, service and switchover processes, the reduced form both f...
std::vector< T > b2
second raw moment of the service time
std::vector< T > lambda
arrival rate per queue
std::vector< T > delta2
variance of the switchover time per queue
std::vector< T > r
mean switchover time per queue
std::vector< T > b
mean service time per queue
One station of the network.
std::vector< Distrib< T > > polling_table_sw
double nservers
may be infinite (a Delay, or an inf-scheduled task)
std::vector< lang::PollingType > polling_type
Polling parameters for a POLLING station, MATLAB's pollingType, switchoverTime and pollingPar on the ...
lang::PollingOrder polling_order
std::vector< std::size_t > polling_table
The polling extensions (Queue.setPollingTable, setPollingOrder, setPollingTimer).
std::vector< Distrib< T > > switchover
lang::PollingTimer polling_timer_scope