LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Q_DT_MAP_MAP_1.m
1function [ql,wait,soj]=Q_DT_MAP_MAP_1(C0,C1,D0,D1,varargin)
2% [ql,wait,soj] = Q_DT_MAP_MAP_1(C0,C1,D0,D1) computes the Queue length,
3% Sojourn time and Waiting time distribution of a discrete-time
4% MAP/MAP/1/FCFS queue
5%
6% INPUT PARAMETERS:
7% * MAP arrival process (with m_a states)
8% the m_axm_a matrices C0 and C1 characterize MAP arrival process
9%
10% * MAP service process (with m_s states)
11% the m_sxm_s matrices D0 and D1 characterize MAP service process
12%
13% RETURN VALUES:
14% * Queue length distribution,
15% ql(i) = Prob[(i-1) customers in the queue]
16% * Waiting time distribution,
17% wait(i) = Prob[a customer has waiting time = (i-1)]
18% * Sojourn time distribution,
19% soj(i) = Prob[a customer has sojourn time = (i-1)]
20%
21% OPTIONAL PARAMETERS:
22% Mode: The underlying function to compute the R matrix of the
23% underlying QBD can be selected using the following
24% parameter values (default: 'CR')
25% 'CR' : Cyclic Reduction [Bini, Meini]
26% 'FI' : Functional Iterations [Neuts]
27% 'IS' : Invariant Subspace [Akar, Sohraby]
28% 'LR' : Logaritmic Reduction [Latouche, Ramaswami]
29% 'NI' : Newton Iteration
30%
31% MaxNumComp: Maximum number of components for the vectors containig
32% the performance measure.
33%
34% Verbose: When set to 1, the computation progress is printed
35% (default:0).
36%
37% Optfname: Optional parameters for the underlying function fname.
38% These parameters are included in a cell with one entry holding
39% the name of the parameter and the next entry the parameter
40% value. In this function, fname can be equal to:
41% 'QBD_CR' : Options for Cyclic Reduction [Bini, Meini]
42% 'QBD_FI' : Options for Functional Iterations [Neuts]
43% 'QBD_IS' : Options for Invariant Subspace [Akar, Sohraby]
44% 'QBD_LR' : Options for Logaritmic Reduction [Latouche, Ramaswami]
45% 'QBD_NI' : Options for Newton Iteration
46%
47% USES: QBD Solver and QBD_pi of the SMCSolver tool
48
49OptionNames=[
50 'Mode ';
51 'MaxNumComp ';
52 'Verbose ';
53 'OptQBD_CR ';
54 'OptQBD_FI ';
55 'OptQBD_IS ';
56 'OptQBD_LR ';
57 'OptQBD_NI '];
58
59OptionTypes=[
60 'char ';
61 'numeric';
62 'numeric';
63 'cell ';
64 'cell ';
65 'cell ';
66 'cell ';
67 'cell '];
68
69OptionValues{1}=['CR';
70 'FI';
71 'IS';
72 'LR';
73 'NI'];
74
75options=[];
76for i=1:size(OptionNames,1)
77 options.(deblank(OptionNames(i,:)))=[];
78end
79
80% Default settings
81options.Mode='CR';
82options.MaxNumComp = 1000;
83options.Verbose = 0;
84options.OptQBD_CR=cell(0);
85options.OptQBD_FI=cell(0);
86options.OptQBD_IS=cell(0);
87options.OptQBD_LR=cell(0);
88options.OptQBD_NI=cell(0);
89
90% Parse Parameters
91Q_DT_MAP_ParsePara(C0,'C0',C1,'C1');
92Q_DT_MAP_ParsePara(D0,'D0',D1,'D1');
93
94% Parse Optional Parameters
95options=Q_ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
96
97% Parse Optional Parameters
98Q_CheckUnusedParaQBD(options);
99
100
101% arrivals
102ma = size(C0,1);
103C = C0+C1;
104avga = stat(C)*C1*ones(ma,1);
105
106% service
107ms = size(D0,1);
108D = D0+D1;
109piD = stat(D);
110avgs = piD*D1*ones(ms,1);
111
112mtot = ms*ma;
113rho = avga/avgs;
114if rho >= 1
115 error('MATLAB:Q_DT_MAP_MAP_1:LoadExceedsOne',...
116 'The load %d of the system exceeds one',rho);
117end
118
119% Compute classic QBD blocks A0, A1 and A2
120Am1 = kron(C0,D1);
121A0 = kron(C0,D0)+kron(C1,D1);
122A1 = kron(C1,D0);
123Bm1 = kron(C0,D1);
124B0 = kron(C0,eye(ms));
125B1 = kron(C1,eye(ms));
126
127if (strfind(options.Mode,'FI')>0)
128 [G,R]=QBD_FI(Am1,A0,A1,options.OptQBD_FI{:});
129elseif (strfind(options.Mode,'LR')>0)
130 [G,R]=QBD_LR(Am1,A0,A1,options.OptQBD_LR{:});
131elseif (strfind(options.Mode,'IS')>0)
132 [G,R]=QBD_IS(Am1,A0,A1,options.OptQBD_IS{:});
133elseif (strfind(options.Mode,'NI')>0)
134 [G,R]=QBD_NI(Am1,A0,A1,options.OptQBD_NI{:});
135else
136 [G,R]=QBD_CR(Am1,A0,A1,options.OptQBD_CR{:});
137end
138
139stv = QBD_pi(Bm1,B0,R,'Boundary',[B1; A0+R*Am1],'MaxNumComp',options.MaxNumComp,'Verbose',options.Verbose);
140
141% Compute queue length distribution
142ql = zeros(1,size(stv,2)/mtot);
143for i=1:size(ql,2)
144 ql(i) = sum(stv((i-1)*mtot+1:i*mtot));
145end
146
147% Compute Waiting & Sojourn time distribution
148if(nargout > 1)
149 % 1. (number in queue, service phase) after arrival
150 stva=reshape(stv,mtot,size(stv,2)/mtot)';
151 stva=stva(2:end,:)*kron(sum(C1,2),D1)+...
152 [stva(1,:)*kron(sum(C1,2),eye(ms)); ...
153 stva(2:end-1,:)*kron(sum(C1,2),D0)];
154 stva=stva/sum(sum(stva));
155 len=size(stva,1);
156 stva=reshape(stva',1,len*ms);
157 % 2. some memory preallocation
158 wait=zeros(1,len*2*ceil(1/avgs));
159 soj=zeros(1,len*2*ceil(1/avgs));
160
161 temp=zeros(ms*len,1);
162 temp(1:ms)=sum(D1,2);
163 wait(1)=sum(stva(1:ms),2); % waiting time = 0
164 soj(1)=0; % sojourn time = 0
165 i=2;j=2;
166 while (min(sum(wait),sum(soj))<1-10^(-10))
167 wait(j)=stva(ms+1:i*ms)*temp(1:(i-1)*ms);
168 soj(j)=stva(1:(i-1)*ms)*temp(1:(i-1)*ms);
169 temp=reshape(temp,ms,len);
170 temp(:,1:i)=D0*[temp(:,1:i-1) zeros(ms,1)]+D1*[zeros(ms,1) temp(:,1:i-1)];
171 temp=reshape(temp,ms*len,1);
172 i=min(i+1,len);
173 j=j+1;
174 end
175 wait=wait(1:max(find(wait>10^(-10))));
176 soj=soj(1:max(find(soj>10^(-10))));
177end