LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mmpp2_fit4.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_FIT4_H
6#define LINE_API_MAM_MMPP2_FIT4_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * MMPP(2) matching mean, SCV, skewness and the lag-1 autocorrelation
12 * (matlab/lib/kpctoolbox/mmpp/mmpp2_fit4.m).
13 *
14 * Same conversion as mmpp2_fit2 except that the autocorrelation is given at
15 * lag 1 rather than as the decay rate, so it is divided by the lag-0
16 * autocorrelation rho0 = (1 - 1/scv)/2 first. skew = -1 is the sentinel that
17 * defers the choice of the third moment, which mmpp2_fit3 does not support;
18 * unlike MATLAB, which would pass E3 = -1 straight into the closed form and
19 * return a meaningless MAP, this port rejects it.
20 *
21 * Gated on transcendental arithmetic through mmpp2_fit3.
22 */
23
29#include "line/num/number.h"
30#include "line/util/error.h"
31
32namespace line {
33namespace mam {
34
35/** MMPP(2) with the given mean, SCV, skewness and lag-1 autocorrelation. */
36template <class T>
37Mmpp2FitResult<T> mmpp2_fit4(const T& mean, const T& scv, const T& skew, const T& acf1) {
39 "mmpp2_fit4 requires transcendental arithmetic");
40 using fitdetail::num_sqrt;
41 using fitdetail::pw;
42 const T one = num_traits<T>::from_int(1);
43 const T two = num_traits<T>::from_int(2);
44 const T three = num_traits<T>::from_int(3);
45
46 if (skew == -one)
47 throw InputError("mmpp2_fit4: skew = -1 (automatic third moment) is not supported");
48 if (scv == num_traits<T>::from_int(0)) throw InputError("mmpp2_fit4: zero SCV");
49 const T rho0 = (one - one / scv) / two;
50 if (rho0 == num_traits<T>::from_int(0))
51 throw InputError("mmpp2_fit4: unit SCV admits no autocorrelation");
52
53 const T E1 = mean;
54 const T E2 = (one + scv) * E1 * E1;
55 const T v = E2 - E1 * E1;
56 if (v < num_traits<T>::from_int(0)) throw InputError("mmpp2_fit4: negative variance");
57 const T E3 = -(two * pw(E1, 3) - three * E1 * E2 - skew * v * num_sqrt(v));
58
60 r.map = mmpp2_fit3(E1, E2, E3, T(acf1 / rho0));
62 return r;
63}
64
65} // namespace mam
66} // namespace line
67
68#endif // LINE_API_MAM_MMPP2_FIT4_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 mean, SCV, skewness and the autocorrelation decay rate (matlab/lib/kpctoolbox/mmpp/m...
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
Mmpp2FitResult< T > mmpp2_fit4(const T &mean, const T &scv, const T &skew, const T &acf1)
MMPP(2) with the given mean, SCV, skewness and lag-1 autocorrelation.
Definition mmpp2_fit4.h:37
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 ...
Number-type abstraction for the templated API port.
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