LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
lossn_mci.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_LOSSN_LOSSN_MCI_H
6#define LINE_API_LOSSN_LOSSN_MCI_H
7
8/**
9 * @file
10 * @ingroup api_lossn
11 * Monte Carlo importance-sampling summation for product-form loss networks.
12 *
13 * Templated port of matlab/src/api/lossn/lossn_mci.m, implementing Ross and
14 * Wang, "Monte Carlo Summation Applied to Product-Form Loss Networks",
15 * Probability in the Engineering and Informational Sciences 6 (1992), 323-348.
16 *
17 * Links j = 1..J carry capacity C(j), routes r = 1..R carry offered load nu(r)
18 * and need A(j, r) circuits on link j. The state n is feasible iff A n <= C,
19 * the equilibrium law is product form with normalizing constant
20 * g(C) = sum_{n feasible} prod_r nu_r^{n_r} / n_r!, and the class-r acceptance
21 * probability is g(C - A(:, r)) / g(C). States are drawn from the truncated
22 * Poisson importance law (Eq. 6) over {0..N_1} x ... x {0..N_R} with
23 * N_r = min_j floor(C_j / A_jr), and the ratio estimators (Eq. 8) give g and
24 * the blocking probabilities with delta-method confidence intervals.
25 *
26 * RANDOMNESS. There is no global generator here and no hidden seeding. The
27 * caller passes its own engine by reference, or a seed, and the uniforms are
28 * drawn as (gen() >> 11) * 2^-53 rather than through a distribution object, so
29 * a given engine and seed reproduce the same estimate on every standard
30 * library. The draw order mirrors the reference (all S samples of route 1,
31 * then of route 2, and so on) so that the two implementations traverse the
32 * same importance law in the same order, though their engines differ and their
33 * sample paths therefore cannot be compared point by point. What CAN be
34 * compared, and is, is convergence to a closed form: a single link with unit
35 * circuit requirements is an Erlang loss system and its blocking probability
36 * is Erlang B.
37 *
38 * ARITHMETIC. The importance weights are formed in log space, exactly as in
39 * the reference, so log, exp, lgamma and the inverse error function are all
40 * unavoidable; the header is gated on num_traits<T>::has_transcendental and is
41 * instantiated at double and Real only. An exact instantiation would be
42 * meaningless in any case: the estimate is a random variable.
43 *
44 * PER-LINK BLOCKING AND REVENUE. The same samples also give the blocking of
45 * route r by link j alone, E(j,r) = 1 - g(C - A(j,r) e_j)/g(C), in
46 * linkLossPoint. When opt.revenue holds a revenue rate w per route, the
47 * estimator also returns W = sum_k w_k E[X_k], the revenue sensitivities
48 * dW/dnu_l = Cov(X_l, r(X))/nu_l with r(n) = sum_k w_k n_k (Ross 1995, Sec.
49 * 6.3) and their delta-method intervals over the four ratio means, and the
50 * route and link implied costs W(C) - W(C - a), each a ratio estimator over
51 * the same weighted samples.
52 *
53 * REFERENCE NOTE. MATLAB's var normalizes by S - 1 and so does the port, and
54 * the covariance is likewise the S - 1 form; with S below 2 the estimator is
55 * undefined and the port rejects it rather than dividing by zero, which the
56 * reference does silently.
57 */
58
59#include <algorithm>
60#include <cmath>
61#include <cstddef>
62#include <cstdint>
63#include <limits>
64#include <random>
65#include <string>
66#include <vector>
67
68#include "line/num/number.h"
69#include "line/util/error.h"
70#include "line/util/matrix.h"
71
72namespace line {
73namespace lossn {
74
75/** Options of lossn_mci, MATLAB's options struct. */
76template <class T>
78 std::size_t samples = 100000; ///< S
79 double alpha = 0.05; ///< 1 - confidence level
80 std::vector<T> gamma; ///< importance parameters, empty = heuristic
81 std::vector<T> revenue; ///< revenue rate w per route, empty = no revenue sensitivity
82};
83
84/** Result of lossn_mci. */
85template <class T>
87 std::vector<T> QLen; ///< mean carried load per route
88 std::vector<T> Loss; ///< blocking probability per route
89 double lG = 0.0; ///< log of the estimated normalizing constant
90 Matrix<T> acceptCI; ///< (R x 2) acceptance confidence interval
91 Matrix<T> lossCI; ///< (R x 2) blocking confidence interval
92 std::vector<T> acceptPoint;
93 std::vector<T> lossPoint;
94 T level = num_traits<T>::from_int(0); ///< 1 - alpha
95 std::size_t nsamples = 0;
96 /// (J x R) blocking of route r by link j alone, 1 - g(C - A(j,r) e_j)/g(C);
97 /// zero where A(j,r) = 0
99 // Filled only when options.revenue is set (hasRevenue):
100 bool hasRevenue = false;
101 T revenue = num_traits<T>::from_int(0); ///< revenue rate W = sum_k w_k E[X_k]
102 std::vector<T> revsens; ///< dW/dnu_l (R)
103 Matrix<T> revsensCI; ///< (R x 2) delta-method interval of revsens
104 std::vector<T> impliedCost; ///< route implied cost W(C) - W(C - A e_k), NaN if undefined (R)
105 Matrix<T> linkImpliedCost; ///< (J x R) link implied cost W(C) - W(C - A(j,r) e_j)
106};
107
108namespace detail {
109
110/** log(sum exp(x)), shifted by the maximum. */
111template <class T>
112T logsumexp(const std::vector<T>& x) {
113 using std::exp;
114 using std::log;
115 if (x.empty()) throw InputError("logsumexp: empty argument");
116 T m = x[0];
117 for (std::size_t i = 1; i < x.size(); ++i)
118 if (x[i] > m) m = x[i];
120 for (std::size_t i = 0; i < x.size(); ++i) s += exp(T(x[i] - m));
121 return T(m + log(s));
122}
123
124/**
125 * log(l!) accumulated term by term, which is what MATLAB's gammaln(l + 1)
126 * evaluates to at the integer arguments this algorithm uses. Summing the logs
127 * rather than taking the log of a factorial keeps the working precision and
128 * cannot overflow, and it removes any dependency on a special-function
129 * library: Boost.Math's lgamma promotes through __float128 for its precision
130 * policy, which drags libquadmath into every binary that links this header.
131 */
132template <class T>
133std::vector<T> log_factorials(std::size_t upTo) {
134 using std::log;
135 std::vector<T> lf(upTo + 1, num_traits<T>::from_int(0));
136 for (std::size_t l = 1; l <= upTo; ++l)
137 lf[l] = T(lf[l - 1] + log(num_traits<T>::from_int(static_cast<long>(l))));
138 return lf;
139}
140
141/**
142 * The standard-normal 1 - alpha/2 quantile, MATLAB's sqrt(2) erfinv(1 - alpha).
143 *
144 * Computed in double by bisection on std::erf, and only then converted to T.
145 * That is not a precision compromise in disguise: alpha reaches this function
146 * as a double, so the quantile it determines carries double information and no
147 * more, whatever the working type of the estimator is. It is also a random
148 * estimator's confidence half width, whose own statistical error dwarfs any
149 * arithmetic one.
150 */
151inline double normal_quantile(double alpha) {
152 if (!(alpha > 0.0) || !(alpha < 1.0))
153 throw InputError("lossn_mci: the confidence level alpha must lie in (0, 1)");
154 const double target = 1.0 - alpha;
155 double lo = 0.0, hi = 10.0;
156 for (int it = 0; it < 200; ++it) {
157 const double mid = 0.5 * (lo + hi);
158 if (std::erf(mid) < target)
159 lo = mid;
160 else
161 hi = mid;
162 }
163 return std::sqrt(2.0) * 0.5 * (lo + hi);
164}
165
166/** A uniform on [0, 1) built from the engine directly, for reproducibility. */
167template <class Rng>
168double uniform01(Rng& gen) {
169 return static_cast<double>(gen() >> 11) * (1.0 / 9007199254740992.0);
170}
171
172} // namespace detail
173
174/**
175 * Estimate the normalizing constant and the blocking probabilities.
176 *
177 * @param nu (R) offered load per route
178 * @param A (J x R) circuit requirement of link j for route r
179 * @param C (J) link capacity
180 * @param opt options
181 * @param gen the caller's random engine, advanced in place
182 */
183template <class T, class Rng>
184LossnMciResult<T> lossn_mci(const std::vector<T>& nu, const Matrix<T>& A, const std::vector<T>& C,
185 const LossnMciOptions<T>& opt, Rng& gen) {
187 "lossn_mci requires transcendental arithmetic (log-space importance weights)");
188 using std::exp;
189 using std::log;
190 using std::pow;
191 using std::sqrt;
192
193 const std::size_t R = nu.size(), J = C.size();
194 if (R == 0 || J == 0) throw InputError("lossn_mci: empty loss network");
195 if (A.rows() != J || A.cols() != R) throw InputError("lossn_mci: A must be J x R");
196 const std::size_t S = opt.samples;
197 if (S < 2) throw InputError("lossn_mci: at least two samples are required");
198 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
199 const bool withRevenue = !opt.revenue.empty();
200 if (withRevenue && opt.revenue.size() != R)
201 throw InputError("lossn_mci: options.revenue must have " + std::to_string(R) + " entries.");
202
203 // per-route maximum feasible occupancy
204 std::vector<std::size_t> N(R, 0);
205 for (std::size_t k = 0; k < R; ++k) {
206 bool any = false;
207 T best = zero;
208 for (std::size_t j = 0; j < J; ++j) {
209 if (!(A(j, k) > zero)) continue;
210 const T ratio = C[j] / A(j, k);
211 if (!any || ratio < best) best = ratio;
212 any = true;
213 }
214 if (!any) continue;
215 const double bd = num_traits<T>::to_double(best);
216 N[k] = bd <= 0.0 ? 0 : static_cast<std::size_t>(std::floor(bd));
217 }
218
219 // importance parameters, Section 3.4 heuristic
220 std::vector<T> gamma(opt.gamma);
221 if (gamma.empty()) {
222 T delta = zero;
223 for (std::size_t j = 0; j < J; ++j) {
224 if (C[j] == zero) throw InputError("lossn_mci: a link has zero capacity");
225 T load = zero;
226 for (std::size_t k = 0; k < R; ++k) load += A(j, k) * nu[k];
227 load = T(load / C[j]);
228 if (j == 0 || load > delta) delta = load;
229 }
230 T base = T(one - num_traits<T>::from_double(0.15) * T(one - delta));
231 const T floorBase = num_traits<T>::from_double(1e-6);
232 if (base < floorBase) base = floorBase;
233 gamma.assign(R, zero);
234 for (std::size_t k = 0; k < R; ++k) {
235 T b = zero;
236 for (std::size_t j = 0; j < J; ++j)
237 if (A(j, k) > b) b = A(j, k);
238 gamma[k] = nu[k] * pow(base, b);
239 }
240 }
241 if (gamma.size() != R) throw InputError("lossn_mci: gamma must have one entry per route");
242 const T gammaFloor = num_traits<T>::from_double(1e-300);
243 for (std::size_t k = 0; k < R; ++k)
244 if (gamma[k] < gammaFloor) gamma[k] = gammaFloor;
245
246 // normalization constant of the importance law, and its per-route cdfs
247 T log_c = zero;
248 std::vector<std::vector<T>> cdf(R);
249 for (std::size_t k = 0; k < R; ++k) {
250 std::vector<T> logterms(N[k] + 1);
251 const std::vector<T> lf = detail::log_factorials<T>(N[k]);
252 for (std::size_t l = 0; l <= N[k]; ++l)
253 logterms[l] =
254 T(num_traits<T>::from_int(static_cast<long>(l)) * log(gamma[k]) - lf[l]);
255 const T lse = detail::logsumexp(logterms);
256 log_c += lse;
257 cdf[k].assign(N[k] + 1, zero);
258 T acc = zero;
259 for (std::size_t l = 0; l <= N[k]; ++l) {
260 acc += exp(T(logterms[l] - lse));
261 cdf[k][l] = acc;
262 }
263 cdf[k][N[k]] = one; // guard rounding, as in the reference
264 }
265
266 // S i.i.d. draws, column by column
267 std::vector<std::size_t> V(S * R, 0);
268 for (std::size_t k = 0; k < R; ++k)
269 for (std::size_t s = 0; s < S; ++s) {
270 const T u = num_traits<T>::from_double(detail::uniform01(gen));
271 std::size_t v = 0;
272 for (std::size_t l = 0; l <= N[k]; ++l)
273 if (u > cdf[k][l]) ++v;
274 V[s * R + k] = v;
275 }
276
277 // feasibility indicators and log likelihood ratios
278 std::vector<T> logratio(R);
279 for (std::size_t k = 0; k < R; ++k) {
280 if (!(nu[k] > zero)) throw InputError("lossn_mci: a route has non-positive offered load");
281 logratio[k] = T(log(nu[k]) - log(gamma[k]));
282 }
283 std::vector<T> log_alpha(S, zero);
284 std::vector<char> inOmega(S, 0);
285 std::vector<char> inOmegaK(S * R, 0);
286 std::vector<T> AVall(S * J, zero); // AVall[s*J+j] = (A n_s)_j, kept for the link indicators
287 for (std::size_t s = 0; s < S; ++s) {
288 T* AV = &AVall[s * J];
289 for (std::size_t j = 0; j < J; ++j) {
290 T t = zero;
291 for (std::size_t k = 0; k < R; ++k)
292 t += A(j, k) * num_traits<T>::from_int(static_cast<long>(V[s * R + k]));
293 AV[j] = t;
294 }
295 bool ok = true;
296 for (std::size_t j = 0; j < J && ok; ++j)
297 if (AV[j] > C[j]) ok = false;
298 inOmega[s] = ok ? 1 : 0;
299 for (std::size_t k = 0; k < R; ++k) {
300 bool okk = true;
301 for (std::size_t j = 0; j < J && okk; ++j)
302 if (AV[j] > T(C[j] - A(j, k))) okk = false;
303 inOmegaK[s * R + k] = okk ? 1 : 0;
304 }
305 T la = zero;
306 for (std::size_t k = 0; k < R; ++k)
307 la += num_traits<T>::from_int(static_cast<long>(V[s * R + k])) * logratio[k];
308 log_alpha[s] = la;
309 }
310
312 res.nsamples = S;
313 res.level = T(one - num_traits<T>::from_double(opt.alpha));
314
315 // normalizing constant
316 std::vector<T> laO;
317 for (std::size_t s = 0; s < S; ++s)
318 if (inOmega[s]) laO.push_back(log_alpha[s]);
319 if (laO.empty()) {
320 res.lG = -std::numeric_limits<double>::infinity();
321 } else {
322 const T lse = detail::logsumexp(laO);
323 res.lG = num_traits<T>::to_double(T(log_c + lse)) -
324 std::log(static_cast<double>(S));
325 }
326
327 // ratio estimators with shifted weights
328 T M = zero;
329 bool anyOmega = false;
330 for (std::size_t s = 0; s < S; ++s)
331 if (inOmega[s]) {
332 if (!anyOmega || log_alpha[s] > M) M = log_alpha[s];
333 anyOmega = true;
334 }
335 std::vector<T> w(S), Z(S);
336 T meanZ = zero;
337 for (std::size_t s = 0; s < S; ++s) {
338 w[s] = exp(T(log_alpha[s] - M));
339 Z[s] = inOmega[s] ? w[s] : zero;
340 meanZ += Z[s];
341 }
342 meanZ = T(meanZ / num_traits<T>::from_int(static_cast<long>(S)));
343
344 const T crit = num_traits<T>::from_double(detail::normal_quantile(opt.alpha));
345 res.acceptPoint.assign(R, zero);
346 res.acceptCI = Matrix<T>(R, 2, zero);
347 res.lossCI = Matrix<T>(R, 2, zero);
348 res.Loss.assign(R, zero);
349 res.QLen.assign(R, zero);
350 if (!(meanZ > zero))
351 throw NumericError(ErrorKind{"Infeasible"}, "lossn_mci: no sampled state was feasible, the estimator is undefined");
352
353 T varZ = zero;
354 for (std::size_t s = 0; s < S; ++s) varZ += T(Z[s] - meanZ) * T(Z[s] - meanZ);
355 varZ = T(varZ / num_traits<T>::from_int(static_cast<long>(S - 1)));
356
357 for (std::size_t k = 0; k < R; ++k) {
358 std::vector<T> Y(S);
359 T meanY = zero;
360 for (std::size_t s = 0; s < S; ++s) {
361 Y[s] = inOmegaK[s * R + k] ? w[s] : zero;
362 meanY += Y[s];
363 }
364 meanY = T(meanY / num_traits<T>::from_int(static_cast<long>(S)));
365 const T phi = T(meanY / meanZ);
366 T varY = zero, covYZ = zero;
367 for (std::size_t s = 0; s < S; ++s) {
368 varY += T(Y[s] - meanY) * T(Y[s] - meanY);
369 covYZ += T(Y[s] - meanY) * T(Z[s] - meanZ);
370 }
371 const T denom = num_traits<T>::from_int(static_cast<long>(S - 1));
372 varY = T(varY / denom);
373 covYZ = T(covYZ / denom);
374 T sig2 = T((varY - num_traits<T>::from_int(2) * phi * covYZ + phi * phi * varZ) /
375 (num_traits<T>::from_int(static_cast<long>(S)) * meanZ * meanZ));
376 if (sig2 < zero) sig2 = zero;
377 const T half = T(crit * sqrt(sig2));
378 res.acceptPoint[k] = phi;
379 res.acceptCI(k, 0) = T(phi - half);
380 res.acceptCI(k, 1) = T(phi + half);
381 res.Loss[k] = T(one - phi);
382 res.QLen[k] = nu[k] * phi;
383 res.lossCI(k, 0) = T(one - res.acceptCI(k, 1));
384 res.lossCI(k, 1) = T(one - res.acceptCI(k, 0));
385 }
386 res.lossPoint = res.Loss;
387
388 // Per-link blocking from the same samples: link j alone blocks a route-r
389 // call when fewer than A(j,r) of its units are free,
390 // E(j,r) = 1 - g(C - A(j,r) e_j)/g(C). Omega(C - a e_j) is a subset of
391 // Omega(C), so its indicator is the in-Omega samples with room on link j.
392 // linkInd[j][m] is the indicator for the m-th distinct positive A(j,:).
393 const T Sd = num_traits<T>::from_int(static_cast<long>(S));
394 std::vector<std::vector<T>> avals(J);
395 std::vector<std::vector<std::vector<char>>> linkInd(J);
396 res.linkLossPoint = Matrix<T>(J, R, zero);
397 for (std::size_t j = 0; j < J; ++j) {
398 for (std::size_t k = 0; k < R; ++k) {
399 const T a = A(j, k);
400 if (!(a > zero)) continue;
401 bool seen = false;
402 for (const T& v : avals[j])
403 if (v == a) seen = true;
404 if (!seen) avals[j].push_back(a);
405 }
406 std::sort(avals[j].begin(), avals[j].end());
407 linkInd[j].resize(avals[j].size());
408 for (std::size_t m = 0; m < avals[j].size(); ++m) {
409 const T room = T(C[j] - avals[j][m]);
410 std::vector<char>& ind = linkInd[j][m];
411 ind.assign(S, 0);
412 T acc = zero;
413 for (std::size_t s = 0; s < S; ++s)
414 if (inOmega[s] && !(AVall[s * J + j] > room)) {
415 ind[s] = 1;
416 acc += w[s];
417 }
418 T e = T(one - T(acc / Sd) / meanZ);
419 if (e < zero) e = zero;
420 if (e > one) e = one;
421 for (std::size_t k = 0; k < R; ++k)
422 if (A(j, k) == avals[j][m]) res.linkLossPoint(j, k) = e;
423 }
424 }
425
426 // Revenue sensitivity (Ross 1995, Sec. 6.3): with revenue rate
427 // W = sum_k w_k E[X_k], the product form gives dW/dnu_l = Cov(X_l, r(X))/nu_l,
428 // r(n) = sum_k w_k n_k. Each moment is a ratio estimator over the same
429 // weighted samples; the interval is the delta method over the four means.
430 if (withRevenue) {
431 const T nan = num_traits<T>::from_double(std::numeric_limits<double>::quiet_NaN());
432 std::vector<T> rv(S, zero), Mv(S, zero);
433 T mM = zero;
434 for (std::size_t s = 0; s < S; ++s) {
435 T r = zero;
436 for (std::size_t k = 0; k < R; ++k)
437 r += num_traits<T>::from_int(static_cast<long>(V[s * R + k])) * opt.revenue[k];
438 rv[s] = r;
439 Mv[s] = T(Z[s] * r);
440 mM += Mv[s];
441 }
442 mM = T(mM / Sd);
443 const T Wpt = T(mM / meanZ);
444 res.hasRevenue = true;
445 res.revenue = Wpt;
446 res.revsens.assign(R, zero);
447 res.revsensCI = Matrix<T>(R, 2, zero);
448 const T denom = num_traits<T>::from_int(static_cast<long>(S - 1));
449 std::vector<T> Av(S), Bv(S);
450 for (std::size_t l = 0; l < R; ++l) {
451 T mA = zero, mB = zero;
452 for (std::size_t s = 0; s < S; ++s) {
453 Bv[s] = T(Z[s] * num_traits<T>::from_int(static_cast<long>(V[s * R + l])));
454 Av[s] = T(Bv[s] * rv[s]);
455 mA += Av[s];
456 mB += Bv[s];
457 }
458 mA = T(mA / Sd);
459 mB = T(mB / Sd);
460 if (!(nu[l] > zero)) {
461 res.revsens[l] = nan;
462 res.revsensCI(l, 0) = nan;
463 res.revsensCI(l, 1) = nan;
464 continue;
465 }
466 const T dW = T(T(mA / meanZ - T(mB / meanZ) * T(mM / meanZ)) / nu[l]);
467 const T mZ2 = T(meanZ * meanZ), mZ3 = T(mZ2 * meanZ);
468 const T grad[4] = {T(T(one / meanZ) / nu[l]), T(T(-mM / mZ2) / nu[l]),
469 T(T(-mB / mZ2) / nu[l]),
470 T(T(-mA / mZ2 + num_traits<T>::from_int(2) * mB * mM / mZ3) / nu[l])};
471 // sample covariance of [Av Bv Mv Z], S - 1 normalization
472 const T mean4[4] = {mA, mB, mM, meanZ};
473 T Sig[4][4];
474 for (int a = 0; a < 4; ++a)
475 for (int b = 0; b < 4; ++b) Sig[a][b] = zero;
476 for (std::size_t s = 0; s < S; ++s) {
477 const T d4[4] = {T(Av[s] - mean4[0]), T(Bv[s] - mean4[1]), T(Mv[s] - mean4[2]),
478 T(Z[s] - mean4[3])};
479 for (int a = 0; a < 4; ++a)
480 for (int b = a; b < 4; ++b) Sig[a][b] += T(d4[a] * d4[b]);
481 }
482 T q = zero;
483 for (int a = 0; a < 4; ++a)
484 for (int b = 0; b < 4; ++b) {
485 const T sab = a <= b ? Sig[a][b] : Sig[b][a];
486 q += T(grad[a] * T(sab / denom) * grad[b]);
487 }
488 if (q < zero) q = zero;
489 const T half = T(crit * sqrt(T(q / Sd)));
490 res.revsens[l] = dW;
491 res.revsensCI(l, 0) = T(dW - half);
492 res.revsensCI(l, 1) = T(dW + half);
493 }
494 // Implied costs: revenue lost by removing a call's units, W(C) - W(C - a)
495 res.impliedCost.assign(R, nan);
496 for (std::size_t k = 0; k < R; ++k) {
497 T den = zero, num = zero;
498 for (std::size_t s = 0; s < S; ++s)
499 if (inOmegaK[s * R + k]) {
500 den += w[s];
501 num += T(w[s] * rv[s]);
502 }
503 if (den > zero) res.impliedCost[k] = T(Wpt - num / den);
504 }
505 res.linkImpliedCost = Matrix<T>(J, R, zero);
506 for (std::size_t j = 0; j < J; ++j)
507 for (std::size_t m = 0; m < avals[j].size(); ++m) {
508 const std::vector<char>& ind = linkInd[j][m];
509 T den = zero, num = zero;
510 for (std::size_t s = 0; s < S; ++s)
511 if (ind[s]) {
512 den += w[s];
513 num += T(w[s] * rv[s]);
514 }
515 const T val = den > zero ? T(Wpt - num / den) : nan;
516 for (std::size_t k = 0; k < R; ++k)
517 if (A(j, k) == avals[j][m]) res.linkImpliedCost(j, k) = val;
518 }
519 }
520 return res;
521}
522
523/**
524 * Overload seeding a local engine. Deterministic in the seed and independent
525 * of any global state; the engine is created and destroyed here.
526 */
527template <class T>
528LossnMciResult<T> lossn_mci(const std::vector<T>& nu, const Matrix<T>& A, const std::vector<T>& C,
529 const LossnMciOptions<T>& opt, std::uint64_t seed) {
530 std::mt19937_64 gen(seed);
531 return lossn_mci(nu, A, C, opt, gen);
532}
533
534} // namespace lossn
535} // namespace line
536
537#endif // LINE_API_LOSSN_LOSSN_MCI_H
InputError(const std::string &what)
Definition error.h:105
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
NumericError(const std::string &what)
Definition error.h:112
The exception types the port throws.
Dense matrix and non-owning view.
LossnMciResult< T > lossn_mci(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C, const LossnMciOptions< T > &opt, Rng &gen)
Estimate the normalizing constant and the blocking probabilities.
Definition lossn_mci.h:184
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
Options of lossn_mci, MATLAB's options struct.
Definition lossn_mci.h:77
std::vector< T > gamma
importance parameters, empty = heuristic
Definition lossn_mci.h:80
double alpha
1 - confidence level
Definition lossn_mci.h:79
std::vector< T > revenue
revenue rate w per route, empty = no revenue sensitivity
Definition lossn_mci.h:81
Result of lossn_mci.
Definition lossn_mci.h:86
std::vector< T > QLen
mean carried load per route
Definition lossn_mci.h:87
Matrix< T > revsensCI
(R x 2) delta-method interval of revsens
Definition lossn_mci.h:103
std::vector< T > Loss
blocking probability per route
Definition lossn_mci.h:88
T revenue
revenue rate W = sum_k w_k E[X_k]
Definition lossn_mci.h:101
Matrix< T > acceptCI
(R x 2) acceptance confidence interval
Definition lossn_mci.h:90
Matrix< T > linkLossPoint
(J x R) blocking of route r by link j alone, 1 - g(C - A(j,r) e_j)/g(C); zero where A(j,...
Definition lossn_mci.h:98
std::vector< T > revsens
dW/dnu_l (R)
Definition lossn_mci.h:102
Matrix< T > linkImpliedCost
(J x R) link implied cost W(C) - W(C - A(j,r) e_j)
Definition lossn_mci.h:105
std::vector< T > lossPoint
Definition lossn_mci.h:93
std::vector< T > impliedCost
route implied cost W(C) - W(C - A e_k), NaN if undefined (R)
Definition lossn_mci.h:104
double lG
log of the estimated normalizing constant
Definition lossn_mci.h:89
std::vector< T > acceptPoint
Definition lossn_mci.h:92
Matrix< T > lossCI
(R x 2) blocking confidence interval
Definition lossn_mci.h:91