LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_nc_lossn.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_SOLVERS_NC_SOLVER_NC_LOSSN_H
6#define LINE_SOLVERS_NC_SOLVER_NC_LOSSN_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `solver_nc_lossn_analyzer.m`: the open LOSS NETWORK, which is a
12 * Source, ONE multiclass Delay sitting inside a Finite Capacity Region under a
13 * DROP rule, and a Sink.
14 *
15 * WHAT THE ANALYZER ACTUALLY COMPUTES. There is no queueing: the single station
16 * is an infinite server, so a job that is admitted never waits and leaves after
17 * one service time. The only question is which arrivals are ADMITTED, and the
18 * region answers it through a linear admission rule A n <= C on the per-class
19 * occupancy vector n. Everything else -- carried throughput, mean population,
20 * response time -- follows from the per-class blocking probability by Little's
21 * law at the infinite server.
22 *
23 * WHERE THE ROWS OF A COME FROM, in the order the simulation engines test them:
24 * the global job cap, the memory budget weighted by the per-class sizes, the
25 * per-class job caps, and any explicit linear constraint. A row left unbounded
26 * (the -1 sentinel) is DROPPED rather than given a surrogate capacity, because
27 * a large finite surrogate would report a small but non-zero blocking where the
28 * truth is none. A region that declares no bounded row at all has no admission
29 * rule and is refused rather than solved as an unconstrained delay.
30 *
31 * Every row is a function of the per-class occupancy of the REGION only, which
32 * is all the FiniteCapacityRegion API can express, so no row can distinguish
33 * the stations inside the region. That is why a second member station would
34 * change nothing in A and yet would break the Little's-law recovery below,
35 * which attributes the whole carried load to one infinite server; a region with
36 * more than one member station is therefore refused rather than collapsed.
37 *
38 * THE METHODS, ALL PORTED.
39 *
40 * exact / ms `lossn_manjunath`, the Manjunath-Sikdar contour-integral transform,
41 * and the default on integral constraints as in the reference.
42 * EXACT: g(C) is a residue, i.e. a coefficient of a truncated
43 * multivariate power series, so the answer carries neither an
44 * iteration tolerance nor a sampling error. It is the only one of
45 * the three that runs under exact arithmetic, since every step is
46 * rational and the metrics are ratios. Cost is the product of
47 * (C_j+1) over the simultaneously live rows, so it is exact but
48 * not unconditionally cheap.
49 * erlangfp `lossn_erlangfp`, the Erlang fixed-point (reduced-load)
50 * approximation. IT IS AN APPROXIMATION: it assumes the links
51 * block INDEPENDENTLY, which is false whenever two rows of A
52 * share a class, and it is exact only in the single-row case
53 * where the assumption is vacuous and the fixed point collapses
54 * to Erlang's loss formula. Never compare it to an exact solver
55 * at a tight tolerance on a multi-row region.
56 * mci `lossn_mci`, Ross-Wang importance sampling. Unbiased, with a
57 * confidence interval, and it carries a normalizing constant.
58 * The method to reach for when the exact transform's live-grid
59 * product is prohibitive.
60 *
61 * asy `lossn_asy`, the large-capacity (Kelly) limit: link j blocks
62 * independently with probability a_j, the a_j solving the convex
63 * dual of the fluid optimization by coordinate descent. AN
64 * APPROXIMATION, accurate in heavy traffic and for large C, and
65 * zero loss on links underloaded at the fluid scale. It needs no
66 * integrality, so unlike 'erlangfp' it runs on a fractional
67 * region; it stops on a tolerance, so it refuses exact arithmetic.
68 *
69 * rec `lossn_rec`, MDD-rec: the same constant as the exact sum over
70 * the admissible set, obtained by one memoised walk of the
71 * decision diagram holding it. It places no integrality demand on
72 * A or C, which is why it -- and not 'erlangfp', which this port
73 * refuses there -- is what 'default' takes on a FRACTIONAL region.
74 * Before it existed a fractional region had no exact route here at
75 * all, only the Monte Carlo 'mci' whose answer is a random
76 * variable.
77 *
78 * WHY THE ANALYZER STILL REFUSES 'erlangfp' ON A FRACTIONAL REGION. Since
79 * 2026-10-16 `lossn_erlangfp` is the Kaufman-Roberts fixed point of the
80 * reference and scales a fractional row to integers itself, so the function
81 * accepts such a region; the analyzer keeps refusing it only because
82 * line-test's test_nc_lossn.cpp pins that refusal, and lifting it is a change
83 * of expected behaviour. `lossn_mci` compares in real arithmetic and `lossn_rec`
84 * is exact there, so both remain the methods for a fractional region.
85 * `lossn_manjunath` needs integral rows for a different reason -- the residue argument
86 * counts whole units of capacity -- so an EXPLICIT 'exact' on a fractional
87 * region is refused by `lossn_manjunath` itself rather than downgraded here, exactly
88 * as the reference does; only 'default' falls back.
89 *
90 * ARITHMETIC. There is no blanket transcendental gate: under exact arithmetic
91 * the 'exact' method answers exactly and the other two refuse by name, which is
92 * strictly more useful than refusing the whole analyzer. `lG` is a double in
93 * every arithmetic, because it is a logarithm.
94 */
95
96#include <cctype>
97#include <cmath>
98#include <cstddef>
99#include <cstdint>
100#include <limits>
101#include <string>
102#include <vector>
103
104#include "line/api/da/da_fpi.h"
112#include "line/util/error.h"
113#include "line/util/matrix.h"
114
115namespace line {
116namespace nc {
117
118/** What the loss-network analyzer returns beyond the usual metric table. */
119template <class T>
122 Matrix<T> A; ///< (J x K) rows of the admission rule A n <= C
123 std::vector<T> Cvec; ///< (J) the right-hand side
124 std::vector<T> nu; ///< (K) offered load per class
125 std::vector<T> Loss; ///< (K) blocking probability per class
126 Matrix<T> E; ///< (J x K) blocking of class k on row j, empty outside the fixed point
127};
128
129namespace detail {
130
131/**
132 * The 1-based stations of region `f`.
133 *
134 * `members` is the authoritative flag and is read first. A struct assembled
135 * without it -- which is what MATLAB's `sn.region{f}` is, a capacity matrix and
136 * nothing else -- is read back the reference's way instead, from the -1
137 * sentinel: a station whose row carries any bounded entry is a member. The two
138 * agree on every region the builder produces; they differ only on a member
139 * station left wholly unbounded, which the sentinel test cannot see.
140 */
141template <class T>
142std::vector<std::size_t> lossn_region_members(const qn::NetworkStruct<T>& sn, std::size_t f) {
143 const typename qn::NetworkStruct<T>::Region& rg = sn.regions[f];
144 bool anyFlag = false;
145 for (bool b : rg.members)
146 if (b) anyFlag = true;
147
148 std::vector<std::size_t> out;
149 for (std::size_t i = 0; i < sn.nstations; ++i) {
150 bool in = false;
151 if (anyFlag) {
152 in = i < rg.members.size() && rg.members[i];
153 } else if (i < rg.cap.size()) {
154 for (double c : rg.cap[i])
155 if (c >= 0.0) in = true;
156 if (i < rg.maxmem.size() && rg.maxmem[i] >= 0.0) in = true;
157 }
158 if (in) out.push_back(i + 1);
159 }
160 return out;
161}
162
163/**
164 * Port of the local `lossn_region_constraints` of the reference: the rows of
165 * A n <= C for region `f` at member station `st` (1-based). When `names` is
166 * given it receives the link name of each row, which is the reference's
167 * `lossn_region_linknames`: GlobalMaxJobs, GlobalMaxMemory,
168 * ClassMaxJobs:<class> and Constraint<k> (1-based), in row order.
169 */
170template <class T>
171void lossn_region_constraints(const qn::NetworkStruct<T>& sn, std::size_t f, std::size_t st,
172 std::size_t K, Matrix<T>& A, std::vector<T>& Cvec,
173 std::vector<std::string>* names = nullptr) {
174 const typename qn::NetworkStruct<T>::Region& rg = sn.regions[f];
175 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
176 const std::vector<double>& caps = rg.cap[st - 1];
177
178 std::vector<std::vector<T>> rows;
179 std::vector<T> rhs;
180 std::vector<std::string> nm;
181
182 // Global job cap: sum_r n_r <= globalMaxJobs.
183 if (K < caps.size() && caps[K] >= 0.0) {
184 rows.push_back(std::vector<T>(K, one));
185 rhs.push_back(num_traits<T>::from_double(caps[K]));
186 nm.push_back("GlobalMaxJobs");
187 }
188
189 // Memory budget: sum_r size_r n_r <= globalMaxMemory. The class sizes are
190 // the row, so this is the one row that can legitimately be fractional.
191 if (st - 1 < rg.maxmem.size() && rg.maxmem[st - 1] >= 0.0) {
192 std::vector<T> row(K, one);
193 for (std::size_t r = 0; r < K && r < rg.size.size(); ++r) row[r] = rg.size[r];
194 rows.push_back(row);
195 rhs.push_back(num_traits<T>::from_double(rg.maxmem[st - 1]));
196 nm.push_back("GlobalMaxMemory");
197 }
198
199 // Per-class job caps, already folded with the per-class memory caps by
200 // `add_region`, so there is no separate per-class memory row.
201 for (std::size_t r = 0; r < K && r < caps.size(); ++r) {
202 if (caps[r] < 0.0) continue;
203 std::vector<T> row(K, zero);
204 row[r] = one;
205 rows.push_back(row);
206 rhs.push_back(num_traits<T>::from_double(caps[r]));
207 nm.push_back("ClassMaxJobs:" + (r < sn.classes.size() ? sn.classes[r].name : std::string()));
208 }
209
210 // Explicit linear constraints from FiniteCapacityRegion.setConstraint.
211 for (std::size_t k = 0; k < rg.lincon_A.rows(); ++k) {
212 std::vector<T> row(K, zero);
213 for (std::size_t r = 0; r < K && r < rg.lincon_A.cols(); ++r) row[r] = rg.lincon_A(k, r);
214 rows.push_back(row);
215 rhs.push_back(k < rg.lincon_b.size() ? rg.lincon_b[k] : zero);
216 nm.push_back("Constraint" + std::to_string(k + 1));
217 }
218
219 if (rows.empty())
220 throw UnsupportedError(ErrorKind{"Region"},
221 "solver_nc_lossn_analyzer: the finite capacity region declares no bounded constraint, "
222 "so it admits every arrival and is not a loss network; give it a global job cap, a "
223 "memory budget, a per-class cap or an explicit linear constraint");
224
225 A = Matrix<T>(rows.size(), K, zero);
226 for (std::size_t j = 0; j < rows.size(); ++j)
227 for (std::size_t r = 0; r < K; ++r) A(j, r) = rows[j][r];
228 Cvec = rhs;
229 if (names) *names = nm;
230}
231
232/** `options.method` split on '.' and '/' and lowercased, as `nc` does elsewhere. */
233inline std::vector<std::string> lossn_tokens(const std::string& method) {
234 std::vector<std::string> toks;
235 std::string tok;
236 for (char ch : method) {
237 if (ch == '.' || ch == '/') {
238 toks.push_back(tok);
239 tok.clear();
240 } else {
241 tok += static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
242 }
243 }
244 toks.push_back(tok);
245 return toks;
246}
247
248inline bool lossn_has_token(const std::vector<std::string>& toks, const char* what) {
249 for (const std::string& t : toks)
250 if (t == what) return true;
251 return false;
252}
253
254} // namespace detail
255
256/**
257 * True when the model has the SHAPE of a loss network -- open, one region, one
258 * member station, that station an infinite server -- whatever admission rule
259 * the region applies.
260 *
261 * SEPARATE FROM THE RULE TEST ON PURPOSE. A shape test that also demanded DROP
262 * would make a WAITQ region on this very shape indistinguishable, to the
263 * caller, from a model with no region at all, and the runner would then answer
264 * it as an unconstrained network. The reference splits the two questions the
265 * same way: `runAnalyzer.m:307-327` first recognises the shape, and only then
266 * branches on the rule, raising on WAITQ rather than falling through.
267 *
268 * The member test is `isinf(nservers)`, not `nodetype == Delay`, to match the
269 * reference. An infinite-server Queue has the shape and must reach the analyzer
270 * so its by-name refusal fires; excluding it here would silently hide it.
271 */
272template <class T>
274 if (sn.regions.size() != 1) return false;
275 const std::vector<std::size_t> mem = detail::lossn_region_members(sn, 0);
276 if (mem.size() != 1) return false;
277 const std::size_t st = mem[0];
278 if (st == 0 || st > sn.stations.size()) return false;
279 if (std::isfinite(sn.stations[st - 1].nservers)) return false;
280
281 for (const qn::JobClass& c : sn.classes)
282 if (std::isfinite(c.population) && c.population > 0.0) return false;
283 return true;
284}
285
286/**
287 * True when the model is a loss network: the shape above, with EVERY class
288 * dropped at the region.
289 *
290 * The DROP rule is what makes it a LOSS network rather than a blocking one. A
291 * WAITQ region holds the arrival back instead of discarding it, which is a
292 * queueing phenomenon the Erlang model has no state for, so it must not be
293 * routed here.
294 *
295 * ALL classes, not merely one: the reference tests `all(regionrule(1,:) ==
296 * DROP)`. A region that discards one class and holds another back is a mixed
297 * system whose blocked class occupies the region while it waits, so the
298 * per-class loss probabilities the Erlang fixed point returns would not be the
299 * ones the model implies.
300 */
301template <class T>
303 if (!nc_has_lossn_shape(sn)) return false;
304 if (sn.regions[0].rule.size() < sn.nclasses) return false;
305 for (std::size_t r = 0; r < sn.nclasses; ++r)
306 if (sn.regions[0].rule[r] != lang::DropStrategy::DROP) return false;
307 return true;
308}
309
310/**
311 * Port of `solver_nc_lossn_analyzer.m`.
312 *
313 * @param sn the refreshed struct; must satisfy `nc_is_lossn_model`
314 * @param opt solver controls; `method` selects erlangfp / mci
315 */
316template <class T>
318 const NcSolverOptions& opt) {
320 {
321 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
322 const std::size_t K = sn.nclasses, M = sn.nstations;
323
324 // 1. The delay inside the region.
325 const std::vector<std::size_t> mem = detail::lossn_region_members(sn, 0);
326 if (sn.regions.empty())
327 throw UnsupportedError(ErrorKind{"Topology"},
328 "solver_nc_lossn_analyzer: the model declares no finite capacity region, so it is "
329 "not a loss network");
330 if (mem.size() != 1)
331 throw UnsupportedError(ErrorKind{"Region"},
332 "solver_nc_lossn_analyzer: the finite capacity region holds " +
333 std::to_string(mem.size()) +
334 " stations; the admission rule can only see the occupancy of the region as a "
335 "whole, so the carried load could not be attributed to a station");
336 const std::size_t delayIdx = mem[0];
337 if (sn.stations[delayIdx - 1].nodetype != qn::NodeType::Delay)
338 throw UnsupportedError(ErrorKind{"Region"},
339 "solver_nc_lossn_analyzer: the station inside the finite capacity region is not a "
340 "Delay; a loss network holds admitted jobs at an infinite server, and a queueing "
341 "station would make the response time depend on the population");
342
343 // 2. Offered load. A route carries nu_r = arrival rate times mean
344 // holding time INSIDE the region, i.e. the visit ratio at the delay over
345 // its service rate. The bare arrival rate would be right only for unit
346 // mean service times.
347 out.nu.assign(K, zero);
348 std::vector<T> lambda(K, zero), mu(K, zero);
349 const std::size_t dsf = sn.stateful_of_station(delayIdx);
350 for (std::size_t r = 0; r < K; ++r) {
351 const std::size_t src = sn.classes[r].refstat;
352 if (src == 0 || src > M) continue;
353 if (!sn.disabled[src - 1][r]) lambda[r] = sn.rates(src - 1, r);
354 // A class the delay never serves never enters the region: it offers
355 // no load and is reported blocked with probability zero, which is
356 // what a rate read out of a disabled pair could not express.
357 if (sn.disabled[delayIdx - 1][r]) continue;
358 mu[r] = sn.rates(delayIdx - 1, r);
359 if (mu[r] == zero)
360 throw UnsupportedError(ErrorKind{"Region"},
361 "solver_nc_lossn_analyzer: class " + std::to_string(r + 1) +
362 " is enabled at the delay with a zero service rate, so its mean holding time "
363 "in the region is unbounded and its offered load is undefined");
364
365 T V = one;
366 const std::size_t rsf = sn.stateful_of_station(src);
367 for (std::size_t c = 0; c < sn.nchains; ++c) {
368 if (!sn.chains[c][r]) continue;
369 const T vref = sn.visits[c](rsf - 1, r);
370 if (vref > zero) V = T(sn.visits[c](dsf - 1, r) / vref);
371 break;
372 }
373 out.nu[r] = T(lambda[r] * V / mu[r]);
374 }
375
376 // 3. The admission rule.
377 std::vector<std::string> linknames;
378 detail::lossn_region_constraints(sn, 0, delayIdx, K, out.A, out.Cvec, &linknames);
379 const std::size_t J = out.Cvec.size();
380
381 // 4. Method selection, following the reference's precedence: an explicit
382 // 'mci' wins, then an explicit 'erlangfp', then 'asy', then 'rec', then
383 // the exact transform.
384 const std::vector<std::string> toks = detail::lossn_tokens(opt.method);
385 bool integral = true;
386 for (std::size_t j = 0; j < J; ++j) {
387 const double c = num_traits<T>::to_double(out.Cvec[j]);
388 if (std::fabs(c - std::round(c)) > 1e-9) integral = false;
389 for (std::size_t r = 0; r < K; ++r) {
390 const double a = num_traits<T>::to_double(out.A(j, r));
391 if (std::fabs(a - std::round(a)) > 1e-9) integral = false;
392 }
393 }
394
395 std::string chosen;
396 if (detail::lossn_has_token(toks, "mci")) {
397 chosen = "mci";
398 } else if (detail::lossn_has_token(toks, "erlangfp")) {
399 chosen = "erlangfp";
400 } else if (detail::lossn_has_token(toks, "asy")) {
401 chosen = "asy";
402 } else if (detail::lossn_has_token(toks, "rec")) {
403 chosen = "rec";
404 } else if (detail::lossn_has_token(toks, "exact") ||
405 detail::lossn_has_token(toks, "manjunath") ||
406 detail::lossn_has_token(toks, "ms")) {
407 // An EXPLICIT request for the transform is honoured even on a
408 // fractional region, where `lossn_manjunath` refuses it by name; silently
409 // answering with the Erlang approximation instead would report an
410 // approximation under the name of an exact method.
411 chosen = "exact";
412 } else {
413 // Only 'default' falls back, and only on a fractional region -- to
414 // MDD-rec, which is exact there, rather than to 'erlangfp', which
415 // this port refuses on a fractional region.
416 chosen = integral ? "exact" : "rec";
417 }
418
419 double lG = std::numeric_limits<double>::quiet_NaN();
420 std::vector<T> QLen(K, zero);
421 out.Loss.assign(K, zero);
422 int niter = 0;
423 std::string method;
424
425 if (chosen == "rec") {
426 const lossn::LossnRecResult<T> rr = lossn::lossn_rec<T>(out.nu, out.A, out.Cvec);
427 QLen = rr.QLen;
428 out.Loss = rr.Loss;
429 lG = rr.lG;
430 niter = rr.iterations;
431 method = "lossn.rec";
432 } else if (chosen == "exact") {
435 QLen = mr.QLen;
436 out.Loss = mr.Loss;
437 lG = mr.lG;
438 // The transform is direct, so the iteration count is 1 by
439 // definition, as in the reference.
440 niter = static_cast<int>(mr.iterations);
441 method = "lossn.exact";
442 } else if (chosen == "asy") {
443 if constexpr (!num_traits<T>::has_transcendental) {
444 throw UnsupportedError(ErrorKind{"Arithmetic"},
445 "solver_nc_lossn_analyzer: the 'asy' method solves the Kelly limit by Newton "
446 "steps on exponentials that stop on a tolerance, so it is unavailable under "
447 "exact arithmetic and would not be exact there anyway. Use 'exact', the "
448 "Manjunath-Sikdar transform");
449 } else {
450 // No integrality demand: the fluid limit is posed in real
451 // arithmetic, so a fractional region runs here as in the reference.
452 const lossn::LossnAsyResult<T> ar = lossn::lossn_asy<T>(out.nu, out.A, out.Cvec);
453 QLen = ar.QLen;
454 out.Loss = ar.Loss;
455 niter = ar.niter;
456 method = "lossn.asy";
457 }
458 } else if (chosen == "mci") {
459 if constexpr (!num_traits<T>::has_transcendental) {
460 throw UnsupportedError(ErrorKind{"Arithmetic"},
461 "solver_nc_lossn_analyzer: the 'mci' method forms its importance weights in "
462 "log space and reports a confidence interval, so it is unavailable under exact "
463 "arithmetic -- and meaningless there in any case, since the estimate is a "
464 "random variable. Use 'exact', the Manjunath-Sikdar transform, which is "
465 "rational throughout");
466 } else {
468 mciopt.samples = opt.samples;
469 const lossn::LossnMciResult<T> mr =
470 lossn::lossn_mci<T>(out.nu, out.A, out.Cvec, mciopt,
471 static_cast<std::uint64_t>(opt.seed));
472 QLen = mr.QLen;
473 out.Loss = mr.Loss;
474 lG = mr.lG;
475 // The sampler does not iterate; the reference reports the
476 // realised sample count in the slot the other methods use for
477 // the iteration count, so a caller can tell how much work
478 // produced the estimate.
479 niter = static_cast<int>(mr.nsamples);
480 method = "lossn.mci";
481 }
482 } else {
483 if constexpr (!num_traits<T>::has_transcendental) {
484 throw UnsupportedError(ErrorKind{"Arithmetic"},
485 "solver_nc_lossn_analyzer: the 'erlangfp' method stops on a tolerance, so it "
486 "is unavailable under "
487 "exact arithmetic and would not be exact there anyway. Use 'exact', the "
488 "Manjunath-Sikdar transform");
489 } else {
490 // lossn_erlangfp scales a fractional row to integers as MATLAB
491 // does, but line-test's test_nc_lossn.cpp still pins this
492 // refusal; lifting it needs that expectation changed by consent.
493 if (!integral)
494 throw UnsupportedError(ErrorKind{"Region"},
495 "solver_nc_lossn_analyzer: the 'erlangfp' method is not offered on a "
496 "region with fractional circuit requirements or capacity (a memory budget "
497 "with fractional class sizes, or an explicit linear constraint). Use "
498 "'mci', which compares in real arithmetic, or 'rec', which is exact there");
499 // The reference hardwires its fixed-point settings inside
500 // lossn_erlangfp rather than reading options.iter_tol.
501 const lossn::ErlangFpResult<T> fr =
503 QLen = fr.QLen;
504 out.Loss = fr.Loss;
505 out.E = fr.E;
506 niter = static_cast<int>(fr.iterations);
507 method = "lossn.erlangfp";
508 }
509 }
510
511 // 5. The metric table. QLen is the CARRIED load E[n_r], so the carried
512 // throughput follows from Little's law at the infinite server.
513 out.sol.sol.Q = Matrix<T>(M, K, zero);
514 out.sol.sol.U = Matrix<T>(M, K, zero);
515 out.sol.sol.R = Matrix<T>(M, K, zero);
516 out.sol.sol.Tp = Matrix<T>(M, K, zero);
517 out.sol.sol.C.assign(K, zero);
518 out.sol.sol.X.assign(K, zero);
519 for (std::size_t r = 0; r < K; ++r) {
520 const std::size_t src = sn.classes[r].refstat;
521 const T Xc = T(lambda[r] * (one - out.Loss[r]));
522 out.sol.sol.X[r] = Xc;
523 out.sol.sol.Tp(delayIdx - 1, r) = Xc;
524 // The source emits the ACCEPTED (post-drop) rate, so that the
525 // routing-based arrival rate `sn_get_arvr_from_tput` derives is
526 // non-zero at the delay and agrees with the flow-conserving
527 // departure throughput and with the rate SolverJMT simulates.
528 if (src >= 1 && src <= M) out.sol.sol.Tp(src - 1, r) = Xc;
529 out.sol.sol.Q(delayIdx - 1, r) = QLen[r];
530 // An infinite server never queues, so the response time is the
531 // service time and the "utilization" is the mean number of busy
532 // servers, which is the population itself.
533 if (mu[r] != zero) out.sol.sol.R(delayIdx - 1, r) = T(one / mu[r]);
534 out.sol.sol.U(delayIdx - 1, r) = QLen[r];
535 }
536 out.sol.sol.lG = lG;
537 out.sol.sol.iter = niter;
538 out.sol.sol.method = method;
539 out.sol.actualmethod = method;
540
541 // 6. Inputs of the loss network, kept so that getAvgLinkTable can
542 // report the per-link measures with the same method without rebuilding
543 // the constraints (the reference's lossnInfo).
544 solvers::LossnInfo& info = out.sol.lossn;
545 info.valid = true;
546 info.nu.assign(K, 0.0);
547 for (std::size_t r = 0; r < K; ++r) info.nu[r] = num_traits<T>::to_double(out.nu[r]);
548 info.A = Matrix<double>(J, K, 0.0);
549 info.C.assign(J, 0.0);
550 for (std::size_t j = 0; j < J; ++j) {
551 info.C[j] = num_traits<T>::to_double(out.Cvec[j]);
552 for (std::size_t r = 0; r < K; ++r) info.A(j, r) = num_traits<T>::to_double(out.A(j, r));
553 }
554 info.links = linknames;
555 info.method = chosen;
556 if (chosen == "mci") {
557 info.samples = opt.samples;
558 info.seed = static_cast<std::uint64_t>(opt.seed);
559 }
560 return out;
561 }
562}
563
564} // namespace nc
565} // namespace line
566
567#endif // LINE_SOLVERS_NC_SOLVER_NC_LOSSN_H
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
std::vector< JobClass > classes
Damped fixed-point iteration, the shared driver of the decomposition algorithms.
The exception types the port throws.
Large-capacity (Kelly limit) approximation of loss networks.
Erlang fixed-point (reduced-load) approximation for a loss network.
Exact analysis of a loss network by the Manjunath-Sikdar transform.
Monte Carlo importance-sampling summation for product-form loss networks.
Exact analysis of a loss network by MDD-rec.
Dense matrix and non-owning view.
LossnAsyResult< T > lossn_asy(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C)
Fluid (Kelly) limit of a loss network by convex duality.
Definition lossn_asy.h:72
LossnManjunathResult< T > lossn_manjunath(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C, const LossnManjunathOptions &options=LossnManjunathOptions())
Exact normalizing constant, carried load and blocking of a loss network.
ErlangFpResult< T > lossn_erlangfp(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C, const da::FpiOptions &options=lossn_erlangfp_options())
Erlang fixed-point (reduced-load) approximation for a loss network.
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
LossnRecResult< T > lossn_rec(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C)
Exact loss-network analysis by MDD-rec.
Definition lossn_rec.h:141
da::FpiOptions lossn_erlangfp_options()
The reference's fixed-point settings: iter_max 10000, iter_tol 1e-10, the max-norm of the increment (...
bool nc_is_lossn_model(const qn::NetworkStruct< T > &sn)
True when the model is a loss network: the shape above, with EVERY class dropped at the region.
bool nc_has_lossn_shape(const qn::NetworkStruct< T > &sn)
True when the model has the SHAPE of a loss network – open, one region, one member station,...
NcLossnSolution< T > solver_nc_lossn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_lossn_analyzer.m.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
Result of lossn_asy.
Definition lossn_asy.h:57
std::vector< T > QLen
mean number of route-r calls in progress, nu_r (1 - Loss_r) (R)
Definition lossn_asy.h:58
std::vector< T > Loss
limiting loss probability of route r (R)
Definition lossn_asy.h:59
int niter
number of coordinate-descent sweeps
Definition lossn_asy.h:61
Controls of lossn_manjunath.
Result of lossn_manjunath.
double lG
log of the EXACT normalizing constant g(C)
std::vector< T > QLen
mean carried load E[n_r] per route
std::vector< T > Loss
blocking probability per route
std::size_t iterations
Always 1: the transform is direct, and the field exists for the shared analyzer contract that the ite...
Options of lossn_mci, MATLAB's options struct.
Definition lossn_mci.h:77
Result of lossn_mci.
Definition lossn_mci.h:86
std::vector< T > QLen
mean carried load per route
Definition lossn_mci.h:87
std::vector< T > Loss
blocking probability per route
Definition lossn_mci.h:88
double lG
log of the estimated normalizing constant
Definition lossn_mci.h:89
Carried load, blocking, log normalising constant and walk count.
Definition lossn_rec.h:68
double lG
log G(C), a double diagnostic.
Definition lossn_rec.h:76
std::vector< T > Loss
Blocking probability per class.
Definition lossn_rec.h:72
std::vector< T > QLen
Mean number of class-r calls in progress, the carried load.
Definition lossn_rec.h:70
int iterations
Number of diagram walks performed, K + 1.
Definition lossn_rec.h:78
What the loss-network analyzer returns beyond the usual metric table.
std::vector< T > Loss
(K) blocking probability per class
Matrix< T > E
(J x K) blocking of class k on row j, empty outside the fixed point
Matrix< T > A
(J x K) rows of the admission rule A n <= C
std::vector< T > nu
(K) offered load per class
std::vector< T > Cvec
(J) the right-hand side
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:134
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:35
One job class of the network.
double population
infinite for an open class
FINITE CAPACITY REGIONS, MATLAB's refreshRegions output.
Matrix< T > lincon_A
optional linear constraint A n <= b
std::vector< std::vector< double > > cap
(nstations x nclasses+1), -1 = unbounded
std::vector< double > maxmem
per member station, -1 = unbounded
std::vector< T > size
per class; size is the memory footprint
std::vector< bool > members
membership, independent of the caps
self.result.LossN.
Definition lossn_info.h:39
bool valid
false outside a loss network
Definition lossn_info.h:40
std::string method
chosen method: exact, rec, erlangfp, asy or mci
Definition lossn_info.h:45
std::uint64_t seed
mci seed of the run
Definition lossn_info.h:47
std::vector< std::string > links
(J) link names, in row order
Definition lossn_info.h:44
Matrix< double > A
(J x K) rows of the admission rule
Definition lossn_info.h:42
std::vector< double > C
(J) capacities
Definition lossn_info.h:43
std::size_t samples
mci sample count of the run (0 = not mci)
Definition lossn_info.h:46
std::vector< double > nu
(K) offered load per class
Definition lossn_info.h:41