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