LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
aph2_fit.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_MAM_APH2_FIT_H
6#define LINE_API_MAM_APH2_FIT_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * APH(2) fit of three moments, with a fallback to adjusted moments
12 * (matlab/lib/m3a/m3a/aph2/aph2_fit.m).
13 *
14 * Exact fitting is attempted first with aph2_fitall; if that yields nothing
15 * the moments are relaxed with aph2_adjust ('simple' method) and the fit is
16 * repeated. The first solution is returned, together with all of them.
17 *
18 * Gated on transcendental arithmetic through aph2_fitall and aph2_adjust.
19 */
20
21#include <vector>
22
26#include "line/num/number.h"
27#include "line/util/error.h"
28
29namespace line {
30namespace mam {
31
32/** Result of aph2_fit. */
33template <class T>
35 Map<T> aph; ///< the selected fit, APHS.front()
36 std::vector<Map<T>> aphs; ///< every feasible form found
37 bool adjusted; ///< true when the moments had to be relaxed
38};
39
40/** Fit an APH(2) to (M1, M2, M3), relaxing the moments if necessary. */
41template <class T>
42Aph2FitResult<T> aph2_fit(const T& M1, const T& M2, const T& M3) {
43 static_assert(num_traits<T>::has_transcendental, "aph2_fit requires transcendental arithmetic");
45 r.adjusted = false;
46 r.aphs = aph2_fitall(M1, M2, M3);
47 if (r.aphs.empty()) {
48 const Aph2AdjustResult<T> adj = aph2_adjust(M1, M2, M3);
49 r.adjusted = true;
50 r.aphs = aph2_fitall(M1, adj.M2a, adj.M3a);
51 if (r.aphs.empty()) throw NumericError("aph2_fit: feasibility could not be restored");
52 }
53 r.aph = r.aphs.front();
54 return r;
55}
56
57} // namespace mam
58} // namespace line
59
60#endif // LINE_API_MAM_APH2_FIT_H
Nearest APH(2)-feasible values of the second and third moments (matlab/lib/m3a/m3a/aph2/aph2_adjust....
All APH(2) representations matching three moments (matlab/lib/m3a/m3a/aph2/aph2_fitall....
NumericError(const std::string &what)
Definition error.h:45
The exception types the port throws.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Aph2FitResult< T > aph2_fit(const T &M1, const T &M2, const T &M3)
Fit an APH(2) to (M1, M2, M3), relaxing the moments if necessary.
Definition aph2_fit.h:42
std::vector< Map< T > > aph2_fitall(const T &M1, const T &M2, const T &M3, const T &degentol)
All feasible APH(2) fits of (M1, M2, M3).
Definition aph2_fitall.h:46
Aph2AdjustResult< T > aph2_adjust(const T &M1, const T &M2, const T &M3, const T &tol)
Feasible (M2, M3) closest to the input, holding M1 fixed.
Definition aph2_adjust.h:46
Number-type abstraction for the templated API port.
Result of aph2_adjust.
Definition aph2_adjust.h:36
Result of aph2_fit.
Definition aph2_fit.h:34
bool adjusted
true when the moments had to be relaxed
Definition aph2_fit.h:37
Map< T > aph
the selected fit, APHS.front()
Definition aph2_fit.h:35
std::vector< Map< T > > aphs
every feasible form found
Definition aph2_fit.h:36
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53