LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MMAPPH1PRPR.m
1% Ret = MMAPPH1PRPR(D, sigma, S, ...)
2%
3% Returns various performane measures of a MMAP[K]/PH[K]/1
4% preemptive resume priority queue, see [1]_.
5%
6% Parameters
7% ----------
8% D : list of matrices of shape (N,N), length (K+1)
9% The D0...DK matrices of the arrival process.
10% D1 corresponds to the lowest, DK to the highest priority.
11% sigma : list of row vectors, length (K)
12% The list containing the initial probability vectors of the service
13% time distributions of the various customer types. The length of the
14% vectors does not have to be the same.
15% S : list of square matrices, length (K)
16% The transient generators of the phase type distributions representing
17% the service time of the jobs belonging to various types.
18% further parameters :
19% The rest of the function parameters specify the options
20% and the performance measures to be computed.
21%
22% The supported performance measures and options in this
23% function are:
24%
25% +----------------+--------------------+----------------------------------------+
26% | Parameter name | Input parameters | Output |
27% +================+====================+========================================+
28% | "ncMoms" | Number of moments | The moments of the number of customers |
29% +----------------+--------------------+----------------------------------------+
30% | "ncDistr" | Upper limit K | The distribution of the number of |
31% | | | customers from level 0 to level K-1 |
32% +----------------+--------------------+----------------------------------------+
33% | "stMoms" | Number of moments | The sojourn time moments |
34% +----------------+--------------------+----------------------------------------+
35% | "stDistr" | A vector of points | The sojourn time distribution at the |
36% | | | requested points (cummulative, cdf) |
37% +----------------+--------------------+----------------------------------------+
38% | "prec" | The precision | Numerical precision used as a stopping |
39% | | | condition when solving the Riccati and |
40% | | | the matrix-quadratic equations |
41% +----------------+--------------------+----------------------------------------+
42% | "erlMaxOrder" | Integer number | The maximal Erlang order used in the |
43% | | | erlangization procedure. The default |
44% | | | value is 200. |
45% +----------------+--------------------+----------------------------------------+
46% | "classes" | Vector of integers | Only the performance measures |
47% | | | belonging to these classes are |
48% | | | returned. If not given, all classes |
49% | | | are analyzed. |
50% +----------------+--------------------+----------------------------------------+
51%
52% (The quantities related to the number of customers in
53% the system include the customer in the server, and the
54% sojourn time related quantities include the service
55% times as well)
56%
57% Returns
58% -------
59% Ret : list of the performance measures
60% Each entry of the list corresponds to a performance
61% measure requested. Each entry is a matrix, where the
62% columns belong to the various job types.
63% If there is just a single item,
64% then it is not put into a list.
65%
66% References
67% ----------
68% .. [1] G. Horvath, "Efficient analysis of the MMAP[K]/PH[K]/1
69% priority queue", European Journal of Operational
70% Research, 246(1), 128-139, 2015.
71
72function varargout = MMAPPH1PRPR(D, sigma, S, varargin)
73
74 K = length(D)-1;
75
76 % parse options
77 erlMaxOrder = 200;
78 precision = 1e-14;
79 classes = 1:K;
80 eaten = [];
81 for i=1:length(varargin)
82 if strcmp(varargin{i},'erlMaxOrder')
83 erlMaxOrder = varargin{i+1};
84 eaten = [eaten, i, i+1];
85 elseif strcmp(varargin{i},'prec')
86 precision = varargin{i+1};
87 eaten = [eaten, i, i+1];
88 elseif strcmp(varargin{i},'classes')
89 classes = varargin{i+1};
90 eaten = [eaten, i, i+1];
91 end
92 end
93
94 global BuToolsCheckInput;
95
96 if isempty(BuToolsCheckInput)
97 BuToolsCheckInput = true;
98 end
99
100 if BuToolsCheckInput && ~CheckMMAPRepresentation(D)
101 error('MMAPPH1PRPR: The arrival process is not a valid MMAP representation!');
102 end
103
104 if BuToolsCheckInput
105 for k=1:K
106 if ~CheckPHRepresentation(sigma{k},S{k})
107 error('MMAPPH1PRPR: the vector and matrix describing the service times is not a valid PH representation!');
108 end
109 end
110 end
111
112 % some preparation
113 D0 = D{1};
114 N = size(D0,1);
115 I = eye(N);
116 sD = zeros(N);
117 for i=1:K+1
118 sD = sD + D{i};
119 end
120
121 s = cell(length(S));
122 M = zeros(1,K);
123 for i=1:K
124 s{i} = sum(-S{i},2);
125 M(i) = M(i) + length(sigma{i});
126 end
127
128 Ret = {};
129 for k=classes
130
131 % step 1. solution of the workload process of the system
132 % ======================================================
133 sM = sum(M(k:K));
134 Qwmm = D0;
135 for i=1:k-1
136 Qwmm = Qwmm + D{i+1};
137 end
138 Qwpm = zeros(N*sM, N);
139 Qwmp = zeros(N, N*sM);
140 Qwpp = zeros(N*sM);
141 kix = 1;
142 for i=k:K
143 Qwmp(:,kix:kix+N*M(i)-1) = kron(D{i+1}, sigma{i});
144 Qwpm(kix:kix+N*M(i)-1,:) = kron(I,s{i});
145 Qwpp(kix:kix+N*M(i)-1,kix:kix+N*M(i)-1) = kron(I,S{i});
146 kix = kix + N*M(i);
147 end
148
149 % calculate fundamental matrices
150 [Psiw, Kw, Uw] = FluidFundamentalMatrices (Qwpp, Qwpm, Qwmp, Qwmm, 'PKU', precision);
151
152 % calculate boundary vector
153 Ua = ones(N,1) + 2*sum(Qwmp*inv(-Kw),2);
154 pm = linsolve ([Uw,Ua]', [zeros(1,N),1]')';
155
156 Bw = zeros(N*sM, N);
157 Bw(1:N*M(k),:) = kron(I,s{k});
158 kappa = pm*Qwmp / sum(pm*Qwmp*inv(-Kw)*Bw);
159
160 if k<K
161 % step 2. construct fluid model for the remaining sojourn time process
162 % ====================================================================
163 % (for each class except the highest priority)
164 Qsmm = D0;
165 for i=1:k
166 Qsmm = Qsmm + D{i+1};
167 end
168 Np = size(Kw,1);
169 Qspm = zeros(Np+N*sum(M(k+1:K)), N);
170 Qsmp = zeros(N, Np+N*sum(M(k+1:K)));
171 Qspp = zeros(Np+N*sum(M(k+1:K)));
172 Qspp(1:Np,1:Np) = Kw;
173 Qspm(1:Np,1:N) = Bw;
174 kix = Np+1;
175 for i=k+1:K
176 Qsmp(:,kix:kix+N*M(i)-1) = kron(D{i+1}, sigma{i});
177 Qspm(kix:kix+N*M(i)-1,:) = kron(I,s{i});
178 Qspp(kix:kix+N*M(i)-1,kix:kix+N*M(i)-1) = kron(I,S{i});
179 kix = kix + N*M(i);
180 end
181 inis = [kappa, zeros(1,N*sum(M(k+1:K)))];
182 Psis = FluidFundamentalMatrices (Qspp, Qspm, Qsmp, Qsmm, 'P', precision);
183
184 % step 3. calculate the performance measures
185 % ==========================================
186 argIx = 1;
187 while argIx<=length(varargin)
188 if any(ismember(eaten, argIx))
189 argIx = argIx + 1;
190 continue;
191 elseif strcmp(varargin{argIx},'stMoms')
192 % MOMENTS OF THE SOJOURN TIME
193 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~
194 numOfSTMoms = varargin{argIx+1};
195 Pn = {Psis};
196 rtMoms = zeros(1,numOfSTMoms);
197 for n=1:numOfSTMoms
198 A = Qspp + Psis*Qsmp;
199 B = Qsmm + Qsmp*Psis;
200 C = -2*n*Pn{n};
201 bino = 1;
202 for i=1:n-1
203 bino = bino * (n-i+1) / i;
204 C = C + bino * Pn{i+1}*Qsmp*Pn{n-i+1};
205 end
206 P = lyap(A, B, C);
207 Pn{n+1} = P;
208 rtMoms(n) = sum(inis*P*(-1)^n) / 2^n;
209 end
210 Ret{end+1} = rtMoms;
211 argIx = argIx + 1;
212 elseif strcmp(varargin{argIx},'stDistr')
213 % DISTRIBUTION OF THE SOJOURN TIME
214 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215 stCdfPoints = varargin{argIx+1};
216 res = [];
217 for t=stCdfPoints
218 L = erlMaxOrder;
219 lambda = L/t/2;
220 Psie = FluidFundamentalMatrices (Qspp-lambda*eye(size(Qspp)), Qspm, Qsmp, Qsmm-lambda*eye(size(Qsmm)), 'P', precision);
221 Pn = {Psie};
222 pr = sum(inis*Psie);
223 for n=1:L-1
224 A = Qspp + Psie*Qsmp - lambda*eye(size(Qspp));
225 B = Qsmm + Qsmp*Psie - lambda*eye(size(Qsmm));
226 C = 2*lambda*Pn{n};
227 for i=1:n-1
228 C = C + Pn{i+1}*Qsmp*Pn{n-i+1};
229 end
230 P = lyap(A, B, C);
231 Pn{n+1} = P;
232 pr = pr + sum(inis*P);
233 end
234 res = [res, pr];
235 end
236 Ret{end+1} = res;
237 argIx = argIx + 1;
238 elseif strcmp(varargin{argIx},'ncMoms')
239 % MOMENTS OF THE NUMBER OF JOBS
240 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241 numOfQLMoms = varargin{argIx+1};
242 % first calculate it at departure instants
243 QLDPn = {Psis};
244 dqlMoms = zeros(1,numOfQLMoms);
245 for n=1:numOfQLMoms
246 A = Qspp + Psis*Qsmp;
247 B = Qsmm + Qsmp*Psis;
248 C = n*QLDPn{n}*D{k+1};
249 bino = 1;
250 for i=1:n-1
251 bino = bino * (n-i+1) / i;
252 C = C + bino * QLDPn{i+1}*Qsmp*QLDPn{n-i+1};
253 end
254 P = lyap(A, B, C);
255 QLDPn{n+1} = P;
256 dqlMoms(n) = sum(inis*P);
257 end
258 dqlMoms = MomsFromFactorialMoms(dqlMoms);
259 % now calculate it at random time instance
260 pi = CTMCSolve (sD);
261 lambdak = sum(pi*D{k+1});
262 QLPn = {pi};
263 qlMoms = zeros(1,numOfQLMoms);
264 iTerm = inv(ones(N,1)*pi - sD);
265 for n=1:numOfQLMoms
266 sumP = sum(inis*QLDPn{n+1}) + n*(inis*QLDPn{n} - QLPn{n}*D{k+1}/lambdak)*iTerm*sum(D{k+1},2);
267 P = sumP*pi + n*(QLPn{n}*D{k+1} - inis*QLDPn{n}*lambdak)*iTerm;
268 QLPn{n+1} = P;
269 qlMoms(n) = sum(P);
270 end
271 qlMoms = MomsFromFactorialMoms(qlMoms);
272 Ret{end+1} = qlMoms;
273 argIx = argIx + 1;
274 elseif strcmp(varargin{argIx},'ncDistr')
275 % DISTRIBUTION OF THE NUMBER OF JOBS
276 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277 numOfQLProbs = varargin{argIx+1};
278 sDk = D0;
279 for i=1:k-1
280 sDk = sDk + D{i+1};
281 end
282 % first calculate it at departure instants
283 Psid = FluidFundamentalMatrices (Qspp, Qspm, Qsmp, sDk, 'P', precision);
284 Pn = {Psid};
285 dqlProbs = inis*Psid;
286 for n=1:numOfQLProbs-1
287 A = Qspp + Psid*Qsmp;
288 B = sDk + Qsmp*Psid;
289 C = Pn{n}*D{k+1};
290 for i=1:n-1
291 C = C + Pn{i+1}*Qsmp*Pn{n-i+1};
292 end
293 P = lyap(A, B, C);
294 Pn{n+1} = P;
295 dqlProbs = [dqlProbs; inis*P];
296 end
297 % now calculate it at random time instance
298 pi = CTMCSolve (sD);
299 lambdak = sum(pi*D{k+1});
300 iTerm = inv(-(sD-D{k+1}));
301 qlProbs = lambdak*dqlProbs(1,:)*iTerm;
302 for n=1:numOfQLProbs-1
303 P = (qlProbs(n,:)*D{k+1}+lambdak*(dqlProbs(n+1,:)-dqlProbs(n,:)))*iTerm;
304 qlProbs = [qlProbs; P];
305 end
306 Ret{end+1} = sum(qlProbs,2)';
307 argIx = argIx + 1;
308 else
309 error (['MMAPPH1PRPR: Unknown parameter ' varargin{argIx}])
310 end
311 argIx = argIx + 1;
312 end
313 elseif k==K
314 % step 3. calculate the performance measures
315 % ==========================================
316 argIx = 1;
317 while argIx<=length(varargin)
318 if any(ismember(eaten, argIx))
319 argIx = argIx + 1;
320 continue;
321 elseif strcmp(varargin{argIx},'stMoms')
322 % MOMENTS OF THE SOJOURN TIME
323 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~
324 numOfSTMoms = varargin{argIx+1};
325 rtMoms = zeros(1,numOfSTMoms);
326 for i=1:numOfSTMoms
327 rtMoms(i) = factorial(i)*kappa*inv(-Kw)^(i+1)*sum(Bw,2);
328 end
329 Ret{end+1} = rtMoms;
330 argIx = argIx + 1;
331 elseif strcmp(varargin{argIx},'stDistr')
332 % DISTRIBUTION OF THE SOJOURN TIME
333 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 stCdfPoints = varargin{argIx+1};
335 rtDistr = [];
336 for t=stCdfPoints
337 rtDistr = [rtDistr, kappa*inv(-Kw)*(eye(size(Kw))-expm(Kw*t))*sum(Bw,2)];
338 end
339 Ret{end+1} = rtDistr;
340 argIx = argIx + 1;
341 elseif strcmp(varargin{argIx},'ncMoms') || strcmp(varargin{argIx},'ncDistr')
342 L = kron(sD-D{k+1},eye(M(k)))+kron(eye(N),S{k});
343 B = kron(eye(N),s{k}*sigma{k});
344 F = kron(D{k+1},eye(M(k)));
345 L0 = kron(sD-D{k+1},eye(M(k)));
346 R = QBDFundamentalMatrices (B, L, F, 'R', precision);
347 p0 = CTMCSolve(L0+R*B);
348 p0 = p0/sum(p0*inv(eye(size(R))-R));
349 if strcmp(varargin{argIx},'ncMoms')
350 % MOMENTS OF THE NUMBER OF JOBS
351 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352 numOfQLMoms = varargin{argIx+1};
353 qlMoms = zeros(1,numOfQLMoms);
354 for i=1:numOfQLMoms
355 qlMoms(i) = sum(factorial(i)*p0*R^i*inv(eye(size(R))-R)^(i+1));
356 end
357 Ret{end+1} = MomsFromFactorialMoms(qlMoms);
358 elseif strcmp(varargin{argIx},'ncDistr')
359 % DISTRIBUTION OF THE NUMBER OF JOBS
360 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361 numOfQLProbs = varargin{argIx+1};
362 qlProbs = p0;
363 for i=1:numOfQLProbs-1
364 qlProbs = [qlProbs; p0*R^i];
365 end
366 Ret{end+1} = sum(qlProbs,2)';
367 end
368 argIx = argIx + 1;
369 else
370 error (['MMAPPH1PRPR: Unknown parameter ' varargin{argIx}])
371 end
372 argIx = argIx + 1;
373 end
374 end
375 end
376 varargout = Ret;
377end