LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mm1k_loss.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_QSYS_QSYS_MM1K_LOSS_H
6#define LINE_API_QSYS_QSYS_MM1K_LOSS_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Blocking probability of the M/M/1/K queue.
12 *
13 * Templated port of matlab/src/api/qsys/qsys_mm1k_loss.m, cross-checked
14 * against jar/src/main/java/jline/api/qsys/Qsys_mm1k_loss.java (identical).
15 *
16 * rho = lambda/mu
17 * Ploss = (1-rho)/(1-rho^(K+1)) * rho^K
18 *
19 * Only integer powers appear, so this is exact for T = Rational. It is the
20 * closed form the Niu-Cooper transform-free M/G/1/K analysis collapses onto
21 * when the service is exponential, and qsys_mg1k_loss must reproduce it.
22 *
23 * The formula has a removable singularity at rho = 1, where the true value is
24 * 1/(K+1). MATLAB divides by zero and returns NaN there; the port raises
25 * instead, since in an exact field the quotient has no value at all.
26 */
27
29#include "line/num/number.h"
30#include "line/util/error.h"
31
32namespace line {
33namespace qsys {
34
35template <class T>
38 T utilization; ///< rho = lambda/mu, the offered load (not the carried one)
39};
40
41/**
42 * @brief Blocking probability of the M/M/1/K queue.
43 *
44 * @param lambda arrival rate
45 * @param mu service rate
46 * @param K system capacity, jobs in service included, K >= 1
47 */
48template <class T>
49Mm1kLossResult<T> qsys_mm1k_loss(const T& lambda, const T& mu, unsigned K) {
50 if (K == 0) throw InputError("qsys_mm1k_loss: K must be at least 1");
51 const T one = num_traits<T>::from_int(1);
52 const T rho = lambda / mu;
53 if (one - num_pow_int(rho, K + 1) == num_traits<T>::from_int(0))
54 throw InputError("qsys_mm1k_loss: rho == 1, the closed form is a removable singularity");
56 r.utilization = rho;
57 r.lossProbability = (one - rho) / (one - num_pow_int(rho, K + 1)) * num_pow_int(rho, K);
58 return r;
59}
60
61} // namespace qsys
62} // namespace line
63
64#endif // LINE_API_QSYS_QSYS_MM1K_LOSS_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Mm1kLossResult< T > qsys_mm1k_loss(const T &lambda, const T &mu, unsigned K)
Blocking probability of the M/M/1/K queue.
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition number.h:192
Number-type abstraction for the templated API port.
Shared return type and arithmetic helpers for the templated qsys port.
T utilization
rho = lambda/mu, the offered load (not the carried one)