LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mmpp2_fit2.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_MMPP2_FIT2_H
6#define LINE_API_MAM_MMPP2_FIT2_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * MMPP(2) matching mean, SCV, skewness and the autocorrelation decay rate
12 * (matlab/lib/kpctoolbox/mmpp/mmpp2_fit2.m).
13 *
14 * Converts (mean, scv, skew) to raw moments and delegates to mmpp2_fit3. A
15 * unit SCV short-circuits to a Poisson process, where the MMPP(2) closed form
16 * is degenerate. MATLAB then warns when the result fails map_isfeasible; this
17 * port reports it through the result struct instead, since a warning printed
18 * from a library is invisible to a caller that only has the return value.
19 *
20 * Gated on transcendental arithmetic: the third moment needs
21 * (E2 - E1^2)^(3/2) and mmpp2_fit3 is itself gated.
22 */
23
28#include "line/num/number.h"
29#include "line/util/error.h"
30
31namespace line {
32namespace mam {
33
34/** Result of the (mean, scv, skew)-parameterized MMPP(2) fits. */
35template <class T>
38 bool feasible; ///< map_isfeasible of the result at the given tolerance
39};
40
41/** MMPP(2) with the given mean, SCV, skewness and decay rate g2. */
42template <class T>
43Mmpp2FitResult<T> mmpp2_fit2(const T& mean, const T& scv, const T& skew, const T& g2) {
45 "mmpp2_fit2 requires transcendental arithmetic");
46 using fitdetail::num_sqrt;
47 using fitdetail::pw;
48 const T one = num_traits<T>::from_int(1);
49 const T two = num_traits<T>::from_int(2);
50 const T three = num_traits<T>::from_int(3);
51
53 if (scv == one) {
54 r.map = map_exponential_mean(mean);
55 r.feasible = true;
56 return r;
57 }
58 const T E1 = mean;
59 const T E2 = (one + scv) * E1 * E1;
60 const T v = E2 - E1 * E1;
61 if (v < num_traits<T>::from_int(0)) throw InputError("mmpp2_fit2: negative variance");
62 const T E3 = -(two * pw(E1, 3) - three * E1 * E2 - skew * v * num_sqrt(v));
63 r.map = mmpp2_fit3(E1, E2, E3, g2);
65 return r;
66}
67
68} // namespace mam
69} // namespace line
70
71#endif // LINE_API_MAM_MMPP2_FIT2_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Scalar helpers shared by the MAP/PH moment-matching headers.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
MAP constructors and structural transformations.
MMPP(2) matching three moments and the autocorrelation decay rate (matlab/lib/kpctoolbox/mmpp/mmpp2_f...
Map< T > mmpp2_fit3(const T &E1, const T &E2, const T &E3, const T &G2, const T &g2tol)
MMPP(2) with moments (E1, E2, E3) and autocorrelation decay rate G2.
Definition mmpp2_fit3.h:51
bool map_isfeasible(const Map< T > &m, const T &tol)
Structural feasibility of a MAP within a tolerance (map_isfeasible.m): off-diagonal D0 and all of D1 ...
Map< T > map_exponential_mean(const T &mean)
Poisson process with the given mean inter-arrival time (map_exponential.m).
Mmpp2FitResult< T > mmpp2_fit2(const T &mean, const T &scv, const T &skew, const T &g2)
MMPP(2) with the given mean, SCV, skewness and decay rate g2.
Definition mmpp2_fit2.h:43
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Result of the (mean, scv, skew)-parameterized MMPP(2) fits.
Definition mmpp2_fit2.h:36
bool feasible
map_isfeasible of the result at the given tolerance
Definition mmpp2_fit2.h:38