5#ifndef LINE_API_FJ_XMAX_ERLANG_H
6#define LINE_API_FJ_XMAX_ERLANG_H
41T erlang_cdf(
const T& t,
unsigned k,
const T& mu) {
42 static_assert(num_traits<T>::has_transcendental,
43 "erlang_cdf requires transcendental arithmetic");
44 const T zero = num_traits<T>::from_int(0);
45 if (t <= zero)
return zero;
49 return num_traits<T>::from_int(1) - num_exp(T(-x)) * S;
54T erlang_survival(
const T& x,
unsigned k,
const T& mu) {
55 static_assert(num_traits<T>::has_transcendental,
56 "erlang_survival requires transcendental arithmetic");
57 const T zero = num_traits<T>::from_int(0);
58 if (x <= zero)
return num_traits<T>::from_int(1);
62 return num_exp(T(-y)) * S;
67T fj_xmax_erlang_quad(
unsigned K,
unsigned k,
const T& mu) {
68 const T kk = num_traits<T>::from_int(
static_cast<long>(k));
69 const T upper = kk / mu * num_traits<T>::from_int(10) + num_traits<T>::from_int(10) * num_sqrt(kk) / mu;
70 const T one = num_traits<T>::from_int(1);
71 return simpson<T>([&](
const T& t) {
return T(one -
num_pow_int(erlang_cdf(t, k, mu), K)); },
72 num_traits<T>::from_int(0), upper);
87 detail::require_positive_K(K,
"fj_xmax_erlang");
88 if (k < 1)
throw InputError(
"fj_xmax_erlang: the stage count k must be a positive integer");
94 for (
unsigned n = 1; n <= K; ++n) {
97 for (
unsigned m = 1; m <= n; ++m)
99 const T term = detail::fj_binom<T>(K, n) * inner;
100 if ((n - 1) % 2 == 0) outer += term;
107 return detail::fj_xmax_erlang_quad<T>(K, k, mu);
110 "fj_xmax_erlang: only k = 2 has a closed form; any other stage count needs a "
111 "quadrature of the Erlang CDF and therefore transcendental arithmetic");
UnsupportedError(const std::string &what)
The exception types the port throws.
Shared return types and arithmetic helpers for the templated fork-join port.
T fj_xmax_erlang(unsigned K, unsigned k, const T &mu)
Expected maximum of K i.i.d.
Conservation laws of a layered queueing network, enumerated from its structure.
T num_factorial(unsigned n)
Factorial as a value of T.
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Number-type abstraction for the templated API port.