LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
RandomMMAP.m
1% D = RandomMMAP(order, types, mean, zeroEntries, maxTrials, prec)
2%
3% Returns a random Markovian arrival process with given mean
4% value.
5%
6% Parameters
7% ----------
8% order : int
9% The size of the MAP
10% types : int
11% The number of different arrival types
12% mean : double, optional
13% The mean inter-arrival times of the MMAP
14% zeroEntries : int, optional
15% The number of zero entries in the D0 and D1 matrices
16% maxTrials : int, optional
17% The maximum number of trials to find a proper MMAP
18% (that has an irreducible phase process and none of
19% its parameters is all-zero)
20% prec : double, optional
21% Numerical precision for checking the irreducibility.
22% The default value is 1e-14.
23%
24% Returns
25% -------
26% D : list/cell of matrices of shape(M,M), length(types+1)
27% The D0...Dtypes matrices of the MMAP
28
29function D = RandomMMAP(order, types, mean, zeroEntries, maxTrials, prec)
30
31 if ~exist('zeroEntries','var')
32 zeroEntries = 0;
33 end
34
35 if ~exist('mean','var')
36 mean = 1;
37 end
38
39 if ~exist('prec','var')
40 prec = 1e-7;
41 end
42
43 if ~exist('maxTrials','var')
44 maxTrials = 1000;
45 end
46
47 if types < 1
48 error('RandomMMAP: ''types'' must be positive integer!');
49 end
50
51 if zeroEntries > (types+1)*order^2 - 2*order
52 error('RandomMAP/MMAP: Too many zero entries requested! Try to decrease the zeroEntries parameter!');
53 end
54
55 % distribute the zero entries among the rows
56 function o = allZeroDistr (states, zeros)
57 if states==1
58 o = zeros;
59 else
60 o = [];
61 for iz=0:zeros
62 x = allZeroDistr (states-1, zeros-iz);
63 for jz=1:size(x,1)
64 xt = sort([x(jz,:), iz]);
65 % check if we have it already
66 found = 0;
67 for kz=1:size(o,1)
68 if sum((o(kz,:)-xt).^2)==0
69 found = 1;
70 break;
71 end
72 end
73 if ~found
74 o = [o; xt];
75 end
76 end
77 end
78 end
79 end
80
81 zeroDistr = allZeroDistr(order, zeroEntries);
82
83 trials = 1;
84 while trials<maxTrials
85 % select a configuration from zeroDistr: it is a list describing the zero entries in each row
86 zdix = randperm(size(zeroDistr,1));
87 for k=1:size(zeroDistr,1)
88 zDistr = zeroDistr(zdix(k),:);
89 bad = 0;
90 for di=1:length(zDistr)
91 if zDistr(di)>=(types+1)*order-1;
92 bad = 1;
93 break;
94 end
95 end
96 if bad
97 trials = trials + 1;
98 continue;
99 end
100 B = zeros(order,(types+1)*order);
101 for i=1:order
102 rp = randperm((types+1)*order-1);
103 a = zeros(1,(types+1)*order-1);
104 for j=1:(types+1)*order-1-zDistr(i)
105 a(rp(j)) = rand();
106 end
107 B(i,1:i-1) = a(1:i-1);
108 B(i,i+1:end) = a(i:end);
109 end
110 % construct MMAP matrices
111 D = cell(1,types+1);
112 for i=1:types+1
113 D{i} = B(:,(i-1)*order+1:i*order);
114 end
115 D{1} = D{1} - diag(sum(B,2));
116 % check if it is a proper MAP (irreducible phase process & no full zero matrix)
117 sumD = D{1};
118 for i=2:length(D)
119 sumD = sumD + D{i};
120 end
121 if rank(D{1})==order && rank(sumD)==order-1
122 alpha = CTMCSolve(sumD);
123 if min(abs(alpha)) > prec
124 fullZero = 0;
125 for i=1:length(D)
126 if all(all(D{i}==0.0))
127 fullZero = 1;
128 break;
129 end
130 end
131 if fullZero==0
132 % scale to the mean value
133 m = MarginalMomentsFromMMAP(D, 1);
134 for i=1:types+1
135 D{i} = D{i} * m / mean;
136 end
137 return;
138 end
139 end
140 end
141 trials = trials + 1;
142 end
143 end
144 error('No feasible random MAP/MMAP found with such many zero entries! Try to increase the maxTrials parameter!');
145end
146