LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MMAPPH1FCFS.m
1% Ret = MMAPPH1FCFS(D, sigma, S, ...)
2%
3% Returns various performane measures of a MMAP[K]/PH[K]/1
4% first-come-first-serve 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% sigma : list of row vectors, length (K)
11% The list containing the initial probability vectors of the service
12% time distributions of the various customer types. The length of the
13% vectors does not have to be the same.
14% S : list of square matrices, length (K)
15% The transient generators of the phase type distributions representing
16% the service time of the jobs belonging to various types.
17% further parameters :
18% The rest of the function parameters specify the options
19% and the performance measures to be computed.
20%
21% The supported performance measures and options in this
22% function are:
23%
24% +----------------+--------------------+----------------------------------------+
25% | Parameter name | Input parameters | Output |
26% +================+====================+========================================+
27% | "ncMoms" | Number of moments | The moments of the number of customers |
28% +----------------+--------------------+----------------------------------------+
29% | "ncDistr" | Upper limit K | The distribution of the number of |
30% | | | customers from level 0 to level K-1 |
31% +----------------+--------------------+----------------------------------------+
32% | "stMoms" | Number of moments | The sojourn time moments |
33% +----------------+--------------------+----------------------------------------+
34% | "stDistr" | A vector of points | The sojourn time distribution at the |
35% | | | requested points (cummulative, cdf) |
36% +----------------+--------------------+----------------------------------------+
37% | "stDistrME" | None | The vector-matrix parameters of the |
38% | | | matrix-exponentially distributed |
39% | | | sojourn time distribution |
40% +----------------+--------------------+----------------------------------------+
41% | "stDistrPH" | None | The vector-matrix parameters of the |
42% | | | matrix-exponentially distributed |
43% | | | sojourn time distribution, converted |
44% | | | to a continuous PH representation |
45% +----------------+--------------------+----------------------------------------+
46% | "prec" | The precision | Numerical precision used as a stopping |
47% | | | condition when solving the Riccati |
48% | | | equation |
49% +----------------+--------------------+----------------------------------------+
50% | "classes" | Vector of integers | Only the performance measures |
51% | | | belonging to these classes are |
52% | | | returned. If not given, all classes |
53% | | | are analyzed. |
54% +----------------+--------------------+----------------------------------------+
55%
56% (The quantities related to the number of customers in
57% the system include the customer in the server, and the
58% sojourn time related quantities include the service
59% times as well)
60%
61% Returns
62% -------
63% Ret : list of the performance measures
64% Each entry of the list corresponds to a performance
65% measure requested. Each entry is a matrix, where the
66% columns belong to the various job types.
67% If there is just a single item,
68% then it is not put into a list.
69%
70% References
71% ----------
72% .. [1] Qiming He, "Analysis of a continuous time
73% SM[K]/PH[K]/1/FCFS queue: Age process, sojourn times,
74% and queue lengths", Journal of Systems Science and
75% Complexity, 25(1), pp 133-155, 2012.
76
77function varargout = MMAPPH1FCFS(D, sigma, S, varargin)
78
79 K = length(D)-1;
80
81 % parse options
82 precision = 1e-14;
83 classes = 1:K;
84 eaten = [];
85 for i=1:length(varargin)
86 if strcmp(varargin{i},'prec')
87 precision = varargin{i+1};
88 eaten = [eaten, i, i+1];
89 elseif strcmp(varargin{i},'classes')
90 classes = varargin{i+1};
91 eaten = [eaten, i, i+1];
92 end
93 end
94
95 global BuToolsCheckInput;
96
97 if isempty(BuToolsCheckInput)
98 BuToolsCheckInput = true;
99 end
100
101 if BuToolsCheckInput && ~CheckMMAPRepresentation(D)
102 error('MMAPPH1FCFS: The arrival process is not a valid MMAP representation!');
103 end
104
105 if BuToolsCheckInput
106 for k=1:K
107 if ~CheckPHRepresentation(sigma{k},S{k})
108 error('MMAPPH1FCFS: the vector and matrix describing the service times is not a valid PH representation!');
109 end
110 end
111 end
112
113 % Various properties of the arrival and service processes
114 D0 = D{1};
115 N = size(D0,1);
116 Ia = eye(N);
117 Da = zeros(N);
118 for q=1:K
119 Da = Da + D{q+1};
120 end
121 theta = CTMCSolve(D0+Da);
122 beta = cell(1,K);
123 lambda = zeros(K,1);
124 mu = zeros(K,1);
125 Nsk = zeros(1,K);
126 ro = 0;
127 for k=1:K
128 lambda(k) = sum(theta*D{k+1});
129 beta{k} = CTMCSolve(S{k} - sum(S{k},2)*sigma{k});
130 mu(k) = sum(beta{k}*(-S{k}));
131 Nsk(k) = size(S{k},1);
132 ro = ro + lambda(k)/mu(k);
133 end
134 alpha = theta*Da/sum(lambda);
135
136 D0i = inv(-D0);
137
138 Sa = S{1};
139 sa = cell(1,K);
140 ba = cell(1,K);
141 sa{1} = sigma{1};
142 ba{1} = beta{1};
143 sv{1} = -sum(S{1},2);
144 Pk = cell(1,K);
145 Pk{1} = D0i*D{2};
146 for q=2:K
147 sa{q} = zeros(1,length(sigma{1}));
148 ba{q} = zeros(1,length(beta{1}));
149 sv{q} = zeros(length(sigma{1}),1);
150 Pk{q} = D0i*D{q+1};
151 end
152 for k=2:K
153 Sa = blkdiag (Sa, S{k});
154 for q=1:K
155 if q==k
156 sa{q} = [sa{q} sigma{k}];
157 ba{q} = [ba{q} beta{k}];
158 sv{q} = [sv{q}; -sum(S{k},2)];
159 else
160 sa{q} = [sa{q} zeros(size(sigma{k}))];
161 ba{q} = [ba{q} zeros(size(beta{k}))];
162 sv{q} = [sv{q}; zeros(length(sigma{k}),1)];
163 end
164 end
165 end
166 P = D0i*Da;
167 iVec = kron(D{2},sa{1});
168 for k=2:K
169 iVec = iVec + kron(D{k+1},sa{k});
170 end
171 Ns = size(Sa,1);
172 Is = eye(Ns);
173
174 % step 1. solve the age process of the queue
175 % ==========================================
176
177 % solve Y0 and calculate T
178 Y0 = FluidFundamentalMatrices (kron(Ia,Sa), kron(Ia,-sum(Sa,2)), iVec, D0, 'P', precision);
179 T = kron(Ia,Sa) + Y0 * iVec;
180
181 % calculate pi0 and v0
182 pi0 = zeros(1,size(T,1));
183 for k=1:K
184 pi0 = pi0 + kron(theta*D{k+1},ba{k}/mu(k));
185 end
186 pi0 = - pi0 * T;
187
188 iT = inv(-T);
189 oa = ones(N,1);
190
191 % step 2. calculate performance measures
192 % ======================================
193 Ret = {};
194 for k=classes
195 argIx = 1;
196 clo = iT*kron(oa,sv{k});
197 while argIx<=length(varargin)
198 if any(ismember(eaten, argIx))
199 argIx = argIx + 1;
200 continue;
201 elseif strcmp(varargin{argIx},'stMoms')
202 numOfSTMoms = varargin{argIx+1};
203 rtMoms = zeros(1,numOfSTMoms);
204 for m=1:numOfSTMoms
205 rtMoms(m) = factorial(m) * pi0 * iT^m * clo / (pi0*clo);
206 end
207 Ret{end+1} = rtMoms;
208 argIx = argIx + 1;
209 elseif strcmp(varargin{argIx},'stDistr')
210 stCdfPoints = varargin{argIx+1};
211 cdf = [];
212 for t=stCdfPoints
213 pr = 1 - pi0 * expm(T*t) * clo / (pi0*clo);
214 cdf = [cdf, pr];
215 end
216 Ret{end+1} = cdf;
217 argIx = argIx + 1;
218 elseif strcmp(varargin{argIx},'stDistrME')
219 Bm = SimilarityMatrixForVectors(clo/(pi0*clo),ones(N*Ns,1));
220 Bmi = inv(Bm);
221 A = Bm * T * Bmi;
222 alpha = pi0 * Bmi;
223 Ret{end+1} = alpha;
224 Ret{end+1} = A;
225 elseif strcmp(varargin{argIx},'stDistrPH')
226 vv = pi0*iT;
227 ix = 1:N*Ns;
228 nz = ix(vv>precision);
229 delta = diag(vv(nz));
230 cl = -T*clo/(pi0*clo);
231 alpha = cl(nz,:)'*delta;
232 A = inv(delta)*T(nz,nz)'*delta;
233 Ret{end+1} = alpha;
234 Ret{end+1} = A;
235 elseif strcmp(varargin{argIx},'ncDistr')
236 numOfQLProbs = varargin{argIx+1};
237 argIx = argIx + 1;
238 values = zeros(1,numOfQLProbs);
239 jm = zeros(Ns,1);
240 jm(sum(Nsk(1:k-1))+1:sum(Nsk(1:k)),:) = 1;
241 jmc = ones(Ns,1);
242 jmc(sum(Nsk(1:k-1))+1:sum(Nsk(1:k)),:) = 0;
243 LmCurr = lyap(T, kron(D0+Da-D{k+1},Is), eye(N*Ns));
244 values(1) = 1-ro+pi0*LmCurr*kron(oa,jmc);
245 for i=1:numOfQLProbs-1
246 LmPrev = LmCurr;
247 LmCurr = lyap(T, kron(D0+Da-D{k+1},Is), LmPrev*kron(D{k+1},Is));
248 values(i+1) = pi0*LmCurr*kron(oa,jmc) + pi0*LmPrev*kron(oa,jm);
249 end
250 Ret{end+1} = values;
251 elseif strcmp(varargin{argIx},'ncMoms')
252 numOfQLMoms = varargin{argIx+1};
253 jm = zeros(Ns,1);
254 jm(sum(Nsk(1:k-1))+1:sum(Nsk(1:k)),:) = 1;
255 ELn = {lyap(T, kron(D0+Da,Is), eye(N*Ns))};
256 qlMoms = zeros(1,numOfQLMoms);
257 for n=1:numOfQLMoms
258 bino = 1;
259 Btag = zeros(N*Ns);
260 for i=0:n-1
261 Btag = Btag + bino * ELn{i+1};
262 bino = bino * (n-i) / (i+1);
263 end
264 ELn{n+1} = lyap(T, kron(D0+Da,Is), Btag*kron(D{k+1},Is));
265 qlMoms(n) = sum(pi0*ELn{n+1}) + pi0*Btag*kron(oa,jm);
266 end
267 Ret{end+1} = qlMoms;
268 argIx = argIx + 1;
269 else
270 error (['MMAPPH1FCFS: Unknown parameter ' varargin{argIx}])
271 end
272 argIx = argIx + 1;
273 end
274 end
275 varargout = Ret;
276end