Loss Networks
Analysis of networks with blocking.
The lossn module implements algorithms for loss networks where arrivals can
be blocked when resources are unavailable.
Key function categories:
Erlang fixed-point:
lossn_erlangfp()Large-capacity (Kelly) limit:
lossn_asy()Per-link blocking and occupancy:
lossn_links()Revenue sensitivities and implied costs:
lossn_revsens()Multirate single link (Kaufman-Roberts):
lossn_kr(),lossn_kr_dim()(dimensioning),lossn_kr_asy()(critical-loading asymptotic)
Loss Network Analysis Algorithms.
Native Python implementations for analyzing loss networks using Erlang formulas and related methods.
- Key algorithms:
lossn_manjunath: Manjunath-Sikdar transform, exact normalization constant lossn_rec: exact normalization constant by MDD-rec, integral A and C not needed lossn_erlangfp: Erlang fixed-point algorithm for loss networks lossn_mci: Monte Carlo importance-sampling summation (Ross-Wang) lossn_kr: Kaufman-Roberts recursion for a multirate link lossn_kr_dim: smallest link capacity meeting blocking targets lossn_kr_asy: critical-loading normal approximation of a link lossn_asy: large-capacity (Kelly) limit of a loss network lossn_links: per-link blocking and occupancy of a loss network lossn_revsens: revenue sensitivities and implied costs erlang_b: Erlang B blocking probability erlang_c: Erlang C delay probability
- lossn_erlangfp(nu, A, c, tol=1e-10, max_iter=10000)[source]
Erlang fixed point (reduced-load) approximation for loss networks.
Calls (jobs) on route (class) r arrive according to Poisson rate nu_r. Call service times on route r have unit mean. The link capacity requirements are:
sum_r A[j,r] * n[j,r] <= c[j]
for all links j, where n[j,r] counts calls on route r on link j.
Link j sees route r offered at nu_r thinned by the blocking of r on every OTHER link, and its occupancy distribution is the Kaufman-Roberts one (Kaufman 1981, Roberts 1981), so B[j,r] = P(more than c[j]-A[j,r] units busy). Unit requirements reduce this to Kelly’s Erlang fixed point. The earlier form fed the multi-unit load to Erlang B, which counted a call of size a as a single unit. Mirrors MATLAB lossn_erlangfp.m.
- Parameters:
- Returns:
qlen: Mean queue-length (carried load) for each route (R,)
loss: Loss probability for each route (R,)
eblock: Blocking probability of route r on link j (J, R)
niter: Number of iterations
- Return type:
Tuple of (qlen, loss, eblock, niter) where
Example
>>> nu = np.array([0.3, 0.1]) >>> A = np.array([[1, 1], [1, 4]]) # 2 links, 2 routes >>> c = np.array([1, 3]) >>> qlen, loss, eblock, niter = lossn_erlangfp(nu, A, c)
- erlang_b(offered_load, servers)[source]
Compute Erlang B blocking probability.
The Erlang B formula gives the probability that an arriving call is blocked in an M/M/c/c loss system.
- Parameters:
- Returns:
Blocking probability.
- Return type:
Example
>>> erlang_b(10.0, 12) # Offered load 10 Erlang, 12 channels 0.1054...
- erlang_c(offered_load, servers)[source]
Compute Erlang C delay probability.
The Erlang C formula gives the probability that an arriving call must wait in an M/M/c queue.
- Parameters:
- Returns:
Delay probability (probability of waiting).
- Return type:
Example
>>> erlang_c(10.0, 12) # Offered load 10 Erlang, 12 agents
- lossn_mci(nu, A, C, samples=100000, gamma=None, seed=None, alpha=0.05, revenue=None)[source]
Monte Carlo importance-sampling summation for loss networks.
A loss network has links j=1..J with capacity C[j] and classes r=1..R with offered load nu[r] and per-link circuit requirement A[j,r]. The state n is feasible iff A @ n <= C (set Omega). The product-form normalization constant is g(C) = sum_{n in Omega} prod_r nu[r]**n_r/n_r!. Class-r acceptance is g(C-A[:,r])/g(C) = 1 - beta_r.
States are drawn from the importance distribution (Eq. 6):
p(n) = (1/c) prod_r gamma_r**n_r / n_r!
over the box {0..N_1} x … x {0..N_R}, N_r = min_j floor(C_j/A_jr). Ratio estimators (Eq. 8) yield g and blocking with delta-method confidence intervals.
- Parameters:
nu (ndarray) – Offered load per class (R,).
A (ndarray) – Circuit requirement matrix (J, R).
C (ndarray) – Link capacity vector (J,).
samples (int) – Number of Monte Carlo samples.
gamma (ndarray | None) – Importance-sampling parameters (R,); default is the Section 3.4 heuristic.
seed (int | None) – RNG seed for reproducibility.
alpha (float) – Confidence-interval significance level (default 0.05).
revenue (ndarray | None) – Revenue per call and unit time of route r (R,); when given, adds the revenue sensitivity to ci.
- Returns:
qlen: Mean carried load E[n_r] per class (R,).
loss: Blocking probability beta_r per class (R,).
lG: Log of the estimated normalization constant g(C).
ci: dict with ‘accept’ (R,2), ‘loss’ (R,2), ‘acceptPoint’ (R,), ‘lossPoint’ (R,), ‘level’ (1-alpha), ‘linkLossPoint’ (J,R blocking of route r on link j alone); with revenue also ‘revenue’ (W), ‘revsens’ (R,) dW/dnu, ‘revsensCI’ (R,2), ‘impliedCost’ (R,), ‘linkImpliedCost’ (J,R).
nsamples: Number of samples used.
- Return type:
Tuple (qlen, loss, lG, ci, nsamples) where
- lossn_manjunath(nu, A, C, max_live_states=None)[source]
Exact normalization constant, carried load and blocking of a loss network.
- Parameters:
nu (ndarray) – Offered load of route (class) r (R,), nonnegative.
A (ndarray) – Capacity requirement of link j for route r (J, R), nonnegative integers.
C (ndarray) – Available capacity of link j (J,), nonnegative integers.
max_live_states (int | None) – Cap on the simultaneously live series coefficients; defaults to DEFAULT_MAX_LIVE_STATES.
- Returns:
qlen: Mean carried load E[n_r] per route (R,).
loss: Blocking probability per route (R,).
lG: Log of the EXACT normalization constant g(C).
niter: Always 1; the transform is direct.
- Return type:
Tuple (qlen, loss, lG, niter) where
- lossn_rec(nu, A, C)[source]
Exact loss-network analysis by MDD-rec.
- Parameters:
nu (
offered load per class,length K)A (
J x K non-negative resource requirement matrix)C (
capacity vector,length J)
- Returns:
(QLen,Loss,lG,niter) with QLen the carried load per class,Loss theblocking probability per class,lG the log normalising constant G(C) andniter the numberofdiagram walks performed,K + 1.
- Return type:
- lossn_kr(rho, b, C)[source]
Exact occupancy distribution and per-class blocking of a stochastic knapsack.
A single link of C bandwidth units is offered K classes of calls. Class k arrives as a Poisson process with offered load rho_k (arrival rate times mean holding time) and holds b_k units for the whole call; a call that finds fewer than b_k free units is lost. The occupancy distribution q(n) = P(n units busy), n = 0..C, satisfies the Kaufman-Roberts recursion:
n q(n) = sum_k b_k rho_k q(n - b_k), q(n) = 0 for n < 0,
and a class-k call is blocked when more than C - b_k units are busy:
B_k = sum_{n = C-b_k+1}^{C} q(n).
The result is insensitive to the holding-time distributions beyond their means. A class with b_k = 0 is never blocked; a class with b_k > C always is.
- Parameters:
rho – Offered load of class k (K,), nonnegative.
b – Bandwidth units held by a class-k call (K,), nonnegative integers.
C – Link capacity in bandwidth units (nonnegative integer).
- Returns:
q: Occupancy distribution, q[n] = P(n units busy), n = 0..C (C+1,).
B: Blocking probability of class k (K,).
QLen: Mean number of class-k calls in progress, rho_k (1 - B_k) (K,).
- Return type:
Tuple (q, B, QLen) where
- Reference:
MATLAB: lossn_kr.m
- lossn_kr_dim(rho, b, Btarget)[source]
Dimensions a multirate link by the Kaufman-Roberts recursion.
Returns the smallest integer capacity C such that every class of the stochastic knapsack (see lossn_kr) has blocking B_k(C) no larger than its target. The unnormalized Kaufman-Roberts terms:
n q(n) = sum_k b_k rho_k q(n - b_k), q(0) = 1,
do not depend on C, so the search extends a single recursion one unit at a time and evaluates B_k(C) = sum_{n>C-b_k} q(n) / sum_{n<=C} q(n) at each step, at a total cost of O(C K). The search scans every C upwards rather than bisecting because the blocking of a wide class need not decrease monotonically in C (Ross 1995, Sec. 2.6).
- Parameters:
rho – Offered load of class k (K,), nonnegative.
b – Bandwidth units held by a class-k call (K,), nonnegative integers.
Btarget – Blocking target, scalar or (K,), each in (0, 1].
- Returns:
C: Smallest capacity with B_k(C) <= Btarget_k for all k.
B: Blocking probabilities at that capacity (K,).
- Return type:
Tuple (C, B) where
- Reference:
MATLAB: lossn_kr_dim.m
- lossn_kr_asy(rho, b, C)[source]
Normal approximation of multirate single-link blocking for large C.
In the critically loaded regime, where C and the offered loads grow together with sum_k b_k rho_k / C -> 1, the normalized occupancy of a stochastic knapsack converges to a truncated multivariate normal law (Kelly 1991; Ross 1995, Theorem 2.8) and blocking is asymptotically proportional to the call size (Ross 1995, Corollary 2.7). For a knapsack of fixed capacity C the resulting approximation is:
alpha = (C - sum_k b_k rho_k) / sqrt(C), sigma^2 = sum_k b_k^2 rho_k / C, delta = phi(alpha/sigma) / (sigma Phi(alpha/sigma)), B_k = b_k delta / sqrt(C),
with phi and Phi the standard normal density and distribution function. B_k is capped at 1. The approximation is accurate when |alpha| is small (roughly below 1); far from critical loading use lossn_kr for the exact values, or lossn_asy for the fluid (Kelly) limit.
- Parameters:
rho – Offered load of class k (K,), nonnegative.
b – Bandwidth units held by a class-k call (K,), nonnegative.
C – Link capacity (positive).
- Returns:
B: Approximate blocking probability of class k (K,).
alpha: Normalized spare capacity (C - sum b rho)/sqrt(C).
sigma: Normalized occupancy standard deviation.
delta: Blocking per unit of call size, times sqrt(C).
- Return type:
Tuple (B, alpha, sigma, delta) where
- Reference:
MATLAB: lossn_kr_asy.m
- lossn_asy(nu, A, C)[source]
Computes the fluid limit of a loss network by convex duality.
Scales offered loads nu and capacities C together, nu -> N nu and C -> N C, and returns the limit of the class loss probabilities as N grows (Kelly 1986; Ross 1995, Theorem 5.13). In this limit link j blocks independently with probability a_j, and the a_j solve the complementary slackness conditions:
sum_k A(j,k) nu_k prod_i (1-a_i)^A(i,k) = C_j if a_j > 0, <= C_j if a_j = 0,
the route loss being 1 - prod_j (1-a_j)^A(j,k). With y_j = -log(1-a_j) these are the optimality conditions of the strictly convex problem:
minimize sum_k nu_k exp(-sum_j A(j,k) y_j) + sum_j C_j y_j, y >= 0,
solved here by cyclic coordinate descent, each coordinate by Newton’s method on a concave increasing function. The result needs no summation over states and costs O(J R) per sweep, so it scales to any capacity; it reports zero loss on links that are underloaded at the fluid scale, so it is accurate in heavy (overloaded) traffic and for large C. A and C need not be integral.
- Parameters:
nu – Offered load of route (class) r (R,).
A – Capacity requirement of link j for route r (J, R), nonnegative.
C – Capacity of link j (J,), nonnegative.
- Returns:
QLen: Mean number of route-r calls in progress, nu_r (1-Loss_r) (R,).
Loss: Limiting loss probability of route r (R,).
a: Limiting blocking probability of link j (J,).
niter: Number of coordinate-descent sweeps.
- Return type:
Tuple (QLen, Loss, a, niter) where
- Reference:
MATLAB: lossn_asy.m
- lossn_links(nu, A, C, method='exact', options=None)[source]
Link-level performance measures of a product-form loss network.
For a loss network with offered loads nu, requirement matrix A and capacities C (A n <= C), returns for every link j and route r the probability E(j,r) that link j alone lacks the A(j,r) free units a route-r call needs, the mean occupancy of each link, and the route losses. With the exact methods the link blocking is:
E(j,r) = 1 - G(C - A(j,r) e_j) / G(C),
where G is the product-form normalization constant and e_j the j-th unit vector, computed from one extra constant per distinct (j, A(j,r)) pair. A route-r call is lost when ANY of its links blocks, so Loss_r is at least max_j E(j,r). The mean occupancy of link j is sum_r A(j,r) QLen_r.
- Supported methods:
‘exact’ (or ‘manjunath’, ‘ms’) Manjunath-style exact recursion ‘rec’ recursive decision diagram (Kirby-Wang style) normalization ‘erlangfp’ Erlang fixed point; E is the per-link Kaufman-Roberts
blocking on the reduced loads
‘asy’ Kelly limit; E(j,r) = 1 - (1-a_j)^A(j,r) ‘mci’ Monte Carlo summation; E from the same samples as Loss
- Parameters:
nu – Offered load of route r (R,).
A – Capacity requirement of link j for route r (J, R).
C – Capacity of link j (J,).
method (str) – ‘exact’ (default), ‘rec’, ‘erlangfp’, ‘asy’ or ‘mci’.
options – lossn_mci options (samples, seed, alpha, gamma) as a dict or attribute object, used by ‘mci’.
- Returns:
E: Blocking probability of route r on link j (J, R; 0 where A(j,r)=0).
Occ: Mean number of busy units on link j (J,).
Loss: Loss probability of route r (R,).
QLen: Mean number of route-r calls in progress (R,).
- Return type:
Tuple (E, Occ, Loss, QLen) where
- Reference:
MATLAB: lossn_links.m
- lossn_revsens(nu, A, C, w, method='exact', options=None)[source]
Derivative of the long-run revenue rate with respect to offered loads.
A loss network with offered loads nu (unit mean holding times), requirement matrix A and capacities C earns w_k per unit time for each route-k call in progress, so its revenue rate is W = sum_k w_k QLen_k. This function returns the sensitivity dW/dnu_k and the implied costs: the expected revenue lost over the lifetime of an admitted route-k call through the extra blocking it causes to later calls. They satisfy (Ross 1995, Theorem 5.11):
dW/dnu_k = (1 - B_k) (w_k - c_k), c_k = W(C) - W(C - A e_k),
so admitting a route-k call raises revenue only if w_k exceeds c_k. The link implied cost (shadow price) of route k on link j is W(C) - W(C - A(j,k) e_j), the revenue lost when link j alone loses the units of one route-k call.
- Supported methods:
- ‘exact’ (or ‘manjunath’, ‘ms’), ‘rec’
Theorem 5.11 with exact normalization constants
- ‘erlangfp’
reduced-load approximation of the implied costs: the link costs c(j,k) solve Ross (1995) eq. 5.21,
c(j,k) = sum_l D(j,l,k) eta(j,l) [w_l - sum_{i~=j} c(i,l)],
with eta the Erlang fixed point reduced loads and D the change of the Kaufman-Roberts blocking of route l on link j when its capacity drops by A(j,k); then
dW/dnu_k = prod_j (1 - E(j,k)) (w_k - sum_j c(j,k))
- ‘mci’ Monte Carlo summation: dW/dnu_l = Cov(X_l, r(X))/nu_l from the
importance samples, with delta-method confidence intervals
- Parameters:
nu – Offered load of route k (R,).
A – Capacity requirement of link j for route k (J, R).
C – Capacity of link j (J,).
w – Revenue per unit time of a route-k call in progress (R,).
method (str) – ‘exact’ (default), ‘rec’, ‘erlangfp’ or ‘mci’.
options – lossn_mci options (samples, seed, alpha, gamma) as a dict or attribute object, used by ‘mci’.
- Returns:
dW: Revenue sensitivity dW/dnu_k (R,).
c: Route implied cost c_k (R,; NaN if a route-k call never fits).
W: Revenue rate sum_k w_k QLen_k.
clink: Link implied cost of route k on link j (J, R; 0 where A(j,k)=0).
ci: ‘mci’ only: dict with ‘revsens’ (R,), ‘revsensCI’ (R,2) and ‘level’; None for the other methods.
- Return type:
Tuple (dW, c, W, clink, ci) where
- Reference:
MATLAB: lossn_revsens.m