LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_xmax_approx.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_FJ_XMAX_APPROX_H
6#define LINE_API_FJ_XMAX_APPROX_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Two-moment approximation to the expected maximum of K i.i.d. samples,
12 * X_K^max ~ mu_X + sigma_X G(K).
13 *
14 * Templated port of matlab/src/api/fj/fj_xmax_approx.m, cross-checked against
15 * FJ_xmax.fj_xmax_approx in jar/src/main/java/jline/api/fj/FJ_xmax.java
16 * (identical).
17 *
18 * MIXED ARITHMETIC. The exponential family uses G(K) = H_K - 1, which is
19 * rational and exact in any field; the uniform, EVD and bound families need
20 * sqrt or log and are only available when T carries transcendental functions.
21 * Asking for one of those at exact arithmetic throws UnsupportedError.
22 */
23
27#include "line/num/number.h"
28#include "line/util/error.h"
29
30namespace line {
31namespace fj {
32
33/**
34 * @brief Two-moment approximation to the expected maximum of K i.i.d.
35 * samples, X_K^max ~ mu_X + sigma_X G(K).
36 *
37 * @param K number of branches, K >= 1
38 * @param mu_X mean of the branch distribution
39 * @param sigma_X standard deviation of the branch distribution, >= 0
40 * @param type which G(K) family to use
41 * @return [Xmax, GK]
42 */
43template <class T>
44FJXmaxApproxResult<T> fj_xmax_approx(unsigned K, const T& mu_X, const T& sigma_X,
46 detail::require_positive_K(K, "fj_xmax_approx");
47 if (sigma_X < num_traits<T>::from_int(0))
48 throw InputError("fj_xmax_approx: sigma_X must be non-negative");
49
51 if (type == FJDistType::Exp) {
53 } else {
55 GK = fj_gk_bound<T>(K, type);
56 } else {
57 throw UnsupportedError(
58 "fj_xmax_approx: only the exponential G(K) is rational; the uniform, EVD and "
59 "bound families need sqrt or log and therefore transcendental arithmetic");
60 }
61 }
62 return {T(mu_X + sigma_X * GK), GK};
63}
64
65} // namespace fj
66} // namespace line
67
68#endif // LINE_API_FJ_XMAX_APPROX_H
InputError(const std::string &what)
Definition error.h:39
UnsupportedError(const std::string &what)
Definition error.h:51
The exception types the port throws.
G(K) factors for the standardized-maximum approximation X_K^max ~ mu + sigma G(K).
Harmonic number H_K = sum_{k=1..K} 1/k.
Shared return types and arithmetic helpers for the templated fork-join port.
FJGKBoundResult< T > fj_gk_bound(unsigned K)
G(K) factors for the standardized-maximum approximation X_K^max ~ mu.
Definition fj_gk_bound.h:44
FJXmaxApproxResult< T > fj_xmax_approx(unsigned K, const T &mu_X, const T &sigma_X, FJDistType type=FJDistType::Exp)
Two-moment approximation to the expected maximum of K i.i.d.
FJDistType
Distribution families for which a G(K) standardized-maximum factor exists.
Definition fj_types.h:41
T fj_harmonic(unsigned K)
Harmonic number H_K = sum_{k=1..K} 1/k.
Definition fj_harmonic.h:37
Number-type abstraction for the templated API port.
[Xmax, GK] of fj_xmax_approx.
Definition fj_types.h:72