LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MAPMAP1.m
1% Ret = MAPMAP1(D0, D1, S0, S1, ...)
2%
3% Returns various performane measures of a continuous time
4% MAP/MAP/1 queue.
5%
6% In a MAP/MAP/1 queue both the arrival and the service
7% processes are characterized by Markovian arrival
8% processes.
9%
10% Parameters
11% ----------
12% D0 : matrix, shape(N,N)
13% The transitions of the arrival MAP not accompanied by
14% job arrivals
15% D1 : matrix, shape(N,N)
16% The transitions of the arrival MAP accompanied by
17% job arrivals
18% S0 : matrix, shape(N,N)
19% The transitions of the service MAP not accompanied by
20% job service
21% S1 : matrix, shape(N,N)
22% The transitions of the service MAP accompanied by
23% job service
24% further parameters :
25% The rest of the function parameters specify the options
26% and the performance measures to be computed.
27%
28% The supported performance measures and options in this
29% function are:
30%
31% +----------------+--------------------+----------------------------------------+
32% | Parameter name | Input parameters | Output |
33% +================+====================+========================================+
34% | "ncMoms" | Number of moments | The moments of the number of customers |
35% +----------------+--------------------+----------------------------------------+
36% | "ncDistr" | Upper limit K | The distribution of the number of |
37% | | | customers from level 0 to level K-1 |
38% +----------------+--------------------+----------------------------------------+
39% | "ncDistrMG" | None | The vector-matrix parameters of the |
40% | | | matrix-geometric distribution of the |
41% | | | number of customers in the system |
42% +----------------+--------------------+----------------------------------------+
43% | "ncDistrDPH" | None | The vector-matrix parameters of the |
44% | | | matrix-geometric distribution of the |
45% | | | number of customers in the system, |
46% | | | converted to a discrete PH |
47% | | | representation |
48% +----------------+--------------------+----------------------------------------+
49% | "stMoms" | Number of moments | The sojourn time moments |
50% +----------------+--------------------+----------------------------------------+
51% | "stDistr" | A vector of points | The sojourn time distribution at the |
52% | | | requested points (cummulative, cdf) |
53% +----------------+--------------------+----------------------------------------+
54% | "stDistrME" | None | The vector-matrix parameters of the |
55% | | | matrix-exponentially distributed |
56% | | | sojourn time distribution |
57% +----------------+--------------------+----------------------------------------+
58% | "stDistrPH" | None | The vector-matrix parameters of the |
59% | | | matrix-exponentially distributed |
60% | | | sojourn time distribution, converted |
61% | | | to a continuous PH representation |
62% +----------------+--------------------+----------------------------------------+
63% | "prec" | The precision | Numerical precision used as a stopping |
64% | | | condition when solving the |
65% | | | matrix-quadratic equation |
66% +----------------+--------------------+----------------------------------------+
67%
68% (The quantities related to the number of customers in
69% the system include the customer in the server, and the
70% sojourn time related quantities include the service
71% times as well)
72%
73% Returns
74% -------
75% Ret : list of the performance measures
76% Each entry of the list corresponds to a performance
77% measure requested. If there is just a single item,
78% then it is not put into a list.
79% % Notes
80% -----
81% "ncDistrMG" and "stDistrME" behave much better numerically than
82% "ncDistrDPH" and "stDistrPH".
83
84function varargout = MAPMAP1(D0, D1, S0, S1, varargin)
85
86 % parse options
87 prec = 1e-14;
88 needST = 0;
89 eaten = [];
90 for i=1:length(varargin)
91 if strcmp(varargin{i},'prec')
92 prec = varargin{i+1};
93 eaten = [eaten, i, i+1];
94 elseif length(varargin{i})>2 && strcmp(varargin{i}(1:2),'st')
95 needST = 1;
96 end
97 end
98
99 global BuToolsCheckInput;
100
101 if isempty(BuToolsCheckInput)
102 BuToolsCheckInput = true;
103 end
104
105 if BuToolsCheckInput && ~CheckMAPRepresentation(D0,D1)
106 error('MAPMAP1: The arrival process (D0,D1) is not a valid MAP representation!');
107 end
108
109 if BuToolsCheckInput && ~CheckMAPRepresentation(S0,S1)
110 error('MAPMAP1: The service process (S0,S1) is not a valid MAP representation!');
111 end
112
113 IA = eye(size(D0,1));
114 IS = eye(size(S0,1));
115
116 B = kron(IA,S1);
117 L = kron(D0,IS)+kron(IA,S0);
118 F = kron(D1,IS);
119 L0 = kron(D0,IS);
120
121 [pi0, R] = QBDSolve (B, L, F, L0, prec);
122 N = length(pi0);
123 I = eye(N);
124
125 if needST
126 % calculate the distribution of the age at departures
127 U = L + R*B;
128 Rh = inv(-U)*F;
129 T = kron(IA,S0) + Rh * B;
130 eta = pi0*F*inv(I-Rh);
131 eta = eta/sum(eta);
132 end
133
134 Ret = {};
135 argIx = 1;
136 while argIx<=length(varargin)
137 if any(ismember(eaten, argIx))
138 argIx = argIx + 1;
139 continue;
140 elseif strcmp(varargin{argIx},'ncDistrDPH')
141 % transform it to DPH
142 alpha = pi0*R*inv(eye(N)-R);
143 A = inv(diag(alpha))*R'*diag(alpha);
144 Ret{end+1} = alpha;
145 Ret{end+1} = A;
146 elseif strcmp(varargin{argIx},'ncDistrMG')
147 % transform it to MG
148 B = SimilarityMatrixForVectors(sum(inv(I-R)*R,2), ones(N,1));
149 Bi = inv(B);
150 A = B*R*Bi;
151 alpha = pi0*Bi;
152 Ret{end+1} = alpha;
153 Ret{end+1} = A;
154 elseif strcmp(varargin{argIx},'ncMoms')
155 numOfMoms = varargin{argIx+1};
156 argIx = argIx + 1;
157 moms = zeros(1,numOfMoms);
158 iR = inv(I-R);
159 for m=1:numOfMoms
160 moms(m) = factorial(m)*sum(pi0*iR^(m+1)*R^m);
161 end
162 Ret{end+1} = MomsFromFactorialMoms(moms);
163 elseif strcmp(varargin{argIx},'ncDistr')
164 numOfQLProbs = varargin{argIx+1};
165 argIx = argIx + 1;
166 values = zeros(1,numOfQLProbs);
167 values(1) = sum(pi0);
168 RPow = I;
169 for p=1:numOfQLProbs-1
170 RPow = RPow * R;
171 values(p+1) = sum(pi0*RPow);
172 end
173 Ret{end+1} = values;
174 elseif strcmp(varargin{argIx},'stDistrPH')
175 % transform it to PH representation
176 beta = CTMCSolve(S0+S1);
177 theta = DTMCSolve(inv(-D0)*D1);
178 vv = kron(theta,beta);
179 ix = 1:N;
180 nz = ix(vv>prec);
181 delta = diag(vv(nz));
182 alpha = ones(1,N)*B(nz,:)'*delta / sum(beta*S1);
183 A = inv(delta)*T(nz,nz)'*delta;
184 Ret{end+1} = alpha;
185 Ret{end+1} = A;
186 elseif strcmp(varargin{argIx},'stDistrME')
187 Ret{end+1} = eta;
188 Ret{end+1} = T;
189 elseif strcmp(varargin{argIx},'stMoms')
190 numOfMoms = varargin{argIx+1};
191 argIx = argIx + 1;
192 moms = zeros(1,numOfMoms);
193 iT = inv(-T);
194 for m=1:numOfMoms
195 moms(m) = factorial(m)*sum(eta*iT^m);
196 end
197 Ret{end+1} = moms;
198 elseif strcmp(varargin{argIx},'stDistr')
199 points = varargin{argIx+1};
200 argIx = argIx + 1;
201 values = zeros(size(points));
202 for p=1:length(points)
203 values(p) = 1-sum(eta*expm(T*points(p)));
204 end
205 Ret{end+1} = values;
206 else
207 error (['MAPMAP1: Unknown parameter ' varargin{argIx}])
208 end
209 argIx = argIx + 1;
210 end
211 varargout = Ret;
212end