LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
lossn_links.h
Go to the documentation of this file.
1#ifndef LINE_API_LOSSN_LOSSN_LINKS_H
2#define LINE_API_LOSSN_LOSSN_LINKS_H
3
4/**
5 * @file lossn_links.h
6 * @ingroup api_lossn
7 * @brief Per-link blocking and occupancy of a loss network.
8 *
9 * Templated port of matlab/src/api/lossn/lossn_links.m.
10 *
11 * Returns, for every link j and route r with A(j,r) > 0, the probability that
12 * link j alone cannot accept a route-r call, E(j,r) = P(fewer than A(j,r) free
13 * units on link j), together with the mean occupancy of each link,
14 * Occ_j = sum_r A(j,r) E[n_r]. Under the product form the link blocking is a
15 * ratio of normalizing constants, E(j,r) = 1 - G(C - A(j,r) e_j)/G(C), which
16 * the exact methods evaluate directly. The route loss satisfies
17 * Loss_r >= max_j E(j,r), with equality only when no two links block
18 * route r in different states.
19 *
20 * Methods:
21 * - 'exact' (also 'manjunath', 'ms'): one Manjunath-Sikdar evaluation per
22 * distinct (link, requirement) pair; needs integral A and C.
23 * - 'rec': as exact with MDD-rec, also for fractional A and C.
24 * - 'erlangfp': the Erlang fixed-point blocking matrix (independence
25 * approximation).
26 * - 'asy': the Kelly limit, E(j,r) = 1 - (1-a_j)^A(j,r).
27 * - 'mci': the importance-sampling estimator of lossn_mci (the options carry
28 * the sample count and the seed).
29 *
30 * ARITHMETIC. The fixed point, the fluid limit and the Monte Carlo estimator
31 * are all transcendental, so the header is gated on
32 * num_traits<T>::has_transcendental.
33 *
34 * Reference: K. W. Ross, "Multiservice Loss Models for Broadband
35 * Telecommunication Networks", Springer, 1995, Sec. 5.1-5.3.
36 *
37 * @see lossn_revsens, lossn_mci, lossn_asy, lossn_erlangfp
38 */
39
40#include <algorithm>
41#include <cctype>
42#include <cmath>
43#include <cstddef>
44#include <cstdint>
45#include <string>
46#include <vector>
47
53#include "line/num/number.h"
54#include "line/util/error.h"
55#include "line/util/matrix.h"
56
57namespace line {
58namespace lossn {
59
60/** Result of lossn_links. */
61template <class T>
63 Matrix<T> E; ///< (J x R) blocking of route r by link j alone; 0 where A(j,r) = 0
64 std::vector<T> Occ; ///< (J) mean number of busy units on link j
65 std::vector<T> Loss; ///< (R) route loss probability, as the chosen method gives it
66 std::vector<T> QLen; ///< (R) mean number of route-r calls in progress
67};
68
69namespace detail {
70
71/** Lowercased copy, as MATLAB's lower(method). */
72inline std::string lossn_lower(std::string s) {
73 for (char& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
74 return s;
75}
76
77/** Distinct positive entries of row j of A, sorted ascending (MATLAB unique). */
78template <class T>
79std::vector<T> lossn_row_levels(const Matrix<T>& A, std::size_t j) {
80 const T zero = num_traits<T>::from_int(0);
81 std::vector<T> v;
82 for (std::size_t r = 0; r < A.cols(); ++r)
83 if (A(j, r) > zero) v.push_back(A(j, r));
84 std::sort(v.begin(), v.end());
85 v.erase(std::unique(v.begin(), v.end()), v.end());
86 return v;
87}
88
89} // namespace detail
90
91/**
92 * @brief Per-link blocking and occupancy of a loss network.
93 *
94 * @param nu offered load of route r (R)
95 * @param A capacity requirement of link j for route r (J x R)
96 * @param C capacity of link j (J)
97 * @param method 'exact' (default), 'rec', 'erlangfp', 'asy' or 'mci'
98 * @param mciopt options for 'mci' (samples, alpha, gamma)
99 * @param seed seed of the 'mci' generator
100 */
101template <class T>
102LossnLinksResult<T> lossn_links(const std::vector<T>& nu, const Matrix<T>& A, const std::vector<T>& C,
103 const std::string& method = "exact",
104 const LossnMciOptions<T>& mciopt = LossnMciOptions<T>(),
105 std::uint64_t seed = 0) {
107 "lossn_links requires transcendental arithmetic");
108 using std::expm1;
109 using std::log1p;
110 const std::size_t R = nu.size();
111 const std::size_t J = C.size();
112 if (A.rows() != J || A.cols() != R)
113 throw InputError("lossn_links: A must be " + std::to_string(J) + "x" + std::to_string(R) +
114 " (J x R).");
115 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
116 const std::string m = detail::lossn_lower(method.empty() ? std::string("exact") : method);
117
119 out.E = Matrix<T>(J, R, zero);
120 if (m == "exact" || m == "manjunath" || m == "ms" || m == "rec") {
121 const bool rec = (m == "rec");
122 // lG of the network at capacity Cv; the exact G under rec
123 T G = zero;
124 double lG = 0.0;
125 if (rec) {
126 const LossnRecResult<T> r0 = lossn_rec(nu, A, C);
127 out.QLen = r0.QLen;
128 out.Loss = r0.Loss;
129 G = r0.G;
130 lG = r0.lG;
131 } else {
132 const LossnManjunathResult<T> r0 = lossn_manjunath(nu, A, C);
133 out.QLen = r0.QLen;
134 out.Loss = r0.Loss;
135 lG = r0.lG;
136 }
137 for (std::size_t j = 0; j < J; ++j) {
138 for (const T& a : detail::lossn_row_levels(A, j)) {
139 T e = one;
140 if (!(T(C[j] - a) < zero)) {
141 std::vector<T> Cs = C;
142 Cs[j] = T(C[j] - a);
143 if (rec) {
144 // 1 - G(Cs)/G(C), which is -expm1(lGs - lG) without the
145 // round trip through a double logarithm
146 e = T(one - lossn_rec(nu, A, Cs).G / G);
147 } else {
148 const double lGs = lossn_manjunath(nu, A, Cs).lG;
149 e = num_traits<T>::from_double(-std::expm1(lGs - lG));
150 }
151 if (e < zero) e = zero;
152 if (e > one) e = one;
153 }
154 for (std::size_t r = 0; r < R; ++r)
155 if (A(j, r) == a) out.E(j, r) = e;
156 }
157 }
158 } else if (m == "erlangfp") {
159 const ErlangFpResult<T> r0 = lossn_erlangfp(nu, A, C);
160 out.QLen = r0.QLen;
161 out.Loss = r0.Loss;
162 out.E = r0.E;
163 } else if (m == "asy") {
164 const LossnAsyResult<T> r0 = lossn_asy(nu, A, C);
165 out.QLen = r0.QLen;
166 out.Loss = r0.Loss;
167 for (std::size_t j = 0; j < J; ++j)
168 for (std::size_t r = 0; r < R; ++r)
169 if (A(j, r) > zero)
170 out.E(j, r) = r0.a[j] >= one ? one : T(-expm1(T(A(j, r) * log1p(T(-r0.a[j])))));
171 } else if (m == "mci") {
172 const LossnMciResult<T> r0 = lossn_mci(nu, A, C, mciopt, seed);
173 out.QLen = r0.QLen;
174 out.Loss = r0.Loss;
175 out.E = r0.linkLossPoint;
176 } else {
177 throw InputError("lossn_links: Unknown method '" + method +
178 "'; use exact, rec, erlangfp, asy or mci.");
179 }
180 out.Occ.assign(J, zero);
181 for (std::size_t j = 0; j < J; ++j)
182 for (std::size_t r = 0; r < R; ++r) out.Occ[j] += T(A(j, r) * out.QLen[r]);
183 return out;
184}
185
186} // namespace lossn
187} // namespace line
188
189#endif // LINE_API_LOSSN_LOSSN_LINKS_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
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.
LossnLinksResult< T > lossn_links(const std::vector< T > &nu, const Matrix< T > &A, const std::vector< T > &C, const std::string &method="exact", const LossnMciOptions< T > &mciopt=LossnMciOptions< T >(), std::uint64_t seed=0)
Per-link blocking and occupancy of a loss network.
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
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Number-type abstraction for the templated API port.
Matrix< T > E
(J x R) blocking of class r on link j (the fixed point)
std::vector< T > QLen
carried traffic per class
std::vector< T > Loss
blocking probability per class
Result of lossn_asy.
Definition lossn_asy.h:57
std::vector< T > a
limiting blocking probability of link j (J)
Definition lossn_asy.h:60
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
Result of lossn_links.
Definition lossn_links.h:62
std::vector< T > Loss
(R) route loss probability, as the chosen method gives it
Definition lossn_links.h:65
std::vector< T > QLen
(R) mean number of route-r calls in progress
Definition lossn_links.h:66
Matrix< T > E
(J x R) blocking of route r by link j alone; 0 where A(j,r) = 0
Definition lossn_links.h:63
std::vector< T > Occ
(J) mean number of busy units on link j
Definition lossn_links.h:64
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
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
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
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
T G
Normalising constant G(C).
Definition lossn_rec.h:74
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