LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_DT_MMAPK_SMK_1.m
1function [wait,waitT,soj,sojT]=Q_DT_MMAPK_SMK_1(D0,D,C,varargin)
2% [wait,waitT,soj,sojT]=Q_DT_MMAPK_SMK_1(D0,D,C) computes the
3% Waiting Time and Sojourn time distribution of a
4% Discrete-Time MMAP[K]/SM[K]/1/FCFS queue (per type and overall)
5%
6% INPUT PARAMETERS:
7% * MMAP[K] arrival process (with m_a states)
8% D{i} holds the m_axm_a matrix D_i, together with the mxm matrix D0
9% these characterize the MMAP[K] arrival process
10%
11% * SM[K] service time distributions (i=1:K) with m_s states
12% C{i} holds the matrix [C_i(1) C_i(2)...C_i(tmax(i))], where the
13% m_sxm_s matrix C_i(j) holds the transition probabilities that the
14% service time of a type-i customer takes j time units (j=1:tmax(i))
15%
16% RETURN VALUES:
17% * Per type queue length distribution,
18% ql{k}(i) = Prob[(i-1) type k customers in the queue]
19% * Overall queue length distribution,
20% qlT(i) = Prob[(i-1) customers in the queue (any type)]
21% * Per type waiting time distribution,
22% wait{k}(i) = Prob[a type k customer has waiting time = (i-1)]
23% * Overall waiting time distribution,
24% waitT(i) = Prob[a customer (of any type) has waiting time = (i-1)]
25% * Per type sojourn time distribution,
26% soj{k}(i) = Prob[a type k customer has sojourn time = (i-1)]
27% * Overall sojourn time distribution,
28% sojT(i) = Prob[a customer (of any type) has sojourn time = (i-1)]
29%
30% OPTIONAL PARAMETERS:
31% Mode: The underlying function to compute the G matrix of the
32% underlying MG1-type Markov chain can be selected using
33% the following parameter values (default: 'CR')
34%
35% 'CR' : Cyclic Reduction [Bini, Meini]
36% 'FI' : Functional Iterations [Neuts]
37% 'IS' : Invariant Subspace [Akar, Sohraby]
38% 'RR' : Ramaswami Reduction [Bini,Meini,Ramaswami]
39%
40% MaxNumComp: Maximum number of components for the vectors containig
41% the performance measure.
42%
43% Verbose: When set to 1, the progress of the computation is printed
44% (default:0).
45%
46% Optfname: Optional parameters for the underlying function fname.
47% These parameters are included in a cell with one entry holding
48% the name of the parameter and the next entry the parameter
49% value. In this function, fname can be equal to:
50% 'MG1_CR' : Options for Cyclic Reduction [Bini, Meini]
51% 'MG1_FI' : Options for Functional Iterations [Neuts]
52% 'MG1_IS' : Options for Invariant Subspace [Akar, Sohraby]
53% 'MG1_RR' : Options for ramaswami Reduction [Bini,Meini,Ramaswami]
54%
55% USES: MG1 Solver and MG1_pi of the SMCSolver tool
56
57
58OptionNames=[
59 'Mode ';
60 'MaxNumComp ';
61 'Verbose ';
62 'OptMG1_CR ';
63 'OptMG1_FI ';
64 'OptMG1_IS ';
65 'OptMG1_RR '];
66
67OptionTypes=[
68 'char ';
69 'numeric';
70 'numeric';
71 'cell ';
72 'cell ';
73 'cell ';
74 'cell '];
75
76OptionValues{1}=['CR';
77 'FI';
78 'IS';
79 'RR'];
80
81options=[];
82for i=1:size(OptionNames,1)
83 options.(deblank(OptionNames(i,:)))=[];
84end
85
86% Default settings
87options.Mode='CR';
88options.MaxNumComp = 1000;
89options.Verbose = 0;
90options.OptMG1_CR=cell(0);
91options.OptMG1_FI=cell(0);
92options.OptMG1_IS=cell(0);
93options.OptMG1_RR=cell(0);
94
95% Parse Parameters
96K=size(D,2);
97Q_DT_MMAPK_ParsePara(D0,'D0',D,'D');
98Q_DT_SMK_ParsePara(C,'C',0);
99
100% Parse Optional Parameters
101options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
102
103% Parse Optional Parameters
104Q_CheckUnusedParaMG1(options);
105
106% Determine constants
107ma=size(D0,1);
108ms=size(C{1},1);
109for k = 1:K
110 tmax(k) = size(C{k},2)/ms;
111end
112mtot=ma*ms;
113
114% Test the load of the queue
115Dplus = D{1};
116for i=2:K
117 Dplus=Dplus+D{i};
118end
119Dsum=D0+Dplus;
120thetaA=stat(Dsum);
121Csum = reshape(sum(reshape(C{1}, ms*ms, tmax(1)), 2), ms, ms);
122thetaS=stat(Csum);
123
124lambdas=zeros(1,K);
125means=zeros(1,K);
126for k=1:K
127 lambdas(k)=thetaA*D{k}*ones(ma,1);
128 Cws = reshape(reshape(C{k},ms*ms, tmax(k))*[1:tmax(k)]', ms, ms);
129 means(k)=thetaS*Cws*ones(ms,1);
130end
131load=lambdas*means';
132if load >= 1
133 error('MATLAB:Q_DT_MMAPK_SMK_1:LoadExceedsOne',...
134 'The load %d of the system exceeds one',load);
135end
136
137% Construct MG1 blocks
138A0 = kron(D0,eye(ms));
139A = [A0 zeros(mtot,max(tmax)*mtot)];
140for k = 1:K
141 A(:,mtot+1:2*mtot) = A(:,mtot+1:2*mtot) + kron( D{k},C{k}(:,1:ms) );
142 for j = 2:tmax(k)
143 A(:,j*mtot+1:(j+1)*mtot) = A(:,j*mtot+1:(j+1)*mtot) + kron( D{k},C{k}(:,(j-1)*ms+1:j*ms) );
144 end
145end
146
147%SMC Solver
148switch options.Mode
149 case 'CR'
150 G = MG1_CR(A,options.OptMG1_CR{:});
151 case 'FI'
152 G = MG1_FI(A,options.OptMG1_FI{:});
153 case 'RR'
154 G = MG1_RR(A,options.OptMG1_RR{:});
155 case 'IS'
156 G = MG1_IS(A,options.OptMG1_IS{:});
157end
158pi=MG1_pi([],A,G,'MaxNumComp',options.MaxNumComp,'Verbose', options.Verbose);
159
160
161% compute overall waiting time distribution
162lambdaA = sum(lambdas);
163Dplus_vec = kron(sum(Dplus,2),ones(ms,1));
164D_vec = cell(1,K);
165for i=1:K
166 D_vec{i} = kron(sum(D{i},2),ones(ms,1));
167end
168sizeW = size(pi,2)/mtot-1;
169waitT=zeros(1,sizeW);
170waitT(1) = (pi(1:mtot)+pi(mtot+1:2*mtot))*Dplus_vec/lambdaA;
171for i = 2:sizeW
172 waitT(i) = pi(i*mtot+1:(i+1)*mtot)*Dplus_vec/lambdaA;
173end
174waitT = waitT(1:max(find(waitT>10^(-10))));
175
176% compute per-type waiting time distribution
177wait = cell(1,K);
178for k = 1:K
179 waitTemp=zeros(1,sizeW);
180 waitTemp(1) = (pi(1:mtot)+pi(mtot+1:2*mtot))*D_vec{k}/lambdas(k);
181 for i = 2:sizeW
182 waitTemp(i) = pi(i*mtot+1:(i+1)*mtot)*D_vec{k}/lambdas(k);
183 end
184 wait{k} = waitTemp;
185 wait{k} = wait{k}(1:max(find(wait{k}>10^(-10))));
186end
187
188% compute overall sojourn time distribution
189sizeS = size(pi,2)/mtot + max(tmax);
190sojT = zeros(1,sizeS);
191Ctilde = zeros(mtot,max(tmax)); %Ctilde(n) = (Dplus kron C(n)) ones(mtot,1)
192Ctilde_k=cell(1,K);
193for k = 1:K
194 Ctemp = reshape(sum(reshape(C{k}', ms,ms*tmax(k)),1), tmax(k), ms)';
195 Ctemp = kron( sum(D{k},2), Ctemp );
196 Ctilde_k{k} = Ctemp;
197 Ctilde(:,1:tmax(k)) = Ctilde(:,1:tmax(k)) + Ctilde_k{k};
198end
199
200
201
202
203for n = 1:sizeS
204 sojTemp = 0;
205 if n <= max(tmax)
206 sojTemp = pi(1:mtot)*Ctilde(:,n);
207 end
208 sojTemp = sojTemp + pi(max(1,n+1-max(tmax))*mtot+1:(min(n,size(pi,2)/mtot-1)+1)*mtot)...
209 *reshape(Ctilde(:,n+1-[max(1,n+1-max(tmax)):min(n,size(pi,2)/mtot-1)]),[],1);
210 sojT(n) = sojTemp/lambdaA;
211end
212sojT = [0 sojT];
213sojT = sojT(1:max(find(sojT>10^(-10))));
214
215% compute per-type sojourn time distribution
216soj = cell(1,K);
217for k = 1:K
218 sizeS_k = size(pi,2)/mtot + tmax(k);
219 soj{k} = zeros(1,sizeS_k);
220 for n = 1:sizeS
221 sojTemp = 0;
222 if n <= tmax(k)
223 sojTemp = pi(1:mtot)*Ctilde_k{k}(:,n);
224 end
225 sojTemp = sojTemp + pi(max(1,n+1-tmax(k))*mtot+1:(min(n,size(pi,2)/mtot-1)+1)*mtot)...
226 *reshape(Ctilde_k{k}(:,n+1-[max(1,n+1-tmax(k)):min(n,size(pi,2)/mtot-1)]),[],1);
227 soj{k}(n) = sojTemp/lambdas(k);
228 end
229 soj{k} = [0 soj{k}];
230 soj{k}=soj{k}(1:max(find(soj{k}>10^(-10))));
231end