1% Ret = MMAPPH1PRPR(D, sigma, S, ...)
3% Returns various performane measures of a
MMAP[K]/PH[K]/1
4% preemptive resume priority queue, see [1]_.
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.
19% The rest of the function parameters specify the options
20% and the performance measures to be computed.
22% The supported performance measures and options in
this
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% +----------------+--------------------+----------------------------------------+
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
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.
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.
72function varargout = MMAPPH1PRPR(D, sigma, S, varargin)
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')
90 eaten = [eaten, i, i+1];
94 global BuToolsCheckInput;
96 if isempty(BuToolsCheckInput)
97 BuToolsCheckInput =
true;
100 if BuToolsCheckInput && ~CheckMMAPRepresentation(D)
101 error(
'MMAPPH1PRPR: The arrival process is not a valid MMAP representation!');
106 if ~CheckPHRepresentation(sigma{k},S{k})
107 error(
'MMAPPH1PRPR: the vector and matrix describing the service times is not a valid PH representation!');
125 M(i) = M(i) + length(sigma{i});
131 % step 1. solution of the workload process of the system
132 % ======================================================
136 Qwmm = Qwmm + D{i+1};
138 Qwpm = zeros(N*sM, N);
139 Qwmp = zeros(N, N*sM);
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});
149 % calculate fundamental matrices
150 [Psiw, Kw, Uw] = FluidFundamentalMatrices (Qwpp, Qwpm, Qwmp, Qwmm,
'PKU', precision);
152 % calculate boundary vector
153 Ua = ones(N,1) + 2*sum(Qwmp*inv(-Kw),2);
154 pm = linsolve ([Uw,Ua]
', [zeros(1,N),1]')
';
157 Bw(1:N*M(k),:) = kron(I,s{k});
158 kappa = pm*Qwmp / sum(pm*Qwmp*inv(-Kw)*Bw);
161 % step 2. construct fluid model for the remaining sojourn time process
162 % ====================================================================
163 % (for each class except the highest priority)
166 Qsmm = Qsmm + D{i+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;
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});
181 inis = [kappa, zeros(1,N*sum(M(k+1:K)))];
182 Psis = FluidFundamentalMatrices (Qspp, Qspm, Qsmp, Qsmm, 'P', precision);
184 % step 3. calculate the performance measures
185 % ==========================================
187 while argIx<=length(varargin)
188 if any(ismember(eaten, argIx))
191 elseif strcmp(varargin{argIx},'stMoms
')
192 % MOMENTS OF THE SOJOURN TIME
193 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~
194 numOfSTMoms = varargin{argIx+1};
196 rtMoms = zeros(1,numOfSTMoms);
198 A = Qspp + Psis*Qsmp;
199 B = Qsmm + Qsmp*Psis;
203 bino = bino * (n-i+1) / i;
204 C = C + bino * Pn{i+1}*Qsmp*Pn{n-i+1};
208 rtMoms(n) = sum(inis*P*(-1)^n) / 2^n;
212 elseif strcmp(varargin{argIx},'stDistr
')
213 % DISTRIBUTION OF THE SOJOURN TIME
214 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215 stCdfPoints = varargin{argIx+1};
220 Psie = FluidFundamentalMatrices (Qspp-lambda*eye(size(Qspp)), Qspm, Qsmp, Qsmm-lambda*eye(size(Qsmm)), 'P', precision);
224 A = Qspp + Psie*Qsmp - lambda*eye(size(Qspp));
225 B = Qsmm + Qsmp*Psie - lambda*eye(size(Qsmm));
228 C = C + Pn{i+1}*Qsmp*Pn{n-i+1};
232 pr = pr + sum(inis*P);
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
244 dqlMoms = zeros(1,numOfQLMoms);
246 A = Qspp + Psis*Qsmp;
247 B = Qsmm + Qsmp*Psis;
248 C = n*QLDPn{n}*D{k+1};
251 bino = bino * (n-i+1) / i;
252 C = C + bino * QLDPn{i+1}*Qsmp*QLDPn{n-i+1};
256 dqlMoms(n) = sum(inis*P);
258 dqlMoms = MomsFromFactorialMoms(dqlMoms);
259 % now calculate it at random time instance
261 lambdak = sum(pi*D{k+1});
263 qlMoms = zeros(1,numOfQLMoms);
264 iTerm = inv(ones(N,1)*pi - sD);
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;
271 qlMoms = MomsFromFactorialMoms(qlMoms);
274 elseif strcmp(varargin{argIx},'ncDistr
')
275 % DISTRIBUTION OF THE NUMBER OF JOBS
276 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277 numOfQLProbs = varargin{argIx+1};
282 % first calculate it at departure instants
283 Psid = FluidFundamentalMatrices (Qspp, Qspm, Qsmp, sDk, 'P', precision);
285 dqlProbs = inis*Psid;
286 for n=1:numOfQLProbs-1
287 A = Qspp + Psid*Qsmp;
291 C = C + Pn{i+1}*Qsmp*Pn{n-i+1};
295 dqlProbs = [dqlProbs; inis*P];
297 % now calculate it at random time instance
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];
306 Ret{end+1} = sum(qlProbs,2)';
309 error ([
'MMAPPH1PRPR: Unknown parameter ' varargin{argIx}])
314 % step 3. calculate the performance measures
315 % ==========================================
317 while argIx<=length(varargin)
318 if any(ismember(eaten, argIx))
321 elseif strcmp(varargin{argIx},
'stMoms')
322 % MOMENTS OF THE SOJOURN TIME
323 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~
324 numOfSTMoms = varargin{argIx+1};
325 rtMoms = zeros(1,numOfSTMoms);
327 rtMoms(i) = factorial(i)*kappa*inv(-Kw)^(i+1)*sum(Bw,2);
331 elseif strcmp(varargin{argIx},
'stDistr')
332 % DISTRIBUTION OF THE SOJOURN TIME
333 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 stCdfPoints = varargin{argIx+1};
337 rtDistr = [rtDistr, kappa*inv(-Kw)*(eye(size(Kw))-expm(Kw*t))*sum(Bw,2)];
339 Ret{end+1} = rtDistr;
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);
355 qlMoms(i) = sum(factorial(i)*p0*R^i*inv(eye(size(R))-R)^(i+1));
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};
363 for i=1:numOfQLProbs-1
364 qlProbs = [qlProbs; p0*R^i];
366 Ret{end+1} = sum(qlProbs,2)
';
370 error (['MMAPPH1PRPR: Unknown parameter
' varargin{argIx}])