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
47inner_options = options;
48inner_options.iter_max = max(20, ceil(options.iter_max/10));
49inner_options.verbose = false;
50
51QN = zeros(M,K);
52UN = zeros(M,K);
53RN = zeros(M,K);
54TN = zeros(M,K);
55CN = zeros(1,K);
56XN = zeros(1,K);
57
58% Last successful inner-kernel outputs (for fallback if final trial diverges)
59QN_last = QN; UN_last = UN; RN_last = RN;
60TN_last = TN; CN_last = CN; XN_last = XN;
61have_good = false;
62
63bisect_tol = max(options.iter_tol, 1e-3);
64
65while max(abs(QN_chain - QNc)) > bisect_tol && it_out < options.iter_max
66 it_out = it_out + 1;
67 if it_out > 1
68 for k=1:K
69 if ~isfinite(QNc(k)) || QNc(k) == 0
70 continue;
71 end
72 if QN_chain(k) < QNc(k)
73 lambda_lb(k) = lambda(k);
74 else
75 lambda_ub(k) = lambda(k);
76 end
77 lambda(k) = 0.5 * (lambda_lb(k) + lambda_ub(k));
78 end
79 end
80
81 try
82 [QN, UN, RN, TN, CN, XN, ~] = solver_mam_basic_mmap_inner(sn, inner_options, lambda);
83 kernel_ok = true;
84 catch
85 % Inner kernel diverged (typically MMAPPH1FCFS / lyap NaN under
86 % saturation). Treat all chains as overloaded so the bisection
87 % drops lambda on its next step.
88 kernel_ok = false;
89 end
90
91 if kernel_ok
92 % SLC clamp: all jobs at refstat for self-looping classes
93 for k=1:K
94 if sn.isslc(k)
95 QN(:,k) = 0;
96 QN(sn.refstat(k), k) = sn.njobs(k);
97 end
98 end
99 QN_chain = sum(QN, 1);
100 QN_chain(isnan(QN_chain) | isinf(QN_chain)) = 1/GlobalConstants.FineTol;
101 QN_last = QN; UN_last = UN; RN_last = RN;
102 TN_last = TN; CN_last = CN; XN_last = XN;
103 have_good = true;
104 else
105 QN_chain = ones(1,K) * (1/GlobalConstants.FineTol);
106 end
107end
108
109% If the last trial diverged, fall back to the most recent successful one
110if ~kernel_ok && have_good
111 QN = QN_last; UN = UN_last; RN = RN_last;
112 TN = TN_last; CN = CN_last; XN = XN_last;
113end
114
115% Final SLC pass: pin throughput/utilisation at refstat (mirrors solver_mna_closed)
116for k=1:K
117 if sn.isslc(k)
118 QN(:,k) = 0;
119 ist = sn.refstat(k);
120 QN(ist, k) = sn.njobs(k);
121 TN(ist, k) = sn.njobs(k) * sn.rates(ist, k);
122 if TN(ist, k) > 0
123 RN(ist, k) = QN(ist, k) / TN(ist, k);
124 else
125 RN(ist, k) = 0;
126 end
127 UN(ist, k) = S(ist, k) * TN(ist, k);
128 end
129end
130
131% Population redistribution within chain (matches solver_mna_closed:323-328)
132for c=1:sn.nchains
133 inchain = sn.inchain{c};
134 if isfinite(sn.njobs(c))
135 sumQ = sum(sum(QN(:,inchain)));
136 if sumQ > 0
137 QN(:,inchain) = sn.njobs(c) .* QN(:,inchain) / sumQ;
138 end
139 end
140end
141
142% Delay/INF utilisation = mean number of jobs (matches solver_mna_closed)
143for ist=1:sn.nstations
144 if sn.sched(ist) == SchedStrategy.INF
145 UN(ist,:) = QN(ist,:);
146 end
147end
148
149CN = sum(RN, 1);
150QN(isnan(QN)) = 0;
151UN(isnan(UN)) = 0;
152RN(isnan(RN)) = 0;
153TN(isnan(TN)) = 0;
154CN(isnan(CN)) = 0;
155totiter = it_out;
156end