1% Ret = FluidQueue(Q, Rin, Rout, ...)
3% Returns various performane measures of a fluid queue.
5% In a fluid queue there
is a background continuous time
6% Markov chain (given by generator Q), and diagonal
7% matrix Rin (Rout) whose ith entry provides the
8% fluid rate at which fluid enters the queue (can be
9% served)
while the background process
is in state i.
13% Q : matrix, shape (N,N)
14% The generator of the background Markov chain
15% Rin : matrix, shape (N,N)
16% Diagonal matrix containing the fluid input rates
17% associated to the states of the background process
18% Rout : matrix, shape (N,N)
19% Diagonal matrix containing the fluid output rates
20% associated to the states of the background process
22% The rest of the function parameters specify the options
23% and the performance measures to be computed.
25% The supported performance measures and options in
this
28% +----------------+--------------------+--------------------------------------+
29% | Parameter name | Input parameters | Output |
30% +================+====================+======================================+
31% |
"flMoms" | Number of moments | The moments of the fluid level |
32% +----------------+--------------------+--------------------------------------+
33% |
"flDistr" | A vector of points | The fluid level distribution at |
34% | | | the requested points (cdf) |
35% +----------------+--------------------+--------------------------------------+
36% |
"flDistrME" | None | The vector-matrix parameters of the |
37% | | | matrix-exponentially distributed |
38% | | | fluid level distribution |
39% +----------------+--------------------+--------------------------------------+
40% |
"flDistrPH" | None | The vector-matrix parameters of the |
41% | | | matrix-exponentially distributed |
42% | | | fluid level distribution, converted |
43% | | | to a PH representation |
44% +----------------+--------------------+--------------------------------------+
45% |
"stMoms" | Number of moments | The sojourn time moments of fluid |
47% +----------------+--------------------+--------------------------------------+
48% |
"stDistr" | A vector of points | The sojourn time distribution at the |
49% | | | requested points (cummulative, cdf) |
50% +----------------+--------------------+--------------------------------------+
51% |
"stDistrME" | None | The vector-matrix parameters of the |
52% | | | matrix-exponentially distributed |
53% | | | sojourn time distribution |
54% +----------------+--------------------+--------------------------------------+
55% |
"stDistrPH" | None | The vector-matrix parameters of the |
56% | | | matrix-exponentially distributed |
57% | | | sojourn time distribution, converted |
58% | | | to a PH representation |
59% +----------------+--------------------+--------------------------------------+
60% |
"prec" | The precision | Numerical precision to check
if the |
61% | | | input
is valid and it
is also used |
62% | | | as a stopping condition when solving |
63% | | | the Riccati equation |
64% +----------------+--------------------+--------------------------------------+
65% |
"Q0" | Matrix, shape(N,N) | The generator of the background |
66% | | | Markov chain when the fluid level
is |
67% | | | zero. If not given, Q0=Q
is assumed |
68% +----------------+--------------------+--------------------------------------+
72% Ret : list of the performance measures
73% Each entry of the list corresponds to a performance
74% measure requested. If there
is just a single item,
75% then it
is not put into a list.
79%
"flDistrME" and
"stDistrME" behave much better numerically than
80%
"flDistrPH" and
"stDistrPH".
82function varargout = FluidQueue(Q, Rin, Rout, varargin)
89 for i=1:length(varargin)
90 if strcmp(varargin{i},
'prec')
92 eaten = [eaten, i, i+1];
93 elseif strcmp(varargin{i},
'Q0')
95 eaten = [eaten, i, i+1];
96 elseif length(varargin{i})>2 && strcmp(varargin{i}(1:2),
'st')
101 global BuToolsCheckInput;
103 if isempty(BuToolsCheckInput)
104 BuToolsCheckInput = true;
107 global BuToolsCheckPrecision;
109 if BuToolsCheckInput && ~CheckGenerator(Q,false)
110 error('FluidQueue: Generator matrix Q
is not Markovian!');
112 if BuToolsCheckInput && ~isempty(Q0) && ~CheckGenerator(Q0,false)
113 error('FluidQueue: Generator matrix Q0
is not Markovian!');
115 if BuToolsCheckInput && (any(diag(Rin)<-BuToolsCheckPrecision) || any(diag(Rout)<-BuToolsCheckPrecision))
116 error('FluidQueue: Fluid rates Rin and Rout must be non-negative !');
119 [mass0, ini, K, clo] = GeneralFluidSolve (Q, Rin-Rout, Q0, prec);
122 iniKi = linsolve(K',-ini')'; % iniki = ini*inv(-K);
123 lambda = sum(mass0*Rin + iniKi*clo*Rin);
128 while argIx<=length(varargin)
129 if any(ismember(eaten, argIx))
132 elseif strcmp(varargin{argIx},
'flDistrPH')
134 Delta = diag(linsolve(K
',-ini')); % Delta = diag (ini*inv(-K));
135 A = inv(Delta)*K
'*Delta;
136 alpha = sum(clo,2)'*Delta;
139 elseif strcmp(varargin{argIx},
'flDistrME')
141 B = SimilarityMatrixForVectors(inv(-K)*sum(clo,2), ones(size(K,1),1));
147 elseif strcmp(varargin{argIx},
'flMoms')
148 numOfMoms = varargin{argIx+1};
150 moms = zeros(1,numOfMoms);
153 moms(m) = factorial(m)*sum(ini*iK^(m+1)*clo);
156 elseif strcmp(varargin{argIx},
'flDistr')
157 points = varargin{argIx+1};
159 values = zeros(size(points));
161 for p=1:length(points)
162 values(p) = sum(mass0) + sum(ini*(eye(size(K,1))-expm(K*points(p)))*iK*clo);
165 elseif strcmp(varargin{argIx},
'stDistrPH')
167 Delta = diag(iniKi/lambda);
168 alpha = reshape(clo*Rin,1,N*length(ini))*kron(eye(N),Delta);
169 A = kron(Rout, inv(Delta)*K
'*Delta) + kron(Q, eye(size(K)));
172 elseif strcmp(varargin{argIx},'stDistrME
')
173 B = SimilarityMatrixForVectors(reshape(inv(-K)*clo*Rin,N*length(ini),1),ones(N*length(ini),1));
175 alpha = kron(ones(1,N), ini/lambda)*Bi;
176 A = B*(kron(sparse(Q'),speye(size(K))) + kron(sparse(Rout),sparse(K)))*Bi;
179 elseif strcmp(varargin{argIx},
'stMoms')
180 numOfMoms = varargin{argIx+1};
182 moms = zeros(1,numOfMoms);
183 Z = kron(sparse(Q
'),speye(size(K))) + kron(sparse(Rout),sparse(K));
185 kini = kron(ones(1,N), ini/lambda);
186 kclo = reshape(inv(-K)*clo*Rin,N*length(ini),1);
188 moms(m) = factorial(m)*sum(kini*iZ^(m+1)*(-Z)*kclo);
191 elseif strcmp(varargin{argIx},'stDistr
')
192 points = varargin{argIx+1};
194 values = zeros(size(points));
195 Z = kron(sparse(Q'),speye(size(K))) + kron(sparse(Rout),sparse(K));
196 kini = kron(ones(1,N), ini/lambda);
197 kclo = reshape(inv(-K)*clo*Rin,N*length(ini),1);
198 for p=1:length(points)
199 values(p) = 1-sum(kini*expm(Z*points(p))*kclo);
203 error ([
'FluidQueue: Unknown parameter ' varargin{argIx}])