LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_xmax_hz.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_HZ_H
6#define LINE_API_FJ_XMAX_HZ_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Harrison-Zertal approximation of the maximum of i.i.d. variables.
12 *
13 * Templated port of matlab/src/api/fj/fj_xmax_hz.m.
14 *
15 * X_K^max ~ m1 + ( m2 / (2 m1) ) ( H_K - 1 )
16 *
17 * The correction is the equilibrium mean of the branch law scaled by H_K - 1:
18 * one branch, plus the residual work still owed by the branches that finish
19 * later. Writing m2/(2 m1) = m1 (1+SCV)/2 shows it is exact for the exponential
20 * and reduces to m1 at K = 1 for every branch law.
21 */
22
25#include "line/num/number.h"
26#include "line/util/error.h"
27
28namespace line {
29namespace fj {
30
31/** [Xmax, resid] of fj_xmax_hz. */
32template <class T>
36};
37
38/**
39 * @brief Harrison-Zertal approximation of the maximum of i.i.d. variables.
40 *
41 * @param m1 mean of the branch distribution, m1 > 0
42 * @param m2 second moment of the branch distribution, m2 >= m1^2
43 * @param K number of branches, K >= 1
44 * @return the approximate expected maximum and the equilibrium mean used
45 */
46template <class T>
47FJXmaxHzResult<T> fj_xmax_hz(const T& m1, const T& m2, unsigned K) {
48 const T zero = num_traits<T>::from_int(0), two = num_traits<T>::from_int(2);
49 if (!(m1 > zero)) throw InputError("fj_xmax_hz: the branch mean must be positive");
50 if (m2 < m1 * m1)
51 throw InputError("fj_xmax_hz: the second moment is below the square of the mean");
52 detail::require_positive_K(K, "fj_xmax_hz");
54 out.resid = m2 / (two * m1);
55 out.Xmax = m1 + out.resid * (fj_harmonic<T>(K) - num_traits<T>::from_int(1));
56 return out;
57}
58
59} // namespace fj
60} // namespace line
61
62#endif // LINE_API_FJ_XMAX_HZ_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Harmonic number H_K = sum_{k=1..K} 1/k.
Shared return types and arithmetic helpers for the templated fork-join port.
FJXmaxHzResult< T > fj_xmax_hz(const T &m1, const T &m2, unsigned K)
Harrison-Zertal approximation of the maximum of i.i.d.
Definition fj_xmax_hz.h:47
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, resid] of fj_xmax_hz.
Definition fj_xmax_hz.h:33