LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
amap2_assemble.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_ASSEMBLE_H
6#define LINE_API_MAM_AMAP2_ASSEMBLE_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * Assemble an AMAP(2) in one of the two canonical forms
12 * (matlab/lib/m3a/m3a/amap2/amap2_assemble.m).
13 *
14 * l1, l2 are the MEAN holding times of the two phases; p1, p2 the two
15 * branching probabilities. Form 1 is used for a non-negative autocorrelation
16 * decay rate, form 2 for a negative one:
17 *
18 * form 1: D0 = [ -1/l1 p1/l1 ; 0 -1/l2 ] D1 = [ (1-p1)/l1 0 ]
19 * [ (1-p2)/l2 p2/l2 ]
20 * form 2: D0 = [ -1/l1 p1/l1 ; 0 -1/l2 ] D1 = [ 0 (1-p1)/l1 ]
21 * [ (1-p2)/l2 p2/l2 ]
22 *
23 * Pure field arithmetic, exact at Rational: no transcendental gate.
24 */
25
27#include "line/num/number.h"
28#include "line/util/error.h"
29#include "line/util/matrix.h"
30
31namespace line {
32namespace mam {
33
34/** AMAP(2) in canonical form 1 (gamma >= 0) or 2 (gamma < 0). */
35template <class T>
36Map<T> amap2_assemble(const T& l1, const T& l2, const T& p1, const T& p2, int form) {
37 const T zero = num_traits<T>::from_int(0);
38 const T one = num_traits<T>::from_int(1);
39 if (l1 == zero || l2 == zero) throw InputError("amap2_assemble: zero phase mean");
40 Map<T> m;
41 m.D0 = Matrix<T>(2, 2, zero);
42 m.D1 = Matrix<T>(2, 2, zero);
43 m.D0(0, 0) = -one / l1;
44 m.D0(0, 1) = p1 / l1;
45 m.D0(1, 1) = -one / l2;
46 if (form == 1) {
47 m.D1(0, 0) = (one - p1) / l1;
48 m.D1(1, 0) = (one - p2) / l2;
49 m.D1(1, 1) = p2 / l2;
50 } else if (form == 2) {
51 m.D1(0, 1) = (one - p1) / l1;
52 m.D1(1, 0) = (one - p2) / l2;
53 m.D1(1, 1) = p2 / l2;
54 } else {
55 throw InputError("amap2_assemble: form must be 1 (gamma >= 0) or 2 (gamma < 0)");
56 }
57 return m;
58}
59
60} // namespace mam
61} // namespace line
62
63#endif // LINE_API_MAM_AMAP2_ASSEMBLE_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
Map< T > amap2_assemble(const T &l1, const T &l2, const T &p1, const T &p2, int form)
AMAP(2) in canonical form 1 (gamma >= 0) or 2 (gamma < 0).
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Matrix< T > D1
Definition map_moment.h:55
Matrix< T > D0
Definition map_moment.h:54