5#ifndef LINE_SOLVERS_MAM_SOLVER_MAM_PASSAGE_TIME_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_PASSAGE_TIME_H
93 "solver_mam_passage_time: the sojourn-time law comes from the age process, whose "
94 "first-return matrix is a tolerance-terminated Riccati doubling; rerun with "
95 "--arith double or --arith real");
104 if (!std::isinf(c.
population)) allopen =
false;
105 if (M != 2 || !allopen)
107 "solver_mam_passage_time: the MAM response-time distribution covers a single open "
108 "queue only (exactly two stations, a Source and one queue, every class open); this "
109 "model has " + std::to_string(M) +
" stations" + (allopen ?
"" :
" and a closed class") +
110 ". The reference warns and returns no result at all for it");
112 std::size_t src = 0, q = 0;
113 for (std::size_t i = 1; i <= M; ++i) {
114 if (L.
stations[i - 1].sched == SchedStrategy::EXT) src = i;
117 if (src == 0 || q == 0)
119 "solver_mam_passage_time: the model must have a Source and one queueing station");
122 if (!(qs == SchedStrategy::FCFS || qs == SchedStrategy::HOL ||
123 qs == SchedStrategy::FCFSPRPRIO || qs == SchedStrategy::PS))
126 " discipline is not covered; the reference supports FCFS, HOL, "
127 "FCFSPRPRIO and PS only");
131 bool prio_distinct =
false;
132 if (qs == SchedStrategy::HOL || qs == SchedStrategy::FCFSPRPRIO)
133 for (std::size_t r = 1; r < K; ++r)
136 const std::size_t npts =
137 opt.num_cdf_pts > 0 ?
opt.num_cdf_pts :
static_cast<std::size_t
>(100);
142 std::vector<Mmap<T>> parts;
143 for (std::size_t r = 0; r < K; ++r) {
148 m.
Dc.assign(1, s.
D1);
152 for (std::size_t p = 1; p < parts.size(); ++p)
156 std::vector<RespTCdf<T>> out(K);
158 if (qs == SchedStrategy::PS && L.
stations[q - 1].nservers != 1.0)
160 "solver_mam_passage_time: getCdfRespT on a PS queue needs a single server; this "
161 "station has " + std::to_string(
static_cast<long long>(L.
stations[q - 1].nservers)) +
".");
163 if (qs == SchedStrategy::PS) {
167 std::vector<Map<T>> svk(K);
169 for (std::size_t r = 0; r < K; ++r) {
171 if (svk[r].D0.rows() != 1) allexp =
false;
174 for (std::size_t r = 1; r < K; ++r)
178 if (A.
order() == 1 && !allexp) {
184 std::vector<double> lamk(K, 0.0);
186 for (std::size_t r = 0; r < K; ++r) {
190 std::vector<std::size_t> off(K + 1, 0);
192 std::vector<std::vector<double>> pie(K);
193 for (std::size_t r = 0; r < K; ++r) {
196 const std::vector<T> pr =
map_pie(svk[r]);
198 n += svk[r].D0.rows();
202 std::vector<double> amix(n, 0.0);
204 for (std::size_t r = 0; r < K; ++r) {
205 if (!(lamk[r] > 0.0))
continue;
206 const std::size_t nk = svk[r].D0.rows();
207 for (std::size_t i = 0; i < nk; ++i) {
208 amix[off[r] + i] = (lamk[r] / lam) * pie[r][i];
209 for (std::size_t j = 0; j < nk; ++j)
214 throw InputError(
"solver_mam_passage_time: the PS CDF grid needs at least two "
215 "points, since F(0) = 0 is prepended rather than evaluated");
216 for (std::size_t r = 0; r < K; ++r) {
217 if (!(lamk[r] > 0.0))
continue;
220 for (std::size_t i = 0; i < pie[r].size(); ++i) mo.
tagAlpha[off[r] + i] = pie[r][i];
225 const double sd = std::sqrt(std::max(mom.
varUncond, 0.0));
227 for (
int j = 0; j < 8; ++j)
228 to.
t.push_back(mom.
meanUncond + 10.0 * std::pow(2.0, j) * sd);
230 std::size_t ipos = 8;
231 for (std::size_t j = 0; j < 8; ++j)
235 std::cerr <<
"[LINE] Warning: the PS response time CDF of class " << (r + 1)
237 <<
" of its mass on the computed support.\n";
239 const double xmax = to.
t[ipos];
240 std::vector<double> x(npts, 0.0);
242 for (std::size_t i = 0; i < npts; ++i)
243 x[i] = xmax *
static_cast<double>(i) /
static_cast<double>(npts - 1);
246 const std::size_t nlin = (npts + 1) / 2;
247 const double x0 = to.
t[0];
248 for (std::size_t i = 0; i < nlin; ++i)
249 x[i] = x0 *
static_cast<double>(i) /
static_cast<double>(nlin - 1);
250 const std::size_t nlog = npts - nlin + 1;
251 const double l0 = std::log10(x0), l1 = std::log10(xmax);
252 for (std::size_t i = 1; i < nlog; ++i)
253 x[nlin - 1 + i] = std::pow(10.0, l0 + (l1 - l0) *
static_cast<double>(i) /
254 static_cast<double>(nlog - 1));
257 go.
t.assign(x.begin() + 1, x.end());
259 out[r].X.resize(npts);
260 out[r].F.resize(npts);
261 for (std::size_t i = 0; i < npts; ++i) {
270 std::vector<T> mu(K, zero);
271 for (std::size_t r = 0; r < K; ++r) {
273 if (sv.
D0.rows() != 1)
275 "solver_mam_passage_time: a PS queue fed by a non-Poisson MAP requires "
276 "exponential (order-1) service times; with Poisson arrivals any phase-type "
277 "service is solved exactly");
278 mu[r] = T(-sv.
D0(0, 0));
280 for (std::size_t r = 1; r < K; ++r)
284 "solver_mam_passage_time: a multiclass PS queue fed by a non-Poisson MAP "
285 "requires identical exponential service rates; with Poisson arrivals "
286 "class-dependent rates are solved exactly");
289 for (std::size_t c = 0; c < A.
classes(); ++c)
290 for (std::size_t i = 0; i < Dagg.rows(); ++i)
291 for (std::size_t j = 0; j < Dagg.cols(); ++j) Dagg(i, j) += A.
Dc[c](i, j);
293 const T rho = T(lambda / mu[0]);
296 "solver_mam_passage_time: the PS queue is unstable, so it has no sojourn-time "
298 const T mean = T(one / T(mu[0] * T(one - rho)));
300 std::vector<T> x(npts, zero);
301 for (std::size_t i = 0; i < npts; ++i)
302 x[i] = (npts == 1) ? xmax
304 static_cast<double>(i) /
305 static_cast<double>(npts - 1)));
307 for (std::size_t r = 0; r < K; ++r) {
309 out[r].F.resize(npts);
310 for (std::size_t i = 0; i < npts; ++i) out[r].F[i] = T(one - res.
w_bar[i]);
316 std::vector<PhService<T>> svc(K);
317 for (std::size_t r = 0; r < K; ++r) {
318 const double ns = L.
stations[q - 1].nservers;
320 const T target = std::isfinite(ns)
332 std::vector<std::size_t> iK(K);
333 for (std::size_t r = 0; r < K; ++r) iK[r] = r;
334 std::stable_sort(iK.begin(), iK.end(), [&L](std::size_t a, std::size_t b) {
335 return L.classes[a].prio > L.classes[b].prio;
337 for (std::size_t j = 1; j < K; ++j)
340 "solver_mam_passage_time: SolverMAM requires either identical priorities or "
341 "all distinct priorities");
345 std::vector<PhService<T>> sl;
346 for (std::size_t j = 0; j < K; ++j) {
347 pa.Dc.push_back(A.
Dc[iK[j]]);
348 sl.push_back(svc[iK[j]]);
350 const bool pr = (qs == SchedStrategy::FCFSPRPRIO);
351 const std::vector<std::vector<T>> moms =
354 for (std::size_t j = 0; j < K; ++j) {
357 xmax = std::max(xmax, m1 + 10.0 * std::sqrt(std::max(m2 - m1 * m1, 0.0)));
359 std::vector<T> x(npts, zero);
360 for (std::size_t i = 0; i < npts; ++i)
363 static_cast<double>(npts - 1));
365 throw InputError(
"solver_mam_passage_time: the priority CDF grid needs at least two "
366 "points, since F(0) = 0 is prepended rather than evaluated");
367 const std::vector<T> pts(x.begin() + 1, x.end());
368 const std::vector<std::vector<T>> dist =
370 for (std::size_t j = 0; j < K; ++j) {
374 o.
F.insert(o.
F.end(), dist[j].begin(), dist[j].end());
381 for (std::size_t r = 0; r < K; ++r) {
384 const std::size_t n = ph[r].A.rows();
386 for (std::size_t i = 0; i < n; ++i) {
388 for (std::size_t j = 0; j < n; ++j) s += ph[r].A(i, j);
389 for (std::size_t j = 0; j < n; ++j) D1(i, j) = T(-s * ph[r].alpha[j]);
391 const Map<T> RDph{ph[r].A, D1};
399 const std::vector<T> c =
map_cdf(RDph, std::vector<T>{probe});
403 "solver_mam_passage_time: the sojourn-time CDF did not reach one within 1000 "
404 "standard deviations");
407 std::vector<T> x(npts, zero);
408 for (std::size_t i = 0; i < npts; ++i)
409 x[i] = (npts == 1) ? xmax
411 static_cast<double>(i) /
412 static_cast<double>(npts - 1)));
435 if (cdf.
F.empty())
throw InputError(
"mam_percentiles_from_cdf: the CDF is empty");
436 std::vector<double> p, t;
437 for (std::size_t i = 0; i < cdf.
F.size(); ++i) {
439 if (!p.empty() && std::fabs(fi - p.back()) < 1e-15) {
446 std::vector<T> out(pcts.size(), zero);
447 for (std::size_t k = 0; k < pcts.size(); ++k) {
449 const double want = pcts[k] > 1.0 ? pcts[k] / 100.0 : pcts[k];
455 while (lo + 2 < p.size() && p[lo + 1] < want) ++lo;
456 const double denom = p[lo + 1] - p[lo];
457 const double frac = (std::fabs(denom) < 1e-300) ? 0.0 : (want - p[lo]) / denom;
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< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
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.
Cumulative distribution of the inter-arrival time of a MAP.
Sojourn time distribution in a MAP/M/1 processor-sharing queue.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
The MMAP assembly primitives solver_mam_basic.m builds its per-station arrival stream from: mmap_expo...
The MMAP[K]/PH[K]/1 FCFS queue: per-class mean number in system and per-class queue-length distributi...
The MMAP[K]/PH[K]/1 priority queue, preemptive resume (mmapph1prpr_*) and non-preemptive (mmapph1nppr...
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
const char * sched_to_text(SchedStrategy s)
std::vector< T > mam_percentiles_from_cdf(const RespTCdf< T > &cdf, const std::vector< double > &pcts)
Port of the CDF path of @@SolverMAM/getPerctRespT.m: linear interpolation of the response-time CDF at...
T map_mean(const Map< T > &m)
Mean inter-arrival time, 1/lambda.
T map_var(const Map< T > &m)
Variance of the inter-arrival time.
std::vector< RespTCdf< T > > solver_mam_passage_time(const qn::NetworkStruct< T > &L, const MamOptions &opt)
Port of solver_mam_passage_time.m.
std::vector< std::vector< T > > mmapph1prpr_stdistr(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, const std::vector< T > &points, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class sojourn-time CDF at the (strictly positive) points, preemptive resume priority.
std::vector< T > map_cdf(const Map< T > &m, const std::vector< T > &points)
Cumulative distribution of the inter-arrival time at the given points.
std::vector< std::vector< T > > mmapph1nppr_stdistr(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, const std::vector< T > &points, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class sojourn-time CDF at the (strictly positive) points, non-preemptive priority.
Map< T > map_scale(const Map< T > &in, const T &new_mean)
Rescale time so that the mean inter-arrival time becomes new_mean.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
std::vector< std::vector< T > > mmapph1prpr_stmoms(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, std::size_t n, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class sojourn-time moments 1..n, preemptive resume priority.
std::vector< StDistrPh< T > > mmapph1fcfs_stdistr_ph(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, double precision=1e-14)
Per-class SOJOURN TIME as a continuous phase-type law, BUTools' 'stDistrPH'.
Mmap< T > mmap_super(const Mmap< T > &a, const Mmap< T > &b)
Superposition of two MMAPs: the phase process is the product chain, and the class list of the result ...
std::vector< std::vector< T > > mmapph1nppr_stmoms(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, std::size_t n, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class sojourn-time moments 1..n, non-preemptive priority.
T map_lambda(const Map< T > &m)
Stationary arrival rate, lambda = pi D1 e.
MapM1psResult< T > map_m1ps_cdfrespt(const Matrix< T > &C, const Matrix< T > &D, const T &mu, const std::vector< T > &x, const T &epsilon, const T &epsilon_prime)
Complementary sojourn time distribution of a MAP/M/1-PS queue by the spectral-radius truncation (map_...
Mg1PsResult qsys_mg1_ps(double lambda, const std::vector< double > &alpha, const Matrix< double > &Tmat, const Mg1PsOptions &opt)
Sojourn-time distribution of the M/G/1 processor-sharing queue.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Sojourn-time distribution of the M/G/1 processor-sharing queue.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
The MATLAB GlobalConstants, as reported by lineStart at its defaults.
static constexpr double FineTol
The options SolverMAM reads.
What the two MAP/M/1-PS sojourn entry points return.
std::vector< T > w_bar
Pr[W > x] at each requested point.
A MAP as the pair of matrices (D0, D1).
An MMAP: the underlying MAP plus the per-class arrival matrices.
std::size_t classes() const
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
std::size_t order() const
One class's response-time CDF, the reference's RD{station, class} = [F, X].
std::vector< T > X
the points they are evaluated at
std::vector< T > F
CDF values.
One job class of the network.
double population
infinite for an open class
Options of qsys_mg1_ps, mirroring the reference's name-value pairs.
std::vector< double > tagAlpha
Initial vector of the TAGGED job's requirement, PH(tagAlpha, T), on the phase-type path only (empty: ...
std::vector< double > t
times to evaluate the sojourn distribution at
Everything qsys_mg1_ps returns.
std::vector< double > cdfUncond