LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_DT_PH_PH_1.m
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
5%
6% INPUT PARAMETERS:
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
10%
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
14%
15% RETURN VALUES:
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)]
22%
23% OPTIONAL PARAMETERS:
24% MaxNumComp: Maximum number of components for the vectors containig
25% the performance measure.
26%
27% Verbose: When set to 1, the computation progress is printed
28% (default:0).
29
30
31OptionNames=[
32 'MaxNumComp ';
33 'Verbose '];
34OptionTypes=[
35 'numeric';
36 'numeric'];
37
38OptionValues=cell(0);
39
40options=[];
41for i=1:size(OptionNames,1)
42 options.(deblank(OptionNames(i,:)))=[];
43end
44
45% Default settings
46options.MaxNumComp = 1000;
47options.Verbose = 0;
48
49% Parse Parameters
50Q_DT_PH_ParsePara(alpha,'alpha',T,'T');
51Q_DT_PH_ParsePara(beta,'beta',S,'S');
52
53% Parse Optional Parameters
54options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
55
56% arrivals
57ma = size(alpha,2);
58t = ones(ma,1)-T*ones(ma,1);
59avga = (alpha*inv(eye(ma)-T)*ones(ma,1));
60
61% service
62ms = size(beta,2);
63s = ones(ms,1)-S*ones(ms,1);
64avgs = beta*inv(eye(ms)-S)*ones(ms,1);
65
66mtot = ma*ms;
67rho = avgs/avga;
68
69if rho >= 1
70 error('MATLAB:Q_DT_PH_PH_1:LoadExceedsOne',...
71 'The load %d of the system exceeds one',rho);
72end
73
74% Compute classic QBD blocks B0, B1, A0, A1 and A2
75A0 = kron(t*alpha,S);
76A1 = kron(T,S)+kron(t*alpha,s*beta);
77% A2 = kron(T,s*beta);
78B0 = kron(t*alpha,eye(ms));
79% B1 = kron(T,eye(ms));
80
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);
88
89A0n = [A0pp zeros(ms,ma); A0mp zeros(ma)];
90A2n = [zeros(ms) A2pm; zeros(ma,ms) A2mm];
91A1n = [A1pp zeros(ms,ma); A1mp zeros(ma)];
92
93
94% Compute Gamma
95itB0 = inv(eye(ma+ms)-A1n)*A0n;
96itB2 = inv(eye(ma+ms)-A1n)*A2n;
97Gamma = itB2(1:ms,ms+1:end);
98itT = itB0;
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;
103 tmp = itT*itB2;
104 Gamma = Gamma + tmp(1:ms,ms+1:end);
105 itT = itT*itB0;
106end
107Gm = inv(eye(ma)-A0mp*Gamma)*A2mm + inv(eye(ma)-A0mp*Gamma)*A1mp*Gamma;
108
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);
113
114% Compute pi_0
115stv = kron((1-rho)*inv(beta*Gamma*inv(eye(ma)-T)*ones(ma,1))*beta*Gamma*inv(eye(ma)-T),beta);
116% Compute pi_1
117stv(2,1:mtot) = stv*Rstar0;
118% Compute pi_2,...
119sumpi=sum(sum(stv));
120numit=2;
121while (sumpi < 1-10^(-10) && numit < 1+options.MaxNumComp)
122 stv(numit+1,1:mtot)=stv(numit,:)*Rstar; %compute pi_(numit+1)
123 numit=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);
127 drawnow;
128 end
129end
130ql = sum(stv,2)';
131stv=reshape(stv',1,[]);
132if (numit == 1+options.MaxNumComp)
133 warning('Maximum Number of Components %d reached',numit-1);
134end
135
136
137% Compute Waiting & Sojourn time distribution
138if(nargout > 1)
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));
145 len=size(stva,1);
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));
150
151 temp=zeros(ms*len,1);
152 temp(1:ms)=s;
153 wait(1)=sum(stva(1:ms),2); % waiting time = 0
154 soj(1)=0; % sojourn time = 0
155 i=2;j=2;
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);
162 i=min(i+1,len);
163 j=j+1;
164 end
165 wait=wait(1:max(find(wait>10^(-10))));
166 soj=soj(1:max(find(soj>10^(-10))));
167end