LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
amap2_fitall_gamma.m
1function AMAPS = amap2_fitall_gamma(M1,M2,M3,GAMMA)
2% Finds the equivalent AMAP(2)s (up to 4) fitting the given set of
3% characteristics. If the characteristics are infeasible, an empty cell
4% array is returned (no approximate fitting is performed).
5% Input:
6% - M1,M2,M3: moments of the inter-arrival times
7% - GAMMA: auto-correlation decay rate of the inter-arrival times
8% Output:
9% - AMAPS: a cell array of feasible AMAP(2) processes
10
11degentol = 1e-8;
12r12tol = 1e-6;
13
14SCV = (M2-M1^2)/M1^2;
15% lower bound of M3 for SCV <= 1
16M3lb = 3*M1^3*(3*SCV-1+sqrt(2)*(1-SCV)^(3/2));
17
18if SCV <= 1 && abs(M3 - M3lb) < degentol
19 % when M3 is close to the lower bound, the sqrt argument is zero
20 tmp0 = 0;
21else
22 tmp0 = M3^2/9 + ((8*M1^3)/3 - 2*M2*M1)*M3 - 3*M1^2*M2^2 + 2*M2^3;
23 if tmp0 < 0
24 % infeasible: square root of negative element
25 AMAPS = {};
26 return;
27 end
28end
29tmp1 = 3*sqrt(tmp0);
30tmp2 = M3 - 3*M1*M2;
31tmp3 = (6*M2 - 12*M1^2);
32
33% maximum number of solutions
34if tmp0 == 0
35 % the diagonal elements of D0 are identical
36 n = 1;
37else
38 n = 2;
39end
40
41% solution parameters
42h1v = zeros(n,1);
43h2v = zeros(n,1);
44
45if n == 1
46 h2v = tmp2/tmp3;
47 h1v = h2v;
48else
49 h2v(1) = (tmp2 + tmp1)/tmp3;
50 h2v(2) = (tmp2 - tmp1)/tmp3;
51 h1v(2) = h2v(1);
52 h1v(1) = h2v(2);
53end
54
55% check for infeasibility
56if min(h2v) <= 0
57 AMAPS = {};
58 return;
59end
60
61if GAMMA > 0
62 AMAPS = cell(1,n*2);
63else
64 AMAPS = cell(1,n);
65end
66
67idx = 1;
68for j = 1:n
69
70 h1 = h1v(j);
71 h2 = h2v(j);
72
73 if (GAMMA >= 0)
74
75 % FIRST canonical form
76
77 z = M1^2*GAMMA^2 + (2*M1*h1 + 2*M1*h2 - 4*h1*h2 - 2*M1^2)*GAMMA + M1^2 - 2*M1*h1 - 2*M1*h2 + h1^2 + 2*h1*h2 + h2^2;
78
79 if abs(z) < degentol
80 % one solution, argument of square root is practically zero
81 r2 = (h1 - M1 + h2 + GAMMA*M1)/(2*h1);
82 r1 = (M1 - h1 - M1*r2 + h1*r2)/(h2 - M1*r2);
83 % construct MAP if feasible
84 if feasible(r1,r2)
85 r1 = fix(r1);
86 r2 = fix(r2);
87 AMAPS{idx} = amap2_assemble(h1, h2, r1, r2, 1);
88 idx = idx + 1;
89 end
90 elseif z > 0
91 % two possible values of r2
92 r2v = zeros(2,1);
93 r2v(1) = (h1 - M1 + h2 - sqrt(z) + GAMMA*M1)/(2*h1);
94 r2v(2) = (h1 - M1 + h2 + sqrt(z) + GAMMA*M1)/(2*h1);
95 % two possible values of r1
96 r1v = zeros(2,1);
97 for i = 1:2
98 r2 = r2v(i);
99 r1v(i) = (M1 - h1 - M1*r2 + h1*r2)/(h2 - M1*r2);
100 end
101 % assemble
102 for i = 1:2
103 r1 = r1v(i);
104 r2 = r2v(i);
105 % construct MAP if feasible
106 if feasible(r1,r2)
107 r1 = fix(r1);
108 r2 = fix(r2);
109 AMAPS{idx} = amap2_assemble(h1, h2, r1, r2, 1);
110 idx = idx + 1;
111 end
112 end
113 end
114
115 else
116
117 % SECOND canonical form
118
119 r2 = (h1 - M1 + h2 + GAMMA*M1)/h1;
120 r1 = (r2 + (h1 + h2 - h1*r2)/M1 - 2)/(r2 - 1);
121 % construct MAP if feasible
122 if feasible(r1,r2)
123 r2 = fix(r2);
124 r1 = fix(r1);
125 AMAPS{idx} = amap2_assemble(h1, h2, r1, r2, 2);
126 idx = idx + 1;
127 end
128
129 end
130end
131
132% return feasible solutions
133AMAPS = AMAPS(1:(idx-1));
134
135 function q = fix(q)
136 q = max(min(q,1),0);
137 end
138
139 function feas = feasible(r1, r2)
140 feas = isreal(r1) && isreal(r2) && ...
141 r1 >= -r12tol && r1 <= 1+r12tol && ...
142 r2 >= -r12tol && r2 <= 1+r12tol;
143 end
144
145end