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
6% * MAP arrival process (with m states)
7% the mxm matrices D0 and D1 characterize the MAP arrival process
9% * s length of deterministic service
11% * c number of servers
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]
19% USES: NSF_GHT and NSF_pi from the SMCSolver tool
23% MaxNumComp: Maximum number of components for the vectors containig
24% the performance measure.
26% Verbose: When set to 1, the computation progress
is printed
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,
36% NumSteps: Number of points in the intervals {[(k-1)*s, k*s), k>0}
37% in which the waiting time distribution
is evaluated.
55for i=1:size(OptionNames,1)
56 options.(deblank(OptionNames(i,:)))=[];
60options.MaxNumComp=1000;
62options.OptNSF_GHT=cell(0);
67 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
68 'the service time s has to be numeric');
71 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
72 'the number of servers c has to be numeric');
76 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
77 'the service time s has to be real');
80 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
81 'the number of servers c has to be real');
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');
89 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
90 'the service time s has to be strictly positive');
93 error('MATLAB:Q_CT_MAP_D_C_ParsePara:InvalidInput',...
94 'the number of servers c has to be strictly positive');
97Q_CT_MAP_ParsePara(D0,'D0',D1,'D1')
99% Parse Optional Parameters
100options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
104lambda = max(abs(diag(D0)));
105P0 = D0/lambda + eye(m);
108% Test the load of the queue
110lambdaA = thetaA*sum(D1,2);
115 error('MATLAB:Q_CT_MAP_D_C:LoadExceedsOne',...
116 'The load %d of the system exceeds one',load);
120% Compute NSF blocks: [
P(0,s)
P(1,s) ...
P(max,s)]
126%Determine number of Poisson terms (Pterms) to compute
P(k,a)
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)];
137Kold = cell(1,Pterms);
140 Kold{j} = Kold{j-1}*P0;
144probCum = min(sum(Ptot,2));
145while probCum < 1 - epsilon
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};
159 probCum = min(sum(Ptot,2));
164A = zeros(m,max(c+1,k)*m);
167 A(1:m,i*m+1:(i+1)*m) = Ps{i};
170G = NSF_GHT(A, c, options.OptNSF_GHT{:});
171pi=NSF_pi([],A,G,
'MaxNumComp', options.MaxNumComp,
'Verbose', options.Verbose);
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));
179% Waiting time distribution
181 %Compute Waiting Time distribution W(t)
for t = {0,s,2s,...}
182 w(1) = sum(pi(1:m*c));
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) );
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;
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;
204 h_tau(j) = exp(-lambda*tau)*lambda*tau;
205 sumh = h_tau(j) + exp(-lambda*tau);
207 while sumh < 1 - epsilon
208 h_tau = [h_tau; h_tau(j)*lambda*tau/(j+1)];
210 sumh = sumh + h_tau(j);
215 Kold = cell(1,Pterms);
218 Kold{j} = Kold{j-1}*P0;
222 P0tau = expm(D0*tau);
227 probCum = min(sum(Ptot,2));
228 while probCum < 1 - epsilon
231 htemp = poisspdf(k, lambda*tau);
235 Ptau{k} = htemp*K{1};
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};
244 Ptot = Ptot + Ptau{k};
249 probCum = min(sum(Ptot,2));
255 %Determine blocks of matrix Ptilde, depending in size of pi
257 numBlocks = size(pi,2)/m;
259 %Compute vectors g (h in Neuts)
264 g = zeros(numBlocks,m);
265 g(1,:) = linsolve(transP0tau,sumPi')
';
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};
273 sumG = sumG + g(k,:)*Ptau{i-k};
275 g(i,:) = linsolve(transP0tau, (sumPi - sumG)')
';
278 g(i:numBlocks,:)=ones(numBlocks-i+1,1)*thetaA;
281 %Compute Waiting Time distribution at t = {tau,s+tau,2s+tau,...}
282 wt = [zeros(1,size(w,2)-1) 1];
284 for i = 2:size(w,2)-1
285 wt(i) = sum(g(i*c,:));