1function [ql,wait,soj]=Q_DT_PH_PH_1(alpha,T,beta,S,varargin)
2%[ql,wt]=Q_DT_PH_PH_1(alpha,T,beta,S) computes the Queuelength,
3% Waiting time and Sojourn time distribution of a
4% Discrete-Time PH/PH/1/FCFS queue
7% * PH inter-arrival time distribution
8% alpha, the 1xma vector of the PH arrival process
9% T, the maxma matrix of the PH arrival process
11% * PH service time distributions
12% beta, the 1xms vector of the PH service time
13% S, the msxms matrix of the PH service time
16% * Queue length distribution,
17% ql(i) = Prob[(i-1) customers in the queue]
18% * Waiting time distribution,
19% wt(i) = Prob[a customer has waiting time = (i-1)]
20% * Sojourn time distribution,
21% soj(i) = Prob[a customer has sojourn time = (i-1)]
24% MaxNumComp: Maximum number of components for the vectors containig
25% the performance measure.
27% Verbose: When set to 1, the computation progress
is printed
41for i=1:size(OptionNames,1)
42 options.(deblank(OptionNames(i,:)))=[];
46options.MaxNumComp = 1000;
50Q_DT_PH_ParsePara(alpha,'alpha',T,'T');
51Q_DT_PH_ParsePara(beta,'beta',S,'S');
53% Parse Optional Parameters
54options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
58t = ones(ma,1)-T*ones(ma,1);
59avga = (alpha*inv(eye(ma)-T)*ones(ma,1));
63s = ones(ms,1)-S*ones(ms,1);
64avgs = beta*inv(eye(ms)-S)*ones(ms,1);
70 error('MATLAB:Q_DT_PH_PH_1:LoadExceedsOne',...
71 'The load %d of the system exceeds one',rho);
74% Compute classic QBD blocks B0, B1, A0, A1 and A2
76A1 = kron(T,S)+kron(t*alpha,s*beta);
78B0 = kron(t*alpha,eye(ms));
79% B1 = kron(T,eye(ms));
81% Compute QBD blocks in approach Latouche & Ramaswami
82A0pp = kron(alpha,eye(ms))*inv(eye(mtot)-kron(T,S))*kron(t,S);
83A0mp = kron(eye(ma),beta)*inv(eye(mtot)-kron(T,S))*kron(t,S);
84A2pm = kron(alpha,eye(ms))*inv(eye(mtot)-kron(T,S))*kron(T,s);
85A2mm = kron(eye(ma),beta)*inv(eye(mtot)-kron(T,S))*kron(T,s);
86A1pp = kron(alpha,eye(ms))*inv(eye(mtot)-kron(T,S))*kron(t,s*beta);
87A1mp = kron(eye(ma),beta)*inv(eye(mtot)-kron(T,S))*kron(t,s*beta);
89A0n = [A0pp zeros(ms,ma); A0mp zeros(ma)];
90A2n = [zeros(ms) A2pm; zeros(ma,ms) A2mm];
91A1n = [A1pp zeros(ms,ma); A1mp zeros(ma)];
95itB0 = inv(eye(ma+ms)-A1n)*A0n;
96itB2 = inv(eye(ma+ms)-A1n)*A2n;
97Gamma = itB2(1:ms,ms+1:end);
99while norm(ones(ms,1)-Gamma*ones(ma,1)) > 1e-10
100 itA1 = itB0*itB2 + itB2*itB0;
101 itB0 = inv(eye(ma+ms)-itA1)*itB0^2;
102 itB2 = inv(eye(ma+ms)-itA1)*itB2^2;
104 Gamma = Gamma + tmp(1:ms,ms+1:end);
107Gm = inv(eye(ma)-A0mp*Gamma)*A2mm + inv(eye(ma)-A0mp*Gamma)*A1mp*Gamma;
109% Compute queue length distribution
110Gstar = inv(eye(mtot)-A1)*(kron(T,s*beta) + kron(t,S)*Gamma*Gm*kron(eye(ma),beta));
111Rstar = A0*inv(eye(mtot)-A1-A0*Gstar);
112Rstar0 = B0*inv(eye(mtot)-A1-A0*Gstar);
115stv = kron((1-rho)*inv(beta*Gamma*inv(eye(ma)-T)*ones(ma,1))*beta*Gamma*inv(eye(ma)-T),beta);
117stv(2,1:mtot) = stv*Rstar0;
121while (sumpi < 1-10^(-10) && numit < 1+options.MaxNumComp)
122 stv(numit+1,1:mtot)=stv(numit,:)*Rstar; %compute pi_(numit+1)
124 sumpi=sumpi+sum(stv(numit,:));
125 if (~mod(numit,options.Verbose))
126 fprintf('Accumulated mass after %d iterations: %d\n',numit,sumpi);
131stv=reshape(stv',1,[]);
132if (numit == 1+options.MaxNumComp)
133 warning('Maximum Number of Components %d reached',numit-1);
137% Compute Waiting & Sojourn time distribution
139 % 1. (number in queue, service phase) after arrival
140 stva=reshape(stv,mtot,size(stv,2)/mtot)';
141 stva=stva(2:end,:)*kron(t,s*beta)+...
142 [stva(1,:)*kron(t,eye(ms)); ...
143 stva(2:end-1,:)*kron(t,S)];
144 stva=stva/sum(sum(stva));
146 stva=reshape(stva',1,len*ms);
147 % 2. some memory preallocation
148 wait=zeros(1,len*2*ceil(1/avgs));
149 soj=zeros(1,len*2*ceil(1/avgs));
151 temp=zeros(ms*len,1);
153 wait(1)=sum(stva(1:ms),2); % waiting time = 0
154 soj(1)=0; % sojourn time = 0
156 while (min(sum(wait),sum(soj))<1-10^(-10))
157 wait(j)=stva(ms+1:i*ms)*temp(1:(i-1)*ms);
158 soj(j)=stva(1:(i-1)*ms)*temp(1:(i-1)*ms);
159 temp=reshape(temp,ms,len);
160 temp(:,1:i)=S*[temp(:,1:i-1) zeros(ms,1)]+s*beta*[zeros(ms,1) temp(:,1:i-1)];
161 temp=reshape(temp,ms*len,1);
165 wait=wait(1:max(find(wait>10^(-10))));
166 soj=soj(1:max(find(soj>10^(-10))));