LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QBDQueue.m
1% Ret = QBDQueue(B, L, F, L0, ...)
2%
3% Returns various performane measures of a continuous time
4% QBD queue.
5%
6% QBD queues have a background continuous time Markov chain
7% with generator Q whose the transitions can be partitioned
8% into three sets: transitions accompanied by an arrival
9% of a new job (F, forward), transitions accompanied by
10% the service of the current job in the server (B,
11% backward) and internal transitions (L, local).
12% Thus we have Q=B+L+F. L0 is the matrix of local
13% transition rates if the queue is empty.
14%
15% Parameters
16% ----------
17% B : matrix, shape(N,N)
18% Transitions of the background process accompanied by
19% the service of the current job in the server
20% L : matrix, shape(N,N)
21% Internal transitions of the background process
22% that do not generate neither arrival nor service
23% F : matrix, shape(N,N)
24% Transitions of the background process accompanied by
25% an arrival of a new job
26% L0 : matrix, shape(N,N)
27% Internal transitions of the background process when
28% there are no jobs in the queue
29% further parameters :
30% The rest of the function parameters specify the options
31% and the performance measures to be computed.
32%
33% The supported performance measures and options in this
34% function are:
35%
36% +----------------+--------------------+----------------------------------------+
37% | Parameter name | Input parameters | Output |
38% +================+====================+========================================+
39% | "ncMoms" | Number of moments | The moments of the number of customers |
40% +----------------+--------------------+----------------------------------------+
41% | "ncDistr" | Upper limit K | The distribution of the number of |
42% | | | customers from level 0 to level K-1 |
43% +----------------+--------------------+----------------------------------------+
44% | "ncDistrMG" | None | The vector-matrix parameters of the |
45% | | | matrix-geometric distribution of the |
46% | | | number of customers in the system |
47% +----------------+--------------------+----------------------------------------+
48% | "ncDistrDPH" | None | The vector-matrix parameters of the |
49% | | | matrix-geometric distribution of the |
50% | | | number of customers in the system, |
51% | | | converted to a discrete PH |
52% | | | representation |
53% +----------------+--------------------+----------------------------------------+
54% | "stMoms" | Number of moments | The sojourn time moments |
55% +----------------+--------------------+----------------------------------------+
56% | "stDistr" | A vector of points | The sojourn time distribution at the |
57% | | | requested points (cummulative, cdf) |
58% +----------------+--------------------+----------------------------------------+
59% | "stDistrME" | None | The vector-matrix parameters of the |
60% | | | matrix-exponentially distributed |
61% | | | sojourn time distribution |
62% +----------------+--------------------+----------------------------------------+
63% | "stDistrPH" | None | The vector-matrix parameters of the |
64% | | | matrix-exponentially distributed |
65% | | | sojourn time distribution, converted |
66% | | | to a continuous PH representation |
67% +----------------+--------------------+----------------------------------------+
68% | "prec" | The precision | Numerical precision used as a stopping |
69% | | | condition when solving the |
70% | | | matrix-quadratic equation |
71% +----------------+--------------------+----------------------------------------+
72%
73% (The quantities related to the number of customers in
74% the system include the customer in the server, and the
75% sojourn time related quantities include the service
76% times as well)
77%
78% Returns
79% -------
80% Ret : list of the performance measures
81% Each entry of the list corresponds to a performance
82% measure requested. If there is just a single item,
83% then it is not put into a list.
84%
85% Notes
86% -----
87% "ncDistrMG" and "stDistrMG" behave much better numerically than
88% "ncDistrDPH" and "stDistrPH".
89
90function varargout = QBDQueue(B, L, F, L0, varargin)
91
92 % parse options
93 prec = 1e-14;
94 needST = 0;
95 eaten = [];
96 for i=1:length(varargin)
97 if strcmp(varargin{i},'prec')
98 prec = varargin{i+1};
99 eaten = [eaten, i, i+1];
100 elseif length(varargin{i})>2 && strcmp(varargin{i}(1:2),'st')
101 needST = 1;
102 end
103 end
104
105 global BuToolsCheckInput;
106
107 if isempty(BuToolsCheckInput)
108 BuToolsCheckInput = true;
109 end
110
111 if BuToolsCheckInput && ~CheckGenerator(B+L+F)
112 error('QBDQueue: The matrix sum (B+L+F) is not a valid generator of a Markov chain!');
113 end
114
115 if BuToolsCheckInput && ~CheckGenerator(L0+F)
116 error('QBDQueue: The matrix sum (L0+F) is not a valid generator of a Markov chain!');
117 end
118
119 [pi0, R] = QBDSolve (B, L, F, L0, prec);
120 N = length(pi0);
121 I = eye(N);
122
123 if needST
124 U = L + R*B;
125 Rh = inv(-U)*F;
126 eta = pi0*F*inv(I-Rh);
127 eta = eta/sum(eta);
128 z = reshape(I,N*N,1);
129 end
130
131 Ret = {};
132 argIx = 1;
133 while argIx<=length(varargin)
134 if any(ismember(eaten, argIx))
135 argIx = argIx + 1;
136 continue;
137 elseif strcmp(varargin{argIx},'ncDistrDPH')
138 % transform it to DPH
139 alpha = pi0*R*inv(eye(N)-R);
140 A = inv(diag(alpha))*R'*diag(alpha);
141 Ret{end+1} = alpha;
142 Ret{end+1} = A;
143 elseif strcmp(varargin{argIx},'ncDistrMG')
144 % transform it to MG
145 B = SimilarityMatrixForVectors(sum(inv(I-R)*R,2), ones(N,1));
146 Bi = inv(B);
147 A = B*R*Bi;
148 alpha = pi0*Bi;
149 Ret{end+1} = alpha;
150 Ret{end+1} = A;
151 elseif strcmp(varargin{argIx},'ncMoms')
152 numOfMoms = varargin{argIx+1};
153 argIx = argIx + 1;
154 moms = zeros(1,numOfMoms);
155 iR = inv(I-R);
156 for m=1:numOfMoms
157 moms(m) = factorial(m)*sum(pi0*iR^(m+1)*R^m);
158 end
159 Ret{end+1} = MomsFromFactorialMoms(moms);
160 elseif strcmp(varargin{argIx},'ncDistr')
161 numOfQLProbs = varargin{argIx+1};
162 argIx = argIx + 1;
163 values = zeros(1,numOfQLProbs);
164 values(1) = sum(pi0);
165 RPow = I;
166 for p=1:numOfQLProbs-1
167 RPow = RPow * R;
168 values(p+1) = sum(pi0*RPow);
169 end
170 Ret{end+1} = values;
171 elseif strcmp(varargin{argIx},'stDistrPH')
172 % transform to ph distribution
173 ix = (1:N);
174 nz = ix(eta>prec);
175 Delta = diag(eta);
176 A = kron(L+F,I(nz,nz)) + kron(B,inv(Delta(nz,nz))*Rh(nz,nz)'*Delta(nz,nz));
177 alpha = z'*kron(I,Delta(:,nz));
178 Ret{end+1} = alpha;
179 Ret{end+1} = A;
180 elseif strcmp(varargin{argIx},'stDistrME')
181 % transform it such that the closing vector is a vector of ones
182 % this is the way butools accepts ME distributions
183 Bm = SimilarityMatrixForVectors(z,ones(length(z),1));
184 Bmi = inv(Bm);
185 A = Bm * (kron(L'+F',I) + kron(B',Rh)) * Bmi;
186 alpha = kron(ones(1,N), eta) * Bmi;
187 Ret{end+1} = alpha;
188 Ret{end+1} = A;
189 elseif strcmp(varargin{argIx},'stMoms')
190 numOfMoms = varargin{argIx+1};
191 argIx = argIx + 1;
192 moms = zeros(1,numOfMoms);
193 Z = kron(L'+F',I)+kron(B',Rh);
194 iZ = inv(-Z);
195 for m=1:numOfMoms
196 moms(m) = factorial(m)*sum(kron(ones(1,N), eta)*iZ^(m+1)*(-Z)*z);
197 end
198 Ret{end+1} = moms;
199 elseif strcmp(varargin{argIx},'stDistr')
200 points = varargin{argIx+1};
201 argIx = argIx + 1;
202 values = zeros(size(points));
203 Z = kron(L'+F',I)+kron(B',Rh);
204 for p=1:length(points)
205 values(p) = 1-sum(kron(ones(1,N), eta)*expm(Z*points(p))*z);
206 end
207 Ret{end+1} = values;
208 else
209 error (['QBDQueue: Unknown parameter ' varargin{argIx}])
210 end
211 argIx = argIx + 1;
212 end
213 varargout = Ret;
214end
215