LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_mam_traffic.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_SOLVERS_MAM_SOLVER_MAM_TRAFFIC_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_TRAFFIC_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `solver_mam_traffic.m` and `solver_mam_traffic_mmap.m`: the traffic
12 * step of the `dec.mmap` decomposition.
13 *
14 * WHAT IT COMPUTES. Given the DEPARTURE process of every class at every station
15 * as a (D0,D1) pair, it produces the ARRIVAL process seen by every node. Each
16 * station's per-class departures are superposed into one marked MAP, that MAP
17 * is split along the routing (`npfqn_traffic_split_cs`, which also carries the
18 * class switching), and the per-link flows arriving at a node are superposed
19 * back (`npfqn_traffic_merge`). The result is the per-link traffic descriptor
20 * table the outer fixed point of `solver_mam.m` iterates on.
21 *
22 * IT IS AN APPROXIMATION, and the approximation is not incidental. The exact
23 * superposition of n marked MAPs is the Kronecker sum, whose order is the
24 * PRODUCT of the operand orders, so a network of any size exhausts memory after
25 * a handful of merges. Both the per-station class superposition here and
26 * `npfqn_traffic_merge` therefore compress back to a bounded representation
27 * (`mmap_compress`, an APH(2) mixture fit) whenever the order passes
28 * `config.space_max`. Compression preserves the class probabilities and the
29 * first three backward moments per class; it does NOT preserve the correlation
30 * structure, and it does not preserve the per-class rates exactly. Nothing here
31 * may be compared against an exact solver for equality: the descriptors are
32 * moment-matched surrogates of the true superposed processes. What survives the
33 * compression exactly is the SPLIT: `npfqn_traffic_split_cs` is linear in the
34 * routing probabilities, so first-moment conservation across a split, and the
35 * whole traffic table of a network that never trips `space_max` and never
36 * merges more than one flow into a node, are identities.
37 *
38 * INDEXING. The reference works in an indexing over the NON-CLASS-SWITCH nodes
39 * ("NCS"): the class-switch nodes are eliminated by taking the stochastic
40 * complement of `sn.rtnodes` over the rows of the surviving nodes, so a switch
41 * shows up only as a class change on the edges around it. `ARV` is returned
42 * NODE-indexed and of length `nnodes` -- the reference preallocates it as
43 * `cell(Inc,1)` and then assigns `ARV{ind}` at node indices, so MATLAB grows it
44 * to `I`; the preallocation size is dead. An entry of order 0 is MATLAB's `[]`:
45 * a class-switch node, or a Source, which has no arrivals to describe.
46 *
47 * REFERENCE DEFECT in `solver_mam_traffic.m`, line 104. When a node has no
48 * incoming flow above `FineTol` the fallback reads `ARV{ind} = LINKS{jnd,1}`.
49 * `jnd` is the loop variable left behind by the `for jnd=1:Inc` above it, so it
50 * is `Inc`, and the column is the literal 1 rather than `inc`: the node is
51 * handed the link from the LAST non-class-switch node to the FIRST one, which
52 * is a flow between two other nodes entirely, or `[]` when that link was never
53 * built. The FJ variant of the same file (`solver_mam_traffic_mmap.m`, lines
54 * 179-188) writes the intended form -- any non-empty link INTO this node, and a
55 * zero-rate MMAP when there is none -- and that is what this port does for both
56 * entry points. Propagating the defect would attribute one node's traffic to
57 * another, which no downstream consumer could detect.
58 *
59 * WHAT IS REFUSED BY NAME. The reference's node switch has a branch only for
60 * Source, Delay and Queue (plus Fork and Join in the FJ variant). Any other
61 * node that a flow passes THROUGH -- a Router, a Logger, a Cache, a Place, a
62 * Transition, a Region -- silently emits no outgoing link there, so everything
63 * downstream of it is described as receiving no traffic at all. That is not a
64 * conservative approximation, it is a wrong answer with no symptom, so such a
65 * model is refused by name rather than reproduced. A Sink is not refused: it
66 * genuinely has no departures.
67 *
68 * WHAT IS NOT PORTED. `sn_build_fj_sync_map` has no home in this tree yet --
69 * it belongs in `line/api/fj/` -- and the FJ variant is unusable without it. It
70 * is transcribed here under its MATLAB name, exactly as
71 * `npfqn_traffic_split_cs.h` inlines `mmap_normalize` for the same reason, and
72 * should be lifted into its own header when one is added. It is a line-by-line
73 * transcription, not a re-derivation. `mmap_max` used to be transcribed here
74 * too; it now comes from `line/api/mam/map_max.h`, whose copy is block for
75 * block the same, because two definitions in `line::mam` made every call that
76 * saw both headers ambiguous.
77 *
78 * ARITHMETIC. The merge, the split and the synchronization are Kronecker
79 * algebra and are exact in any field. Compression is not: `mmap_compress` fits
80 * an APH(2) and needs square roots, so every call to it is behind the same
81 * compile-time gate `npfqn_traffic_merge` uses, and the exact instantiation
82 * refuses at run time only when compression is actually reached.
83 */
84
85#include <cstddef>
86#include <map>
87#include <string>
88#include <utility>
89#include <vector>
90
100#include "line/util/error.h"
101#include "line/util/linalg.h"
102#include "line/util/matrix.h"
103
104namespace line {
105namespace mam {
106
107/** `DEP{i,r}`, the departure process of class r from i in (D0,D1) form. */
108template <class T>
109using DepTable = std::vector<std::vector<Map<T>>>;
110
111/**
112 * The fields of `options.config` the traffic step reads.
113 *
114 * `merge` carries MATLAB's `config.merge` and `config.compress` together, since
115 * `npfqn_traffic_merge` already owns both.
116 */
118 std::size_t space_max = 128;
119 /** `config.fj_sync_q_len`, the join's synchronization queue; MATLAB's default. */
120 std::size_t fj_sync_q_len = 2;
122};
123
124/** The traffic step's view of `SolverOptions('MAM')`. */
127 c.space_max = opt.space_max;
128 return c;
129}
130
131/**
132 * `sn_build_fj_sync_map`: which incoming flows at a Join must be synchronized.
133 *
134 * `node_sync[j][i]` is the sync group of the flow from node i into node j, with
135 * 0 meaning an independent flow. Both indices are 0-based over nodes; group ids
136 * are 1-based, as in the reference.
137 */
138struct FjSyncMap {
139 std::vector<std::vector<std::size_t>> node_sync;
140 std::vector<std::size_t> fork_of_group; ///< 1-based node index, by group
141 std::vector<std::size_t> join_of_group; ///< 1-based node index, by group
142 std::size_t ngroups = 0;
143};
144
145namespace traffic_detail {
146
147/**
148 * `npfqn_traffic_split_cs` takes the MMAP as MATLAB's flat cell and the rest of
149 * the port takes `mam::Mmap`, so the two representations have to meet here.
150 */
151template <class T>
152npfqn::Mmap<T> to_flat(const Mmap<T>& m) {
154 v.reserve(2 + m.classes());
155 v.push_back(m.D0);
156 v.push_back(m.D1);
157 for (const Matrix<T>& Dc : m.Dc) v.push_back(Dc);
158 return v;
159}
160
161template <class T>
162Mmap<T> from_flat(const npfqn::Mmap<T>& v) {
163 if (v.size() < 3) throw InputError("solver_mam_traffic: a split flow carries no marking");
164 Mmap<T> m;
165 m.D0 = v[0];
166 m.D1 = v[1];
167 m.Dc.assign(v.begin() + 2, v.end());
168 return m;
169}
170
171/** See `npfqn_traffic_merge`'s compress_or_refuse: the same gate, named here. */
172template <class T>
173Mmap<T> compress_or_refuse(const Mmap<T>& m) {
174 if constexpr (num_traits<T>::has_transcendental) {
176 } else {
177 throw UnsupportedError(ErrorKind{"Arithmetic"},
178 "solver_mam_traffic: the superposition passed config.space_max and must be compressed, "
179 "which needs transcendental arithmetic (aph2_fit); raise space_max or run at double");
180 }
181}
182
183/** An MMAP of `nclasses` classes that never fires, MATLAB's `{[0],[0],[0]}`. */
184template <class T>
185Mmap<T> silent_mmap(std::size_t nclasses) {
186 const T zero = num_traits<T>::from_int(0);
187 Mmap<T> m;
188 m.D0 = Matrix<T>(1, 1, zero);
189 m.D1 = Matrix<T>(1, 1, zero);
190 m.Dc.assign(nclasses, Matrix<T>(1, 1, zero));
191 return m;
192}
193
194/**
195 * One cell of DEP as a single-class MMAP.
196 *
197 * MATLAB replaces an empty or NaN-carrying entry by the silent MMAP and
198 * otherwise sets `D1^(1) = D1`, i.e. reads the renewal departure process as an
199 * MMAP with one class. The NaN test is the reference's `any(any(isnan(D0)))`.
200 */
201template <class T>
202Mmap<T> dep_cell(const DepTable<T>& DEP, std::size_t i, std::size_t r) {
203 if (i >= DEP.size() || r >= DEP[i].size()) return silent_mmap<T>(1);
204 const Map<T>& d = DEP[i][r];
205 if (d.order() == 0) return silent_mmap<T>(1);
206 for (std::size_t a = 0; a < d.D0.rows(); ++a)
207 for (std::size_t b = 0; b < d.D0.cols(); ++b)
208 if (npfqn::detail::num_isnan(d.D0(a, b))) return silent_mmap<T>(1);
209 Mmap<T> m;
210 m.D0 = d.D0;
211 m.D1 = d.D1;
212 m.Dc.assign(1, d.D1);
213 return m;
214}
215
216/**
217 * `sum(mmap_lambda(.))`, MATLAB's test for a link that carries traffic.
218 *
219 * A link whose D1 is identically zero is short-circuited to zero. Its rate is
220 * zero by inspection -- lambda_c = theta D1^(c) e -- and computing theta would
221 * mean solving a singular 0 x = 0, which is exactly the shape the silent MMAP
222 * has. This is not a deviation: it is the same number, obtained without the
223 * degenerate solve.
224 */
225template <class T>
226T total_rate(const Mmap<T>& m) {
227 const T zero = num_traits<T>::from_int(0);
228 bool silent = true;
229 for (std::size_t i = 0; i < m.D1.rows() && silent; ++i)
230 for (std::size_t j = 0; j < m.D1.cols(); ++j)
231 if (!(m.D1(i, j) == zero)) {
232 silent = false;
233 break;
234 }
235 if (silent) return zero;
236 T s = zero;
237 for (const T& v : mmap_lambda(m)) s += v;
238 return s;
239}
240
241/** The node types the reference's switch has no branch for; see the header note. */
242template <class T>
243void reject_opaque_node(const qn::NetworkStruct<T>& sn, std::size_t a, bool fj_aware) {
244 const qn::NodeType ty = sn.nodes[a].nodetype;
245 const char* what = nullptr;
246 switch (ty) {
247 case qn::NodeType::Router: what = "Router"; break;
248 case qn::NodeType::Logger: what = "Logger"; break;
249 case qn::NodeType::Cache: what = "Cache"; break;
250 case qn::NodeType::Place: what = "Place"; break;
251 case qn::NodeType::Transition: what = "Transition"; break;
252 case qn::NodeType::Region: what = "Region"; break;
253 case qn::NodeType::Fork:
254 case qn::NodeType::Join:
255 if (fj_aware) return;
256 throw UnsupportedError(ErrorKind{"Fork"},
257 std::string("solver_mam_traffic: node '") + sn.nodes[a].name +
258 "' is a Fork or a Join, which the plain traffic step has no branch for; the "
259 "fork-join variant is solver_mam_traffic_mmap, which synchronizes the join with "
260 "mmap_max");
261 default: return;
262 }
263 throw UnsupportedError(ErrorKind{"NodeType"}, std::string("solver_mam_traffic: node '") + sn.nodes[a].name + "' is a " +
264 what +
265 " node. The reference's node switch has no branch for it, so it emits "
266 "no outgoing link and every node downstream of it is described as "
267 "receiving no traffic at all; that is a wrong traffic table with no "
268 "symptom, not a conservative approximation");
269}
270
271} // namespace traffic_detail
272
273namespace traffic_detail {
274
275/** The NCS bookkeeping both entry points open with. */
276struct NcsIndex {
277 std::vector<bool> is_ncs; ///< by 0-based node
278 std::vector<std::size_t> to_ncs; ///< 1-based NCS index, 0 for a class switch
279 std::vector<std::size_t> keep; ///< 0-based rtnodes rows of the surviving nodes
280 std::size_t inc_count = 0;
281};
282
283template <class T>
284NcsIndex build_ncs_index(const qn::NetworkStruct<T>& sn) {
285 const std::size_t I = sn.nof_nodes(), R = sn.nclasses;
286 NcsIndex x;
287 x.is_ncs.assign(I, false);
288 x.to_ncs.assign(I, 0);
289 for (std::size_t a = 0; a < I; ++a) {
290 if (sn.nodes[a].nodetype == qn::NodeType::ClassSwitch) continue;
291 x.is_ncs[a] = true;
292 x.to_ncs[a] = ++x.inc_count;
293 for (std::size_t r = 0; r < R; ++r) x.keep.push_back(a * R + r);
294 }
295 return x;
296}
297
298/** The per-station (or per-node) class superposition, bounded by space_max. */
299template <class T>
300Mmap<T> superpose_classes(const DepTable<T>& DEP, std::size_t row, std::size_t R,
301 const TrafficConfig& config) {
302 Mmap<T> d = dep_cell(DEP, row, 0);
303 for (std::size_t r = 1; r < R; ++r) {
304 d = mmap_super(d, dep_cell(DEP, row, r));
305 if (d.order() > config.space_max) d = compress_or_refuse(d);
306 }
307 return d;
308}
309
310/** Row `inc` of the complemented routing, reshaped into split_cs's (R x Inc R). */
311template <class T>
312Matrix<T> split_probabilities(const Matrix<T>& rtncs, std::size_t inc, std::size_t Inc,
313 std::size_t R) {
314 Matrix<T> P(R, Inc * R, num_traits<T>::from_int(0));
315 for (std::size_t r = 0; r < R; ++r)
316 for (std::size_t jnc = 0; jnc < Inc; ++jnc)
317 for (std::size_t s = 0; s < R; ++s)
318 P(r, jnc * R + s) = rtncs(inc * R + r, jnc * R + s);
319 return P;
320}
321
322/**
323 * The reference's fallback for a node with no incoming flow, in the corrected
324 * form the FJ variant writes; see the header note on the line-104 defect.
325 */
326template <class T>
327Mmap<T> no_flow_arrival(const std::vector<std::vector<Mmap<T>>>& LINKS, std::size_t inc,
328 std::size_t R) {
329 for (std::size_t jnc = 0; jnc < LINKS.size(); ++jnc)
330 if (LINKS[jnc][inc].order() != 0) return LINKS[jnc][inc];
331 return silent_mmap<T>(R);
332}
333
334} // namespace traffic_detail
335
336/**
337 * `sn_build_fj_sync_map`.
338 *
339 * A node sits on the parallel path of a (Fork, Join) pair when the fork routes
340 * to it and it routes to the join, both for at least one class; every such node
341 * feeds one sync group at that join. Transcription of
342 * matlab/src/api/fj/sn_build_fj_sync_map.m; it belongs in `line/api/fj/`.
343 */
344template <class T>
346 const std::size_t I = sn.nof_nodes(), K = sn.nclasses;
347 const T zero = num_traits<T>::from_int(0);
348 FjSyncMap m;
349 m.node_sync.assign(I, std::vector<std::size_t>(I, 0));
350 for (const std::pair<std::size_t, std::size_t>& fjp : sn.fj) {
351 const std::size_t f = fjp.first - 1, j = fjp.second - 1;
352 const std::size_t gid = ++m.ngroups;
353 m.fork_of_group.push_back(f + 1);
354 m.join_of_group.push_back(j + 1);
355 for (std::size_t a = 0; a < I; ++a) {
356 if (a == f || a == j) continue;
357 bool from_fork = false, to_join = false;
358 for (std::size_t k = 0; k < K; ++k) {
359 if (sn.rtnodes(f * K + k, a * K + k) > zero) from_fork = true;
360 if (sn.rtnodes(a * K + k, j * K + k) > zero) to_join = true;
361 }
362 if (from_fork && to_join) m.node_sync[j][a] = gid;
363 }
364 }
365 return m;
366}
367
368/**
369 * Port of `solver_mam_traffic.m`.
370 *
371 * @param DEP station-indexed: `DEP[ist][r]` is the class-r departure process
372 * of station `ist` (0-based), an empty Map standing for MATLAB's
373 * `[]`, "this class does not depart from here"
374 * @param sn the refreshed network struct
375 * @param config the `options.config` fields the traffic analyzer reads
376 * @return node-indexed arrival descriptors of length `nnodes`; an entry
377 * of order 0 is MATLAB's `[]`
378 */
379template <class T>
380std::vector<Mmap<T>> solver_mam_traffic(const qn::NetworkStruct<T>& sn, const DepTable<T>& DEP,
381 const TrafficConfig& config) {
382 namespace td = traffic_detail;
383 const std::size_t I = sn.nof_nodes(), R = sn.nclasses;
384 if (R == 0) throw InputError("solver_mam_traffic: the model has no classes");
385
386 const td::NcsIndex x = td::build_ncs_index(sn);
387 const std::size_t Inc = x.inc_count;
388 const Matrix<T> rtncs = mc::dtmc_stochcomp(sn.rtnodes, x.keep);
389
390 // Outgoing flows: superpose each station's classes, then split along the
391 // routing. Only the branches of the reference's switch produce links.
392 std::vector<std::vector<Mmap<T>>> LINKS(Inc, std::vector<Mmap<T>>(Inc));
393 for (std::size_t a = 0; a < I; ++a) {
394 if (!x.is_ncs[a]) continue;
395 const qn::NodeType ty = sn.nodes[a].nodetype;
396 if (ty != qn::NodeType::Source && ty != qn::NodeType::Delay && ty != qn::NodeType::Queue) {
397 td::reject_opaque_node(sn, a, false);
398 continue;
399 }
400 const std::size_t inc = x.to_ncs[a] - 1;
401 const std::size_t ist = sn.nodes[a].station;
402 if (ist == 0)
403 throw InputError("solver_mam_traffic: node '" + sn.nodes[a].name +
404 "' serves jobs but carries no station index");
405 const Mmap<T> dep = td::superpose_classes(DEP, ist - 1, R, config);
406 const Matrix<T> Psplit = td::split_probabilities(rtncs, inc, Inc, R);
407 const std::vector<npfqn::Mmap<T>> F =
408 npfqn::npfqn_traffic_split_cs(td::to_flat(dep), Psplit);
409 for (std::size_t jnc = 0; jnc < Inc; ++jnc)
410 LINKS[inc][jnc] = mmap_normalize(td::from_flat(F[jnc]));
411 }
412
413 // Incoming flows: superpose the links that carry traffic into each node.
414 std::vector<Mmap<T>> ARV(I);
415 for (std::size_t a = 0; a < I; ++a) {
416 if (!x.is_ncs[a] || sn.nodes[a].nodetype == qn::NodeType::Source) continue;
417 const std::size_t inc = x.to_ncs[a] - 1;
418 std::vector<Mmap<T>> flows;
419 for (std::size_t jnc = 0; jnc < Inc; ++jnc) {
420 const Mmap<T>& lk = LINKS[jnc][inc];
421 if (lk.order() == 0) continue;
422 if (!(num_traits<T>::to_double(td::total_rate(lk)) > lang::GlobalConstants::FineTol))
423 continue;
424 flows.push_back(lk);
425 }
426 if (flows.size() > 1) ARV[a] = npfqn::npfqn_traffic_merge(flows, config.merge);
427 else if (flows.size() == 1) ARV[a] = flows[0];
428 else ARV[a] = td::no_flow_arrival(LINKS, inc, R);
429 }
430 return ARV;
431}
432
433/**
434 * Port of `solver_mam_traffic_mmap.m`, the fork-join aware traffic step.
435 *
436 * It differs from `solver_mam_traffic` in three places: DEP is NODE-indexed,
437 * Fork and Join nodes produce outgoing links, and the flows arriving at a join
438 * along one sync group are combined with `mmap_max` rather than superposed --
439 * a join fires when its slowest branch delivers, which superposition, being the
440 * union of the two point processes, would get badly wrong.
441 *
442 * @param DEP node-indexed: `DEP[ind][r]`, 0-based over nodes
443 * @param fjSyncMap from `sn_build_fj_sync_map`
444 * @param sn the refreshed network struct
445 * @param config the `options.config` fields the traffic analyzer reads
446 */
447template <class T>
448std::vector<Mmap<T>> solver_mam_traffic_mmap(const qn::NetworkStruct<T>& sn, const DepTable<T>& DEP,
449 const TrafficConfig& config,
450 const FjSyncMap& fjSyncMap) {
451 namespace td = traffic_detail;
452 const std::size_t I = sn.nof_nodes(), R = sn.nclasses;
453 if (R == 0) throw InputError("solver_mam_traffic_mmap: the model has no classes");
454 if (fjSyncMap.node_sync.size() != I)
455 throw InputError("solver_mam_traffic_mmap: the sync map is not indexed over the nodes");
456
457 const td::NcsIndex x = td::build_ncs_index(sn);
458 const std::size_t Inc = x.inc_count;
459 const Matrix<T> rtncs = mc::dtmc_stochcomp(sn.rtnodes, x.keep);
460
461 std::vector<std::vector<std::size_t>> syncNCS(Inc, std::vector<std::size_t>(Inc, 0));
462 for (std::size_t a = 0; a < I; ++a) {
463 if (!x.is_ncs[a]) continue;
464 for (std::size_t b = 0; b < I; ++b)
465 if (x.is_ncs[b] && fjSyncMap.node_sync[a][b] > 0)
466 syncNCS[x.to_ncs[a] - 1][x.to_ncs[b] - 1] = fjSyncMap.node_sync[a][b];
467 }
468
469 std::vector<std::vector<Mmap<T>>> LINKS(Inc, std::vector<Mmap<T>>(Inc));
470 for (std::size_t a = 0; a < I; ++a) {
471 if (!x.is_ncs[a]) continue;
472 const qn::NodeType ty = sn.nodes[a].nodetype;
473 if (ty != qn::NodeType::Source && ty != qn::NodeType::Delay &&
474 ty != qn::NodeType::Queue && ty != qn::NodeType::Fork && ty != qn::NodeType::Join) {
475 td::reject_opaque_node(sn, a, true);
476 continue;
477 }
478 const std::size_t inc = x.to_ncs[a] - 1;
479 const Mmap<T> dep = td::superpose_classes(DEP, a, R, config);
480 const Matrix<T> Psplit = td::split_probabilities(rtncs, inc, Inc, R);
481 const std::vector<npfqn::Mmap<T>> F =
482 npfqn::npfqn_traffic_split_cs(td::to_flat(dep), Psplit);
483 for (std::size_t jnc = 0; jnc < Inc; ++jnc)
484 LINKS[inc][jnc] = mmap_normalize(td::from_flat(F[jnc]));
485 }
486
487 std::vector<Mmap<T>> ARV(I);
488 for (std::size_t a = 0; a < I; ++a) {
489 if (!x.is_ncs[a] || sn.nodes[a].nodetype == qn::NodeType::Source) continue;
490 const std::size_t inc = x.to_ncs[a] - 1;
491
492 // Ordered by group id, which is what MATLAB's unique() delivers.
493 std::map<std::size_t, std::vector<Mmap<T>>> groups;
494 std::vector<Mmap<T>> independent;
495 for (std::size_t jnc = 0; jnc < Inc; ++jnc) {
496 const Mmap<T>& lk = LINKS[jnc][inc];
497 if (lk.order() == 0) continue;
498 if (!(num_traits<T>::to_double(td::total_rate(lk)) > lang::GlobalConstants::FineTol))
499 continue;
500 const std::size_t gid = syncNCS[inc][jnc];
501 if (gid == 0) independent.push_back(lk);
502 else groups[gid].push_back(lk);
503 }
504
505 std::vector<Mmap<T>> flows;
506 for (const auto& g : groups) {
507 Mmap<T> synced = g.second.front();
508 for (std::size_t f = 1; f < g.second.size(); ++f) {
509 synced = mmap_normalize(mmap_max(synced, g.second[f], static_cast<unsigned>(config.fj_sync_q_len)));
510 if (synced.order() > config.space_max) synced = td::compress_or_refuse(synced);
511 }
512 flows.push_back(synced);
513 }
514 flows.insert(flows.end(), independent.begin(), independent.end());
515
516 if (flows.size() > 1) ARV[a] = npfqn::npfqn_traffic_merge(flows, config.merge);
517 else if (flows.size() == 1) ARV[a] = flows[0];
518 else ARV[a] = td::no_flow_arrival(LINKS, inc, R);
519 }
520 return ARV;
521}
522
523} // namespace mam
524} // namespace line
525
526#endif // LINE_SOLVERS_MAM_SOLVER_MAM_TRAFFIC_H
InputError(const std::string &what)
Definition error.h:105
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
The exception types the port throws.
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
The option and result types SolverMAM shares with its analyzers.
Maximum of two independent MAPs, and its marked k-stage generalization.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
Compression of a marked MAP into a smaller representation, and the two M3A primitives it is built fro...
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
@ DEP
a job departs
Definition lang_types.h:120
NodeType
Node kinds, with the values of MATLAB NodeType.
Definition lang_types.h:345
FjSyncMap sn_build_fj_sync_map(const qn::NetworkStruct< T > &sn)
sn_build_fj_sync_map.
Mmap< T > mmap_normalize(const Mmap< T > &in)
Clamp negative off-diagonal and per-class entries to zero and rebuild D1 and the diagonal of D0 from ...
Mmap< T > mmap_max(const Mmap< T > &a, const Mmap< T > &b, unsigned k)
MMAP of the maximum over k synchronization rounds of two independent MMAPs.
Definition map_max.h:88
@ MixtureOrder1
'default', 'mixture', 'mixture.order1'
std::vector< std::vector< Map< T > > > DepTable
DEP{i,r}, the departure process of class r from i in (D0,D1) form.
TrafficConfig traffic_config(const MamOptions &opt)
The traffic step's view of SolverOptions('MAM').
std::vector< T > mmap_lambda(const Mmap< T > &m)
Alias kept for parity with the MATLAB name.
std::vector< Mmap< T > > solver_mam_traffic_mmap(const qn::NetworkStruct< T > &sn, const DepTable< T > &DEP, const TrafficConfig &config, const FjSyncMap &fjSyncMap)
Port of solver_mam_traffic_mmap.m, the fork-join aware traffic step.
Mmap< T > mmap_compress(const Mmap< T > &in, MmapCompressMethod method)
Compress an MMAP (mmap_compress.m).
Mmap< T > mmap_super(const Mmap< T > &a, const Mmap< T > &b)
Superposition of two MMAPs: the phase process is the product chain, and the class list of the result ...
Definition mmap_lambda.h:88
std::vector< Mmap< T > > solver_mam_traffic(const qn::NetworkStruct< T > &sn, const DepTable< T > &DEP, const TrafficConfig &config)
Port of solver_mam_traffic.m.
Matrix< T > dtmc_stochcomp(const Matrix< T > &P, const std::vector< std::size_t > &keep)
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
std::vector< Mmap< T > > npfqn_traffic_split_cs(const Mmap< T > &MMAP, const Matrix< T > &P)
Splitting of a marked MAP departure flow with class switching.
std::vector< Matrix< T > > Mmap
An MMAP as the MATLAB cell {D0, D1, D1^(1), ..., D1^(R)}.
mam::Mmap< T > npfqn_traffic_merge(const std::vector< mam::Mmap< T > > &flows, const MergeConfig &config=MergeConfig())
Merge a list of MMAPs carrying the same classes.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
Superposition of several marked arrival flows into one.
Splitting of a marked MAP departure flow with class switching.
static constexpr double FineTol
Definition lang_types.h:823
sn_build_fj_sync_map: which incoming flows at a Join must be synchronized.
std::vector< std::size_t > join_of_group
1-based node index, by group
std::vector< std::size_t > fork_of_group
1-based node index, by group
std::vector< std::vector< std::size_t > > node_sync
The options SolverMAM reads.
Definition mam_types.h:30
An MMAP: the underlying MAP plus the per-class arrival matrices.
Definition mmap_lambda.h:45
std::size_t classes() const
Definition mmap_lambda.h:51
Matrix< T > D0
Definition mmap_lambda.h:46
Matrix< T > D1
Definition mmap_lambda.h:47
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
Definition mmap_lambda.h:48
std::size_t order() const
Definition mmap_lambda.h:50
The fields of options.config the traffic step reads.
std::size_t fj_sync_q_len
config.fj_sync_q_len, the join's synchronization queue; MATLAB's default.
MATLAB's config struct.