LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_CT_MAP_D_C.m
1function [ql,w]=Q_CT_MAP_D_C(D0,D1,s,c,varargin)
2%[ql]=Q_MAP_D_C(D0,D1,s,c) computes the Queuelength distribution
3% of a MAP/D/c/FCFS queue with deterministic services of length s
4%
5% INPUT PARAMETERS:
6% * MAP arrival process (with m states)
7% the mxm matrices D0 and D1 characterize the MAP arrival process
8%
9% * s length of deterministic service
10%
11% * c number of servers
12%
13% RETURN VALUES:
14% * Queue length distribution,
15% ql(i) = Prob[(i-1) customers in the queue]
16% * Waiting time distribution,
17% wt(i) = Prob[a customer has waiting time <= (i-1)*s/NumSteps]
18%
19% USES: NSF_GHT and NSF_pi from the SMCSolver tool
20%
21% OPTIONAL PARAMETERS:
22%
23% MaxNumComp: Maximum number of components for the vectors containig
24% the performance measure.
25%
26% Verbose: When set to 1, the computation progress is printed
27% (default:0).
28%
29% Optfname: Optional parameters for the underlying function fname.
30% These parameters are included in a cell with one entry holding
31% the name of the parameter and the next entry the parameter
32% value. In this function, fname can be equal to:
33% 'NSF_GHT': Options for Non-Skip-Free Markov Chains [Gail,
34% Hantler, Taylor]
35%
36% NumSteps: Number of points in the intervals {[(k-1)*s, k*s), k>0}
37% in which the waiting time distribution is evaluated.
38% (default:1).
39
40
41OptionNames=[
42 'MaxNumComp ';
43 'Verbose ';
44 'OptNSF_GHT ';
45 'NumSteps '];
46OptionTypes=[
47 'numeric';
48 'numeric';
49 'cell ';
50 'numeric'];
51
52OptionValues=cell(0);
53
54options=[];
55for i=1:size(OptionNames,1)
56 options.(deblank(OptionNames(i,:)))=[];
57end
58
59% Default settings
60options.MaxNumComp=1000;
61options.Verbose=0;
62options.OptNSF_GHT=cell(0);
63options.NumSteps=1;
64
65% Parse Parameters
66if (~isnumeric(s))
67 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
68 'the service time s has to be numeric');
69end
70if (~isnumeric(c))
71 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
72 'the number of servers c has to be numeric');
73end
74% check real
75if (~isreal(s))
76 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
77 'the service time s has to be real');
78end
79if (~isreal(c))
80 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
81 'the number of servers c has to be real');
82end
83if (ceil(c)-floor(c)>0)
84 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
85 'the number of servers c has to be an integer');
86end
87%check positivity
88if (s < 10E-14)
89 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
90 'the service time s has to be strictly positive');
91end
92if (c < 10E-14)
93 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
94 'the number of servers c has to be strictly positive');
95end
96%arrival process
97Q_CT_MAP_ParsePara(D0,'D0',D1,'D1')
98
99% Parse Optional Parameters
100options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
101
102% Determine constants
103m = size(D0,2);
104lambda = max(abs(diag(D0)));
105P0 = D0/lambda + eye(m);
106P1 = D1/lambda;
107
108% Test the load of the queue
109thetaA = stat(P0+P1);
110lambdaA = thetaA*sum(D1,2);
111epsilon = 10^-12;
112
113load=lambdaA*s/c;
114if load >= 1-epsilon
115 error('MATLAB:Q_CT_MAP_D_C:LoadExceedsOne',...
116 'The load %d of the system exceeds one',load);
117end
118
119
120% Compute NSF blocks: [P(0,s) P(1,s) ... P(max,s)]
121%Zero arrivals
122P0s = expm(D0*s);
123Ptot = P0s;
124
125
126%Determine number of Poisson terms (Pterms) to compute P(k,a)
127j = 1;
128h(j) = exp(-lambda*s)*lambda*s;
129sumh = h(j) + exp(-lambda*s);
130while sumh < 1 - epsilon
131 h = [h; h(j)*lambda*s/(j+1)];
132 j = j + 1;
133 sumh = sumh + h(j);
134end
135Pterms = j;
136
137Kold = cell(1,Pterms);
138Kold{1} = eye(m);
139for j = 2:Pterms
140 Kold{j} = Kold{j-1}*P0;
141end
142
143k = 1;
144probCum = min(sum(Ptot,2));
145while probCum < 1 - epsilon
146 K{1} = P1*Kold{1};
147 htemp = h(k);
148 Ps{k} = htemp*K{1};
149 for j = 2:Pterms
150 K{j} = P0*K{j-1} + P1*Kold{j};
151 htemp = htemp*lambda*s/(k-1+j);
152 Ps{k} = Ps{k} + htemp*K{j};
153 end
154 Ptot = Ptot + Ps{k};
155
156 for j = 1:Pterms
157 Kold{j} = K{j};
158 end
159 probCum = min(sum(Ptot,2));
160 k = k + 1;
161end
162
163%Compute matrix G
164A = zeros(m,max(c+1,k)*m);
165A(1:m,1:m) = P0s;
166for i = 1:k-1
167 A(1:m,i*m+1:(i+1)*m) = Ps{i};
168end
169
170G = NSF_GHT(A, c, options.OptNSF_GHT{:});
171pi=NSF_pi([],A,G,'MaxNumComp', options.MaxNumComp, 'Verbose', options.Verbose);
172
173% Compute queue length
174ql = zeros(1, size(pi,2)/m);
175for i = 1:size(pi,2)/m
176 ql(i)=sum(pi((i-1)*m+1:i*m));
177end
178
179% Waiting time distribution
180if nargout > 1
181 %Compute Waiting Time distribution W(t) for t = {0,s,2s,...}
182 w(1) = sum(pi(1:m*c));
183 WTacum = w(1);
184 i = 2;
185 while WTacum < 1 - 10^-10 && i*m*c < size(pi,2)
186 w(i) = w(i-1) + sum( pi((i-1)*m*c+1:i*m*c) );
187 WTacum = w(i);
188 i = i+1;
189 end
190
191
192 %Compute Waiting Time distribution W(t) for t = {tau,s+tau,2s+tau,...}
193 %with tau = i*s/NumSteps, for i ={1,2,...,NumSteps-1}
194 options.NumSteps = floor(options.NumSteps)
195 if options.NumSteps > 1
196 for step = 1:options.NumSteps-1
197 %General tau = i*s/NumSteps
198 tau = step*s/options.NumSteps;
199
200 %Compute P(k,tau), k\geq0
201 %Determine number of Poisson terms (Pterms) to compute P(k,tau)
202 clear h_tau K Kold Ptau;
203 j = 1;
204 h_tau(j) = exp(-lambda*tau)*lambda*tau;
205 sumh = h_tau(j) + exp(-lambda*tau);
206
207 while sumh < 1 - epsilon
208 h_tau = [h_tau; h_tau(j)*lambda*tau/(j+1)];
209 j = j + 1;
210 sumh = sumh + h_tau(j);
211 end
212 Pterms = j;
213
214 %Compute terms K
215 Kold = cell(1,Pterms);
216 Kold{1} = eye(m);
217 for j = 2:Pterms
218 Kold{j} = Kold{j-1}*P0;
219 end
220
221 %P(0,tau)
222 P0tau = expm(D0*tau);
223 Ptot = P0tau;
224
225 %P(k,tau), k>0
226 k = 1;
227 probCum = min(sum(Ptot,2));
228 while probCum < 1 - epsilon
229 K{1} = P1*Kold{1};
230 if k > Pterms
231 htemp = poisspdf(k, lambda*tau);
232 else
233 htemp = h_tau(k);
234 end
235 Ptau{k} = htemp*K{1};
236
237 for j = 2:Pterms
238 K{j} = P0*K{j-1} + P1*Kold{j};
239 htemp = htemp*lambda*tau/(k-1+j);
240 Ptau{k} = Ptau{k} + htemp*K{j};
241 j=j+1;
242 end
243
244 Ptot = Ptot + Ptau{k};
245
246 for j = 1:Pterms
247 Kold{j} = K{j};
248 end
249 probCum = min(sum(Ptot,2));
250 k = k + 1;
251 end
252 %Ptot
253 probCum=sum(Ptot,2);
254
255 %Determine blocks of matrix Ptilde, depending in size of pi
256 Kmax = size(Ptau,2);
257 numBlocks = size(pi,2)/m;
258
259 %Compute vectors g (h in Neuts)
260 sumPi = pi(1:m);
261
262 transP0tau = P0tau';
263
264 g = zeros(numBlocks,m);
265 g(1,:) = linsolve(transP0tau,sumPi')';
266
267 i = 2;
268 while sum(g(i-1,:),2) < WTacum && i <=numBlocks
269 sumPi = sumPi + pi((i-1)*m+1:i*m);
270 Kstart = max(0,i-1-Kmax);
271 sumG = g(Kstart+1,:)*Ptau{i-1-Kstart};
272 for k = Kstart+2:i-1
273 sumG = sumG + g(k,:)*Ptau{i-k};
274 end
275 g(i,:) = linsolve(transP0tau, (sumPi - sumG)')';
276 i=i+1;
277 end
278 g(i:numBlocks,:)=ones(numBlocks-i+1,1)*thetaA;
279 %plot(g)
280
281 %Compute Waiting Time distribution at t = {tau,s+tau,2s+tau,...}
282 wt = [zeros(1,size(w,2)-1) 1];
283 wt(1) = sum(g(c,:));
284 for i = 2:size(w,2)-1
285 wt(i) = sum(g(i*c,:));
286 end
287 w = [w;wt];
288 end
289 w = reshape(w,1,[]);
290 end
291end