LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mam_basic_mmap_closed.m
1function [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_basic_mmap_closed(sn, options)
2% [QN,UN,RN,TN,CN,XN,TOTITER] = SOLVER_MAM_BASIC_MMAP_CLOSED(SN, OPTIONS)
3%
4% Closed-network wrapper around solver_mam_basic_mmap_inner. Drives a
5% per-class bisection on the surrogate arrival rate LAMBDA so that the
6% inner solver's queue lengths match the closed population SN.NJOBS.
7% Mirrors the outer-loop structure of solver_mna_closed.
8%
9% Copyright (c) 2012-2026, Imperial College London
10% All rights reserved.
11
12K = sn.nclasses;
13M = sn.nstations;
14S = 1./sn.rates;
15
16% Per-class bisection bounds: upper = slowest non-INF station rate for that class
17nonInfStations = find(sn.nservers < Inf);
18lambda_lb = zeros(1,K);
19lambda_ub = zeros(1,K);
20for k=1:K
21 rates_k = [];
22 if ~isempty(nonInfStations)
23 rates_k = sn.rates(nonInfStations, k);
24 rates_k = rates_k(isfinite(rates_k) & rates_k > 0);
25 end
26 if isempty(rates_k)
27 infStations = find(sn.nservers == Inf);
28 rates_inf = sn.rates(infStations, k);
29 rates_inf = rates_inf(isfinite(rates_inf) & rates_inf > 0);
30 if isempty(rates_inf)
31 lambda_ub(k) = 1;
32 else
33 lambda_ub(k) = max(rates_inf);
34 end
35 else
36 lambda_ub(k) = min(rates_k);
37 end
38end
39
40QNc = sn.njobs;
41QNc(~isfinite(QNc)) = 0; % open classes contribute 0; only closed populations gate convergence
42QN_chain = zeros(1,K);
43
44it_out = 0;
45lambda = lambda_ub;
46% Self-looping classes are pinned by the SLC clamp below; they must not
47% contribute a (saturating) surrogate arrival stream to the inner kernel.
48lambda(sn.isslc) = 0;
49
50inner_options = options;
51inner_options.iter_max = max(20, ceil(options.iter_max/10));
52inner_options.verbose = false;
53
54QN = zeros(M,K);
55UN = zeros(M,K);
56RN = zeros(M,K);
57TN = zeros(M,K);
58CN = zeros(1,K);
59XN = zeros(1,K);
60
61% Last successful inner-kernel outputs (for fallback if final trial diverges)
62QN_last = QN; UN_last = UN; RN_last = RN;
63TN_last = TN; CN_last = CN; XN_last = XN;
64have_good = false;
65
66bisect_tol = max(options.iter_tol, 1e-3);
67
68while max(abs(QN_chain - QNc)) > bisect_tol && it_out < options.iter_max
69 it_out = it_out + 1;
70 if it_out > 1
71 for k=1:K
72 if ~isfinite(QNc(k)) || QNc(k) == 0 || sn.isslc(k)
73 continue;
74 end
75 if QN_chain(k) < QNc(k)
76 lambda_lb(k) = lambda(k);
77 else
78 lambda_ub(k) = lambda(k);
79 end
80 lambda(k) = 0.5 * (lambda_lb(k) + lambda_ub(k));
81 end
82 end
83
84 try
85 [QN, UN, RN, TN, CN, XN, ~] = solver_mam_basic_mmap_inner(sn, inner_options, lambda);
86 kernel_ok = true;
87 catch
88 % Inner kernel diverged (typically MMAPPH1FCFS / lyap NaN under
89 % saturation). Treat all chains as overloaded so the bisection
90 % drops lambda on its next step.
91 kernel_ok = false;
92 end
93
94 if kernel_ok
95 % SLC clamp: all jobs at refstat for self-looping classes
96 for k=1:K
97 if sn.isslc(k)
98 QN(:,k) = 0;
99 QN(sn.refstat(k), k) = sn.njobs(k);
100 end
101 end
102 QN_chain = sum(QN, 1);
103 QN_chain(isnan(QN_chain) | isinf(QN_chain)) = 1/GlobalConstants.FineTol;
104 QN_last = QN; UN_last = UN; RN_last = RN;
105 TN_last = TN; CN_last = CN; XN_last = XN;
106 have_good = true;
107 else
108 QN_chain = ones(1,K) * (1/GlobalConstants.FineTol);
109 end
110end
111
112% If the last trial diverged, fall back to the most recent successful one
113if ~kernel_ok && have_good
114 QN = QN_last; UN = UN_last; RN = RN_last;
115 TN = TN_last; CN = CN_last; XN = XN_last;
116end
117
118% Final SLC pass: pin throughput/utilisation at refstat (mirrors solver_mna_closed)
119for k=1:K
120 if sn.isslc(k)
121 QN(:,k) = 0;
122 ist = sn.refstat(k);
123 QN(ist, k) = sn.njobs(k);
124 TN(ist, k) = sn.njobs(k) * sn.rates(ist, k);
125 if TN(ist, k) > 0
126 RN(ist, k) = QN(ist, k) / TN(ist, k);
127 else
128 RN(ist, k) = 0;
129 end
130 UN(ist, k) = S(ist, k) * TN(ist, k);
131 end
132end
133
134% Population redistribution within chain (matches solver_mna_closed:323-328)
135for c=1:sn.nchains
136 inchain = sn.inchain{c};
137 if isfinite(sn.njobs(c))
138 sumQ = sum(sum(QN(:,inchain)));
139 if sumQ > 0
140 QN(:,inchain) = sn.njobs(c) .* QN(:,inchain) / sumQ;
141 end
142 end
143end
144
145% Delay/INF utilisation = mean number of jobs (matches solver_mna_closed)
146for ist=1:sn.nstations
147 if sn.sched(ist) == SchedStrategy.INF
148 UN(ist,:) = QN(ist,:);
149 end
150end
151
152CN = sum(RN, 1);
153QN(isnan(QN)) = 0;
154UN(isnan(UN)) = 0;
155RN(isnan(RN)) = 0;
156TN(isnan(TN)) = 0;
157CN(isnan(CN)) = 0;
158totiter = it_out;
159end