1function [wait,waitT,soj,sojT]=Q_DT_MMAPK_SMK_1(D0,D,C,varargin)
2% [wait,waitT,soj,sojT]=Q_DT_MMAPK_SMK_1(D0,D,C) computes the
3% Waiting Time and Sojourn time distribution of a
4% Discrete-Time
MMAP[K]/SM[K]/1/FCFS queue (per type and overall)
7% *
MMAP[K] arrival process (with m_a states)
8% D{i} holds the m_axm_a matrix D_i, together with the mxm matrix D0
9% these characterize the
MMAP[K] arrival process
11% * SM[K] service time distributions (i=1:K) with m_s states
12% C{i} holds the matrix [C_i(1) C_i(2)...C_i(tmax(i))], where the
13% m_sxm_s matrix C_i(j) holds the transition probabilities that the
14% service time of a type-i customer takes j time units (j=1:tmax(i))
17% * Per type queue length distribution,
18% ql{k}(i) = Prob[(i-1) type k customers in the queue]
19% * Overall queue length distribution,
20% qlT(i) = Prob[(i-1) customers in the queue (any type)]
21% * Per type waiting time distribution,
22% wait{k}(i) = Prob[a type k customer has waiting time = (i-1)]
23% * Overall waiting time distribution,
24% waitT(i) = Prob[a customer (of any type) has waiting time = (i-1)]
25% * Per type sojourn time distribution,
26% soj{k}(i) = Prob[a type k customer has sojourn time = (i-1)]
27% * Overall sojourn time distribution,
28% sojT(i) = Prob[a customer (of any type) has sojourn time = (i-1)]
31% Mode: The underlying function to compute the G matrix of the
32% underlying MG1-type Markov chain can be selected using
33% the following parameter values (default:
'CR')
35%
'CR' : Cyclic Reduction [Bini, Meini]
36%
'FI' : Functional Iterations [Neuts]
37%
'IS' : Invariant Subspace [Akar, Sohraby]
38%
'RR' : Ramaswami Reduction [Bini,Meini,Ramaswami]
40% MaxNumComp: Maximum number of components for the vectors containig
41% the performance measure.
43% Verbose: When set to 1, the progress of the computation
is printed
46% Optfname: Optional parameters for the underlying function fname.
47% These parameters are included in a cell with one entry holding
48% the name of the parameter and the next entry the parameter
49% value. In this function, fname can be equal to:
50%
'MG1_CR' : Options for Cyclic Reduction [Bini, Meini]
51%
'MG1_FI' : Options for Functional Iterations [Neuts]
52%
'MG1_IS' : Options for Invariant Subspace [Akar, Sohraby]
53%
'MG1_RR' : Options for ramaswami Reduction [Bini,Meini,Ramaswami]
55% USES: MG1 Solver and MG1_pi of the SMCSolver tool
82for i=1:size(OptionNames,1)
83 options.(deblank(OptionNames(i,:)))=[];
88options.MaxNumComp = 1000;
90options.OptMG1_CR=cell(0);
91options.OptMG1_FI=cell(0);
92options.OptMG1_IS=cell(0);
93options.OptMG1_RR=cell(0);
97Q_DT_MMAPK_ParsePara(D0,'D0',D,'D');
98Q_DT_SMK_ParsePara(C,'C',0);
100% Parse Optional Parameters
101options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
103% Parse Optional Parameters
104Q_CheckUnusedParaMG1(options);
110 tmax(k) = size(C{k},2)/ms;
114% Test the load of the queue
121Csum = reshape(sum(reshape(C{1}, ms*ms, tmax(1)), 2), ms, ms);
127 lambdas(k)=thetaA*D{k}*ones(ma,1);
128 Cws = reshape(reshape(C{k},ms*ms, tmax(k))*[1:tmax(k)]
', ms, ms);
129 means(k)=thetaS*Cws*ones(ms,1);
133 error(
'MATLAB:Q_DT_MMAPK_SMK_1:LoadExceedsOne',...
134 'The load %d of the system exceeds one',load);
137% Construct MG1 blocks
138A0 = kron(D0,eye(ms));
139A = [A0 zeros(mtot,max(tmax)*mtot)];
141 A(:,mtot+1:2*mtot) = A(:,mtot+1:2*mtot) + kron( D{k},C{k}(:,1:ms) );
143 A(:,j*mtot+1:(j+1)*mtot) = A(:,j*mtot+1:(j+1)*mtot) + kron( D{k},C{k}(:,(j-1)*ms+1:j*ms) );
150 G = MG1_CR(A,options.OptMG1_CR{:});
152 G = MG1_FI(A,options.OptMG1_FI{:});
154 G = MG1_RR(A,options.OptMG1_RR{:});
156 G = MG1_IS(A,options.OptMG1_IS{:});
158pi=MG1_pi([],A,G,
'MaxNumComp',options.MaxNumComp,
'Verbose', options.Verbose);
161% compute overall waiting time distribution
162lambdaA = sum(lambdas);
163Dplus_vec = kron(sum(Dplus,2),ones(ms,1));
166 D_vec{i} = kron(sum(D{i},2),ones(ms,1));
168sizeW = size(pi,2)/mtot-1;
170waitT(1) = (pi(1:mtot)+pi(mtot+1:2*mtot))*Dplus_vec/lambdaA;
172 waitT(i) = pi(i*mtot+1:(i+1)*mtot)*Dplus_vec/lambdaA;
174waitT = waitT(1:max(find(waitT>10^(-10))));
176% compute per-type waiting time distribution
179 waitTemp=zeros(1,sizeW);
180 waitTemp(1) = (pi(1:mtot)+pi(mtot+1:2*mtot))*D_vec{k}/lambdas(k);
182 waitTemp(i) = pi(i*mtot+1:(i+1)*mtot)*D_vec{k}/lambdas(k);
185 wait{k} = wait{k}(1:max(find(wait{k}>10^(-10))));
188% compute overall sojourn time distribution
189sizeS = size(pi,2)/mtot + max(tmax);
190sojT = zeros(1,sizeS);
191Ctilde = zeros(mtot,max(tmax)); %Ctilde(n) = (Dplus kron C(n)) ones(mtot,1)
194 Ctemp = reshape(sum(reshape(C{k}
', ms,ms*tmax(k)),1), tmax(k), ms)';
195 Ctemp = kron( sum(D{k},2), Ctemp );
197 Ctilde(:,1:tmax(k)) = Ctilde(:,1:tmax(k)) + Ctilde_k{k};
206 sojTemp = pi(1:mtot)*Ctilde(:,n);
208 sojTemp = sojTemp + pi(max(1,n+1-max(tmax))*mtot+1:(min(n,size(pi,2)/mtot-1)+1)*mtot)...
209 *reshape(Ctilde(:,n+1-[max(1,n+1-max(tmax)):min(n,size(pi,2)/mtot-1)]),[],1);
210 sojT(n) = sojTemp/lambdaA;
213sojT = sojT(1:max(find(sojT>10^(-10))));
215% compute per-type sojourn time distribution
218 sizeS_k = size(pi,2)/mtot + tmax(k);
219 soj{k} = zeros(1,sizeS_k);
223 sojTemp = pi(1:mtot)*Ctilde_k{k}(:,n);
225 sojTemp = sojTemp + pi(max(1,n+1-tmax(k))*mtot+1:(min(n,size(pi,2)/mtot-1)+1)*mtot)...
226 *reshape(Ctilde_k{k}(:,n+1-[max(1,n+1-tmax(k)):min(n,size(pi,2)/mtot-1)]),[],1);
227 soj{k}(n) = sojTemp/lambdas(k);
230 soj{k}=soj{k}(1:max(find(soj{k}>10^(-10))));