LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
amap2_fit_gamma.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_AMAP2_FIT_GAMMA_H
6#define LINE_API_MAM_AMAP2_FIT_GAMMA_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * AMAP(2) fit of three moments and the autocorrelation decay rate
12 * (matlab/lib/m3a/m3a/amap2/amap2_fit_gamma.m).
13 *
14 * A unit SCV short-circuits to a Poisson process, since the AMAP(2) canonical
15 * forms are degenerate there. Otherwise every exact solution is enumerated
16 * with amap2_fitall_gamma, normalized, and the first is returned.
17 *
18 * When no exact solution exists the characteristics are relaxed into the
19 * feasible region with amap2_adjust_gamma at the reference default (method 3:
20 * priority M2 > M3 > GAMMA, closed form through aph2_adjust and the GAMMA
21 * bounds) and refitted. As in the reference, those approximate solutions are
22 * not passed through map_normalize. Only when the refit is empty as well does
23 * the Poisson process matching the mean come back, flagged through
24 * Amap2FitGammaResult::poisson_fallback.
25 *
26 * Gated on transcendental arithmetic through amap2_fitall_gamma.
27 */
28
29#include <vector>
30
35#include "line/num/number.h"
36
37namespace line {
38namespace mam {
39
40/** Result of amap2_fit_gamma. */
41template <class T>
43 Map<T> amap; ///< the selected fit
44 std::vector<Map<T>> amaps; ///< every solution found (of the adjusted characteristics when adjusted)
45 bool adjusted; ///< true when the fit is of characteristics relaxed by amap2_adjust_gamma
46 bool poisson_fallback; ///< true when SCV == 1, or no AMAP(2) exists even after adjustment
47};
48
49/**
50 * Fit an AMAP(2) to (M1, M2, M3, GAMMA). cvtol is the tolerance on
51 * |M2 - 2 M1^2| below which the Poisson short-circuit fires (MATLAB 1e-6).
52 */
53template <class T>
54Amap2FitGammaResult<T> amap2_fit_gamma(const T& M1, const T& M2, const T& M3, const T& GAMMA,
55 const T& cvtol) {
57 "amap2_fit_gamma requires transcendental arithmetic");
58 const T two = num_traits<T>::from_int(2);
60 r.adjusted = false;
61 r.poisson_fallback = false;
62
63 if (num_abs(T(M2 - two * M1 * M1)) < cvtol) {
65 r.amaps.push_back(r.amap);
66 r.poisson_fallback = true;
67 return r;
68 }
69
70 std::vector<Map<T>> all = amap2_fitall_gamma(M1, M2, M3, GAMMA);
71 for (std::size_t j = 0; j < all.size(); ++j) all[j] = map_normalize(all[j]);
72 r.amaps = all;
73
74 if (r.amaps.empty()) {
75 // approximate fit of the nearest feasible characteristics (reference default method 3)
76 const Amap2AdjustGammaResult<T> adj = amap2_adjust_gamma(M1, M2, M3, GAMMA);
77 r.amaps = amap2_fitall_gamma(M1, adj.M2a, adj.M3a, adj.GAMMAa);
78 r.adjusted = true;
79 }
80
81 if (r.amaps.empty()) {
83 r.amaps.push_back(r.amap);
84 r.poisson_fallback = true;
85 return r;
86 }
87 r.amap = r.amaps.front();
88 return r;
89}
90
91/** amap2_fit_gamma with the MATLAB default cvtol = 1e-6. */
92template <class T>
93Amap2FitGammaResult<T> amap2_fit_gamma(const T& M1, const T& M2, const T& M3, const T& GAMMA) {
94 return amap2_fit_gamma(M1, M2, M3, GAMMA, T(num_traits<T>::from_double(1e-6)));
95}
96
97} // namespace mam
98} // namespace line
99
100#endif // LINE_API_MAM_AMAP2_FIT_GAMMA_H
Nearest AMAP(2)-feasible (M2, M3, GAMMA) (matlab/lib/m3a/m3a/amap2/amap2_adjust_gamma....
All AMAP(2) representations matching three moments and the autocorrelation decay rate (matlab/lib/m3a...
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
MAP constructors and structural transformations.
Amap2FitGammaResult< T > amap2_fit_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T &cvtol)
Fit an AMAP(2) to (M1, M2, M3, GAMMA).
Amap2AdjustGammaResult< T > amap2_adjust_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const std::vector< T > &weights, int method, int constraints, const T &tol)
Nearest AMAP(2)-feasible characteristics.
Map< T > map_exponential_mean(const T &mean)
Poisson process with the given mean inter-arrival time (map_exponential.m).
Map< T > map_normalize(const Map< T > &in)
Clamp negative off-diagonal entries of D0 and negative entries of D1 to zero, then rebuild the diagon...
std::vector< Map< T > > amap2_fitall_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T &degentol, const T &r12tol)
Every AMAP(2) matching (M1, M2, M3, GAMMA).
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
T num_abs(const T &v)
Definition number.h:184
Number-type abstraction for the templated API port.
Result of amap2_adjust_gamma.
Result of amap2_fit_gamma.
bool adjusted
true when the fit is of characteristics relaxed by amap2_adjust_gamma
bool poisson_fallback
true when SCV == 1, or no AMAP(2) exists even after adjustment
Map< T > amap
the selected fit
std::vector< Map< T > > amaps
every solution found (of the adjusted characteristics when adjusted)
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53