111 "solver_mam_decmmap: the departure-process fixed point stops on a tolerance, "
112 "MMAP[K]/PH[K]/1 runs the ADDA doubling iteration and the ETAQA departure process "
113 "needs transcendental arithmetic; rerun with --arith double or --arith real");
115 using namespace decmmap_detail;
116 using namespace basic_mmap_detail;
117 using basic_detail::station_visits;
118 using basic_detail::truncate_renorm;
124 check_disciplines(L);
127 "SolverMAM: the dec.mmap method solves open models only. solver_mam.m warns and "
128 "returns the ZERO matrices it initialised for anything else, which reports an empty "
129 "network rather than refusing; use 'dec.source', 'dec.source.mmap' or 'mna'");
134 std::vector<T> lambda(K, zero);
135 for (std::size_t c = 0; c < C; ++c) {
136 if (L.
inchain[c].empty())
continue;
137 const std::size_t rs = L.
classes[L.
inchain[c][0] - 1].refstat - 1;
139 for (std::size_t k : L.
inchain[c]) {
140 if (L.
disabled[rs][k - 1])
continue;
142 tot += L.
rates(rs, k - 1);
144 for (std::size_t k : L.
inchain[c]) lambda[k - 1] = tot;
148 const MmapPhTable<T> ph = mmap_ph_table(L);
151 Matrix<T> QN(M, K, zero), UN(M, K, zero), RN(M, K, zero), TN(M, K, zero);
152 for (std::size_t i = 0; i < M; ++i)
153 if (L.
stations[i].sched == SchedStrategy::EXT)
154 for (std::size_t r = 0; r < K; ++r)
161 auto sweep = [&](
const std::vector<T>&,
162 std::size_t itnum) -> std::pair<std::vector<T>, std::vector<T>> {
164 for (std::size_t i = 0; i < M; ++i)
165 for (std::size_t r = 0; r < K; ++r)
166 DEP[i][r] = (lambda[r] > zero && V(i, r) > zero)
167 ?
map_scale(ph.PH[i][r], T(one / T(lambda[r] * V(i, r))))
178 std::vector<T> xref(M * K, zero);
179 for (std::size_t i = 0; i < M; ++i)
180 for (std::size_t r = 0; r < K; ++r) xref[i * K + r] = QN(i, r);
182 for (std::size_t i = 0; i < M; ++i) {
185 const double ns = L.
stations[i].nservers;
186 bool finiteCapUsed =
false;
188 if (L.
nodes[ind].nodetype == qn::NodeType::Queue && ARV[ind].order() > 0) {
189 if (ARV[ind].order() > tcfg.
space_max) ARV[ind] = compress_arrival(ARV[ind]);
191 for (std::size_t r = 0; r < K; ++r) TN(i, r) = lam[r];
193 std::vector<PhService<T>> sl;
194 for (std::size_t r = 0; r < K; ++r) sl.push_back(ph.svc[i][r]);
196 if (sc == SchedStrategy::FCFS || sc == SchedStrategy::HOL ||
197 sc == SchedStrategy::FCFSPRPRIO) {
198 if (std::isfinite(L.
stations[i].cap)) {
199 const std::size_t capK =
200 static_cast<std::size_t
>(std::llround(L.
stations[i].cap));
201 T meanQ = zero, lossProb = zero;
205 for (std::size_t r = 0; r < K; ++r)
209 lamTot, det.
muRate,
static_cast<unsigned>(std::llround(ns)),
210 static_cast<unsigned>(capK));
214 const basic_detail::TruncRenorm<T>
tr =
215 truncate_renorm(ARV[ind], sl, capK);
217 lossProb =
tr.lossProb;
219 std::vector<T> eff(K, zero), Sact(K, zero);
221 for (std::size_t r = 0; r < K; ++r) {
224 eff[r] = T(inflow * T(one - lossProb));
231 for (std::size_t r = 0; r < K; ++r) {
232 const T c = T(eff[r] * Sact[r]);
235 const T w = T(T(meanQ / sumTN) - T(sw / sumTN));
236 Wq = (w > zero) ? w : zero;
238 for (std::size_t r = 0; r < K; ++r) {
240 UN(i, r) = T(TN(i, r) *
map_mean(ph.PH[i][r]));
241 if (TN(i, r) > zero) {
242 RN(i, r) = T(Wq + Sact[r]);
243 QN(i, r) = T(TN(i, r) * RN(i, r));
249 finiteCapUsed =
true;
254 bool prio_distinct =
false;
255 if (sc != SchedStrategy::FCFS)
256 for (std::size_t r = 1; r < K; ++r)
258 if (prio_distinct && ARV[ind].classes() == K) {
265 std::vector<std::size_t> iK(K);
266 for (std::size_t r = 0; r < K; ++r) iK[r] = r;
267 std::stable_sort(iK.begin(), iK.end(),
268 [&L](std::size_t a, std::size_t b) {
269 return L.classes[a].prio > L.classes[b].prio;
271 for (std::size_t j = 1; j < K; ++j)
274 "solver_mam: Solver MAM requires either identical "
275 "priorities or all distinct priorities");
279 std::vector<PhService<T>> slp;
280 for (std::size_t j = 0; j < K; ++j) {
281 pa.Dc.push_back(ARV[ind].Dc[iK[j]]);
282 slp.push_back(sl[iK[j]]);
284 const std::vector<std::vector<T>> pm =
287 for (std::size_t j = 0; j < K; ++j) QN(i, iK[j]) = pm[j][0];
290 for (std::size_t r = 0; r < K; ++r)
291 QN(i, r) = m[ARV[ind].classes() == 1 ? 0 : r];
294 }
else if (sc == SchedStrategy::PS) {
295 for (std::size_t r = 0; r < K; ++r)
296 UN(i, r) = T(TN(i, r) *
map_mean(ph.PH[i][r]));
298 for (std::size_t r = 0; r < K; ++r) usum += UN(i, r);
299 const T uden = (usum < T(one - ftol)) ? usum : T(one - ftol);
300 for (std::size_t r = 0; r < K; ++r) QN(i, r) = T(UN(i, r) / T(one - uden));
305 if (!finiteCapUsed) {
306 for (std::size_t r = 0; r < K; ++r) {
307 UN(i, r) = T(TN(i, r) *
map_mean(ph.PH[i][r]));
308 if (std::isfinite(ns))
309 QN(i, r) = T(QN(i, r) + TN(i, r) *
313 RN(i, r) = T(QN(i, r) / TN(i, r));
319 for (std::size_t i = 0; i < M; ++i) {
321 if (L.
nodes[ind].nodetype != qn::NodeType::Queue || ARV[ind].order() == 0)
continue;
323 const bool fcfs = (sc == SchedStrategy::FCFS || sc == SchedStrategy::HOL ||
324 sc == SchedStrategy::FCFSPRPRIO);
325 if (!fcfs && sc != SchedStrategy::PS)
continue;
327 for (std::size_t r = 0; r < K; ++r) rho += UN(i, r);
328 for (std::size_t r = 0; r < K; ++r) {
330 const Map<T>& Srv = ph.PH[i][r];
333 if (etaqa_sz <= tcfg.
space_max && rho < T(one - ftol)) {
339 }
catch (
const Error&) {
346 if (lambda[r] > zero && V(i, r) > zero)
347 dep =
map_scale(dep, T(one / T(lambda[r] * V(i, r))));
352 std::vector<T> xnew(M * K, zero);
353 for (std::size_t i = 0; i < M; ++i)
354 for (std::size_t r = 0; r < K; ++r) xnew[i * K + r] = QN(i, r);
355 return std::make_pair(xnew, xref);
359 fo.
iter_max =
static_cast<std::size_t
>(
opt.iter_max);
371 out.
C.assign(K, zero);
372 out.
X.assign(K, zero);