LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_CT_MMAPK_PHK_1.m
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)
5%
6% INPUT PARAMETERS:
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
10%
11% * PH[K] services time distributions (i=1:K)
12% alpha{i} holds the 1xmi alpha vector of the PH service time of
13% type i customers
14% S{i} holds the mixmi matrix S of the PH service time of a type
15% i customer
16%
17% RETURN VALUES:
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)
30%
31% USES: Q_Sylvest
32%
33% Optional Parameters:
34%
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
39% (default: 'Sylvest')
40%
41% MaxNumComp: Maximum number of components for the vectors containig
42% the performance measure.
43%
44% Verbose: When set to 1, the progress of the computation is printed
45% (default:0).
46
47
48OptionNames=['Mode ';
49 'MaxNumComp';
50 'Verbose '];
51OptionTypes=['char ';
52 'numeric';
53 'numeric'];
54
55OptionValues{1}=['Direct';
56 'Sylves'];
57
58options=[];
59for i=1:size(OptionNames,1)
60 options.(deblank(OptionNames(i,:)))=[];
61end
62
63% Default settings
64options.Mode='Sylves';
65options.MaxNumComp = 1000;
66options.Verbose = 0;
67
68% Parse Parameters
69K=size(alpha,2);
70Q_CT_MMAPK_ParsePara(D0,'D0',D,'D')
71for i=1:K
72 Q_CT_PH_ParsePara(alpha{i}, ['alpha_' int2str(i)], S{i}, ['S_', int2str(i)] )
73end
74
75% Parse Optional Parameters
76options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
77
78
79% Determine constants
80m=size(D0,1);
81smk=zeros(1,K+1);
82smk(1)=0;
83for i=1:K
84 smk(i+1)=smk(i)+size(alpha{i},2);
85end
86mser=smk(K+1);
87mtot=mser*m;
88
89% Test the load of the queue
90Dsum=D0;
91for i=1:K
92 Dsum=Dsum+D{i};
93end
94invD0=(-D0)^(-1);
95pi=stat(eye(m)-Dsum/max(-diag(Dsum)));
96lambdas=zeros(1,K);
97mus=zeros(1,K);
98lambda=sum(pi*(Dsum-D0));
99for i=1:K
100 lambdas(i)=sum(pi*D{i});
101 temp=S{i}-sum(S{i},2)*alpha{i};
102 if (size(S{i},1)>1)
103 beta{i}=stat(eye(size(S{i},1))-temp/max(-diag(temp)));
104 else
105 beta{i}=1;
106 end
107 mus(i)=-beta{i}*sum(S{i},2);
108end
109load=lambdas*(1./mus)';
110if load >= 1
111 error('MATLAB:Q_CT_MMAPK_PHK_1:LoadExceedsOne',...
112 'The load %d of the system exceeds one',load);
113end
114
115% Construct building blocks
116LM=zeros(mtot,mtot);
117Tser=zeros(mser,mser);
118tser=zeros(mser,1);
119
120for i=1:K
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);
123end
124for i=1:K
125 LM=LM+kron(D{i},tser*[zeros(1,smk(i)) alpha{i} zeros(1,smk(K+1)-smk(i+1))]);
126end
127
128% Compute T iteratively
129Told=zeros(mtot,mtot);
130eyeTser=kron(eye(m),Tser);
131D0eye=kron(D0,eye(mser));
132Tnew=eyeTser;
133if (options.Mode=='Direct')
134 eyeD0eye=kron(eye(mtot),D0eye);
135 while(max(max(abs(Told-Tnew)))>10^(-10))
136 Told=Tnew;
137 L=-reshape(eye(mtot),1,mtot^2)*(kron(Tnew',eye(mtot))+...
138 eyeD0eye)^(-1);
139 Tnew=eyeTser+reshape(L,mtot,mtot)'*LM;
140 end
141 L=reshape(L,mtot,mtot)';
142else
143 [U,Tr]=schur(D0,'complex');
144 %U'*Tr*U = A
145 U=kron(U,eye(mser));
146 Tr=kron(Tr,eye(mser));
147 while(max(max(abs(Told-Tnew)))>10^(-10))
148 Told=Tnew;
149 L=Q_Sylvest(U,Tr,Tnew);
150 Tnew=eyeTser+L*LM;
151 end
152end
153
154
155%Compute Witing Time and Sojourn Time distributions
156
157% Compute S
158theta_tot=zeros(1,mtot);
159for i=1:K
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));
161end
162theta_tot=theta_tot/load;
163nonz=find(theta_tot>0);
164theta_tot_red=theta_tot(nonz);
165Tnewr=Tnew(:,nonz);
166Tnewr=Tnewr(nonz,:);
167Smat=diag(theta_tot_red)^(-1)*Tnewr'*diag(theta_tot_red);
168
169% alpha vector of PH representation of Sojourn time
170for i=1:K
171 temp=zeros(mser,1);
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);
175end
176soj_alpha{K+1}=load*(diag(theta_tot)*kron(ones(m,1),tser))'/lambda;
177soj_alpha{K+1}=soj_alpha{K+1}(nonz);
178
179% alpha vector of PH representation of Waiting time
180for i=1:K
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);
183end
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);
186
187
188% Overall queue length distribution
189[V,NBAR]=hess(Tnew);
190[U,Tr]=schur(D0,'complex');
191%U'*Tr*U = D0
192U=kron(U,eye(mser));
193Tr=kron(Tr,eye(mser));
194
195n=1;
196Cn=Tnew;
197qlT=1-load;
198while (sum(qlT)<1-10^(-10) && n < 1+options.MaxNumComp)
199 F=-V'*Cn*U;
200 tempmat=zeros(mtot,mtot-1);
201 for k=1:mtot
202 if (k==1)
203 temp=F(:,k);
204 else
205 temp=F(:,k)-Ln(:,1:k-1)*Tr(1:k-1,k);
206 end
207 Ln(:,k)=(NBAR+eye(mtot)*Tr(k,k))\temp;
208 end
209 Ln=real(V*Ln*U');
210 Cn=Ln*kron(Dsum-D0,eye(mser));
211 qlT(n+1)=-load*theta_tot*sum(Ln,2);
212 n=n+1;
213end
214if (n == 1+options.MaxNumComp)
215 warning('Maximum Number of Components %d reached',n-1);
216end
217
218
219% Queue length distribution per type
220% Remark:
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))
223[V,NBAR]=hess(Tnew);
224for i=1:K
225 ek=zeros(mser,1);
226 ek(smk(i)+1:smk(i+1),1)=ones(smk(i+1)-smk(i),1);
227 ek=kron(ones(m,1),ek);
228 nek=ones(mtot,1)-ek;
229 [U,Tr]=schur(Dsum-D{i},'complex');
230 %U'*Tr*U = Dsum-D{i}
231 U=kron(U,eye(mser));
232 Tr=kron(Tr,eye(mser));
233
234 ql{i}(1)=1-load;
235 n=1;
236 Cn=Tnew;
237 while (sum(ql{i})<1-10^(-10) && n < 1+options.MaxNumComp)
238 F=-V'*Cn*U;
239 tempmat=zeros(mtot,mtot-1);
240 for k=1:mtot
241 if (k==1)
242 temp=F(:,k);
243 else
244 temp=F(:,k)-Ln(:,1:k-1)*Tr(1:k-1,k);
245 end
246 Ln(:,k)=(NBAR+eye(mtot)*Tr(k,k))\temp;
247 end
248 Ln=real(V*Ln*U');
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;
252 n=n+1;
253 end
254 if (n == 1+options.MaxNumComp)
255 warning('Maximum Number of Components %d reached',n-1);
256 end
257end