LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_CT_MAP_M_C.m
1function [ql,wait_alpha,Smat]=Q_CT_MAP_M_C(D0,D1,mu,c,varargin)
2% [ql,wait_alpha,Smat]=Q_CT_MAP_M_C(D0,D1,mu,c) computes the Queuelength
3% and waiting time distribution of a MAP/M/c/FCFS queue
4%
5% INPUT PARAMETERS:
6% * MAP(D0,D1) arrival process (with m states)
7%
8% * mu exponential service rate
9%
10% * c number of servers
11%
12% RETURN VALUES:
13% * Queue length distribution,
14% ql(i) = Prob[(i-1) customers in the queue]
15%
16% * Waiting time distribution,
17% is PH characterized by (wait_alpha,Smat)
18%
19% USES: USES: QBD Solver from SMCSolver and Q_Sylvest
20%
21% OPTIONAL PARAMETERS:
22%
23% Mode: The underlying methods used to compute the performance
24% measures. For this function two different modes can be
25% specified. The parameter value may include a specific option
26% for one of them, or a combination of one name for each option,
27% i.e., both 'Sylves', 'FI' and 'SylvesFI' are possible values
28% for this parameter.
29%
30% 1. The method to solve the linear system at each iteration of
31% the algorithm to compute matrix T (default: 'Sylves')
32% 'Sylves' : solves a Sylvester matrix equation at each step
33% using a Hessenberg algorithm
34% 'Direct' : solves the Sylvester matrix equation at each
35% step by rewriting it as a (large) system of
36% linear equations.
37%
38% 2. The underlying function to compute the R matrix of the
39% underlying QBD can be selected using the following
40% parameter values (default: 'CR')
41% 'CR' : Cyclic Reduction [Bini, Meini]
42% 'FI' : Functional Iterations [Neuts]
43% 'IS' : Invariant Subspace [Akar, Sohraby]
44% 'LR' : Logaritmic Reduction [Latouche, Ramaswami]
45% 'NI' : Newton Iteration
46%
47% MaxNumComp: Maximum number of components for the vectors containig
48% the performance measure.
49%
50% Verbose: When set to 1, the progress of the computation is printed
51% (default:0).
52%
53% Optfname: Optional parameters for the underlying function fname.
54% These parameters are included in a cell with one entry holding
55% the name of the parameter and the next entry the parameter
56% value. In this function, fname can be equal to:
57% 'QBD_CR' : Options for Cyclic Reduction [Bini, Meini]
58% 'QBD_FI' : Options for Functional Iterations [Neuts]
59% 'QBD_IS' : Options for Invariant Subspace [Akar, Sohraby]
60% 'QBD_LR' : Options for Logaritmic Reduction [Latouche, Ramaswami]
61% 'QBD_NI' : Options for Newton Iteration
62
63
64OptionNames=[
65 'Mode ';
66 'MaxNumComp ';
67 'Verbose ';
68 'OptQBD_CR ';
69 'OptQBD_FI ';
70 'OptQBD_IS ';
71 'OptQBD_LR ';
72 'OptQBD_NI '];
73
74OptionTypes=[
75 'char ';
76 'numeric';
77 'numeric';
78 'cell ';
79 'cell ';
80 'cell ';
81 'cell ';
82 'cell '];
83
84
85OptionValues{1}=['Direct ';
86 'Sylves ';
87 'CR ';
88 'FI ';
89 'IS ';
90 'LR ';
91 'NI ';
92 'DirectCR';
93 'DirectFI';
94 'DirectIS';
95 'DirectLR';
96 'DirectNI';
97 'SylvesCR';
98 'SylvesFI';
99 'SylvesIS';
100 'SylvesLR';
101 'SylvesNI'];
102
103options=[];
104for i=1:size(OptionNames,1)
105 options.(deblank(OptionNames(i,:)))=[];
106end
107
108% Default settings
109options.Mode='SylvesCR';
110options.MaxNumComp = 1000;
111options.Verbose = 0;
112options.OptQBD_CR=cell(0);
113options.OptQBD_FI=cell(0);
114options.OptQBD_IS=cell(0);
115options.OptQBD_LR=cell(0);
116options.OptQBD_NI=cell(0);
117
118% Parse Parameters
119if (~isnumeric(mu))
120 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
121 'the service rate mu has to be numeric');
122end
123if (~isnumeric(c))
124 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
125 'the number of servers c has to be numeric');
126end
127% check real
128if (~isreal(mu))
129 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
130 'the service rate mu has to be real');
131end
132if (~isreal(c))
133 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
134 'the number of servers c has to be real');
135end
136if (ceil(c)-floor(c)>0)
137 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
138 'the number of servers c has to be an integer');
139end
140%check positivity
141if (mu < 10E-14)
142 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
143 'the service rate mu has to be strictly positive');
144end
145if (c < 10E-14)
146 error('MATLAB:Q_CT_MAP_M_C_ParsePara:InvalidInput',...
147 'the number of servers c has to be strictly positive');
148end
149%arrival process
150Q_CT_MAP_ParsePara(D0,'D0',D1,'D1')
151
152
153% Parse Optional Parameters
154options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
155% Check for unused parameter
156Q_CheckUnusedParaQBD(options);
157
158
159% Test the load of the queue
160invD0=(-D0)^(-1);
161pi_a=stat(D1*invD0);
162lambda=sum(pi_a*D1);
163
164load=lambda/(mu*c);
165if load >= 1
166 error('MATLAB:Q_CT_MAP_M_C:LoadExceedsOne',...
167 'The load %d of the system exceeds one',load);
168end
169
170% Determine constants
171m = size(D0,2);
172A0 = c*mu*eye(m);
173A1 = D0 - c*mu*eye(m);
174A2 = D1;
175
176%Compute Matrix R
177if (strfind(options.Mode,'FI')>0)
178 [G,R]=QBD_FI(A0,A1,A2,options.OptQBD_FI{:});
179elseif (strfind(options.Mode,'LR')>0)
180 [G,R]=QBD_LR(A0,A1,A2,options.OptQBD_LR{:});
181elseif (strfind(options.Mode,'IS')>0)
182 [G,R]=QBD_IS(A0,A1,A2,options.OptQBD_IS{:});
183elseif (strfind(options.Mode,'NI')>0)
184 [G,R]=QBD_NI(A0,A1,A2,options.OptQBD_NI{:});
185else
186 [G,R]=QBD_CR(A0,A1,A2,options.OptQBD_CR{:});
187end
188
189%Gaver-Jacobs-Latouche LD-QBD
190piGJL = zeros(1,c*m);
191if c > 1
192 invC = cell(1,c-1);
193 invC{1} = inv(-D0);
194 for i =2:c-1
195 invC{i} = inv(-D0+(i-1)*mu*eye(m) - (i-1)*mu*invC{i-1}*D1);
196 end
197
198 piGJL((c-1)*m+1:c*m) = stat(D0-(c-1)*mu*eye(m) + R*A0 + (c-1)*mu*invC{c-1}*D1 + eye(m));
199 for i =c-1:-1:1
200 piGJL((i-1)*m+1:i*m) = piGJL(i*m+1:(i+1)*m)*i*mu*invC{i};
201 end
202else
203 piGJL(1:m) = stat(D0 + R*A0 + eye(m));
204end
205K = sum(piGJL(1:(c-1)*m)) + piGJL((c-1)*m+1:c*m)*sum(inv(eye(m)-R),2);
206piGJL = piGJL/K;
207
208piC1 = piGJL((c-1)*m+1:c*m);
209sumpi = sum(piGJL);
210
211
212numit=1;
213while (sumpi < 1-10^(-10) && numit < 1+options.MaxNumComp-c)
214 piC1(numit+1,1:m)=piC1(numit,:)*R;
215 numit=numit+1;
216 sumpi=sumpi+sum(piC1(numit,:));
217 if (~mod(numit,options.Verbose))
218 fprintf('Accumulated mass after %d iterations: %d\n',numit,sumpi);
219 drawnow;
220 end
221end
222qlC = sum(piC1,2);
223piC1=reshape(piC1',1,[]);
224piT = [piGJL(1:(c-1)*m) piC1];
225
226% Queue length distribution
227ql = zeros(1,c-1);
228for i = 1:c-1
229 ql(i) = sum(piGJL((i-1)*m+1:i*m));
230end
231ql = [ql qlC'];
232
233
234% Waiting time distribution
235if nargout > 1
236 % a) Probability waiting = 0 and alpha vector
237 prob_zero=sum(reshape(piGJL(1:c*m),m,c)'*sum(D1,2));
238 prob_zero=prob_zero/sum(reshape(piT,m,size(piT,2)/m)'*sum(D1,2));
239 temp=piGJL((c-1)*m+1:c*m)*(eye(m)-R)^(-1)*D1;
240 alpha_vec=temp/sum(temp);
241
242 % b) Ph representation
243 % Compute Sojourn and Waiting time
244 Told=zeros(m,m);
245 Tnew=-A0; % A0=eye(m)*mu*c
246 if (strfind(options.Mode,'Direct')>0)
247 while(max(max(abs(Told-Tnew)))>10^(-10))
248 Told=Tnew;
249 L=-reshape(eye(m),1,m^2)*(kron(Tnew',eye(m))+...
250 kron(eye(m),D0))^(-1);
251 Tnew=-A0+reshape(L,m,m)'*D1*mu*c;
252 end
253 L=reshape(L,m,m)';
254 else
255 [U,Tr]=schur(D0,'complex');
256 %U'*Tr*U = A
257 while(max(max(abs(Told-Tnew)))>10^(-10))
258 Told=Tnew;
259 L=Q_Sylvest(U,Tr,Tnew);
260 Tnew=-A0+L*D1*mu*c;
261 end
262 end
263
264 % Compute Smat
265 theta_tot=alpha_vec;
266 nonz=find(theta_tot>0);
267 theta_tot_red=theta_tot(nonz);
268 Tnew=Tnew(:,nonz);
269 Tnew=Tnew(nonz,:);
270 Smat=diag(theta_tot_red)^(-1)*Tnew'*diag(theta_tot_red);
271
272
273 % alpha vector of PH representation of Waiting time
274 rho_vec=sum(Tnew+A0,2);
275 wait_alpha=alpha_vec.*rho_vec'/(alpha_vec*rho_vec);
276 wait_alpha=(1-prob_zero)*wait_alpha(nonz);
277end