LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sim_prio_tailquantile.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_API_SIM_SIM_PRIO_TAILQUANTILE_H
6#define LINE_API_SIM_SIM_PRIO_TAILQUANTILE_H
7
8/**
9 * @file
10 * @ingroup api_sim
11 * Tail quantile of the sojourn time in a non-preemptive priority M/M/1 queue.
12 *
13 * Port of matlab/src/api/sim/sim_prio_tailquantile.m, cross-checked against
14 * jar/src/main/java/jline/api/sim/Sim_prio_tailquantile.java and
15 * python/line_solver/api/sim/prio_tailquantile.py.
16 *
17 * K classes, Poisson arrivals lambda[k], exponential service mu[k], one server,
18 * NON-PREEMPTIVE priority (class index 0 highest), FCFS within a class. For p
19 * close to 1 the p-quantile Q_k(p) of each class's steady-state response time
20 * is estimated with Algorithm 1 of Guang et al.:
21 * 1. m2 plain regenerative cycles estimate E[alpha_k];
22 * 2. adaptive cross-entropy learns exponential importance rates, raising the
23 * level gamma_t ((1-rho) sample quantile of the per-cycle maximum class-k
24 * response time) until it passes Q_k(p) (Remark 1) or reaches gammaMax;
25 * without gammaMax the CE cycles stay under the importance rates for their
26 * whole length while those are stable (sum lambda~/mu~ < 0.95), and the
27 * switching level of step 3 is the eq. (8) pilot quantile of the last CE batch;
28 * 3. m1 cycles under a SWITCHING change of measure: importance rates until
29 * the first class-k arrival whose lower bound R' (own service + queued
30 * class <= k work + residual service) exceeds gammaMax, original rates
31 * after; each class-k job carries L at its enter-service epoch;
32 * 4. Q^ = R_(n_p), n_p = min{n : sum_{i>=n} L_(i) <= (1-p)(m1/m2) sum alpha_k}
33 * (eq. 8), with the batching interval of Section 4 built on the Student-t
34 * quantile with r - 1 degrees of freedom (the printed 1.96 is the r -> inf
35 * limit and covers only 92% at r = 10).
36 *
37 * RANDOM NUMBERS. One MRG32k3a stream (line::rng::Mrg32k3a, L'Ecuyer's
38 * double-precision form), seeded by the same affine map and consumed in the
39 * same order as the other three codebases, so a seed gives the same estimate
40 * everywhere up to last-ulp differences of log().
41 *
42 * WARNINGS BECOME FIELDS. Where MATLAB line_warning()s that the CE loop hit
43 * maxIter, the result carries ceConverged = false and the message in warnings.
44 *
45 * Reference: J. Guang, G. Hong, X. Chen, X. Peng, L. Chen, B. Bai, G. Zhang,
46 * "Tail quantile estimation for non-preemptive priority queues", Proc. Winter
47 * Simulation Conference 2022, 85-96.
48 */
49
50#include <algorithm>
51#include <cmath>
52#include <cstddef>
53#include <cstdio>
54#include <limits>
55#include <numeric>
56#include <string>
57#include <vector>
58
60#include "line/util/error.h"
61#include "line/util/rng_ssj.h"
62
63namespace line {
64namespace sim {
65
66/** Options of sim_prio_tailquantile; defaults as in the MATLAB reference. */
68 int cycles = 10000; ///< m1 = m2 when neither is set
69 int m1 = 0; ///< importance-sampled cycles, 0 = cycles
70 int m2 = 0; ///< plain cycles, 0 = cycles
71 int ceSamples = 10000; ///< N, cycles per CE iteration
72 double rho = 0.1; ///< CE elite fraction
73 int maxIter = 50; ///< CE iteration cap
74 std::vector<double> gammaMax; ///< empty, one value, or one per target class
75 std::string importance = "ce"; ///< "ce" or "none"
76 std::vector<std::vector<double>> isRates; ///< [lambda~, mu~] rows; needs gammaMax
77 std::vector<int> classes; ///< 1-based target classes, empty = all
78 int batches = 10; ///< r, batches for the interval
79 double confidence = 0.95; ///< interval level
80 long long seed = 23000; ///< in [0, 2^31)
81};
82
83/** Estimate for one target class. */
85 int classIndex = 0; ///< 1-based
86 double p = 0;
87 double quantile = 0;
88 double ciLower = 0;
89 double ciUpper = 0;
90 double halfWidth = 0;
91 double tailProb = 0; ///< estimated P(R > quantile)
92 std::vector<double> batchQuantiles;
93 std::vector<double> lambdaIS;
94 std::vector<double> muIS;
95 double gammaMax = 0; ///< switching level of the importance-sampled cycles
96 int ceIterations = 0;
97 std::vector<double> ceLevels;
98 bool ceConverged = true;
99 int numSamples = 0; ///< class-k jobs in the m1 cycles
100 double meanAlpha = 0; ///< estimate of E[alpha_k]
101 int m1 = 0;
102 int m2 = 0;
103 std::string importance;
104 std::vector<std::string> warnings;
105};
106
107namespace detail_prio_tq {
108
109inline void seed_stream(rng::Mrg32k3a& g, long long seed) {
110 const long long a[6] = {1, 65539, 69069, 1, 65539, 69069};
111 const long long b[6] = {12345, 54321, 98765, 13579, 24680, 11111};
112 long long s[6];
113 for (int i = 0; i < 6; ++i) {
114 const long long m = (i < 3) ? 4294967087LL : 4294944443LL;
115 s[i] = 1 + (seed * a[i] + b[i]) % (m - 1);
116 }
117 g.set_seed(s);
118}
119
120/** One regenerative cycle; buffers are reused across cycles. */
121struct Cycle {
122 int K;
123 std::vector<double> R, logL;
124 std::vector<int> nArr, nA, nS;
125 std::vector<double> sS;
126 double T = 0;
127 std::vector<double> na;
128 std::vector<std::vector<double>> qa, qs;
129 std::vector<std::size_t> head;
130
131 explicit Cycle(int K_)
132 : K(K_), nArr(K_), nA(K_), nS(K_), sS(K_), na(K_), qa(K_), qs(K_), head(K_) {}
133
134 void run(const std::vector<double>& lam, const std::vector<double>& mu,
135 const std::vector<double>& lamIS, const std::vector<double>& muIS,
136 int k, double gsw, bool useIS, rng::Mrg32k3a& g) {
137 R.clear();
138 logL.clear();
139 std::fill(nArr.begin(), nArr.end(), 0);
140 std::fill(nA.begin(), nA.end(), 0);
141 std::fill(nS.begin(), nS.end(), 0);
142 std::fill(sS.begin(), sS.end(), 0.0);
143 for (int l = 0; l < K; ++l) {
144 qa[l].clear();
145 qs[l].clear();
146 head[l] = 0;
147 }
148 T = 0;
149 bool isOn = useIS;
150 double logJ = 0;
151 double c = 0;
152 for (int l = 0; l < K; ++l) c += lamIS[l] - lam[l];
153 double logFrozen = 0;
154 for (int l = 0; l < K; ++l) {
155 const double rate = isOn ? lamIS[l] : lam[l];
156 na[l] = -std::log(g.next_double()) / rate;
157 }
158 bool busy = false;
159 double dep = std::numeric_limits<double>::infinity();
160 int svcCls = -1;
161 double svcArr = 0, svcLogL = 0, work = 0;
162 int nqk = 0;
163 while (true) {
164 double tmin = na[0];
165 int l = 0;
166 for (int j = 1; j < K; ++j) {
167 if (na[j] < tmin) {
168 tmin = na[j];
169 l = j;
170 }
171 }
172 if (busy && dep <= tmin) {
173 const double t = dep;
174 if (svcCls == k) {
175 R.push_back(t - svcArr);
176 logL.push_back(svcLogL);
177 }
178 int j = -1;
179 for (int jj = 0; jj < K; ++jj) {
180 if (head[jj] < qa[jj].size()) {
181 j = jj;
182 break;
183 }
184 }
185 if (j < 0) {
186 if (isOn) T = t;
187 return;
188 }
189 const double arr = qa[j][head[j]];
190 double S = qs[j][head[j]];
191 ++head[j];
192 if (j <= k) {
193 work -= S;
194 --nqk;
195 if (nqk == 0) work = 0;
196 }
197 if (j > k) {
198 const double rate = isOn ? muIS[j] : mu[j];
199 S = -std::log(g.next_double()) / rate;
200 if (isOn) {
201 ++nS[j];
202 sS[j] += S;
203 logJ += std::log(mu[j] / muIS[j]) - (mu[j] - muIS[j]) * S;
204 }
205 }
206 dep = t + S;
207 svcCls = j;
208 svcArr = arr;
209 if (j == k) svcLogL = isOn ? logJ + c * t : logFrozen;
210 } else {
211 const double t = tmin;
212 ++nArr[l];
213 if (isOn) {
214 ++nA[l];
215 logJ += std::log(lam[l] / lamIS[l]);
216 }
217 double S = 0;
218 if (l <= k) {
219 const double rate = isOn ? muIS[l] : mu[l];
220 S = -std::log(g.next_double()) / rate;
221 if (isOn) {
222 ++nS[l];
223 sS[l] += S;
224 logJ += std::log(mu[l] / muIS[l]) - (mu[l] - muIS[l]) * S;
225 }
226 }
227 bool switched = false;
228 if (l == k && isOn) {
229 const double rp = busy ? dep - t + work + S : work + S;
230 if (rp > gsw) {
231 // tau_k: freeze L; the memoryless arrival clocks restart
232 // under the original rates.
233 isOn = false;
234 switched = true;
235 T = t;
236 logFrozen = logJ + c * t;
237 for (int j = 0; j < K; ++j) na[j] = t - std::log(g.next_double()) / lam[j];
238 }
239 }
240 if (!switched) {
241 const double rate = isOn ? lamIS[l] : lam[l];
242 na[l] = t - std::log(g.next_double()) / rate;
243 }
244 if (!busy) {
245 if (l > k) {
246 const double rate = isOn ? muIS[l] : mu[l];
247 S = -std::log(g.next_double()) / rate;
248 if (isOn) {
249 ++nS[l];
250 sS[l] += S;
251 logJ += std::log(mu[l] / muIS[l]) - (mu[l] - muIS[l]) * S;
252 }
253 }
254 busy = true;
255 dep = t + S;
256 svcCls = l;
257 svcArr = t;
258 if (l == k) svcLogL = isOn ? logJ + c * t : logFrozen;
259 } else {
260 qa[l].push_back(t);
261 qs[l].push_back(S);
262 if (l <= k) {
263 work += S;
264 ++nqk;
265 }
266 }
267 }
268 }
269 }
270};
271
272inline double sample_var(const std::vector<double>& x) {
273 const std::size_t n = x.size();
274 if (n < 2) return 0.0;
275 double s = 0;
276 for (double v : x) s += v;
277 const double mx = s / static_cast<double>(n);
278 double acc = 0;
279 for (double v : x) acc += (v - mx) * (v - mx);
280 return acc / static_cast<double>(n - 1);
281}
282
283/** Eq. (8) over R[from, to); returns {estimate, tail weight above it}. */
284inline std::pair<double, double> quantile(const std::vector<double>& R, const std::vector<double>& L,
285 std::size_t from, std::size_t to, double p,
286 int m1, int m2, double sumAlpha) {
287 const std::size_t n = to - from;
288 std::vector<std::size_t> ord(n);
289 std::iota(ord.begin(), ord.end(), from);
290 std::stable_sort(ord.begin(), ord.end(), [&R](std::size_t a, std::size_t b) { return R[a] < R[b]; });
291 const double thr = (1 - p) * m1 / m2 * sumAlpha;
292 double suf = 0;
293 std::size_t np = n + 1;
294 for (std::size_t i = n; i >= 1; --i) {
295 suf += L[ord[i - 1]];
296 if (suf <= thr) {
297 np = i;
298 } else {
299 break;
300 }
301 }
302 if (np > n) np = n;
303 const double q = R[ord[np - 1]];
304 double tail = 0;
305 for (std::size_t i = n; i >= 1; --i) {
306 if (R[ord[i - 1]] > q) {
307 tail += L[ord[i - 1]];
308 } else {
309 break;
310 }
311 }
312 return {q, tail};
313}
314
315} // namespace detail_prio_tq
316
317/**
318 * Tail quantile of the steady-state response time per class in a
319 * non-preemptive priority M/M/1 queue, with its batching confidence interval.
320 *
321 * @param lambda arrival rates (index 0 = highest priority)
322 * @param mu service rates
323 * @param p quantile level in (0,1)
324 * @param opt procedure options
325 * @return one result per target class
326 */
327inline std::vector<PrioTailQuantileResult> sim_prio_tailquantile(
328 const std::vector<double>& lambda, const std::vector<double>& mu, double p,
331 const int K = static_cast<int>(lambda.size());
332 if (K < 1 || static_cast<int>(mu.size()) != K)
333 throw InputError("sim_prio_tailquantile: lambda and mu must be nonempty vectors of equal length");
334 double util = 0;
335 for (int l = 0; l < K; ++l) {
336 if (!(lambda[l] > 0) || std::isinf(lambda[l]) || !(mu[l] > 0) || std::isinf(mu[l]))
337 throw InputError("sim_prio_tailquantile: the arrival and service rates must be positive and finite");
338 util += lambda[l] / mu[l];
339 }
340 if (util >= 1) throw InputError("sim_prio_tailquantile: the queue must be stable, utilization >= 1");
341 if (!(p > 0 && p < 1)) throw InputError("sim_prio_tailquantile: p must lie in (0,1)");
342 const int m1 = opt.m1 > 0 ? opt.m1 : opt.cycles;
343 const int m2 = opt.m2 > 0 ? opt.m2 : opt.cycles;
344 const int N = opt.ceSamples;
345 const int r = opt.batches;
346 if (r < 2) throw InputError("sim_prio_tailquantile: batches must be an integer >= 2");
347 if (m1 < r || m2 < r)
348 throw InputError("sim_prio_tailquantile: m1 and m2 must be no smaller than the number of batches");
349 if (N < 1) throw InputError("sim_prio_tailquantile: ceSamples must be positive");
350 if (!(opt.rho > 0 && opt.rho < 1)) throw InputError("sim_prio_tailquantile: rho must lie in (0,1)");
351 if (opt.maxIter < 1) throw InputError("sim_prio_tailquantile: maxIter must be positive");
352 if (!(opt.confidence > 0 && opt.confidence < 1))
353 throw InputError("sim_prio_tailquantile: confidence must lie in (0,1)");
354 if (opt.seed < 0 || opt.seed >= (1LL << 31))
355 throw InputError("sim_prio_tailquantile: seed must be an integer in [0, 2^31)");
356 std::vector<int> classes = opt.classes;
357 if (classes.empty())
358 for (int l = 1; l <= K; ++l) classes.push_back(l);
359 for (int c : classes)
360 if (c < 1 || c > K) throw InputError("sim_prio_tailquantile: classes must be indices in 1..K");
361 const int nc = static_cast<int>(classes.size());
362 std::string importance = opt.importance;
363 std::transform(importance.begin(), importance.end(), importance.begin(), ::tolower);
364 if (importance != "ce" && importance != "none")
365 throw InputError("sim_prio_tailquantile: importance must be 'ce' or 'none'");
366 std::vector<double> gmax;
367 if (!opt.gammaMax.empty()) {
368 gmax = opt.gammaMax.size() == 1 ? std::vector<double>(nc, opt.gammaMax[0]) : opt.gammaMax;
369 if (static_cast<int>(gmax.size()) != nc)
370 throw InputError("sim_prio_tailquantile: gammaMax must be a scalar or one value per target class");
371 for (double gv : gmax)
372 if (!(gv > 0)) throw InputError("sim_prio_tailquantile: gammaMax must be positive");
373 }
374 std::vector<std::vector<double>> isr;
375 if (!opt.isRates.empty()) {
376 if (!(opt.isRates.size() == 1 || static_cast<int>(opt.isRates.size()) == nc))
377 throw InputError("sim_prio_tailquantile: isRates must be 1 x 2K or one row per target class");
378 for (const auto& row : opt.isRates) {
379 if (static_cast<int>(row.size()) != 2 * K)
380 throw InputError("sim_prio_tailquantile: isRates must be 1 x 2K or one row per target class");
381 for (double v : row)
382 if (!(v > 0) || std::isinf(v))
383 throw InputError("sim_prio_tailquantile: isRates must be positive and finite");
384 }
385 if (gmax.empty())
386 throw InputError("sim_prio_tailquantile: isRates needs gammaMax, the level at which the measure switches back");
387 for (int i = 0; i < nc; ++i) isr.push_back(opt.isRates[opt.isRates.size() == 1 ? 0 : i]);
388 importance = "given";
389 }
390 const double z = sim_norminv((1 + opt.confidence) / 2); // Remark 1 test
391 const double tcrit = sim_tinv((1 + opt.confidence) / 2, static_cast<double>(r - 1)); // batching interval
392 const double inf = std::numeric_limits<double>::infinity();
393
396 Cycle cyc(K);
397 std::vector<std::vector<int>> alphaAll(m2);
398 for (int i = 0; i < m2; ++i) {
399 cyc.run(lambda, mu, lambda, mu, 0, inf, false, g);
400 alphaAll[i] = cyc.nArr;
401 }
402
403 std::vector<PrioTailQuantileResult> results;
404 for (int ci = 0; ci < nc; ++ci) {
405 const int kk = classes[ci];
406 const int k = kk - 1;
408 std::vector<double> alpha(m2);
409 double sumAlpha = 0;
410 for (int i = 0; i < m2; ++i) {
411 alpha[i] = alphaAll[i][k];
412 sumAlpha += alpha[i];
413 }
414 const double abar = sumAlpha / m2;
415 if (abar <= 0)
416 throw InputError("sim_prio_tailquantile: no class-" + std::to_string(kk) +
417 " job was seen in the plain cycles; increase m2");
418 std::vector<double> lamIS = lambda, muIS = mu;
419 double gsw = inf;
420 bool useIS = false;
421 if (importance == "given") {
422 lamIS.assign(isr[ci].begin(), isr[ci].begin() + K);
423 muIS.assign(isr[ci].begin() + K, isr[ci].end());
424 gsw = gmax[ci];
425 useIS = true;
426 } else if (importance == "ce") {
427 useIS = true;
428 double gPrev = inf;
429 bool reached = false;
430 const bool hasTarget = !gmax.empty();
431 const double gTarget = hasTarget ? gmax[ci] : 0.0;
432 std::vector<std::vector<double>> jobsR, jobsL;
433 for (int it = 1; it <= opt.maxIter; ++it) {
434 // CE-stage switching level: with a known target switch there; otherwise
435 // keep the whole cycle under the importance rates while they are stable,
436 // so the CE statistics see the full excursion, else use the last level.
437 double loadIS = 0;
438 for (int l = 0; l < K; ++l) loadIS += lamIS[l] / muIS[l];
439 const double gswCE = hasTarget ? gTarget : (loadIS < 0.95 ? inf : gPrev);
440 std::vector<double> maxR(N, 0.0), T(N);
441 std::vector<std::vector<int>> nA(N), nS(N);
442 std::vector<std::vector<double>> sS(N);
443 jobsR.assign(N, {});
444 jobsL.assign(N, {});
445 for (int i = 0; i < N; ++i) {
446 cyc.run(lambda, mu, lamIS, muIS, k, gswCE, true, g);
447 jobsR[i] = cyc.R;
448 jobsL[i].resize(cyc.logL.size());
449 for (std::size_t j = 0; j < cyc.logL.size(); ++j) jobsL[i][j] = std::exp(cyc.logL[j]);
450 for (double v : cyc.R)
451 if (v > maxR[i]) maxR[i] = v;
452 T[i] = cyc.T;
453 nA[i] = cyc.nA;
454 nS[i] = cyc.nS;
455 sS[i] = cyc.sS;
456 }
457 std::vector<double> srt = maxR;
458 std::sort(srt.begin(), srt.end());
459 double gl = srt[static_cast<std::size_t>(std::ceil((1 - opt.rho) * N)) - 1];
460 if (hasTarget) gl = std::min(gl, gTarget);
461 std::vector<double> w(N, 0.0);
462 for (int i = 0; i < N; ++i) {
463 double acc = 0;
464 for (std::size_t j = 0; j < jobsR[i].size(); ++j)
465 if (jobsR[i][j] > gl) acc += jobsL[i][j];
466 w[i] = acc;
467 }
468 // Closed-form CE solution, eqs. (5)-(6).
469 double wT = 0;
470 for (int i = 0; i < N; ++i) wT += w[i] * T[i];
471 for (int l = 0; l < K; ++l) {
472 double na = 0, ns = 0, ws = 0;
473 for (int i = 0; i < N; ++i) {
474 na += w[i] * nA[i][l];
475 ns += w[i] * nS[i][l];
476 ws += w[i] * sS[i][l];
477 }
478 if (na > 0 && wT > 0) lamIS[l] = na / wT;
479 if (ns > 0 && ws > 0) muIS[l] = ns / ws;
480 }
481 res.ceIterations = it;
482 res.ceLevels.push_back(gl);
483 bool stop;
484 if (hasTarget) {
485 stop = gl >= gTarget;
486 } else {
487 double sw = 0;
488 for (double v : w) sw += v;
489 const double ghat = (sw / N) / abar;
490 const double se = std::sqrt(detail_prio_tq::sample_var(w) / N +
491 ghat * ghat * detail_prio_tq::sample_var(alpha) / m2) / abar;
492 stop = ghat + z * se < 1 - p;
493 }
494 gPrev = gl;
495 if (stop) {
496 reached = true;
497 break;
498 }
499 }
500 if (!reached) {
501 char buf[256];
502 std::snprintf(buf, sizeof(buf),
503 "class %d: the CE level did not pass Q(p) in %d iterations (last level %g); "
504 "the estimate stays unbiased but may be inefficient.", kk, opt.maxIter, gPrev);
505 res.ceConverged = false;
506 res.warnings.push_back(buf);
507 }
508 gsw = gPrev;
509 if (!hasTarget && reached) {
510 // Pilot switching level: the eq. (8) quantile of the last CE batch.
511 std::vector<double> Rp, Lp;
512 for (int i = 0; i < N; ++i) {
513 Rp.insert(Rp.end(), jobsR[i].begin(), jobsR[i].end());
514 Lp.insert(Lp.end(), jobsL[i].begin(), jobsL[i].end());
515 }
516 if (!Rp.empty())
517 gsw = detail_prio_tq::quantile(Rp, Lp, 0, Rp.size(), p, N, m2, sumAlpha).first;
518 }
519 }
520
521 std::vector<double> Rall, Lall;
522 std::vector<std::size_t> cycEnd(m1 + 1, 0);
523 for (int i = 0; i < m1; ++i) {
524 cyc.run(lambda, mu, lamIS, muIS, k, gsw, useIS, g);
525 for (std::size_t j = 0; j < cyc.R.size(); ++j) {
526 Rall.push_back(cyc.R[j]);
527 Lall.push_back(std::exp(cyc.logL[j]));
528 }
529 cycEnd[i + 1] = Rall.size();
530 }
531 if (Rall.empty())
532 throw InputError("sim_prio_tailquantile: no class-" + std::to_string(kk) +
533 " job was seen in the importance-sampled cycles; increase m1");
534 const auto qt = detail_prio_tq::quantile(Rall, Lall, 0, Rall.size(), p, m1, m2, sumAlpha);
535 const double q = qt.first;
536 std::vector<double> qb(r);
537 for (int b = 0; b < r; ++b) {
538 const int i1 = static_cast<int>(static_cast<long long>(b) * m1 / r);
539 const int i2 = static_cast<int>(static_cast<long long>(b + 1) * m1 / r);
540 const int j1 = static_cast<int>(static_cast<long long>(b) * m2 / r);
541 const int j2 = static_cast<int>(static_cast<long long>(b + 1) * m2 / r);
542 if (cycEnd[i2] <= cycEnd[i1])
543 throw InputError("sim_prio_tailquantile: batch " + std::to_string(b + 1) + " holds no class-" +
544 std::to_string(kk) + " job; increase m1 or reduce batches");
545 double sa = 0;
546 for (int j = j1; j < j2; ++j) sa += alpha[j];
547 qb[b] = detail_prio_tq::quantile(Rall, Lall, cycEnd[i1], cycEnd[i2], p, i2 - i1, j2 - j1, sa).first;
548 }
549 double ss = 0;
550 for (double v : qb) ss += (v - q) * (v - q);
551 const double hw = tcrit * std::sqrt(ss / (r - 1)) / std::sqrt(static_cast<double>(r));
552
553 res.classIndex = kk;
554 res.p = p;
555 res.quantile = q;
556 res.ciLower = q - hw;
557 res.ciUpper = q + hw;
558 res.halfWidth = hw;
559 res.tailProb = (qt.second / m1) / abar;
560 res.batchQuantiles = qb;
561 res.lambdaIS = lamIS;
562 res.muIS = muIS;
563 res.gammaMax = gsw;
564 res.numSamples = static_cast<int>(Rall.size());
565 res.meanAlpha = abar;
566 res.m1 = m1;
567 res.m2 = m2;
568 res.importance = importance;
569 results.push_back(res);
570 }
571 return results;
572}
573
574} // namespace sim
575} // namespace line
576
577#endif // LINE_API_SIM_SIM_PRIO_TAILQUANTILE_H
InputError(const std::string &what)
Definition error.h:105
SSJ's umontreal.ssj.rng.MRG32k3a, state and all.
Definition rng_ssj.h:120
void set_seed(const long long s[6])
SSJ's setSeed(long[6]).
Definition rng_ssj.h:125
double next_double()
SSJ's nextValue(): the combined generator, returning a double in (0, 1).
Definition rng_ssj.h:141
The exception types the port throws.
void seed_stream(rng::Mrg32k3a &g, long long seed)
double sample_var(const std::vector< double > &x)
std::pair< double, double > quantile(const std::vector< double > &R, const std::vector< double > &L, std::size_t from, std::size_t to, double p, int m1, int m2, double sumAlpha)
Eq.
double sim_norminv(double p)
Standard normal quantile function.
Definition sim_dist.h:62
double sim_tinv(double p, double nu)
Quantile function of Student's t distribution.
Definition sim_dist.h:77
std::vector< PrioTailQuantileResult > sim_prio_tailquantile(const std::vector< double > &lambda, const std::vector< double > &mu, double p, const PrioTailQuantileOptions &opt=PrioTailQuantileOptions())
Tail quantile of the steady-state response time per class in a non-preemptive priority M/M/1 queue,...
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
The two random number generators the Java LDES engine draws from, reproduced exactly: SSJ's MRG32k3a ...
Normal and Student t quantiles used by the output-analysis routines.
Options of sim_prio_tailquantile; defaults as in the MATLAB reference.
int m1
importance-sampled cycles, 0 = cycles
int ceSamples
N, cycles per CE iteration.
int batches
r, batches for the interval
int cycles
m1 = m2 when neither is set
std::vector< double > gammaMax
empty, one value, or one per target class
std::vector< std::vector< double > > isRates
[lambda~, mu~] rows; needs gammaMax
std::vector< int > classes
1-based target classes, empty = all
Estimate for one target class.
double tailProb
estimated P(R > quantile)
int numSamples
class-k jobs in the m1 cycles
double gammaMax
switching level of the importance-sampled cycles
double meanAlpha
estimate of E[alpha_k]
One regenerative cycle; buffers are reused across cycles.
std::vector< std::vector< double > > qa
void run(const std::vector< double > &lam, const std::vector< double > &mu, const std::vector< double > &lamIS, const std::vector< double > &muIS, int k, double gsw, bool useIS, rng::Mrg32k3a &g)
std::vector< std::vector< double > > qs