LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
28
#include "
line/api/qsys/qsys_types.h
"
29
#include "
line/num/number.h
"
30
#include "
line/util/error.h
"
31
32
namespace
line
{
33
namespace
qsys
{
34
35
template
<
class
T>
36
struct
Mm1kLossResult
{
37
T
lossProbability
;
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
*/
48
template
<
class
T>
49
Mm1kLossResult<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"
);
55
Mm1kLossResult<T>
r;
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
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::qsys_mm1k_loss
Mm1kLossResult< T > qsys_mm1k_loss(const T &lambda, const T &mu, unsigned K)
Blocking probability of the M/M/1/K queue.
Definition
qsys_mm1k_loss.h:49
line
Definition
aoi_dist2ph.h:52
line::num_pow_int
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition
number.h:192
number.h
Number-type abstraction for the templated API port.
qsys_types.h
Shared return type and arithmetic helpers for the templated qsys port.
line::num_traits
Definition
number.h:111
line::qsys::Mm1kLossResult
Definition
qsys_mm1k_loss.h:36
line::qsys::Mm1kLossResult::utilization
T utilization
rho = lambda/mu, the offered load (not the carried one)
Definition
qsys_mm1k_loss.h:38
line::qsys::Mm1kLossResult::lossProbability
T lossProbability
Definition
qsys_mm1k_loss.h:37
include
line
api
qsys
qsys_mm1k_loss.h
Generated by
1.18.0