LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_tag.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_LANG_QN_FJ_TAG_H
6#define LINE_LANG_QN_FJ_TAG_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * Port of `matlab/src/api/fj/sn_fj_validate.m` and
12 * `matlab/src/io/@@ModelAdapter/fjtag.m`: the model-to-model transform that makes
13 * a closed fork-join network EXACTLY solvable by a Markov chain.
14 *
15 * WHY A TRANSFORM AND NOT A JOIN HANDLER. A join must release one parent job
16 * once ALL siblings of THAT parent have arrived. A per-class count vector at the
17 * join cannot express "of that parent": with two parents outstanding and two
18 * branches, the counts (1,1) are consistent both with one sibling from each
19 * parent (nothing may join) and with both siblings of one parent (a join must
20 * fire). Any solver that reads only counts has to guess, and guessing is what
21 * makes a join an approximation.
22 *
23 * WHAT THE TRANSFORM DOES. For each (fork f, class r) with matched join j, each
24 * branch b = 1..B and each TAG t = 1..T, it mints an auxiliary closed class
25 * A(f,r,b,t) with population 0. The tag names the parent job. A fork firing
26 * consumes one parent held at the fork and emits one sibling per branch in the
27 * classes of ONE tag -- the lowest free one -- and the join fires only when
28 * every branch of some tag is present. Identity matching is then exact even when
29 * siblings overtake one another, and the price is B*T extra classes per (fork,
30 * class): the state space grows accordingly, which is why this is the exact
31 * solver's route and `fj_mmt` remains the mean-value one.
32 *
33 * WHY T IS THE CHAIN POPULATION AND NOT THE CLASS POPULATION. Class switching
34 * OUTSIDE the fork-join section can concentrate the whole chain in class r -- a
35 * class switch on the edge into the fork does exactly that -- so the number of
36 * concurrently outstanding forked jobs is bounded by the chain, not by the
37 * declared population of r.
38 *
39 * WHY THE LOWEST FREE TAG. Tags are interchangeable, so without a canonical
40 * choice each firing would produce T! equivalent successors and the chain would
41 * carry a permutation group's worth of duplicate states. Allocating the lowest
42 * free tag makes exactly one `fjsync` entry enabled per (fork, class) in any
43 * state.
44 *
45 * HOW THIS DIFFERS FROM THE REFERENCE'S ROUTE. `fjtag.m` copies the Network
46 * OBJECT, adds `ClosedClass` objects, re-links it and calls `getStruct`. Here
47 * the transform is applied to the refreshed `NetworkStruct` directly, as
48 * `tag_chain` and `fj_mmt` already are: the auxiliary routing is written into P
49 * and one `refresh_struct()` re-derives the chains, capacities and rt. The
50 * post-edits that follow are the reference's own -- it overrides the visits and
51 * the auxiliary capacities after `getStruct` for the same reason, because the
52 * engines read them only as a zero-versus-nonzero support gate.
53 */
54
55#include <algorithm>
56#include <cmath>
57#include <cstddef>
58#include <limits>
59#include <map>
60#include <string>
61#include <vector>
62
65#include "line/util/error.h"
66
67namespace line {
68namespace qn {
69
70/** The augmented struct and everything needed to read its results back. */
71template <class T>
72struct FjTagged {
74 /** fjclassmap[a-1] is the ORIGINAL class of auxiliary class a, 0 for originals. */
75 std::vector<std::size_t> fjclassmap;
76 std::vector<std::size_t> fjforkmap, fjjoinmap, fjbranchmap, fjtagmap;
77 std::vector<FjSync<T>> fjsync;
78 std::map<std::size_t, FjJoinParam> joinparam; ///< keyed by 1-based Join node
79 std::size_t korig = 0;
80};
81
82namespace fj_detail {
83
84/** Total per-class node visits, `cellsum(sn.nodevisits)`. */
85template <class T>
86std::vector<std::vector<double>> node_visit_sum(const NetworkStruct<T>& sn) {
87 const std::size_t I = sn.nodes.size(), K = sn.nclasses;
88 std::vector<std::vector<double>> V(I, std::vector<double>(K, 0.0));
89 for (std::size_t c = 0; c < sn.nodevisits.size(); ++c)
90 for (std::size_t i = 0; i < I; ++i)
91 for (std::size_t r = 0; r < K; ++r)
92 V[i][r] += num_traits<T>::to_double(sn.nodevisits[c](i, r));
93 return V;
94}
95
96} // namespace fj_detail
97
98/**
99 * Port of `sn_fj_validate`: is this fork-join model inside the exact solver's
100 * reach?
101 *
102 * The checks here are the STRUCTURAL ones that can be asked of the original
103 * struct; the branch-level ones (class switching on a branch, nesting, sibling
104 * traps) can only be asked during branch discovery and are raised there.
105 */
106template <class T>
107void sn_fj_validate(const NetworkStruct<T>& sn, std::size_t tag_pool = 0) {
108 const std::vector<std::vector<double>> Vn = fj_detail::node_visit_sum(sn);
109 for (std::size_t f = 1; f <= sn.nodes.size(); ++f) {
110 if (sn.nodes[f - 1].nodetype != NodeType::Fork) continue;
111 std::size_t nj = 0;
112 for (std::size_t p = 0; p < sn.fj.size(); ++p)
113 if (sn.fj[p].first == f) ++nj;
114 if (nj == 0)
115 throw UnsupportedError(ErrorKind{"Fork"},
116 "sn_fj_validate: the Fork node '" + sn.nodes[f - 1].name +
117 "' has no matched Join; the exact fork-join implementation needs the pair, since "
118 "the tag pool is sized by the join that consumes it");
119 if (nj > 1)
120 throw UnsupportedError(ErrorKind{"Fork"}, "sn_fj_validate: the Fork node '" + sn.nodes[f - 1].name +
121 "' has several matched Joins, which the exact fork-join "
122 "implementation does not support");
123 // TASKS PER LINK. The tag-augmented construction carries an integer
124 // weight per branch, so a link whose count is an integer is served
125 // exactly, whether or not it differs from its siblings'. What it cannot
126 // carry is a count that is not fixed at build time: a DISTRIBUTION has
127 // to be drawn per firing, and the auxiliary class capacity would have to
128 // be its support's maximum with a different tag occupancy per draw.
129 const qn::NodeDef& fk = sn.nodes[f - 1];
130 const qn::ForkParam<T>* fp = sn.fork_param_of(f);
131 const double w = fk.tasks_per_link;
132 if (fp == 0) {
133 if (w != std::floor(w))
134 throw UnsupportedError(ErrorKind{"Fork"},
135 "sn_fj_validate: the Fork node '" + fk.name +
136 "' has a non-integer tasksPerLink; a sibling is a job and cannot be emitted "
137 "in fractions");
138 } else {
139 bool uncertain = false;
140 for (std::size_t k = 0; k < fp->fan_out_link.rows(); ++k)
141 for (std::size_t r = 0; r < fp->fan_out_link.cols(); ++r) {
142 const double p = num_traits<T>::to_double(fp->fan_out_prob(k, r));
143 if (p == 0.0) continue; // link not taken
144 if (!fp->fan_out_dist[k][r].disabled)
145 throw UnsupportedError(ErrorKind{"Fork"},
146 "sn_fj_validate: the Fork node '" + fk.name +
147 "' draws its tasks per link from a distribution, which the exact "
148 "fork-join implementation cannot carry: the tag occupancy would "
149 "differ per firing. Use SolverJMT or SolverLDES, which draw the "
150 "degree at the fork epoch");
151 const double lv = num_traits<T>::to_double(fp->fan_out_link(k, r));
152 if (lv != std::floor(lv))
153 throw UnsupportedError(ErrorKind{"Fork"},
154 "sn_fj_validate: the Fork node '" + fk.name +
155 "' has a non-integer tasksPerLink; a sibling is a job and cannot be "
156 "emitted in fractions");
157 // A PER-LINK COUNT is carried: `ForkInfo::wlink` holds one
158 // integer per branch and it reaches the auxiliary capacity,
159 // the join's required count and the emission list. The only
160 // thing that has to be fixed at build time is that it is an
161 // integer and does not change per firing, which is what the
162 // two tests above ask.
163 if (p != 1.0) uncertain = true;
164 }
165 // BRANCH PROBABILITIES. A branch that may decline makes the SET of
166 // siblings random, so a firing has 2^B outcomes and the join's
167 // required count is a function of which subset fired. The tag
168 // construction records no such per-firing state -- `required[r]` is
169 // fixed when the state space is built -- so this path would emit
170 // every branch anyway and answer with the CERTAIN-fork number. It is
171 // refused by name instead: silently returning the answer to a
172 // different model is the one outcome worth avoiding. MATLAB and
173 // Python refuse it here for the same reason.
174 if (uncertain)
175 throw UnsupportedError(ErrorKind{"Fork"},
176 "sn_fj_validate: the Fork node '" + fk.name +
177 "' has a branch activation probability below one, so the SET of siblings is "
178 "random and the tag construction fixes it when the state space is built. Use "
179 "SolverJMT or SolverLDES, which draw the activation at the fork epoch, or "
180 "SolverMVA, whose MMT transform sees the expected degree");
181 }
182 for (std::size_t r = 1; r <= sn.nclasses; ++r) {
183 if (!(Vn[f - 1][r - 1] > 0)) continue;
184 // The tag pool is the chain population, so the WHOLE chain must be
185 // closed -- an open class anywhere in it makes the pool unbounded.
186 std::size_t c = 0;
187 for (std::size_t cc = 0; cc < sn.chains.size(); ++cc)
188 if (sn.chains[cc][r - 1]) { c = cc + 1; break; }
189 bool open = !std::isfinite(sn.njobs()[r - 1]);
190 if (c != 0)
191 for (std::size_t s = 0; s < sn.nclasses; ++s)
192 if (sn.chains[c - 1][s] && !std::isfinite(sn.njobs()[s])) open = true;
193 // An OPEN chain has no population to size the tag pool by; SolverCTMC
194 // sizes it by its cutoff (`tag_pool`) and truncates the fork-join
195 // section there, as it truncates every open station.
196 if (open && tag_pool == 0)
197 throw UnsupportedError(ErrorKind{"Fork"},
198 "sn_fj_validate: class '" + sn.classes[r - 1].name +
199 "' is routed through the Fork node '" + sn.nodes[f - 1].name +
200 "' and belongs to an OPEN chain. The tag pool is sized by the chain "
201 "population, which is unbounded here; use SolverMVA (fj_mmt) or SolverSSA");
202 }
203 }
204 for (std::size_t j = 1; j <= sn.nodes.size(); ++j) {
205 if (sn.nodes[j - 1].nodetype != NodeType::Join) continue;
206 bool matched = false;
207 std::size_t fsrc = 0;
208 for (std::size_t p = 0; p < sn.fj.size(); ++p)
209 if (sn.fj[p].second == j) { matched = true; fsrc = sn.fj[p].first; }
210 if (!matched)
211 throw UnsupportedError(ErrorKind{"Fork"}, "sn_fj_validate: the Join node '" + sn.nodes[j - 1].name +
212 "' has no matched Fork");
213 // JOIN STRATEGY. PARTIAL is served: `FjJoinParam::required[r][b]` is a
214 // per-branch count, so a quorum is that count LOWERED and not a
215 // different mechanism. What it must be is REACHABLE -- a quorum above
216 // what the fork is certain to emit would never fire, and a join that
217 // never fires turns the chain into an absorbing set rather than an
218 // error.
219 typename std::map<std::size_t, typename NetworkStruct<T>::JoinDecl>::const_iterator jd =
220 sn.joindecl.find(j);
221 if (jd != sn.joindecl.end()) {
222 if (jd->second.strategy != lang::JoinStrategy::STD &&
223 jd->second.strategy != lang::JoinStrategy::PARTIAL)
224 throw UnsupportedError(ErrorKind{"Fork"},
225 "sn_fj_validate: only JoinStrategy STD and PARTIAL are supported by the exact "
226 "fork-join implementation; the Join node '" + sn.nodes[j - 1].name +
227 "' declares neither");
228 if (jd->second.strategy == lang::JoinStrategy::PARTIAL && jd->second.quorum > 0.0 &&
229 fsrc != 0) {
230 const qn::NodeDef& fk2 = sn.nodes[fsrc - 1];
231 const qn::ForkParam<T>* fp2 = sn.fork_param_of(fsrc);
232 double emitted = 0.0;
233 if (fp2 == 0) {
234 for (std::size_t nd = 1; nd <= sn.nodes.size(); ++nd)
235 for (std::size_t r = 1; r <= sn.nclasses; ++r)
236 if (num_traits<T>::to_double(sn.rtnodes((fsrc - 1) * sn.nclasses + r - 1,
237 (nd - 1) * sn.nclasses + r - 1)) >
238 0) {
239 emitted += fk2.tasks_per_link;
240 break;
241 }
242 } else {
243 for (std::size_t k = 0; k < fp2->fan_out_link.rows(); ++k)
244 for (std::size_t r = 0; r < fp2->fan_out_link.cols(); ++r)
245 if (num_traits<T>::to_double(fp2->fan_out_prob(k, r)) == 1.0)
246 emitted += num_traits<T>::to_double(fp2->fan_out_link(k, r));
247 }
248 if (jd->second.quorum > emitted)
249 throw UnsupportedError(ErrorKind{"Model"},
250 "sn_fj_validate: the Join node '" + sn.nodes[j - 1].name +
251 "' asks for more siblings than the Fork node '" + sn.nodes[fsrc - 1].name +
252 "' is certain to emit, so it could never fire");
253 }
254 }
255 }
256}
257
258/**
259 * Can the exact fork-join construction be asked for this model?
260 *
261 * The fork-join model class `sn_fj_validate` admits, asked as a predicate
262 * rather than thrown, so that a REPORT can reach it: `solver_ctmc_analyzer` and
263 * the SSA runner reach the SAME rules through `fj_tag`, which calls the
264 * validator on its first line. The message the validator throws is about "the
265 * exact fork-join implementation", which both share, so this predicate belongs
266 * beside it rather than inside either solver.
267 *
268 * IT WRAPS THE VALIDATOR RATHER THAN RESTATING IT, and that is the point: the
269 * rules are eight and they move (pairing, join strategy, tasks-per-link, branch
270 * probability, open classes through a fork), so a second copy would be a second
271 * thing to keep in step. There is exactly one body of rules and two ways in --
272 * one that throws, for the run, and this one, which answers.
273 *
274 * WHAT IT REFUSES AND WHY THE ANALYZER IS RIGHT TO. The fork-join PAIRING is a
275 * declaration carried by the Join (`Join(model, name, fork)` in all four
276 * codebases), not a derivation from the routing: a nested model such as
277 * fj_basic_nesting has two forks and two joins whose pairing the routing alone
278 * does not determine. So a Join built without naming its fork leaves `sn.fj`
279 * empty, and "has no matched Join" is the honest answer to a model that
280 * declares none -- not a topology test that failed to see one.
281 *
282 * @param sn the refreshed struct of the model
283 * @return an empty string when the fork-join construction may run
284 *
285 * @param tag_pool the CTMC cutoff that truncates an open chain's fork-join
286 * section, 0 for none (SolverSSA): an open chain through a Fork is then
287 * refused, as before
288 */
289template <class T>
290std::string sn_fj_supports(const NetworkStruct<T>& sn, std::size_t tag_pool = 0) {
291 bool any_fj = sn.has_fork();
292 for (std::size_t i = 0; i < sn.nodes.size() && !any_fj; ++i)
293 if (sn.nodes[i].nodetype == NodeType::Join) any_fj = true;
294 if (!any_fj) return std::string();
295 try {
296 sn_fj_validate(sn, tag_pool);
297 } catch (const line::Error& e) {
298 // the validator's own refusal, turned into an answer
299 return std::string(e.what());
300 }
301 return std::string();
302}
303
304/**
305 * Port of `ModelAdapter.fjtag`.
306 *
307 * OPEN CHAINS AND QUORUM JOINS (python `fjtag(model, tag_pool)`). An open chain
308 * has no population to size the tag pool by, so it is sized by the caller's
309 * truncation: at most `tag_pool` fork-join jobs are in progress at once, and a
310 * parent finding every tag in use waits at the Fork (`after_event_fork` refuses
311 * one more once it holds `tag_pool`). A QUORUM join releases its parent before
312 * the stragglers finish, so a closed chain's sibling groups in progress are not
313 * bounded by its population either: its pool is max(N, tag_pool), and without a
314 * truncation the join is refused by name. SolverCTMC passes its cutoff;
315 * SolverSSA passes none.
316 *
317 * @param sn a refreshed struct whose Fork nodes all have a matched Join
318 * @param tag_pool the truncation, 0 for none
319 */
320template <class T>
321FjTagged<T> fj_tag(const NetworkStruct<T>& sn, std::size_t tag_pool = 0) {
322 sn_fj_validate(sn, tag_pool);
323
324 const std::size_t K = sn.nclasses;
325 const std::size_t I = sn.nodes.size();
326 const std::vector<std::vector<double>> Vn = fj_detail::node_visit_sum(sn);
327 const T zero = num_traits<T>::from_int(0);
328 const double inf = std::numeric_limits<double>::infinity();
329
330 FjTagged<T> out;
331 out.korig = K;
332 out.V = sn;
333 NetworkStruct<T>& V = out.V;
334 V.isfjaugmented = true;
335
336 // A Fork holds the parent job for the instant between its arrival and the
337 // firing, so in the augmented model it is STATEFUL. `stateful_nodes` must
338 // stay ASCENDING, because `stateful_index` is a position in it and every
339 // network state row is indexed by that position.
340 for (std::size_t i = 0; i < I; ++i)
341 if (V.nodes[i].nodetype == NodeType::Fork) V.nodes[i].stateful = true;
342 V.stateful_nodes.clear();
343 for (std::size_t i = 0; i < I; ++i)
344 if (V.nodes[i].stateful) V.stateful_nodes.push_back(i + 1);
345
346 // One row per (fork, class): the branch structure the post-edits and the
347 // firing list are both built from.
348 struct ForkInfo {
349 std::size_t f = 0, j = 0, r = 0, w = 1;
350 /** Per-branch tasksPerLink, empty when every branch carries `w`. */
351 std::vector<std::size_t> wlink;
352 std::vector<std::size_t> branchheads;
353 std::vector<std::vector<std::size_t>> branchsets;
354 std::vector<std::vector<std::size_t>> auxmatrix; // B x T
355 bool open = false; ///< the chain is open
356 std::size_t quorum = 0; ///< siblings a quorum join waits for, 0 = standard join
357 };
358 std::vector<ForkInfo> info;
359
360 for (std::size_t f = 1; f <= I; ++f) {
361 if (sn.nodes[f - 1].nodetype != NodeType::Fork) continue;
362 std::size_t j = 0;
363 for (std::size_t p = 0; p < sn.fj.size(); ++p)
364 if (sn.fj[p].first == f) j = sn.fj[p].second;
365 const std::size_t w = static_cast<std::size_t>(sn.nodes[f - 1].tasks_per_link);
366
367 for (std::size_t r = 1; r <= K; ++r) {
368 if (!(Vn[f - 1][r - 1] > 0)) continue;
369 ForkInfo fi;
370 fi.f = f;
371 fi.j = j;
372 fi.r = r;
373 fi.w = w == 0 ? 1 : w;
374
375 // Branch heads: the nodes the fork routes class r to directly.
376 for (std::size_t nd = 1; nd <= I; ++nd)
377 if (num_traits<T>::to_double(sn.rtnodes((f - 1) * K + (r - 1),
378 (nd - 1) * K + (r - 1))) > 0)
379 fi.branchheads.push_back(nd);
380 const std::size_t B = fi.branchheads.size();
381 if (B < 2)
382 throw UnsupportedError(ErrorKind{"Fork"},
383 "fj_tag: the Fork node '" + sn.nodes[f - 1].name +
384 "' has a single output link for class '" + sn.classes[r - 1].name +
385 "'. A degenerate fork is not a fork -- remove it, or give it a second branch");
386
387 // PER-BRANCH TASKS PER LINK. `w` is the node-wide count and stays
388 // the mean the scalar slot carries; `wlink` is the count of the link
389 // that actually feeds branch b, and it is filled only when the
390 // branches disagree, so a plain fork keeps exactly the shape it had.
391 {
392 const qn::ForkParam<T>* fkn = sn.fork_param_of(f);
393 if (fkn != 0) {
394 std::vector<std::size_t> wv(B, 0);
395 bool uniform = true;
396 for (std::size_t b = 0; b < B; ++b) {
397 const double lv = num_traits<T>::to_double(
398 fkn->fan_out_link(fi.branchheads[b] - 1, r - 1));
399 wv[b] = static_cast<std::size_t>(lv + 0.5);
400 if (wv[b] == 0) wv[b] = 1;
401 if (wv[b] != wv[0]) uniform = false;
402 }
403 if (uniform) {
404 fi.w = wv[0];
405 } else {
406 fi.wlink = wv;
407 }
408 }
409 }
410
411 // Branch discovery: the class-r reachable closure from each head, up
412 // to but excluding the join.
413 fi.branchsets.assign(B, std::vector<std::size_t>());
414 for (std::size_t b = 0; b < B; ++b) {
415 std::vector<std::size_t> visitset(1, fi.branchheads[b]);
416 std::vector<std::size_t> frontier(1, fi.branchheads[b]);
417 while (!frontier.empty()) {
418 const std::size_t cn = frontier.front();
419 frontier.erase(frontier.begin());
420 if (sn.nodes[cn - 1].nodetype == NodeType::Fork)
421 throw UnsupportedError(ErrorKind{"Fork"},
422 "fj_tag: nested fork-join (the Fork node '" + sn.nodes[cn - 1].name +
423 "' sits on a branch of '" + sn.nodes[f - 1].name +
424 "') is not supported: a sibling would need a tag from each enclosing "
425 "fork and this transform mints one tag dimension");
426 if (sn.nodes[cn - 1].nodetype == NodeType::Join && cn != j)
427 throw UnsupportedError(ErrorKind{"Fork"},
428 "fj_tag: overlapping fork-join pairs (the Join node '" +
429 sn.nodes[cn - 1].name + "' sits on a branch of '" +
430 sn.nodes[f - 1].name + "', which closes at '" + sn.nodes[j - 1].name +
431 "') are not supported");
432 for (std::size_t nd = 1; nd <= I; ++nd)
433 for (std::size_t s = 1; s <= K; ++s) {
435 sn.rtnodes((cn - 1) * K + (r - 1), (nd - 1) * K + (s - 1))) >
436 0))
437 continue;
438 if (s != r)
439 throw UnsupportedError(ErrorKind{"Fork"},
440 "fj_tag: class switching between the Fork node '" +
441 sn.nodes[f - 1].name + "' and its Join is not supported: the "
442 "sibling classes are minted per ORIGINAL class, so a sibling "
443 "that switches has no auxiliary twin to switch into");
444 if (nd == j) continue;
445 if (std::find(visitset.begin(), visitset.end(), nd) == visitset.end()) {
446 visitset.push_back(nd);
447 frontier.push_back(nd);
448 }
449 }
450 }
451 // Every branch node must REACH the join. A sibling that can be
452 // trapped away from it never joins, so the parent never
453 // completes and the chain has an absorbing set the reference
454 // refuses rather than solves.
455 std::vector<std::size_t> canreach(1, j);
456 bool changed = true;
457 while (changed) {
458 changed = false;
459 for (std::size_t a = 0; a < visitset.size(); ++a) {
460 const std::size_t cn = visitset[a];
461 if (std::find(canreach.begin(), canreach.end(), cn) != canreach.end())
462 continue;
463 for (std::size_t b2 = 0; b2 < canreach.size(); ++b2)
465 sn.rtnodes((cn - 1) * K + (r - 1),
466 (canreach[b2] - 1) * K + (r - 1))) > 0) {
467 canreach.push_back(cn);
468 changed = true;
469 break;
470 }
471 }
472 }
473 for (std::size_t a = 0; a < visitset.size(); ++a)
474 if (std::find(canreach.begin(), canreach.end(), visitset[a]) == canreach.end())
475 throw UnsupportedError(ErrorKind{"Fork"},
476 "fj_tag: the Join node '" + sn.nodes[j - 1].name +
477 "' is unreachable from the branch node '" +
478 sn.nodes[visitset[a] - 1].name +
479 "'; a sibling trapped there never joins and its parent never completes");
480 fi.branchsets[b] = visitset;
481 }
482
483 // The tag pool: the population of the CHAIN, not of the class.
484 std::size_t c = 0;
485 for (std::size_t cc = 0; cc < sn.chains.size(); ++cc)
486 if (sn.chains[cc][r - 1]) { c = cc + 1; break; }
487 double tot = 0;
488 if (c == 0) {
489 tot = sn.njobs()[r - 1];
490 } else {
491 for (std::size_t s = 0; s < K; ++s)
492 if (sn.chains[c - 1][s]) tot += sn.njobs()[s];
493 }
494 // Siblings one firing emits, summed over the branches.
495 std::size_t emitted = 0;
496 for (std::size_t b = 0; b < B; ++b) emitted += fi.wlink.empty() ? fi.w : fi.wlink[b];
497 const std::size_t kq = ::line::sn::sn_join_quorum(sn, j, emitted);
498 fi.open = !std::isfinite(tot);
499 fi.quorum = kq < emitted ? kq : 0;
500 std::size_t Tt = 0;
501 if (fi.open) {
502 // the chain-open refusal is the validator's, when no pool is given
503 Tt = tag_pool;
504 } else if (fi.quorum > 0) {
505 if (tag_pool == 0)
506 throw UnsupportedError(ErrorKind{"JoinPartial"},
507 "A quorum (PARTIAL) join lets the stragglers of a fork outlive their parent, so "
508 "the native CTMC needs a cutoff to bound the sibling groups in progress.");
509 Tt = std::max(static_cast<std::size_t>(tot + 0.5), tag_pool);
510 } else {
511 Tt = static_cast<std::size_t>(tot + 0.5);
512 }
513 // An auxiliary class is closed, so it needs a station of its own route
514 // as reference: an open class's is the Source.
515 std::size_t aux_ref = sn.classes[r - 1].refstat;
516 if (fi.open) {
517 bool found = false;
518 for (std::size_t b = 0; b < B && !found; ++b)
519 for (std::size_t x = 0; x < fi.branchsets[b].size() && !found; ++x) {
520 const std::size_t cn = fi.branchsets[b][x];
521 if (sn.nodes[cn - 1].station != 0 && sn.nodes[cn - 1].nodetype != NodeType::Join) {
522 aux_ref = sn.nodes[cn - 1].station;
523 found = true;
524 }
525 }
526 }
527 if (Tt == 0)
528 throw InputError("fj_tag: the chain of class '" + sn.classes[r - 1].name +
529 "' routed through '" + sn.nodes[f - 1].name +
530 "' carries no jobs, so no fork firing can ever occur");
531
532 fi.auxmatrix.assign(B, std::vector<std::size_t>(Tt, 0));
533 for (std::size_t t = 1; t <= Tt; ++t)
534 for (std::size_t b = 0; b < B; ++b) {
535 JobClass ac = sn.classes[r - 1];
536 ac.name = sn.classes[r - 1].name + "_f" + std::to_string(f) + "_b" +
537 std::to_string(b + 1) + "_t" + std::to_string(t);
538 ac.type = JobClassType::CLOSED;
539 ac.population = 0.0;
540 ac.completes = false;
541 ac.is_ref_class = false;
542 ac.refstat = aux_ref;
543 const std::size_t a = V.add_class(ac);
544 fi.auxmatrix[b][t - 1] = a;
545
546 // The sibling is served exactly as the parent would have
547 // been, at every station of its own branch.
548 for (std::size_t x = 0; x < fi.branchsets[b].size(); ++x) {
549 const std::size_t cn = fi.branchsets[b][x];
550 const std::size_t ist = sn.nodes[cn - 1].station;
551 if (ist == 0 || sn.nodes[cn - 1].nodetype == NodeType::Join) continue;
552 V.set_service(ist, a, sn.service[ist - 1][r - 1]);
553 // ...and under the parent's SERVER RULES: its setup and
554 // delay-off laws and its server parallelism are per class
555 // too, so a sibling that did not inherit them would be
556 // refused at a setup station ("served without a setup and
557 // delay-off law") and would seize one server where the
558 // parent seizes n (python/JAR/MATLAB `fjtag`, 2026-11-24).
559 typename std::map<std::size_t, SetupDelayOffParam<T>>::iterator sdp =
560 V.setupparam.find(ist);
561 if (sdp != V.setupparam.end()) {
562 SetupDelayOffParam<T>& P = sdp->second;
563 if (r - 1 < P.setup.size() && !P.setup[r - 1].disabled) {
564 const lang::Distrib<T> law = P.setup[r - 1];
565 if (P.setup.size() < a) P.setup.resize(a, lang::Distrib<T>::disabled_dist());
566 P.setup[a - 1] = law;
567 }
568 if (r - 1 < P.delayoff.size() && !P.delayoff[r - 1].disabled) {
569 const lang::Distrib<T> law = P.delayoff[r - 1];
570 if (P.delayoff.size() < a)
571 P.delayoff.resize(a, lang::Distrib<T>::disabled_dist());
572 P.delayoff[a - 1] = law;
573 }
574 }
575 std::vector<std::size_t>& par = V.stations[ist - 1].server_parallelism;
576 if (r - 1 < par.size() && par[r - 1] > 1) {
577 const std::size_t deg = par[r - 1];
578 if (par.size() < a) par.resize(a, 1);
579 par[a - 1] = deg;
580 }
581 }
582 // The sibling routing is the parent's, restricted to the
583 // branch. The auxiliary class TERMINATES at the join: it has
584 // no outgoing row there, because the join consumes it and
585 // releases a parent instead.
586 for (std::size_t x = 0; x < fi.branchsets[b].size(); ++x) {
587 const std::size_t cn = fi.branchsets[b][x];
588 for (std::size_t nd = 1; nd <= I; ++nd) {
589 const T p = sn.get_route(r, r, cn, nd);
590 if (num_traits<T>::to_double(p) != 0) V.set_route(a, a, cn, nd, p);
591 }
592 }
593 }
594 info.push_back(fi);
595 }
596 }
597
598 const std::size_t Kaug = V.classes.size();
599 out.fjclassmap.assign(Kaug, 0);
600 out.fjforkmap.assign(Kaug, 0);
601 out.fjjoinmap.assign(Kaug, 0);
602 out.fjbranchmap.assign(Kaug, 0);
603 out.fjtagmap.assign(Kaug, 0);
604 for (std::size_t row = 0; row < info.size(); ++row) {
605 const ForkInfo& fi = info[row];
606 for (std::size_t b = 0; b < fi.auxmatrix.size(); ++b)
607 for (std::size_t t = 0; t < fi.auxmatrix[b].size(); ++t) {
608 const std::size_t a = fi.auxmatrix[b][t];
609 out.fjclassmap[a - 1] = fi.r;
610 out.fjforkmap[a - 1] = fi.f;
611 out.fjjoinmap[a - 1] = fi.j;
612 out.fjbranchmap[a - 1] = b + 1;
613 out.fjtagmap[a - 1] = t + 1;
614 }
615 }
616
617 // Pad every per-class table to the widened class set BEFORE the refresh, so
618 // that an untouched auxiliary class looks exactly as the refresh would have
619 // found it: unbounded capacity, derived drop rule, no routing strategy of its
620 // own. `add_class` grows only the service table.
621 for (std::size_t i = 0; i < V.stations.size(); ++i) {
622 Station<T>& st = V.stations[i];
623 if (st.classcap.size() < Kaug) st.classcap.resize(Kaug, inf);
624 if (st.droprule.size() < Kaug) st.droprule.resize(Kaug, 0);
625 if (!st.schedparam.empty() && st.schedparam.size() < Kaug)
626 st.schedparam.resize(Kaug, zero);
627 if (!st.cdscalingpeak.empty() && st.cdscalingpeak.size() < Kaug)
628 st.cdscalingpeak.resize(Kaug, zero);
629 if (!st.jdscalingpeak.empty() && st.jdscalingpeak.size() < Kaug)
630 st.jdscalingpeak.resize(Kaug, zero);
631 }
632 for (std::size_t row = 0; row < info.size(); ++row) {
633 const ForkInfo& fi = info[row];
634 for (std::size_t b = 0; b < fi.auxmatrix.size(); ++b)
635 for (std::size_t t = 0; t < fi.auxmatrix[b].size(); ++t) {
636 const std::size_t a = fi.auxmatrix[b][t];
637 for (std::size_t x = 0; x < fi.branchsets[b].size(); ++x) {
638 const std::size_t cn = fi.branchsets[b][x];
639 if (sn.nodes[cn - 1].station == 0) continue;
640 Station<T>& st = V.stations[sn.nodes[cn - 1].station - 1];
641 if (!st.schedparam.empty())
642 st.schedparam[a - 1] = st.schedparam[fi.r - 1];
643 }
644 }
645 }
646 for (std::size_t i = 0; i < I; ++i) {
647 NodeDef& nd = V.nodes[i];
648 if (nd.routing.empty()) continue;
649 if (nd.routing.size() < Kaug) nd.routing.resize(Kaug, RoutingStrategy::PROB);
650 for (std::size_t row = 0; row < info.size(); ++row) {
651 const ForkInfo& fi = info[row];
652 for (std::size_t b = 0; b < fi.auxmatrix.size(); ++b)
653 for (std::size_t t = 0; t < fi.auxmatrix[b].size(); ++t)
654 nd.routing[fi.auxmatrix[b][t] - 1] =
655 sn.nodes[i].routing.size() >= fi.r ? sn.nodes[i].routing[fi.r - 1]
656 : RoutingStrategy::PROB;
657 }
658 }
659 // An explicit ClassSwitch matrix is (nclasses x nclasses); widen it with the
660 // identity on the auxiliary block. A sibling never switches class -- the
661 // transform refuses a branch that switches -- so the identity is not a
662 // default, it is the only admissible row.
663 for (typename std::map<std::size_t, Matrix<T>>::iterator it = V.csmatrix.begin();
664 it != V.csmatrix.end(); ++it) {
665 const Matrix<T> old = it->second;
666 Matrix<T> C(Kaug, Kaug, zero);
667 for (std::size_t x = 0; x < old.rows() && x < Kaug; ++x)
668 for (std::size_t y = 0; y < old.cols() && y < Kaug; ++y) C(x, y) = old(x, y);
669 for (std::size_t a = K; a < Kaug; ++a) C(a, a) = num_traits<T>::from_int(1);
670 it->second = C;
671 }
672
673 V.nclasses = Kaug;
674 V.refresh_struct();
675
676 // ---- post-edits, exactly as `fjtag.m` applies them after getStruct ----
677 //
678 // WHY THE VISITS ARE OVERWRITTEN. An auxiliary class has population 0 and a
679 // routing block that terminates at the join, so it is a TRANSIENT class whose
680 // visit ratios are not defined by any traffic equation -- the refresh either
681 // divides by a zero visit at the reference station or spreads mass over a
682 // sub-stochastic block. The engines read auxiliary visits only as a
683 // zero-versus-nonzero support gate ("may this class appear at this node"), so
684 // that is what is written: 1 on the branch support, 0 elsewhere. The ORIGINAL
685 // classes' visits are restored from the pre-augmentation struct for the same
686 // reason: making the fork stateful changes the stateful index space and the
687 // fork's own row, which the original model's visits never had.
688 for (std::size_t r = 1; r <= K; ++r) {
689 std::size_t corig = 0, cnew = 0;
690 for (std::size_t cc = 0; cc < sn.chains.size(); ++cc)
691 if (sn.chains[cc][r - 1]) { corig = cc + 1; break; }
692 for (std::size_t cc = 0; cc < V.chains.size(); ++cc)
693 if (V.chains[cc][r - 1]) { cnew = cc + 1; break; }
694 if (corig == 0 || cnew == 0) continue;
695 for (std::size_t isf = 1; isf <= V.stateful_nodes.size(); ++isf) {
696 const std::size_t ind = V.stateful_nodes[isf - 1];
697 const std::size_t isf_old = sn.stateful_index(ind);
698 if (isf_old != 0) {
699 V.visits[cnew - 1](isf - 1, r - 1) = sn.visits[corig - 1](isf_old - 1, r - 1);
700 } else {
701 // The stateful Fork had no row before. Its visit is read only as
702 // a capacity gate, so a nonzero marker is all it needs.
703 V.visits[cnew - 1](isf - 1, r - 1) =
704 num_traits<T>::from_double(Vn[ind - 1][r - 1] > 0 ? 1.0 : 0.0);
705 }
706 }
707 for (std::size_t i = 0; i < I; ++i)
708 V.nodevisits[cnew - 1](i, r - 1) = sn.nodevisits[corig - 1](i, r - 1);
709 }
710 for (std::size_t row = 0; row < info.size(); ++row) {
711 const ForkInfo& fi = info[row];
712 std::size_t cnew = 0;
713 for (std::size_t cc = 0; cc < V.chains.size(); ++cc)
714 if (V.chains[cc][fi.r - 1]) { cnew = cc + 1; break; }
715 if (cnew == 0) continue;
716 for (std::size_t b = 0; b < fi.auxmatrix.size(); ++b) {
717 std::vector<std::size_t> support = fi.branchsets[b];
718 support.push_back(fi.j);
719 // THIS BRANCH's count, not the node-wide one. Capping the auxiliary
720 // class of a branch that was sent 3 tasks at the node-wide mean of 2
721 // makes the third sibling unplaceable, and the chain deadlocks with
722 // no error to say why.
723 const std::size_t wb = fi.wlink.empty() ? fi.w : fi.wlink[b];
724 for (std::size_t t = 0; t < fi.auxmatrix[b].size(); ++t) {
725 const std::size_t a = fi.auxmatrix[b][t];
726 for (std::size_t c2 = 0; c2 < V.nchains; ++c2) {
727 for (std::size_t x = 0; x < V.visits[c2].rows(); ++x)
728 V.visits[c2](x, a - 1) = zero;
729 for (std::size_t x = 0; x < V.nodevisits[c2].rows(); ++x)
730 V.nodevisits[c2](x, a - 1) = zero;
731 }
732 for (std::size_t i = 0; i < V.stations.size(); ++i)
733 V.classcap[i][a - 1] = 0.0;
734 for (std::size_t x = 0; x < support.size(); ++x) {
735 const std::size_t cn = support[x];
736 V.nodevisits[cnew - 1](cn - 1, a - 1) = num_traits<T>::from_int(1);
737 const std::size_t isf = V.stateful_index(cn);
738 if (isf != 0)
739 V.visits[cnew - 1](isf - 1, a - 1) = num_traits<T>::from_int(1);
740 // Each auxiliary class holds at most `tasksPerLink` siblings
741 // network-wide: one tag is outstanding at a time under STD.
742 if (V.nodes[cn - 1].station != 0)
743 V.classcap[V.nodes[cn - 1].station - 1][a - 1] =
744 static_cast<double>(wb);
745 }
746 }
747 }
748 FjJoinParam& jp = out.joinparam[fi.j];
749 jp.fork = fi.f;
750 if (std::find(jp.origclasses.begin(), jp.origclasses.end(), fi.r) == jp.origclasses.end())
751 jp.origclasses.push_back(fi.r);
752 jp.auxmatrix[fi.r] = fi.auxmatrix;
753 // Siblings of branch b a STANDARD firing consumes: the tasks that branch
754 // was sent -- the per-destination count when the fork declares one, the
755 // node-wide count otherwise.
756 std::vector<std::size_t> reqb(fi.auxmatrix.size(), fi.w);
757 if (!fi.wlink.empty())
758 for (std::size_t b = 0; b < reqb.size() && b < fi.wlink.size(); ++b)
759 reqb[b] = fi.wlink[b];
760 jp.required[fi.r] = reqb;
761 // QUORUM (JoinStrategy.PARTIAL): the join fires on the first k of the
762 // tag's siblings, whichever branches they come from, and the stragglers
763 // are discarded when they reach it (SolverLDES). One debt counter per
764 // tag, leading the Join row, says how many stragglers of a fired tag are
765 // still on the branches (`after_event_join`). Lowering the per-branch
766 // count instead, as this port did before, waits for k siblings on EVERY
767 // branch, which is a different join.
768 if (fi.quorum > 0) {
769 jp.quorum[fi.r] = fi.quorum;
770 jp.debtoff[fi.r] = jp.debtwidth;
771 jp.debtwidth += fi.auxmatrix.empty() ? 0 : fi.auxmatrix[0].size();
772 }
773 // An OPEN class never visits its branches (its siblings do), so its
774 // infinite class capacity there would leave the branch station unbounded
775 // and its ordered buffer at the width of the empty initial row: the
776 // station would hold at most S+1 siblings whatever the tag pool.
777 if (fi.open)
778 for (std::size_t b = 0; b < fi.branchsets.size(); ++b)
779 for (std::size_t x = 0; x < fi.branchsets[b].size(); ++x) {
780 const std::size_t cn = fi.branchsets[b][x];
781 if (sn.nodes[cn - 1].station != 0 && sn.nodes[cn - 1].nodetype != NodeType::Join)
782 V.classcap[sn.nodes[cn - 1].station - 1][fi.r - 1] = 0.0;
783 }
784 }
785 // An open chain's branch station is bounded by its tags: with every class
786 // capacity finite, an unbounded station takes their sum (python fjtag).
787 for (std::size_t i = 0; i < V.stations.size() && i < V.cap.size(); ++i) {
788 if (std::isfinite(V.cap[i])) continue;
789 bool allfin = true;
790 double rowsum = 0.0;
791 for (std::size_t a = 0; a < V.classcap[i].size(); ++a) {
792 if (!std::isfinite(V.classcap[i][a])) allfin = false;
793 else rowsum += V.classcap[i][a];
794 }
795 if (allfin) V.cap[i] = rowsum;
796 }
797
798 // The firing list: one entry per (fork, class, tag).
799 for (std::size_t row = 0; row < info.size(); ++row) {
800 const ForkInfo& fi = info[row];
801 const std::size_t Tt = fi.auxmatrix.empty() ? 0 : fi.auxmatrix[0].size();
802 for (std::size_t t = 1; t <= Tt; ++t) {
803 FjSync<T> e;
804 e.fork = fi.f;
805 e.join = fi.j;
806 e.cls = fi.r;
807 e.tag = t;
808 e.branchheads = fi.branchheads;
809 for (std::size_t b = 0; b < fi.auxmatrix.size(); ++b)
810 e.auxclasses.push_back(fi.auxmatrix[b][t - 1]);
811 e.auxall = fi.auxmatrix;
812 e.weight = fi.w;
813 e.weightlink = fi.wlink; // empty whenever every branch agrees
814 out.fjsync.push_back(e);
815 }
816 }
817
818 V.fjclassmap = out.fjclassmap;
819 V.fjjoinparam = out.joinparam;
820 return out;
821}
822
823} // namespace qn
824} // namespace line
825
826#endif // LINE_LANG_QN_FJ_TAG_H
Base error for the multiprecision C++ port.
Definition error.h:73
InputError(const std::string &what)
Definition error.h:105
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
UnsupportedError(const std::string &what)
Definition error.h:119
A network plus its refreshed NetworkStruct.
void set_route(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
P{r,s}(i,j) = p, with 1-based NODE and class indices.
std::size_t add_class(const JobClass &cl)
Add a class and grow the service table.
std::vector< Matrix< T > > nodevisits
(nchains) each (nnodes x nclasses)
std::size_t stateful_index(std::size_t ind) const
1-based stateful index of node ind, 0 when the node is not stateful.
std::vector< std::size_t > stateful_nodes
1-based node indices, ascending
std::vector< std::vector< bool > > chains
(nchains x nclasses)
std::map< std::size_t, SetupDelayOffParam< T > > setupparam
Setup / delay-off, keyed by 1-based STATION index.
std::map< std::size_t, FjJoinParam > fjjoinparam
sn.nodeparam{j}.fj for each Join node: the tag matrix and the required sibling multiplicity after_eve...
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
void refresh_struct()
The whole chain, in MATLAB's refreshStruct order.
void set_service(std::size_t station, std::size_t cls, const Distrib< T > &d)
std::vector< NodeDef > nodes
every node, in creation order
std::vector< std::vector< double > > classcap
std::map< std::size_t, Matrix< T > > csmatrix
The class-switch matrix of a ClassSwitch node, by 1-based NODE index.
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
std::vector< std::size_t > fjclassmap
sn.fjclassmap: the ORIGINAL class of each auxiliary sibling class, 0 for an original class.
bool isfjaugmented
sn.isfjaugmented: this struct came out of fj_tag, so its Fork nodes are STATEFUL and its Join nodes c...
The exception types the port throws.
std::string sn_fj_supports(const NetworkStruct< T > &sn, std::size_t tag_pool=0)
Can the exact fork-join construction be asked for this model?
Definition fj_tag.h:290
FjTagged< T > fj_tag(const NetworkStruct< T > &sn, std::size_t tag_pool=0)
Port of ModelAdapter.fjtag.
Definition fj_tag.h:321
void sn_fj_validate(const NetworkStruct< T > &sn, std::size_t tag_pool=0)
Port of sn_fj_validate: is this fork-join model inside the exact solver's reach?
Definition fj_tag.h:107
std::size_t sn_join_quorum(const qn::NetworkStruct< T > &sn, std::size_t joinNode, std::size_t nbranches)
The number of siblings the Join node joinNode (1-based) fires on, out of nbranches forked.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
Quorum joins: how many siblings a Join fires on, and what that drops.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
std::string name
Definition error.h:38
static Distrib disabled_dist()
sn.nodeparam{j}.fj: what a Join node needs to fire on identity.
std::vector< std::size_t > origclasses
std::map< std::size_t, std::size_t > quorum
QUORUM joins (JoinStrategy.PARTIAL), keyed by original class: the join fires on the first quorum[r] o...
std::map< std::size_t, std::vector< std::vector< std::size_t > > > auxmatrix
std::map< std::size_t, std::size_t > debtoff
std::map< std::size_t, std::vector< std::size_t > > required
One fork firing synchronization: sn.fjsync{k}.
std::size_t fork
1-based Fork node
std::vector< std::size_t > weightlink
Per-branch tasksPerLink, EMPTY when every branch carries weight.
std::size_t weight
tasksPerLink: siblings emitted per branch
std::vector< std::size_t > branchheads
1-based node per branch
std::size_t join
1-based Join node that closes it
std::size_t cls
1-based ORIGINAL class being forked
std::vector< std::vector< std::size_t > > auxall
(B x T) every auxiliary class of this (fork, class), for the tag scan.
std::vector< std::size_t > auxclasses
the tag's auxiliary class per branch
std::size_t tag
1-based tag this entry allocates
The augmented struct and everything needed to read its results back.
Definition fj_tag.h:72
std::vector< FjSync< T > > fjsync
Definition fj_tag.h:77
NetworkStruct< T > V
Definition fj_tag.h:73
std::size_t korig
Definition fj_tag.h:79
std::vector< std::size_t > fjjoinmap
Definition fj_tag.h:76
std::vector< std::size_t > fjforkmap
Definition fj_tag.h:76
std::vector< std::size_t > fjbranchmap
Definition fj_tag.h:76
std::map< std::size_t, FjJoinParam > joinparam
keyed by 1-based Join node
Definition fj_tag.h:78
std::vector< std::size_t > fjclassmap
fjclassmap[a-1] is the ORIGINAL class of auxiliary class a, 0 for originals.
Definition fj_tag.h:75
std::vector< std::size_t > fjtagmap
Definition fj_tag.h:76
Variable forking levels, the twin of MATLAB sn.nodeparam{f}.fanOutLink / .fanOutProb / ....
std::vector< std::vector< lang::Distrib< T > > > fan_out_dist
One job class of the network.
std::size_t refstat
1-based reference station
bool completes
Whether passage through the reference station is a COMPLETION.
double population
infinite for an open class
bool is_ref_class
marks the chain's reference class
A node of the network.
std::vector< RoutingStrategy > routing
sn.routing, per class.
double tasks_per_link
Fork.output.tasksPerLink == MATLAB sn.nodeparam{f}.fanOut: how many tasks a fork emits per outgoing l...
Setup and delay-off of a station that powers down when it falls idle.
One station of the network.
std::vector< T > jdscalingpeak
sn.jdscalingpeak for this station: the declared peak joint-dependent scaling per class.
std::vector< int > droprule
Per-class blocking rule as an INT, with 0 meaning "not set".
std::vector< T > cdscalingpeak
sn.cdscalingpeak for this station: the DECLARED peak rate scaling per class, empty when the station i...
std::vector< T > schedparam
sn.schedparam, per class: the DPS / GPS weight, or the SEPT / LEPT rank.
std::vector< double > classcap
Per-class buffer from setChainCapacity; infinite where unset.