1function [ql,qlT,soj_alpha,wait_alpha,Smat]=Q_CT_MMAPK_PHK_1(D0,D,alpha,S,varargin)
2%[ql,qlT,soj_alpha,wait_alpha,Smat]=Q_CT_MMAPK_PHK_1(D0,D,alpha,S)
3% computes the Sojourn time and Waiting time distribution of
4% a continuous-time
MMAP[K]/PH[K]/1/FCFS queue (per type and overall)
7% *
MMAP[K] arrival process (with m states)
8% D{i} holds the mxm matrix D_i, together with the mxm matrix D0
9% these characterize the
MMAP[K] arrival process
11% * PH[K] services time distributions (i=1:K)
12% alpha{i} holds the 1xmi alpha vector of the PH service time of
14% S{i} holds the mixmi matrix S of the PH service time of a type
18% * Per type queue length distribution,
19% ql{k}(i) = Prob[(i-1) type k customers in the queue]
20% * Overall queue length distribution,
21% qlT(i) = Prob[(i-1) customers in the queue (any type)]
22% * Overall sojourn time distribution,
23%
is PH characterized by (soj_alpha{K+1},Smat)
24% * Type k sojourn time distribution,
25%
is PH characterized by (soj_alpha{k},Smat)
26% * Overall waiting time distribution,
27%
is PH characterized by (wait_alpha{K+1},Smat)
28% * Type k waiting time distribution,
29%
is PH characterized by (wait_alpha{k},Smat)
35% Mode:
'Sylves' solves a Sylvester matrix equation at each step
36% using an Hessenberg algorithm
37%
'Direct' solves the Sylvester matrix equation at each
38% step by rewriting it as a (large) system of linear equations
41% MaxNumComp: Maximum number of components for the vectors containig
42% the performance measure.
44% Verbose: When set to 1, the progress of the computation
is printed
55OptionValues{1}=[
'Direct';
59for i=1:size(OptionNames,1)
60 options.(deblank(OptionNames(i,:)))=[];
65options.MaxNumComp = 1000;
70Q_CT_MMAPK_ParsePara(D0,'D0',D,'D')
72 Q_CT_PH_ParsePara(alpha{i}, [
'alpha_' int2str(i)], S{i}, [
'S_', int2str(i)] )
75% Parse Optional Parameters
76options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
84 smk(i+1)=smk(i)+size(alpha{i},2);
89% Test the load of the queue
95pi=stat(eye(m)-Dsum/max(-diag(Dsum)));
98lambda=sum(pi*(Dsum-D0));
100 lambdas(i)=sum(pi*D{i});
101 temp=S{i}-sum(S{i},2)*alpha{i};
103 beta{i}=stat(eye(size(S{i},1))-temp/max(-diag(temp)));
107 mus(i)=-beta{i}*sum(S{i},2);
109load=lambdas*(1./mus)
';
111 error('MATLAB:Q_CT_MMAPK_PHK_1:LoadExceedsOne
',...
112 'The load %d of the system exceeds one
',load);
115% Construct building blocks
117Tser=zeros(mser,mser);
121 Tser(smk(i)+1:smk(i+1),smk(i)+1:smk(i+1))=S{i};
122 tser(smk(i)+1:smk(i+1),1)=-sum(S{i},2);
125 LM=LM+kron(D{i},tser*[zeros(1,smk(i)) alpha{i} zeros(1,smk(K+1)-smk(i+1))]);
128% Compute T iteratively
129Told=zeros(mtot,mtot);
130eyeTser=kron(eye(m),Tser);
131D0eye=kron(D0,eye(mser));
133if (options.Mode=='Direct
')
134 eyeD0eye=kron(eye(mtot),D0eye);
135 while(max(max(abs(Told-Tnew)))>10^(-10))
137 L=-reshape(eye(mtot),1,mtot^2)*(kron(Tnew',eye(mtot))+...
139 Tnew=eyeTser+reshape(L,mtot,mtot)
'*LM;
141 L=reshape(L,mtot,mtot)';
143 [U,Tr]=schur(D0,
'complex');
146 Tr=kron(Tr,eye(mser));
147 while(max(max(abs(Told-Tnew)))>10^(-10))
149 L=Q_Sylvest(U,Tr,Tnew);
155%Compute Witing Time and Sojourn Time distributions
158theta_tot=zeros(1,mtot);
160 theta_tot=theta_tot+kron(pi*D{i},[zeros(1,smk(i)) beta{i} zeros(1,smk(K+1)-smk(i+1))]/mus(i));
162theta_tot=theta_tot/load;
163nonz=find(theta_tot>0);
164theta_tot_red=theta_tot(nonz);
167Smat=diag(theta_tot_red)^(-1)*Tnewr'*diag(theta_tot_red);
169% alpha vector of PH representation of Sojourn time
172 temp(smk(i)+1:smk(i+1))=tser(smk(i)+1:smk(i+1));
173 soj_alpha{i}=load*(diag(theta_tot)*kron(ones(m,1),temp))
'/lambdas(i);
174 soj_alpha{i}=soj_alpha{i}(nonz);
176soj_alpha{K+1}=load*(diag(theta_tot)*kron(ones(m,1),tser))'/lambda;
177soj_alpha{K+1}=soj_alpha{K+1}(nonz);
179% alpha vector of PH representation of Waiting time
181 wait_alpha{i}=load*(diag(theta_tot)*L*kron(sum(D{i},2),tser))
'/lambdas(i);
182 wait_alpha{i}=wait_alpha{i}(nonz);
184wait_alpha{K+1}=load*(diag(theta_tot)*L*kron(sum(Dsum-D0,2),tser))'/lambda;
185wait_alpha{K+1}=wait_alpha{K+1}(nonz);
188% Overall queue length distribution
190[U,Tr]=schur(D0,
'complex');
193Tr=kron(Tr,eye(mser));
198while (sum(qlT)<1-10^(-10) && n < 1+options.MaxNumComp)
200 tempmat=zeros(mtot,mtot-1);
205 temp=F(:,k)-Ln(:,1:k-1)*Tr(1:k-1,k);
207 Ln(:,k)=(NBAR+eye(mtot)*Tr(k,k))\temp;
210 Cn=Ln*kron(Dsum-D0,eye(mser));
211 qlT(n+1)=-load*theta_tot*sum(Ln,2);
214if (n == 1+options.MaxNumComp)
215 warning('Maximum Number of Components %d reached
',n-1);
219% Queue length distribution per type
221% L(0) solution to TL(0)+L(0)(Dsum-Dk)=-I
222% L(n) to TL(n)+L(n)(Dsum-Dk)=-L(n-1)*kron(Dk,eye(mser))
226 ek(smk(i)+1:smk(i+1),1)=ones(smk(i+1)-smk(i),1);
227 ek=kron(ones(m,1),ek);
229 [U,Tr]=schur(Dsum-D{i},'complex
');
232 Tr=kron(Tr,eye(mser));
237 while (sum(ql{i})<1-10^(-10) && n < 1+options.MaxNumComp)
239 tempmat=zeros(mtot,mtot-1);
244 temp=F(:,k)-Ln(:,1:k-1)*Tr(1:k-1,k);
246 Ln(:,k)=(NBAR+eye(mtot)*Tr(k,k))\temp;
249 Cn=Ln*kron(D{i},eye(mser));
250 ql{i}(n)=ql{i}(n)-load*theta_tot*Ln*nek;
251 ql{i}(n+1)=-load*theta_tot*Ln*ek;
254 if (n == 1+options.MaxNumComp)
255 warning(
'Maximum Number of Components %d reached',n-1);