LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
FluFluQueue.m
1% Ret = FluFluQueue(Qin, Rin, Qout, Rout, srv0stop, ...)
2%
3% Returns various performane measures of a fluid queue
4% with independent fluid arrival and service processes.
5%
6% Two types of boundary behavior is available. If
7% srv0stop=false, the output process evolves continuously
8% even if the queue is empty. If srv0stop=true, the
9% output process slows down if there is fewer fluid in
10% the queue than it can serve. If the queue is empty
11% and the fluid input rate is zero, the output process
12% freezes till fluid arrives.
13%
14% Parameters
15% ----------
16% Qin : matrix, shape (N,N)
17% The generator of the background Markov chain
18% corresponding to the input process
19% Rin : matrix, shape (N,N)
20% Diagonal matrix containing the fluid input rates
21% associated to the states of the input background
22% process
23% Qout : matrix, shape (N,N)
24% The generator of the background Markov chain
25% corresponding to the output process
26% Rout : matrix, shape (N,N)
27% Diagonal matrix containing the fluid output rates
28% associated to the states of the input background
29% process
30% srv0stop : bool
31% If true, the service output process slows down if
32% there is fewer fluid in the queue than it can
33% serve. If false, the output process evolves
34% continuously.
35% further parameters :
36% The rest of the function parameters specify the options
37% and the performance measures to be computed.
38%
39% The supported performance measures and options in this
40% function are:
41%
42% +----------------+--------------------+--------------------------------------+
43% | Parameter name | Input parameters | Output |
44% +================+====================+======================================+
45% | "flMoms" | Number of moments | The moments of the fluid level |
46% +----------------+--------------------+--------------------------------------+
47% | "flDistr" | A vector of points | The fluid level distribution at |
48% | | | the requested points (cdf) |
49% +----------------+--------------------+--------------------------------------+
50% | "flDistrME" | None | The vector-matrix parameters of the |
51% | | | matrix-exponentially distributed |
52% | | | fluid level distribution |
53% +----------------+--------------------+--------------------------------------+
54% | "flDistrPH" | None | The vector-matrix parameters of the |
55% | | | matrix-exponentially distributed |
56% | | | fluid level distribution, converted |
57% | | | to a PH representation |
58% +----------------+--------------------+--------------------------------------+
59% | "stMoms" | Number of moments | The sojourn time moments of fluid |
60% | | | drops |
61% +----------------+--------------------+--------------------------------------+
62% | "stDistr" | A vector of points | The sojourn time distribution at the |
63% | | | requested points (cummulative, cdf) |
64% +----------------+--------------------+--------------------------------------+
65% | "stDistrME" | None | The vector-matrix parameters of the |
66% | | | matrix-exponentially distributed |
67% | | | sojourn time distribution |
68% +----------------+--------------------+--------------------------------------+
69% | "stDistrPH" | None | The vector-matrix parameters of the |
70% | | | matrix-exponentially distributed |
71% | | | sojourn time distribution, converted |
72% | | | to a PH representation |
73% +----------------+--------------------+--------------------------------------+
74% | "prec" | The precision | Numerical precision to check if the |
75% | | | input is valid and it is also used |
76% | | | as a stopping condition when solving |
77% | | | the Riccati equation |
78% +----------------+--------------------+--------------------------------------+
79%
80% Returns
81% -------
82% Ret : list of the performance measures
83% Each entry of the list corresponds to a performance
84% measure requested. If there is just a single item,
85% then it is not put into a list.
86%
87% Notes
88% -----
89% "flDistrME" and "stDistrME" behave much better numerically than
90% "flDistrPH" and "stDistrPH".
91%
92% References
93% ----------
94% .. [1] Horvath G, Telek M, "Sojourn times in fluid queues
95% with independent and dependent input and output
96% processes PERFORMANCE EVALUATION 79: pp. 160-181, 2014.
97
98function varargout = FluFluQueue(Qin, Rin, Qout, Rout, srv0stop, varargin)
99
100 % parse options
101 prec = 1e-14;
102 needST = 0;
103 needQL = 0;
104 eaten = [];
105 for i=1:length(varargin)
106 if strcmp(varargin{i},'prec')
107 prec = varargin{i+1};
108 eaten = [eaten, i, i+1];
109 elseif length(varargin{i})>2 && strcmp(varargin{i}(1:2),'st')
110 needST = 1;
111 elseif length(varargin{i})>2 && strcmp(varargin{i}(1:2),'fl')
112 needQL = 1;
113 end
114 end
115
116 global BuToolsCheckInput;
117
118 if isempty(BuToolsCheckInput)
119 BuToolsCheckInput = true;
120 end
121 global BuToolsCheckPrecision;
122
123 if BuToolsCheckInput && ~CheckGenerator(Qin,false)
124 error('FluFlu: Generator matrix Qin is not Markovian!');
125 end
126 if BuToolsCheckInput && ~CheckGenerator(Qout,false)
127 error('FluFlu: Generator matrix Qout is not Markovian!');
128 end
129 if BuToolsCheckInput && (any(diag(Rin)<-BuToolsCheckPrecision) || any(diag(Rout)<-BuToolsCheckPrecision))
130 error('FluFlu: Fluid rates Rin and Rout must be non-negative !');
131 end
132
133 Iin = eye(size(Qin));
134 Iout = eye(size(Qout));
135
136 if needQL
137 Q = kron(Qin,Iout)+kron(Iin,Qout);
138 if srv0stop
139 Q0 = kron(Qin,Iout)+kron(Rin, pinv(Rout)*Qout);
140 else
141 Q0 = Q;
142 end
143 [mass0, ini, K, clo] = GeneralFluidSolve (Q, kron(Rin,Iout)-kron(Iin,Rout), Q0, prec);
144 end
145 if needST
146 Rh = kron(Rin,Iout) - kron(Iin,Rout);
147 Qh = kron(Qin, Rout) + kron(Rin, Qout);
148 [massh, inih, Kh, cloh] = GeneralFluidSolve (Qh, Rh, [], prec);
149
150 % sojourn time density in case of
151 % srv0stop = false: inih*expm(Kh*x)*cloh*kron(Rin,Iout)/lambda
152 % srv0stop = true: inih*expm(Kh*x)*cloh*kron(Rin,Rout)/lambda/mu
153
154 lambda = sum(CTMCSolve(Qin)*Rin);
155 mu = sum(CTMCSolve(Qout)*Rout);
156 end
157
158 Ret = {};
159 argIx = 1;
160 while argIx<=length(varargin)
161 if any(ismember(eaten, argIx))
162 argIx = argIx + 1;
163 continue;
164 elseif strcmp(varargin{argIx},'flDistrPH')
165 % transform it to PH
166 Delta = diag(linsolve(K',-ini')); % Delta = diag (ini*inv(-K));
167 A = inv(Delta)*K'*Delta;
168 alpha = sum(clo,2)'*Delta;
169 Ret{end+1} = alpha;
170 Ret{end+1} = A;
171 elseif strcmp(varargin{argIx},'flDistrME')
172 % transform it to ME
173 B = SimilarityMatrixForVectors(inv(-K)*sum(clo,2), ones(size(K,1),2));
174 Bi = inv(B);
175 alpha = ini*Bi;
176 A = B*K*Bi;
177 Ret{end+1} = alpha;
178 Ret{end+1} = A;
179 elseif strcmp(varargin{argIx},'flMoms')
180 numOfMoms = varargin{argIx+1};
181 argIx = argIx + 1;
182 moms = zeros(1,numOfMoms);
183 iK = inv(-K);
184 for m=1:numOfMoms
185 moms(m) = factorial(m)*sum(ini*iK^(m+1)*clo);
186 end
187 Ret{end+1} = moms;
188 elseif strcmp(varargin{argIx},'flDistr')
189 points = varargin{argIx+1};
190 argIx = argIx + 1;
191 values = zeros(size(points));
192 iK = inv(-K);
193 for p=1:length(points)
194 values(p) = sum(mass0) + sum(ini*(eye(size(K,1))-expm(K*points(p)))*iK*clo);
195 end
196 Ret{end+1} = values;
197 elseif strcmp(varargin{argIx},'stDistrPH')
198 % convert result to PH representation
199 Delta = diag(linsolve(Kh',-inih')); % Delta = diag (inih*inv(-Kh));
200 A = inv(Delta)*Kh'*Delta;
201 if ~srv0stop
202 alpha = sum(Delta*cloh*kron(Rin,Iout)/lambda,2)';
203 else
204 alpha = sum(Delta*cloh*kron(Rin,Rout)/lambda/mu,2)';
205 end
206 Ret{end+1} = alpha;
207 Ret{end+1} = A;
208 elseif strcmp(varargin{argIx},'stDistrME')
209 % convert result to ME representation
210 if ~srv0stop
211 B = SimilarityMatrixForVectors(sum(cloh*kron(Rin,Iout)/lambda,2), ones(size(Kh,1),1));
212 else
213 B = SimilarityMatrixForVectors(sum(cloh*kron(Rin,Rout)/lambda/mu,2), ones(size(Kh,1),1));
214 end
215 iB = inv(B);
216 A = B*Kh*iB;
217 alpha = inih*inv(-Kh)*iB;
218 Ret{end+1} = alpha;
219 Ret{end+1} = A;
220 elseif strcmp(varargin{argIx},'stMoms')
221 numOfMoms = varargin{argIx+1};
222 argIx = argIx + 1;
223 moms = zeros(1,numOfMoms);
224 if srv0stop
225 kclo = cloh*kron(Rin,Rout)/lambda/mu;
226 else
227 kclo = cloh*kron(Rin,Iout)/lambda;
228 end
229 iKh = inv(-Kh);
230 for m=1:numOfMoms
231 moms(m) = factorial(m)*sum(inih*iKh^(m+1)*kclo);
232 end
233 Ret{end+1} = moms;
234 elseif strcmp(varargin{argIx},'stDistr')
235 points = varargin{argIx+1};
236 argIx = argIx + 1;
237 values = zeros(size(points));
238 if srv0stop
239 kclo = cloh*kron(Rin,Rout)/lambda/mu;
240 else
241 kclo = cloh*kron(Rin,Iout)/lambda;
242 end
243 iKh = inv(-Kh);
244 for p=1:length(points)
245 values(p) = 1-sum(inih*expm(Kh*points(p))*iKh*kclo);
246 end
247 Ret{end+1} = values;
248 else
249 error (['FluFluQueue: Unknown parameter ' varargin{argIx}])
250 end
251 argIx = argIx + 1;
252 end
253 varargout = Ret;
254end
255