LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mam_map_bmap_1.m
1function [QN, UN, RN, TN, piAgg, R] = solver_mam_map_bmap_1(mapArr, bmapSvc, varargin)
2% SOLVER_MAM_MAP_BMAP_1 Solve MAP/BMAP/1 queue using GI/M/1-type analysis.
3%
4% Solves a MAP/BMAP/1 queue where:
5% - Arrivals follow a Markovian Arrival Process (MAP)
6% - Service follows a Batch Markovian Arrival Process (BMAP) for
7% batch service completions
8% - Single server
9%
10% The queue is modeled as a GI/M/1-type Markov chain because:
11% - MAP arrivals increase level by exactly 1
12% - BMAP service can decrease level by 1, 2, 3, ... (batch sizes)
13%
14% USAGE:
15% [QN, UN, RN, TN] = solver_mam_map_bmap_1(mapArr, bmapSvc)
16% [QN, UN, RN, TN, piAgg, R] = solver_mam_map_bmap_1(mapArr, bmapSvc)
17%
18% INPUT:
19% mapArr - MAP object or cell array {C0, C1} for arrivals
20% bmapSvc - BMAP object or cell array {D0, D1, D2, ...} for batch service
21%
22% OUTPUT:
23% QN - Mean queue length E[N]
24% UN - Server utilization rho
25% RN - Mean response time E[R]
26% TN - Throughput (arrival rate)
27% piAgg - Aggregated stationary probabilities [pi0, pi1, piStar]
28% R - R matrix from GI/M/1-type solution
29%
30% The GI/M/1-type structure for MAP/BMAP/1 is:
31% B1 A0 0 0 ...
32% B2 A1 A0 0 ...
33% Q = B3 A2 A1 A0 ...
34% ...
35%
36% Where:
37% A0 = C1 ⊗ I_ms (MAP arrival, level +1)
38% A1 = C0 ⊗ I_ms + I_ma ⊗ D0 (phase changes, level 0)
39% A_{k+1} = I_ma ⊗ D_k (batch size k service, level -k)
40%
41% REFERENCES:
42% Riska, A., & Smirni, E. (2003). ETAQA: An Efficient Technique for the
43% Analysis of QBD-Processes by Aggregation. Performance Evaluation.
44%
45% See also: solver_mam_bmap_m_1, MAP, BMAP
46
47%% Parse inputs
48if isa(mapArr, 'MAP')
49 C0 = mapArr.getD0();
50 C1 = mapArr.getD1();
51elseif iscell(mapArr)
52 C0 = mapArr{1};
53 C1 = mapArr{2};
54else
55 error('mapArr must be a MAP object or cell array {C0, C1}');
56end
57
58if isa(bmapSvc, 'BMAP')
59 K = bmapSvc.getNumberOfPhases() - 1; % Max batch size
60 D = cell(1, K + 1);
61 D{1} = bmapSvc.getD0();
62 for k = 1:K
63 D{k+1} = bmapSvc.D(1, k); % D_k for batch size k
64 end
65elseif iscell(bmapSvc)
66 D = bmapSvc;
67 K = length(D) - 1; % Max batch size
68else
69 error('bmapSvc must be a BMAP object or cell array {D0, D1, D2, ...}');
70end
71
72%% Get dimensions
73ma = size(C0, 1); % Number of MAP phases
74ms = size(D{1}, 1); % Number of BMAP phases
75m = ma * ms; % Combined phases per level
76
77%% Validate inputs
78% Check MAP is valid generator
79rowSumsC = sum(C0 + C1, 2);
80if max(abs(rowSumsC)) > 1e-10
81 error('MAP matrices C0 + C1 must have zero row sums');
82end
83
84% Check BMAP is valid generator
85DTotal = D{1};
86for k = 1:K
87 DTotal = DTotal + D{k+1};
88end
89rowSumsD = sum(DTotal, 2);
90if max(abs(rowSumsD)) > 1e-10
91 error('BMAP matrices D0 + D1 + ... + DK must have zero row sums');
92end
93
94%% Compute arrival and service rates
95% Arrival rate from MAP
96piC = map_prob({C0, C1});
97lambdaArr = piC * C1 * ones(ma, 1);
98
99% Service rate from BMAP (total customers served per unit time)
100piD = map_prob({D{1}, DTotal - D{1}}); % D0, sum of D1...DK
101muTotal = 0;
102for k = 1:K
103 muTotal = muTotal + k * (piD * D{k+1} * ones(ms, 1));
104end
105
106% Utilization
107rho = lambdaArr / muTotal;
108
109if rho >= 1.0
110 warning('System is unstable (rho = %.4f >= 1). Results may be invalid.', rho);
111end
112
113%% Construct A matrix for GI/M/1-type (repeating part)
114% A = [A0; A1; A2; ...; A_{K+1}] with (K+2) blocks of size m x m
115%
116% A0 = C1 ⊗ I_ms (level +1: arrival)
117% A1 = C0 ⊗ I_ms + I_ma ⊗ D0 (level 0: phase changes)
118% A_{k+1} = I_ma ⊗ D_k (level -k: batch service of k)
119
120A = zeros(m * (K + 2), m);
121
122% A0: MAP arrival (level +1)
123A0 = kron(C1, eye(ms));
124A(1:m, :) = A0;
125
126% A1: Phase changes only (level 0)
127A1 = kron(C0, eye(ms)) + kron(eye(ma), D{1});
128A(m+1:2*m, :) = A1;
129
130% A_{k+1}: Batch service of size k (level -k)
131for k = 1:K
132 Ak = kron(eye(ma), D{k+1});
133 A((k+1)*m+1:(k+2)*m, :) = Ak;
134end
135
136%% Construct B matrix for boundary levels
137% For levels 0, 1, ..., K-1, we need special handling because
138% batch service of size k is only possible when queue length >= k
139%
140% B = [B1; B2; ...; B_{K+1}] where B_i is m x m
141%
142% The boundary structure accounts for:
143% - Level 0: no service possible (empty queue)
144% - Level 1: only batch size 1 service possible
145% - Level k: batch sizes 1, 2, ..., k possible
146
147B = zeros(m * (K + 1) + m, m); % B has mb=m boundary rows, then K+1 blocks
148
149% B1 (level 0 -> level 0): Phase changes only, no service from empty
150% Arrivals from level 0 are handled by B0 = A0
151B1 = kron(C0, eye(ms)) + kron(eye(ma), D{1});
152% Add service transitions that would go to negative levels back to level 0
153for k = 1:K
154 B1 = B1 + kron(eye(ma), D{k+1}); % Service from empty stays at 0
155end
156B(1:m, :) = B1;
157
158% B2, B3, ..., B_{K+1}: Transitions to level 0 from levels 1, 2, ..., K
159for j = 1:K
160 % From level j, we can service batches of size 1, 2, ..., j going to level 0
161 Bj = zeros(m, m);
162 % Only batch sizes <= j are valid; larger batches get truncated
163 for k = j:K
164 % Batch size k from level j: if k > j, customer stays at 0
165 % But for GI/M/1 B matrix, we accumulate transitions to level 0
166 % B_{j+1} handles transition from level j to level 0
167 Bj = Bj + kron(eye(ma), D{k+1});
168 end
169 B(m + (j-1)*m + 1 : m + j*m, :) = Bj;
170end
171
172%% Compute R matrix using GI/M/1 ETAQA
173R = GIM1_R_ETAQA(A);
174
175%% Compute stationary probabilities using GI/M/1 ETAQA
176piAgg = GIM1_pi_ETAQA(B, A, R, 'Boundary', A0);
177
178%% Compute performance metrics
179% Extract probability components
180pi0 = piAgg(1:m);
181pi1 = piAgg(m+1:2*m);
182piStar = piAgg(2*m+1:3*m);
183
184% Mean queue length using ETAQA moments
185QN = GIM1_qlen_ETAQA(B, A, R, piAgg, 1, 'Boundary', A0);
186
187% Throughput equals arrival rate (in steady state)
188TN = lambdaArr;
189
190% Utilization
191UN = rho;
192
193% Mean response time via Little's Law
194RN = QN / TN;
195
196end