LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_CT_PH_PH_1.m
1function [ql,wait_alpha,wait_T]=Q_CT_PH_PH_1(alpha,T,beta,S,varargin)
2%[ql,wtalpha,wtT]=Q_CT_PH_PH_1(alpha,T,beta,S) computes the Queuelength
3% and Waiting time distribution of a Continuous-Time PH/PH/1/FCFS queue
4%
5% INPUT PARAMETERS:
6% * PH inter-arrival time distribution
7% alpha: the 1xma vector of the PH arrival process
8% T: the maxma matrix of the PH arrival process
9%
10% * PH service time distributions
11% beta: the 1xms vector of the PH service time
12% S: the msxms matrix of the PH service time
13%
14% RETURN VALUES:
15% * Queue length distribution,
16% ql(i) = Prob[(i-1) customers in the queue]
17% * Waiting time distribution,
18% is PH characterized by (wait_alpha, wait_T)
19%
20% OPTIONAL PARAMETERS:
21% MaxNumComp: Maximum number of components for the vectors containig
22% the performance measure.
23%
24% Verbose: When set to 1, the computation progress is printed
25% (default:0).
26
27
28OptionNames=[
29 'MaxNumComp ';
30 'Verbose '];
31
32OptionTypes=[
33 'numeric';
34 'numeric'];
35
36OptionValues=cell(0);
37
38options=[];
39for i=1:size(OptionNames,1)
40 options.(deblank(OptionNames(i,:)))=[];
41end
42
43% Default settings
44options.MaxNumComp = 1000;
45options.Verbose = 0;
46
47% Parse Parameters
48Q_CT_PH_ParsePara(alpha,'alpha',T,'T');
49Q_CT_PH_ParsePara(beta,'beta',S,'S');
50
51% Parse Optional Parameters
52options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
53
54
55% arrivals
56ma = size(alpha,2);
57t = -T*ones(ma,1);
58avgt = (alpha*inv(-T)*ones(ma,1));
59
60% service
61ms = size(beta,2);
62s = -S*ones(ms,1);
63avgs = beta*inv(-S)*ones(ms,1);
64
65mtot = ms*ma;
66rho = avgs/avgt;
67if rho >= 1
68 error('MATLAB:Q_CT_PH_PH_1:LoadExceedsOne',...
69 'The load %d of the system exceeds one',rho);
70end
71
72% Compute classic QBD blocks A0, A1 and A2
73A0 = kron(t*alpha,eye(ms));
74A1 = kron(T,eye(ms))+kron(eye(ma),S);
75% A2 = kron(eye(ma),s*beta);
76% B = kron(T,eye(ms));
77
78% Compute QBD blocks in approach Latouche & Ramaswami
79invmA1 = inv(-A1);
80A0pp = kron(alpha,eye(ms))*invmA1*kron(t,eye(ms));
81A0mp = kron(eye(ma),beta)*invmA1*kron(t,eye(ms));
82A2pm = kron(alpha,eye(ms))*invmA1*kron(eye(ma),s);
83A2mm = kron(eye(ma),beta)*invmA1*kron(eye(ma),s);
84
85A0n = [A0pp zeros(ms,ma); A0mp zeros(ma)];
86A2n = [zeros(ms) A2pm;zeros(ma,ms) A2mm];
87
88% Compute matrix Gamma: NE corner of matrix G
89itB0 = A0n;
90itB2 = A2n;
91Gamma = itB2(1:ms,ms+1:end);
92itT = itB0;
93check=1;
94numit = 1;
95while check > 10e-14
96 itA1 = itB0*itB2 + itB2*itB0;
97 itB0 = inv(eye(ma+ms)-itA1)*itB0^2;
98 itB2 = inv(eye(ma+ms)-itA1)*itB2^2;
99 tmp = itT*itB2;
100 Gamma = Gamma + tmp(1:ms,ms+1:end);
101 itT = itT*itB0;
102 check = norm(ones(ms,1)-Gamma*ones(ma,1));
103 numit=numit+1;
104 if (options.Verbose==1)
105 fprintf('Check after %d iterations: %d\n',numit,check);
106 drawnow;
107 end
108end
109
110Gm = inv(eye(ma)-A0mp*Gamma)*A2mm;
111R_Gam = A0pp*inv(eye(ms)-Gamma*A0mp);
112
113
114% Compute queue length distribution
115Gstar = invmA1*kron(eye(ma),s*beta) + invmA1*kron(t,eye(ms))*Gamma*Gm*kron(eye(ma),beta);
116Rstar = A0*inv(-A1-A0*Gstar);
117
118% Compute pi_0
119pi = kron((1-rho)*inv(beta*Gamma*inv(-T)*ones(ma,1))*beta*Gamma*inv(-T),beta);
120% Compute pi_1,...
121sumpi=sum(pi);
122numit=1;
123while (sumpi < 1-10^(-10) && numit < 1+options.MaxNumComp)
124 pi(numit+1,1:mtot)=pi(numit,:)*Rstar; %compute pi_(numit+1)
125 numit=numit+1;
126 sumpi=sumpi+sum(pi(numit,:));
127 if (~mod(numit,options.Verbose))
128 fprintf('Accumulated mass after %d iterations: %d\n',numit,sumpi);
129 drawnow;
130 end
131end
132ql = sum(pi,2)';
133pi=reshape(pi',1,[]);
134if (numit == 1+options.MaxNumComp)
135 warning('Maximum Number of Components %d reached',numit-1);
136end
137
138
139% Compute waiting time PH representation
140if nargout > 1
141 sigtilde = inv(beta*inv(S)*ones(ms,1))*beta*inv(S);
142 Delta = diag(sigtilde);
143 wait_T = inv(Delta)*(S+R_Gam*s*beta)'*Delta;
144 sigrho = rho*sigtilde;
145 theta = (-beta*inv(S)*ones(ms,1))*s'*Delta;
146 D = inv(Delta)*R_Gam'*Delta;
147 wait_alpha = (1-inv(beta*inv(eye(ms)-R_Gam)*ones(ms,1))*beta*ones(ms,1))*inv(theta*D*ones(ms,1))*theta*D;
148end