LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
feature_set.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_FEATURE_SET_H
6#define LINE_LANG_QN_FEATURE_SET_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * The language-feature gate: what a MODEL uses against what a SOLVER declares.
12 *
13 * SCOPE. This is the port of three MATLAB pieces that together form the single
14 * universal check every `runAnalyzer` performs before it computes anything:
15 *
16 * matlab/src/solvers/SolverFeatureSet.m the canonical name registry
17 * and the SUPPORTS comparison
18 * matlab/src/lang/@@MNetwork/getUsedLangFeatures.m the USED side
19 * matlab/src/solvers/@@NetworkSolver/NetworkSolver.m:169-216
20 * runAnalyzerChecks, which
21 * raises line_error naming the
22 * offending feature
23 *
24 * WHY IT EXISTS. Without it, every refusal is ad hoc and per solver, and the
25 * constructs nobody wrote a refusal for are neither handled nor rejected: the
26 * solver returns numbers for a model the user did not describe. A finite
27 * capacity region silently ignored is not a small error, it is a different
28 * model. A generic "unsupported model" is nearly as bad, because the user
29 * cannot tell which construct to remove, so `supports` returns the offending
30 * FEATURES and a reason naming them.
31 *
32 * THE ASYMMETRY THAT MATTERS. A feature DECLARED but not implemented is worse
33 * than one left undeclared: the undeclared one produces a clean refusal, the
34 * over-declared one produces a wrong number. So a C++ solver's declared set is
35 * what its C++ code actually handles, never a transcription of the MATLAB set.
36 *
37 * WHAT THE REGISTRY IS FOR. `Feature` lists every name in
38 * SolverFeatureSet.fields, including names this port can never emit. That is
39 * deliberate and is the reference's own convention: SUPPORTS iterates the
40 * registry, so a capability name MISSING from the registry is invisible to the
41 * gate and passes as if the capability were absent. Keeping the registry
42 * complete keeps that failure mode out.
43 *
44 * WHAT NetworkStruct CANNOT EXPRESS. `used_lang_features` derives each feature
45 * from a field that exists. Where MATLAB has a feature and NetworkStruct has no
46 * field for it, the feature is NEVER emitted, and that is recorded by name at
47 * the point where it would have been derived rather than faked from a proxy.
48 * The list is SetupDelayOff, Reneging, Balking, QueueingPlace and
49 * CacheRetrieval's MATLAB-only cousins; see the comments in
50 * used_lang_features. Breakdown LEFT that list on 2026-08-15, when
51 * `NetworkStruct::breakdownparam` gave it a field to be derived from.
52 */
53
54#include <cmath>
55#include <cstddef>
56#include <algorithm>
57#include <initializer_list>
58#include <sstream>
59#include <string>
60#include <vector>
61
64#include "line/util/error.h"
65
66namespace line {
67namespace qn {
68
69// ---------------------------------------------------------------------------
70// The canonical feature registry
71// ---------------------------------------------------------------------------
72
73/**
74 * SolverFeatureSet.fields, in its order, as an X-list.
75 *
76 * The order is the reference's and is kept so that the two lists can be
77 * diffed entry by entry; `supports` reports in this order too, which makes the
78 * reason string reproducible.
79 */
80#define LINE_QN_FEATURE_LIST(X) \
81 X(ClassSwitch) \
82 X(Cache) \
83 X(Delay) \
84 X(DelayStation) \
85 X(Fork) \
86 X(Join) \
87 X(Logger) \
88 X(Place) \
89 X(QueueingPlace) \
90 X(Queue) \
91 X(JobSink) \
92 X(Sink) \
93 X(Source) \
94 X(Router) \
95 X(Transition) \
96 X(Coxian) \
97 X(Cox2) \
98 X(APH) \
99 X(Det) \
100 X(Disabled) \
101 X(Erlang) \
102 X(Exp) \
103 X(Gamma) \
104 X(HyperExp) \
105 X(Immediate) \
106 X(Lognormal) \
107 X(MAP) \
108 X(DMAP) \
109 X(MMAP) \
110 X(BMAP) \
111 X(MMPP2) \
112 X(NHPP) \
113 X(MAPt) \
114 X(PHt) \
115 X(EmpiricalCdf) \
116 X(Expolynomial) \
117 X(Normal) \
118 X(Pareto) \
119 X(PH) \
120 X(ME) \
121 X(RAP) \
122 X(Replayer) \
123 X(Trace) \
124 X(Uniform) \
125 X(Weibull) \
126 X(LogLogistic) \
127 X(MassAtOrigin) \
128 X(Defective) \
129 X(Bernoulli) \
130 X(Binomial) \
131 X(Geometric) \
132 X(Poisson) \
133 X(DiscreteSampler) \
134 X(DiscreteUniform) \
135 X(Empirical) \
136 X(GMM) \
137 X(MMDP) \
138 X(MMDP2) \
139 X(MMPP) \
140 X(MultivariateNormal) \
141 X(NegBinomial) \
142 X(Prior) \
143 X(Zipf) \
144 X(StatelessClassSwitcher) \
145 X(CacheClassSwitcher) \
146 X(CacheRetrieval) \
147 X(CacheItemSize) \
148 X(InfiniteServer) \
149 X(Forker) \
150 X(Joiner) \
151 X(LogTunnel) \
152 X(SharedServer) \
153 X(Buffer) \
154 X(Region) \
155 X(Linkage) \
156 X(Enabling) \
157 X(Inhibiting) \
158 X(Timing) \
159 X(Firing) \
160 X(Storage) \
161 X(RandomSource) \
162 X(Dispatcher) \
163 X(Server) \
164 X(ServiceTunnel) \
165 X(RoutingStrategy_PROB) \
166 X(RoutingStrategy_RAND) \
167 X(RoutingStrategy_RROBIN) \
168 X(RoutingStrategy_WRROBIN) \
169 X(RoutingStrategy_JSQ) \
170 X(RoutingStrategy_SQ) \
171 X(RoutingStrategy_SDR) \
172 X(SchedStrategy_INF) \
173 X(SchedStrategy_FCFS) \
174 X(SchedStrategy_FCFSPR) \
175 X(SchedStrategy_FCFSPI) \
176 X(SchedStrategy_FCFSPRIO) \
177 X(SchedStrategy_FCFSPRPRIO) \
178 X(SchedStrategy_FCFSPIPRIO) \
179 X(SchedStrategy_LCFS) \
180 X(SchedStrategy_LCFSPR) \
181 X(SchedStrategy_LCFSPI) \
182 X(SchedStrategy_LCFSPRIO) \
183 X(SchedStrategy_LCFSPRPRIO) \
184 X(SchedStrategy_LCFSPIPRIO) \
185 X(SchedStrategy_SEPT) \
186 X(SchedStrategy_LEPT) \
187 X(SchedStrategy_SJF) \
188 X(SchedStrategy_LJF) \
189 X(SchedStrategy_SRPT) \
190 X(SchedStrategy_SRPTPRIO) \
191 X(SchedStrategy_PSJF) \
192 X(SchedStrategy_FB) \
193 X(SchedStrategy_LRPT) \
194 X(SchedStrategy_SETF) \
195 X(SchedStrategy_FSP) \
196 X(SchedStrategy_PAS) \
197 X(SchedStrategy_OI) \
198 X(SchedStrategy_PS) \
199 X(SchedStrategy_DPS) \
200 X(SchedStrategy_GPS) \
201 X(SchedStrategy_PSPRIO) \
202 X(SchedStrategy_DPSPRIO) \
203 X(SchedStrategy_GPSPRIO) \
204 X(SchedStrategy_SIRO) \
205 X(SchedStrategy_HOL) \
206 X(SchedStrategy_EXT) \
207 X(SchedStrategy_POLLING) \
208 X(SchedStrategy_EDD) \
209 X(SchedStrategy_EDF) \
210 X(SchedStrategy_LPS) \
211 X(ReplacementStrategy_RR) \
212 X(ReplacementStrategy_FIFO) \
213 X(ReplacementStrategy_SFIFO) \
214 X(ReplacementStrategy_LRU) \
215 X(ReplacementStrategy_HLRU) \
216 X(ReplacementStrategy_CLIMB) \
217 X(ReplacementStrategy_QLRU) \
218 X(ClosedClass) \
219 X(OpenClass) \
220 X(SelfLoopingClass) \
221 X(OpenSignal) \
222 X(ClosedSignal) \
223 X(SignalType_NEGATIVE) \
224 X(SignalType_REPLY) \
225 X(SignalType_CATASTROPHE) \
226 X(SignalBatchRemoval) \
227 X(SignalRemovalPolicy) \
228 X(BatchArrival) \
229 X(LoadDependence) \
230 X(ClassDependence) \
231 X(JointDependence) \
232 X(GlobalDependence) \
233 X(SetupDelayOff) \
234 X(ServerParallelism) \
235 X(Retrial) \
236 X(Balking) \
237 X(Reneging) \
238 X(Breakdown) \
239 X(HeteroServers) \
240 X(DepartureDiscipline) \
241 X(JoinPartial) \
242 X(Host) \
243 X(Processor) \
244 X(Task) \
245 X(Entry) \
246 X(Activity) \
247 X(SyncCall) \
248 X(AsyncCall) \
249 X(ActivityPrecedence_PRE_SEQ) \
250 X(ActivityPrecedence_POST_SEQ) \
251 X(ActivityPrecedence_PRE_AND) \
252 X(ActivityPrecedence_POST_AND) \
253 X(ActivityPrecedence_PRE_OR) \
254 X(ActivityPrecedence_POST_OR) \
255 X(SchedStrategy_REF) \
256 /* Layered cache-queueing models: a CacheTask holds a segmented cache whose
257 items are ItemEntry entries, and a read is a call to one of them whose
258 bound activity branches on a POST_CACHE precedence into hit and miss.
259 Registered in all four codebases because SolverLDES.getLNFeatureSet
260 DECLARES all three, and an unregistered name makes setTrue line_error --
261 so that whole feature set threw before it could compare anything. */ \
262 X(CacheTask) \
263 X(ItemEntry) \
264 X(ActivityPrecedence_POST_CACHE) \
265 /* Variable forking levels. A Fork emits tasksPerLink jobs on every
266 outgoing link; these three name the ways that degree stops being one
267 number. ForkFanoutVector: the count differs by destination or by class
268 (sn.nodeparam{f}.fanOutLink). ForkFanoutRandom: the count is a draw from
269 a DiscreteSampler, redrawn per link and per forked job
270 (sn.nodeparam{f}.fanOutDist). ForkBranchProbability: a branch fires only
271 with probability p, so the SIBLING COUNT is random even when each link
272 carries a fixed number (sn.nodeparam{f}.fanOutProb). Appended at the tail
273 so every earlier index is unchanged. */ \
274 X(ForkFanoutVector) \
275 X(ForkFanoutRandom) \
276 X(ForkBranchProbability) \
277 /* Ported from MATLAB SolverFeatureSet.m (2026-09-05), in this order, so
278 that every earlier enumerator is unchanged. Both are "having something"
279 properties the registry could not name, so every rule about them lived
280 only in structural predicates and was invisible to the gate.
281 MultiServer: a finite-server station serving more than one job at once,
282 i.e. a station whose nservers is finite and > 1 (a Delay / INF station is
283 not one), which `NetworkStruct::has_multi_server` already tests.
284 FiniteCapacity: a station or per-class buffer that can BIND, exactly the
285 condition `has_binding_capacity` tests (station cap / classcap below the
286 population that can reach it; an open class always binds; a Cache model
287 is exempt), which is also what `check_binding_capacity` refuses on. */ \
288 X(MultiServer) \
289 X(FiniteCapacity) \
290 X(MPH) \
291 X(MMAPt) \
292 X(MPHt) \
293 /* Marked + scheduled + BATCHED; see process_is_batch. */ \
294 X(BMMAPt) \
295 /* An FSPN fluid place or fluid arc; appended at the tail so every earlier id stays pinned. */ \
296 X(FluidPlace) \
297 /* Polling extensions (Haverkort ch. 9, 16.2), appended at the tail in all
298 four codebases. PollingTable: a visit table that repeats or reorders
299 classes (set_polling_table). PollingOrder: a load-dependent next queue,
300 skip-empty, longest-queue-first or threshold (set_polling_order).
301 PollingTimer: time-limited visits, a local holding timer or a global
302 timed token (set_polling_timer). */ \
303 X(PollingTable) \
304 X(PollingOrder) \
305 X(PollingTimer) \
306 /* Round robin with a finite quantum (Haverkort 1998, Sect. 6.4),
307 appended at the tail so every earlier id stays pinned. */ \
308 X(SchedStrategy_RR) \
309 /* NNPP, the nonstationary non-Poisson arrival process (thinning + SCIATA),
310 appended at the tail so every earlier id stays pinned. LDES only. */ \
311 X(NNPP) \
312 /* Non-persistent retrial customers (join / persistence probabilities)
313 and orbital search, appended at the tail so every earlier id stays
314 pinned. MATLAB lists them after Retrial. CTMC and SSA only. */ \
315 X(RetrialNonPersistent) \
316 X(OrbitalSearch)
317
318/** One language feature. COUNT is the registry size and is not a feature. */
319enum class Feature : int {
320#define LINE_QN_FEATURE_ENUM(id) id,
322#undef LINE_QN_FEATURE_ENUM
324};
325
326/** The number of registered features, MATLAB `numel(SolverFeatureSet.fields)`. */
327inline constexpr std::size_t feature_count() { return static_cast<std::size_t>(Feature::COUNT); }
328
329/** The canonical registry name, byte for byte the MATLAB field name. */
330inline const char* feature_name(Feature f) {
331 switch (f) {
332#define LINE_QN_FEATURE_NAME(id) \
333 case Feature::id: \
334 return #id;
336#undef LINE_QN_FEATURE_NAME
337 default:
338 return "Unknown";
339 }
340}
341
342/**
343 * A human-readable phrase for the reason string, e.g. "a Finite Capacity
344 * Region". Structured names are derived from their suffix so that the whole
345 * SchedStrategy_ / RoutingStrategy_ / ReplacementStrategy_ / SignalType_ /
346 * ActivityPrecedence_ families need no per-entry table to stay in step.
347 */
348inline std::string feature_phrase(Feature f) {
349 switch (f) {
350 case Feature::Region: return "a Finite Capacity Region";
351 case Feature::Fork: return "a Fork node";
352 case Feature::Join: return "a Join node";
353 case Feature::Forker: return "a fork output section";
354 case Feature::ForkFanoutVector:
355 return "a fork whose tasks per link differ by destination or by class";
356 case Feature::ForkFanoutRandom:
357 return "a fork whose tasks per link are drawn from a distribution";
358 case Feature::ForkBranchProbability:
359 return "a fork whose branches fire only with a probability";
360 case Feature::Joiner: return "a join input section";
361 case Feature::Cache: return "a Cache node";
362 case Feature::CacheRetrieval: return "a delayed-hit cache retrieval system";
363 case Feature::CacheItemSize: return "per-item storage costs with per-list cost caps";
364 case Feature::ClassSwitch: return "a ClassSwitch node";
365 case Feature::Router: return "a Router node";
366 case Feature::Logger: return "a Logger node";
367 case Feature::Source: return "a Source node";
368 case Feature::Sink: return "a Sink node";
369 case Feature::Place: return "an SPN Place";
370 case Feature::QueueingPlace: return "a queueing SPN Place";
371 case Feature::Transition: return "an SPN Transition";
372 case Feature::Inhibiting: return "an SPN inhibitor arc";
373 case Feature::FluidPlace: return "an FSPN fluid place or fluid arc";
374 case Feature::PollingTable: return "a polling table (Queue.setPollingTable)";
375 case Feature::PollingOrder: return "a load-dependent polling order (Queue.setPollingOrder)";
376 case Feature::PollingTimer: return "a time-limited polling visit (Queue.setPollingTimer)";
377 case Feature::Retrial: return "a retrial orbit";
378 case Feature::RetrialNonPersistent: return "non-persistent retrial customers (set_orbit_persistence)";
379 case Feature::OrbitalSearch: return "orbital search at a retrial station (set_orbital_search)";
380 case Feature::Balking: return "job balking";
381 case Feature::Reneging: return "job reneging";
382 case Feature::Breakdown: return "server breakdowns";
383 case Feature::SetupDelayOff: return "server setup and delay-off times";
384 case Feature::LoadDependence: return "load-dependent service rates";
385 case Feature::ClassDependence: return "class-dependent service rates";
386 case Feature::JointDependence: return "joint-dependent service rates";
387 case Feature::GlobalDependence: return "globally state-dependent (Whittle) service rates";
388 case Feature::BatchArrival: return "batch arrivals";
389 case Feature::OpenSignal: return "an open G-network signal class";
390 case Feature::ClosedSignal: return "a closed G-network signal class";
391 case Feature::SignalBatchRemoval: return "a signal batch-removal distribution";
392 case Feature::SignalRemovalPolicy: return "a non-random signal removal policy";
393 case Feature::OpenClass: return "an open job class";
394 case Feature::ClosedClass: return "a closed job class";
395 case Feature::SelfLoopingClass: return "a self-looping job class";
396 case Feature::Queue: return "a Queue station";
397 case Feature::Delay:
398 case Feature::DelayStation: return "a Delay station";
399 // "multi-server" is the vocabulary every other refusal in this tree uses
400 // (jmt_method_refusal, ba, ssa nrm), and the gate reports must agree with them.
401 case Feature::MultiServer: return "a multi-server station";
402 case Feature::FiniteCapacity: return "a finite station or per-class buffer that binds";
403 default: break;
404 }
405 const std::string nm = feature_name(f);
406 const std::size_t us = nm.find('_');
407 if (us != std::string::npos) {
408 const std::string head = nm.substr(0, us), tail = nm.substr(us + 1);
409 if (head == "SchedStrategy") return "the " + tail + " scheduling discipline";
410 if (head == "RoutingStrategy") return "the " + tail + " routing strategy";
411 if (head == "ReplacementStrategy") return "the " + tail + " cache replacement policy";
412 if (head == "SignalType") return tail + " signals";
413 if (head == "ActivityPrecedence") return "the " + tail + " activity precedence";
414 }
415 return "the " + nm + " feature";
416}
417
418// ---------------------------------------------------------------------------
419// The set
420// ---------------------------------------------------------------------------
421
422/** A subset of the registry: MATLAB's SolverFeatureSet, whose `list` is a flag per field. */
424public:
425 FeatureSet() : bits_(feature_count(), false) {}
426
428 if (f != Feature::COUNT) bits_[static_cast<std::size_t>(f)] = true;
429 return *this;
430 }
431 FeatureSet& set(std::initializer_list<Feature> fs) {
432 for (Feature f : fs) set(f);
433 return *this;
434 }
436 if (f != Feature::COUNT) bits_[static_cast<std::size_t>(f)] = false;
437 return *this;
438 }
439 bool has(Feature f) const {
440 return f != Feature::COUNT && bits_[static_cast<std::size_t>(f)];
441 }
442 /** The features held, in registry order. */
443 std::vector<Feature> list() const {
444 std::vector<Feature> out;
445 for (std::size_t i = 0; i < bits_.size(); ++i)
446 if (bits_[i]) out.push_back(static_cast<Feature>(i));
447 return out;
448 }
449 bool empty() const {
450 for (std::size_t i = 0; i < bits_.size(); ++i)
451 if (bits_[i]) return false;
452 return true;
453 }
454
455private:
456 std::vector<bool> bits_;
457};
458
459/**
460 * The registry name a specialization falls back to when it is not declared.
461 *
462 * Some registry names denote a SPECIAL CASE of another name rather than a
463 * capability of their own: a Cox2 is a Coxian restricted to two phases, and a
464 * Trace is a Replayer under another class name. Recording only the general name
465 * left the specific entry unreachable -- dead registry surface that no model
466 * could ever set (see _kb/06-solver-catalog.md, "A registered name nothing
467 * emits gates nothing"). Recording the specific name
468 * instead would silently REJECT those models at every solver that declares only
469 * the general one, which is every solver that accepts them today.
470 *
471 * So the recorder emits the most specific name it can, and the gate resolves an
472 * undeclared specific name against its generalization here. A solver that
473 * genuinely supports only the special case (two-phase Coxian, say) keeps the
474 * option of declaring the specialization alone: the fallback is consulted only
475 * when the specific name is missing, never in the other direction.
476 *
477 * COUNT means "no generalization"; the feature stands on its own.
478 */
480 switch (f) {
481 case Feature::Cox2: return Feature::Coxian;
482 // Trace is emitted by MATLAB, the JAR and python, which each carry a
483 // Trace class distinct from Replayer. This port has no such type -- the
484 // JSON wire writes both as "Replayer" -- so the entry stays inert here
485 // and the fallback is kept only so the four tables read alike.
486 case Feature::Trace: return Feature::Replayer;
487 default: return Feature::COUNT;
488 }
489}
490
491/** The outcome of the gate: the verdict, the offending features, the message. */
493 bool ok = true;
494 std::vector<Feature> missing; ///< used but not declared, in registry order
495 std::string reason; ///< empty when ok
496};
497
498/**
499 * SolverFeatureSet.supports: is every feature the model uses declared?
500 *
501 * `solver` names the solver in the reason so the message is actionable on its
502 * own; MATLAB gets that name from the mfilename of the raising runAnalyzer.
503 */
504inline SupportResult feature_set_supports(const std::string& solver, const FeatureSet& declared,
505 const FeatureSet& used) {
507 for (std::size_t i = 0; i < feature_count(); ++i) {
508 const Feature f = static_cast<Feature>(i);
509 if (!used.has(f) || declared.has(f)) continue;
510 // A specialization the solver did not name is covered by the general
511 // capability when that one IS declared; see feature_generalization.
512 const Feature g = feature_generalization(f);
513 if (g != Feature::COUNT && declared.has(g)) continue;
514 r.missing.push_back(f);
515 }
516 if (r.missing.empty()) return r;
517 r.ok = false;
518 if (r.missing.size() == 1) {
519 r.reason = solver + ": this model uses " + feature_phrase(r.missing[0]) +
520 ", which this solver does not support";
521 } else {
522 r.reason = solver + ": this model uses features which this solver does not support: ";
523 for (std::size_t i = 0; i < r.missing.size(); ++i) {
524 if (i) r.reason += ", ";
525 r.reason += feature_phrase(r.missing[i]);
526 }
527 }
528 return r;
529}
530
531/**
532 * The refusal a failed gate raises: `LINE:unsupported:<kind>`, where the kind is the FIRST
533 * missing feature in registry order (`_kb/17-error-vocabulary.md`). The message still lists
534 * every missing feature; the id names one so a caller can branch on it without parsing prose.
535 */
537 return UnsupportedError(
538 ErrorKind{r.missing.empty() ? std::string("Unspecified") : std::string(feature_name(r.missing[0]))},
539 r.reason);
540}
541
542// ---------------------------------------------------------------------------
543// Enum to feature
544// ---------------------------------------------------------------------------
545
546/**
547 * The feature name of a distribution, MATLAB `serviceProcess{r}{3}.name`.
548 *
549 * Immediate and Disabled return COUNT: they are internal placeholders, not
550 * user-facing distributions, and getUsedLangFeatures excludes them by name.
551 * Expolynomial and Normal have no ProcessType in MATLAB either, so those two
552 * registry entries can never be emitted by this port.
553 */
555 switch (p) {
556 case ProcessType::EXP: return Feature::Exp;
557 case ProcessType::ERLANG: return Feature::Erlang;
558 case ProcessType::HYPEREXP: return Feature::HyperExp;
559 case ProcessType::PH: return Feature::PH;
560 case ProcessType::APH: return Feature::APH;
561 case ProcessType::MAP: return Feature::MAP;
562 case ProcessType::UNIFORM: return Feature::Uniform;
563 case ProcessType::DET: return Feature::Det;
564 case ProcessType::COXIAN: return Feature::Coxian;
565 case ProcessType::GAMMA: return Feature::Gamma;
566 case ProcessType::PARETO: return Feature::Pareto;
567 case ProcessType::MMPP2: return Feature::MMPP2;
568 case ProcessType::REPLAYER: return Feature::Replayer;
569 case ProcessType::COX2: return Feature::Cox2;
570 case ProcessType::WEIBULL: return Feature::Weibull;
571 case ProcessType::LOGLOGISTIC: return Feature::LogLogistic;
572 case ProcessType::MASSATORIGIN: return Feature::MassAtOrigin;
573 case ProcessType::DEFECTIVE: return Feature::Defective;
574 case ProcessType::LOGNORMAL: return Feature::Lognormal;
575 case ProcessType::DUNIFORM: return Feature::DiscreteUniform;
576 case ProcessType::BERNOULLI: return Feature::Bernoulli;
577 case ProcessType::BINOMIAL: return Feature::Binomial;
578 case ProcessType::POISSON: return Feature::Poisson;
579 case ProcessType::GEOMETRIC: return Feature::Geometric;
580 case ProcessType::BMAP: return Feature::BMAP;
581 case ProcessType::ME: return Feature::ME;
582 case ProcessType::RAP: return Feature::RAP;
583 case ProcessType::DISCRETESAMPLER: return Feature::DiscreteSampler;
584 case ProcessType::ZIPF: return Feature::Zipf;
585 case ProcessType::DMAP: return Feature::DMAP;
586 case ProcessType::MMAP: return Feature::MMAP;
587 case ProcessType::EMPIRICALCDF: return Feature::EmpiricalCdf;
588 // A Prior IS user-facing, unlike Immediate and Disabled, and emitting it
589 // is what makes every solver but SolverUQ refuse the model instead of
590 // lowering the epistemic mixture to a rate and answering with it.
591 case ProcessType::PRIOR: return Feature::Prior;
592 case ProcessType::NHPP: return Feature::NHPP;
593 case ProcessType::NNPP: return Feature::NNPP;
594 case ProcessType::MAPT: return Feature::MAPt;
595 case ProcessType::PHT: return Feature::PHt;
596 case ProcessType::MPH: return Feature::MPH;
597 case ProcessType::MMAPT: return Feature::MMAPt;
598 case ProcessType::MPHT: return Feature::MPHt;
599 case ProcessType::BMMAPT: return Feature::BMMAPt;
600 default: return Feature::COUNT;
601 }
602}
603
604/**
605 * SchedStrategy.toFeature. FORK and NONE are internal markers with no registry
606 * name; MATLAB aliases FCFSPRIO to HOL, so HOL covers both.
607 */
609 switch (s) {
610 case SchedStrategy::INF: return Feature::SchedStrategy_INF;
611 case SchedStrategy::FCFS: return Feature::SchedStrategy_FCFS;
612 case SchedStrategy::FCFSPR: return Feature::SchedStrategy_FCFSPR;
613 case SchedStrategy::FCFSPI: return Feature::SchedStrategy_FCFSPI;
614 case SchedStrategy::FCFSPRPRIO: return Feature::SchedStrategy_FCFSPRPRIO;
615 case SchedStrategy::FCFSPIPRIO: return Feature::SchedStrategy_FCFSPIPRIO;
616 case SchedStrategy::LCFS: return Feature::SchedStrategy_LCFS;
617 case SchedStrategy::LCFSPR: return Feature::SchedStrategy_LCFSPR;
618 case SchedStrategy::LCFSPI: return Feature::SchedStrategy_LCFSPI;
619 case SchedStrategy::LCFSPRIO: return Feature::SchedStrategy_LCFSPRIO;
620 case SchedStrategy::LCFSPRPRIO: return Feature::SchedStrategy_LCFSPRPRIO;
621 case SchedStrategy::LCFSPIPRIO: return Feature::SchedStrategy_LCFSPIPRIO;
622 case SchedStrategy::SEPT: return Feature::SchedStrategy_SEPT;
623 case SchedStrategy::LEPT: return Feature::SchedStrategy_LEPT;
624 case SchedStrategy::SJF: return Feature::SchedStrategy_SJF;
625 case SchedStrategy::LJF: return Feature::SchedStrategy_LJF;
626 case SchedStrategy::SRPT: return Feature::SchedStrategy_SRPT;
627 case SchedStrategy::SRPTPRIO: return Feature::SchedStrategy_SRPTPRIO;
628 case SchedStrategy::PSJF: return Feature::SchedStrategy_PSJF;
629 case SchedStrategy::FB: return Feature::SchedStrategy_FB;
630 case SchedStrategy::LRPT: return Feature::SchedStrategy_LRPT;
631 case SchedStrategy::SETF: return Feature::SchedStrategy_SETF;
632 case SchedStrategy::FSP: return Feature::SchedStrategy_FSP;
633 case SchedStrategy::PAS: return Feature::SchedStrategy_PAS;
634 case SchedStrategy::OI: return Feature::SchedStrategy_OI;
635 // Round robin (finite quantum): set by the CTMC, SSA and LDES feature sets
636 // (solver_feature_sets.h); every other solver refuses it BY NAME.
637 case SchedStrategy::RR: return Feature::SchedStrategy_RR;
638 case SchedStrategy::PS: return Feature::SchedStrategy_PS;
639 case SchedStrategy::DPS: return Feature::SchedStrategy_DPS;
640 case SchedStrategy::GPS: return Feature::SchedStrategy_GPS;
641 case SchedStrategy::PSPRIO: return Feature::SchedStrategy_PSPRIO;
642 case SchedStrategy::DPSPRIO: return Feature::SchedStrategy_DPSPRIO;
643 case SchedStrategy::GPSPRIO: return Feature::SchedStrategy_GPSPRIO;
644 case SchedStrategy::SIRO: return Feature::SchedStrategy_SIRO;
645 case SchedStrategy::HOL: return Feature::SchedStrategy_HOL;
646 case SchedStrategy::EXT: return Feature::SchedStrategy_EXT;
647 case SchedStrategy::POLLING: return Feature::SchedStrategy_POLLING;
648 case SchedStrategy::EDD: return Feature::SchedStrategy_EDD;
649 case SchedStrategy::EDF: return Feature::SchedStrategy_EDF;
650 case SchedStrategy::LPS: return Feature::SchedStrategy_LPS;
651 case SchedStrategy::REF: return Feature::SchedStrategy_REF;
652 default: return Feature::COUNT;
653 }
654}
655
656/**
657 * RoutingStrategy.toFeature. FIRING and DISABLED are internal markers, not
658 * user-selectable capabilities, and map to no registry name (RoutingStrategy.m:132-139).
659 */
661 switch (r) {
662 case RoutingStrategy::PROB: return Feature::RoutingStrategy_PROB;
663 case RoutingStrategy::RAND: return Feature::RoutingStrategy_RAND;
664 case RoutingStrategy::RROBIN: return Feature::RoutingStrategy_RROBIN;
665 case RoutingStrategy::WRROBIN: return Feature::RoutingStrategy_WRROBIN;
666 case RoutingStrategy::JSQ: return Feature::RoutingStrategy_JSQ;
667 case RoutingStrategy::SQ: return Feature::RoutingStrategy_SQ;
668 case RoutingStrategy::SDR: return Feature::RoutingStrategy_SDR;
669 default: return Feature::COUNT;
670 }
671}
672
673/** ReplacementStrategy.toFeature. */
675 switch (s) {
676 case ReplacementStrategy::RR: return Feature::ReplacementStrategy_RR;
677 case ReplacementStrategy::FIFO: return Feature::ReplacementStrategy_FIFO;
678 case ReplacementStrategy::SFIFO: return Feature::ReplacementStrategy_SFIFO;
679 case ReplacementStrategy::LRU: return Feature::ReplacementStrategy_LRU;
680 case ReplacementStrategy::HLRU: return Feature::ReplacementStrategy_HLRU;
681 case ReplacementStrategy::CLIMB: return Feature::ReplacementStrategy_CLIMB;
682 case ReplacementStrategy::QLRU: return Feature::ReplacementStrategy_QLRU;
683 default: return Feature::COUNT;
684 }
685}
686
687/**
688 * The SERVER section a Queue gets for a discipline, MATLAB Queue.m:79-108.
689 *
690 * The section class name is itself a feature: MNetwork.addNode registers
691 * class(node.server) alongside class(node), which is where SharedServer,
692 * InfiniteServer and Server enter the used set. PreemptiveServer and
693 * PollingServer are absent from the registry, so those disciplines contribute
694 * only their SchedStrategy_ name, exactly as in the reference.
695 */
697 switch (s) {
698 case SchedStrategy::PS:
699 case SchedStrategy::DPS:
700 case SchedStrategy::GPS:
701 case SchedStrategy::PSPRIO:
702 case SchedStrategy::DPSPRIO:
703 case SchedStrategy::GPSPRIO:
704 case SchedStrategy::LPS: return Feature::SharedServer;
705 case SchedStrategy::INF: return Feature::InfiniteServer;
706 case SchedStrategy::LCFSPR:
707 case SchedStrategy::LCFSPRPRIO:
708 case SchedStrategy::LCFSPI:
709 case SchedStrategy::LCFSPIPRIO:
710 case SchedStrategy::FCFSPR:
711 case SchedStrategy::FCFSPRPRIO:
712 case SchedStrategy::FCFSPI:
713 case SchedStrategy::FCFSPIPRIO:
714 case SchedStrategy::EDF: return Feature::COUNT; // PreemptiveServer, unregistered
715 case SchedStrategy::POLLING: return Feature::COUNT; // PollingServer, unregistered
716 default: return Feature::Server;
717 }
718}
719
720// ---------------------------------------------------------------------------
721// The used side
722// ---------------------------------------------------------------------------
723
724/**
725 * getUsedLangFeatures: the features the MODEL uses.
726 *
727 * MATLAB derives them from the Network OBJECT, where a node still knows its
728 * MATLAB class and its section classes; this port derives them from the
729 * refreshed struct, which is the only thing a C++ solver runner holds. The two
730 * agree because the section classes are a pure function of the node kind and
731 * the discipline (Queue.m:48-108, Source.m:66-68, Cache.m:54-76, Fork.m:106-109,
732 * Join.m:33-35, Place.m:27-31, Transition.m:29-36), which is what
733 * feature_of_server_section and the node switch below encode.
734 *
735 * FEATURES THIS PORT CANNOT EMIT, because NetworkStruct carries no field for
736 * them. Each is a real MATLAB feature, and a model using one reaches a C++
737 * solver unflagged; the fix is a struct field, not a proxy here.
738 * SetupDelayOff MATLAB Queue.setupTime / delayoffTime, carried by
739 * NetworkStruct::setupparam and solved by solver_mam_basic.
740 * Reneging MATLAB Queue.impatienceTypes. state_events.h takes the
741 * reneging classes as a CALL PARAMETER, so the struct does
742 * not record them and they cannot be derived here.
743 * Balking MATLAB Queue.balkingStrategies. No struct field.
744 * QueueingPlace was on this list until 2026-09-16, when `add_place(nm, sched)`
745 * gave a Place a discipline and `is_queueing_place` derived the flag from the
746 * service law -- which is `Place.queueing`'s own trigger, `setService` -- so it
747 * needs no flag of its own and is emitted below like any field-backed feature.
748 * Breakdown was on this list until 2026-08-15, when
749 * `NetworkStruct::breakdownparam` was added for the LDES engine; it is derived
750 * below like any other field-backed feature. `state_events.h` still takes the
751 * breakdown nodes as a call parameter, which is why the CTMC declaration of it
752 * stays inert -- the two are independent.
753 *
754 * FEATURES EMITTED HERE THAT MATLAB DOES NOT EMIT. LoadDependence is in the
755 * registry and is declared by solvers, but getUsedLangFeatures never set it, so
756 * in MATLAB it was unenforced. Deriving it from `lldscaling` is a strict
757 * tightening: the solvers that declare it are unaffected, and the ones that do
758 * not now refuse instead of silently dropping the scaling. Retrial was in this
759 * paragraph until 2026-09-05, when MATLAB's recorder gained the same arm.
760 */
761template <class T>
762bool has_binding_capacity(const NetworkStruct<T>& sn);
763
764template <class T>
766 FeatureSet u;
767 const std::size_t R = sn.classes.size();
768
769 for (std::size_t r = 0; r < R; ++r) {
770 u.set(sn.classes[r].type == JobClassType::CLOSED ? Feature::ClosedClass
771 : Feature::OpenClass);
772 // A self-looping class is a closed class whose routing returns to its own
773 // reference station. It was declared by eight solvers and never marked, so
774 // a solver that omitted the name (the bounds, RCAT, LQNS) was never asked;
775 // it is now refused unless it declares the name.
776 if (sn.classes[r].self_looping) u.set(Feature::SelfLoopingClass);
777 if (r < sn.issignal.size() && sn.issignal[r]) {
778 // Open vs closed signal follows the class type; MATLAB resolves the
779 // unresolved Signal placeholder by the presence of a Source, which
780 // is the same decision the refresh has already made here.
781 u.set(sn.classes[r].type == JobClassType::CLOSED ? Feature::ClosedSignal
782 : Feature::OpenSignal);
783 if (r < sn.signaltype.size()) {
784 switch (sn.signaltype[r]) {
785 case lang::SignalType::NEGATIVE: u.set(Feature::SignalType_NEGATIVE); break;
786 case lang::SignalType::REPLY: u.set(Feature::SignalType_REPLY); break;
788 u.set(Feature::SignalType_CATASTROPHE);
789 break;
790 }
791 }
792 if (r < sn.signalremdist.size() && !sn.signalremdist[r].empty())
793 u.set(Feature::SignalBatchRemoval);
794 if (r < sn.signalrempolicy.size() &&
795 sn.signalrempolicy[r] != lang::RemovalPolicy::RANDOM)
796 u.set(Feature::SignalRemovalPolicy);
797 }
798 }
799
800 // Globally state-dependent scaling phi(n) over the full network state, the
801 // Whittle primitive. SolverCTMC, SolverSSA and SolverLDES plumb it, so every
802 // other solver must reject the model rather than solve it unscaled.
803 if (static_cast<bool>(sn.gdscaling)) u.set(Feature::GlobalDependence);
804
805 if (!sn.regions.empty()) u.set(Feature::Region);
806 if (sn.sourceIdx != 0) u.set(Feature::Source);
807 if (sn.sinkNode != 0) u.set(Feature::Sink);
808 if (!sn.fj.empty()) u.set({Feature::Fork, Feature::Forker, Feature::Join, Feature::Joiner});
809
810 for (std::size_t i = 0; i < sn.nodes.size(); ++i) {
811 const NodeDef& nd = sn.nodes[i];
812 const std::size_t ind = i + 1;
813 const std::size_t ist = nd.station; // 1-based, 0 when the node serves no jobs
814
815 switch (nd.nodetype) {
816 case NodeType::Queue:
817 case NodeType::Delay: {
818 u.set({nd.nodetype == NodeType::Delay ? Feature::Delay : Feature::Queue,
819 Feature::Buffer, Feature::Dispatcher});
820 if (ist == 0) break;
821 const Station<T>& st = sn.stations[ist - 1];
823 bool any_class = false;
824 for (std::size_t r = 0; r < R; ++r) {
825 // A disabled pair is MATLAB's empty serviceProcess: it emits
826 // no distribution, no discipline and no routing.
827 if (ist - 1 < sn.disabled.size() && r < sn.disabled[ist - 1].size() &&
828 sn.disabled[ist - 1][r])
829 continue;
830 any_class = true;
831 if (ist - 1 < sn.service.size() && r < sn.service[ist - 1].size())
832 u.set(feature_of_process(sn.service[ist - 1][r].type));
833 if (r < nd.routing.size()) u.set(feature_of_routing(nd.routing[r]));
834 }
835 if (any_class) u.set(feature_of_sched(st.sched));
836 if (!st.lldscaling.empty()) u.set(Feature::LoadDependence);
837 if (static_cast<bool>(st.cdscaling)) u.set(Feature::ClassDependence);
838 if (static_cast<bool>(st.jdscaling)) u.set(Feature::JointDependence);
839 // Impatience, balking and heterogeneous pools. MATLAB's
840 // getUsedLangFeatures emits Balking and Reneging from the same
841 // declarations; HeteroServers has no MATLAB counterpart and is
842 // emitted here for the same reason Retrial and LoadDependence
843 // are -- a solver that ignores the pools would answer for the
844 // homogeneous station and say nothing about the difference.
845 for (std::size_t r = 0; r < R; ++r) {
846 if (r < st.impatience.size() && st.impatience[r] != lang::ImpatienceType::NONE)
847 u.set(st.impatience[r] == lang::ImpatienceType::BALKING ? Feature::Balking
848 : Feature::Reneging);
849 if (r < st.orbit_impatience.size() && !st.orbit_impatience[r].disabled)
850 u.set(Feature::Reneging);
851 // Non-persistent retrial customers and orbital search change
852 // the retrial dynamics; a solver that only knows the classical
853 // orbit would answer the persistent model, so each is gated by
854 // name (MATLAB getUsedLangFeatures).
855 if (st.orbit_join_of(r) < num_traits<T>::from_int(1) ||
857 u.set(Feature::RetrialNonPersistent);
859 u.set(Feature::OrbitalSearch);
860 if (r < st.balking.size() &&
861 st.balking[r].strategy != lang::BalkingStrategy::NONE)
862 u.set(Feature::Balking);
863 }
864 if (!st.server_types.empty()) u.set(Feature::HeteroServers);
865 for (std::size_t n : st.server_parallelism)
866 if (n > 1) { u.set(Feature::ServerParallelism); break; }
867 break;
868 }
869 case NodeType::Source: {
870 u.set({Feature::Source, Feature::RandomSource, Feature::ServiceTunnel,
871 Feature::Dispatcher});
872 // The Source branch emits the arrival distributions only: MATLAB
873 // registers no discipline and no routing for it.
874 if (ist == 0 || ist - 1 >= sn.service.size()) break;
875 for (std::size_t r = 0; r < R && r < sn.service[ist - 1].size(); ++r)
876 u.set(feature_of_process(sn.service[ist - 1][r].type));
877 // A batch arrival releases several jobs per epoch, which no
878 // single-arrival event handler produces.
879 for (const Distrib<T>& b : sn.stations[ist - 1].arrival_batch)
880 if (!b.disabled) { u.set(Feature::BatchArrival); break; }
881 break;
882 }
883 case NodeType::Sink:
884 u.set(Feature::Sink);
885 break;
886 case NodeType::Router: {
887 // A ROUTER EMITS ITS ROUTING STRATEGY AND NOTHING ELSE. All
888 // three reference codebases agree and this port was the only
889 // one that did not: getUsedLangFeatures.m:77-78 (case 'Router'),
890 // Network.java:3184-3190 and network.py:1983-1987 each record
891 // RoutingStrategy.toFeature(...) alone. This branch additionally
892 // emitted Router, Buffer, Dispatcher and ServiceTunnel, and
893 // since neither mva_feature_set nor nc_feature_set declares
894 // Router -- correctly, SolverMVA.m:231-257 does not either --
895 // every model with a dispatcher was refused by the two solvers
896 // MATLAB and python solve it with. The whole cluster family
897 // (Network.cluster/clusterClosed/clusterMixed) is exactly that
898 // shape, and the Router is eliminated by the stochastic
899 // complement long before any solver sees it.
900 for (std::size_t r = 0; r < R && r < nd.routing.size(); ++r)
902 break;
903 }
904 case NodeType::ClassSwitch:
905 u.set({Feature::ClassSwitch, Feature::StatelessClassSwitcher, Feature::Buffer,
906 Feature::Dispatcher});
907 break;
908 case NodeType::Cache: {
909 u.set({Feature::Cache, Feature::CacheClassSwitcher, Feature::Buffer,
910 Feature::Dispatcher});
911 auto it = sn.nodeparam.find(ind);
912 if (it == sn.nodeparam.end()) break;
913 u.set(feature_of_replacement(it->second.replacestrat));
914 if (it->second.retrieval_capacity > 0 || !it->second.retrieval_classes.empty())
915 u.set(Feature::CacheRetrieval);
916 if (!it->second.costcap.empty()) u.set(Feature::CacheItemSize);
917 break;
918 }
919 case NodeType::Fork: {
920 u.set({Feature::Fork, Feature::Forker, Feature::Buffer, Feature::ServiceTunnel});
921 // Variable forking levels. A name declared but never marked is
922 // a name no solver can ever refuse, so all three are marked
923 // here. A plain fork has no override block at all, so this
924 // costs one map lookup in the classic case.
925 const qn::ForkParam<T>* fp = sn.fork_param_of(i);
926 if (fp != 0) {
927 const double tpl = sn.nodes[i - 1].tasks_per_link;
928 bool vector_valued = false, random_valued = false, probabilistic = false;
929 for (std::size_t k = 0; k < fp->fan_out_link.rows(); ++k)
930 for (std::size_t r = 0; r < fp->fan_out_link.cols(); ++r) {
931 const double p = num_traits<T>::to_double(fp->fan_out_prob(k, r));
932 if (p == 0.0) continue; // link this class does not take
933 if (p != 1.0) probabilistic = true;
934 if (num_traits<T>::to_double(fp->fan_out_link(k, r)) != tpl)
935 vector_valued = true;
936 if (!fp->fan_out_dist[k][r].disabled) random_valued = true;
937 }
938 if (vector_valued) u.set(Feature::ForkFanoutVector);
939 if (random_valued) u.set(Feature::ForkFanoutRandom);
940 if (probabilistic) u.set(Feature::ForkBranchProbability);
941 }
942 break;
943 }
944 case NodeType::Join:
945 u.set({Feature::Join, Feature::Joiner, Feature::Dispatcher,
946 Feature::ServiceTunnel});
947 break;
948 case NodeType::Logger:
949 u.set({Feature::Logger, Feature::LogTunnel, Feature::Buffer, Feature::Dispatcher});
950 break;
951 case NodeType::Place:
952 u.set({Feature::Place, Feature::Storage, Feature::Linkage,
953 Feature::ServiceTunnel});
954 // A QUEUEING PLACE, i.e. one `setService` gave a law to. The
955 // three reference recorders emit this name and NOTHING else for
956 // it -- not the discipline, not the service distribution, not
957 // the server section `installQueueServer` swapped in -- and
958 // this port must not emit more: a feature set refuses a model
959 // for HAVING a name, so a name MATLAB does not raise is a model
960 // this port alone would turn away.
961 if (nd.station != 0 && sn.is_queueing_place(nd.station - 1))
962 u.set(Feature::QueueingPlace);
963 // A FLUID place (FSPN) holds a real level that only solvers declaring FluidPlace read; every
964 // other solver would answer the token net alone and drop the fluid without a word.
965 if (sn.is_fluid_node(ind)) u.set(Feature::FluidPlace);
966 break;
967 case NodeType::Transition: {
968 u.set({Feature::Transition, Feature::Enabling, Feature::Timing, Feature::Firing});
969 auto it = sn.transparam.find(ind);
970 if (it == sn.transparam.end()) break;
971 // Inhibiting only for a FINITE threshold: Inf is "never blocks",
972 // and a plain SPN must not be gated out of solvers lacking it.
973 for (const auto& row : it->second.inhibiting) {
974 bool finite = false;
975 for (std::size_t p = 0; p < row.rows() && !finite; ++p)
976 for (std::size_t r = 0; r < row.cols(); ++r)
977 if (std::isfinite(num_traits<T>::to_double(row(p, r)))) {
978 finite = true;
979 break;
980 }
981 if (finite) { u.set(Feature::Inhibiting); break; }
982 }
983 // Fluid arcs without a fluid place still need a solver that reads them.
984 if (it->second.has_fluid_arcs()) u.set(Feature::FluidPlace);
985 break;
986 }
987 case NodeType::Region:
988 u.set(Feature::Region);
989 break;
990 }
991 }
992
993 // A ClassSwitch is never materialised as a node by this port (see the
994 // NetworkStruct header), so the switch matrix is the only trace it leaves.
995 if (!sn.csmatrix.empty())
996 u.set({Feature::ClassSwitch, Feature::StatelessClassSwitcher, Feature::Buffer,
997 Feature::Dispatcher});
998
999 if (!sn.retrialparam.empty()) u.set(Feature::Retrial);
1000 // Breakdown became a STRUCT FIELD on 2026-08-15, so it is derivable here
1001 // where balking and reneging still are not: a solver that does not declare
1002 // it is now refused on a model that carries it, instead of running as
1003 // though the server never failed.
1004 if (!sn.breakdownparam.empty()) u.set(Feature::Breakdown);
1005 if (!sn.setupparam.empty()) u.set(Feature::SetupDelayOff);
1006 // A PARTIAL join fires on a quorum rather than on every sibling, and a FIFO
1007 // depository releases a served token only after the earlier ones: both
1008 // change which transitions exist, so a solver that has neither must refuse.
1009 for (const auto& kv : sn.joindecl)
1010 if (kv.second.strategy == lang::JoinStrategy::PARTIAL) u.set(Feature::JoinPartial);
1011 for (const Station<T>& st : sn.stations)
1013 if (d != lang::DepartureDiscipline::NORMAL) u.set(Feature::DepartureDiscipline);
1014 for (const auto& row : sn.droprule)
1015 for (DropStrategy d : row)
1016 if (d == DropStrategy::RETRIAL || d == DropStrategy::RETRIAL_WITH_LIMIT)
1017 u.set(Feature::Retrial);
1018
1019 // A finite-server station serving several jobs at once. A Delay carries an
1020 // infinite nservers and is NOT one, which is what `has_multi_server` already
1021 // tests: the single-server recursions answered a c-server station as one
1022 // server of the same rate, and only a structural predicate could say so.
1023 if (sn.has_multi_server()) u.set(Feature::MultiServer);
1024 // Polling extensions: a solver that reads only the polling type would
1025 // answer the plain cyclic system, so each one has its own registry name.
1026 for (const Station<T>& st : sn.stations) {
1027 if (st.sched != SchedStrategy::POLLING) continue;
1028 if (!st.polling_table.empty()) u.set(Feature::PollingTable);
1029 if (st.polling_order != lang::PollingOrder::CYCLIC) u.set(Feature::PollingOrder);
1030 if (st.polling_timer_scope != lang::PollingTimer::NONE) u.set(Feature::PollingTimer);
1031 }
1032 // A station or per-class buffer that can BIND: the one predicate
1033 // `check_binding_capacity` refuses on (station caps against the class
1034 // populations, open classes always bind, Cache models exempt), asked here so
1035 // the refusal has a registry name and a solver method that does not declare
1036 // it is gated on exactly the models the structural gate refuses.
1037 if (has_binding_capacity(sn)) u.set(Feature::FiniteCapacity);
1038
1039 return u;
1040}
1041
1042// ---------------------------------------------------------------------------
1043// The gate
1044// ---------------------------------------------------------------------------
1045
1046/**
1047 * runAnalyzerChecks: refuse a model the solver does not declare, by name.
1048 *
1049 * Throws UnsupportedError, which is what every other by-name refusal in this
1050 * port throws and what the CLI reports without a stack.
1051 *
1052 * THE TWO MESSAGE FORMS, NetworkSolver.m:184-190. The reference emits a
1053 * different message when `resolveMethod` changed the method under the user's
1054 * feet than when the user named it:
1055 *
1056 * method == options.method "features not supported by the solver"
1057 * otherwise "features not supported by the solver's '%s' method"
1058 *
1059 * That distinction is not cosmetic. The only resolution today is MVA's
1060 * `default` -> `rqna` upgrade, and rqna's set WITHDRAWS ClosedClass and
1061 * SelfLoopingClass, so a user who asked for nothing but `default` can be
1062 * refused for having a closed class. Without the method in the message the
1063 * refusal cannot be understood, because nothing the user typed mentions rqna.
1064 *
1065 * Both method arguments default to empty, which selects the plain form and
1066 * leaves every call site that does not resolve a method unchanged.
1067 */
1068template <class T>
1069void feature_gate(const std::string& solver, const FeatureSet& declared,
1070 const NetworkStruct<T>& sn, const std::string& requested_method = "",
1071 const std::string& resolved_method = "") {
1072 const bool upgraded = !resolved_method.empty() && resolved_method != requested_method;
1073 const std::string label = upgraded ? solver + "'s '" + resolved_method + "' method" : solver;
1074 const SupportResult r = feature_set_supports(label, declared, used_lang_features(sn));
1075 if (!r.ok) throw feature_refusal(r);
1076}
1077
1078/** `%g` for a capacity, so the message reads 2 and not 2.000000. */
1079inline std::string capacity_str(double v) {
1080 std::ostringstream os;
1081 os << v;
1082 return os.str();
1083}
1084
1085/**
1086 * Which solvers to point at when a finite capacity is refused.
1087 *
1088 * The two lists differ, and naming the wrong one sends the user to a solver that
1089 * also refuses. An OPEN refused arrival is LOST, which SolverJMT reproduces (its
1090 * queue section carries the drop rule directly). A CLOSED one BLOCKS: LINE
1091 * disables the upstream departure and holds the job where it is, and no JMT drop
1092 * strategy expresses that -- 'waiting queue' does not enforce the size at all and
1093 * 'BAS blocking' completes the service before blocking, a different queueing
1094 * model. The JMT writer refuses the closed case by name
1095 * (`assert_station_cap_exportable` in `jmt_writer.h`, BUG-81), so it must not be
1096 * advertised here for it.
1097 */
1098inline std::string capacity_fallback_advice(bool is_open_class) {
1099 return is_open_class ? "Use SolverCTMC, SolverJMT or SolverLDES"
1100 : "Use SolverCTMC, SolverSSA or SolverLDES";
1101}
1102
1103/**
1104 * The refusal `check_binding_capacity` raises, as a string, or empty when no
1105 * buffer binds. Split out so that a caller which must DECIDE on the same rule --
1106 * `fluid_resolve_method`, which sends a blocked model to the one method that
1107 * carries the constraint -- asks the gate's own question rather than a second
1108 * copy of it that could drift from it.
1109 */
1110template <class T>
1111std::string binding_capacity_reason(const std::string& solver, const NetworkStruct<T>& sn) {
1112 for (const NodeDef& nd : sn.nodes)
1113 if (nd.nodetype == NodeType::Cache) return std::string();
1114
1115 double totaljobs = 0.0; // infinite as soon as one class is open
1116 bool any_open = false;
1117 for (const JobClass& c : sn.classes) {
1118 totaljobs += c.population;
1119 if (std::isinf(c.population)) any_open = true;
1120 }
1121
1122 for (const Station<T>& st : sn.stations) {
1123 if (st.nodetype == NodeType::Source || st.nodetype == NodeType::Sink) continue;
1124 if (std::isfinite(st.cap) && st.cap >= 0.0 && st.cap < totaljobs)
1125 return solver + ": finite station capacity (setCapacity=" + capacity_str(st.cap) +
1126 ") at station '" + st.name +
1127 "' is not supported by this solver, which has no "
1128 "representation of a finite buffer and would return the "
1129 "unconstrained answer. " +
1130 capacity_fallback_advice(any_open);
1131 const std::size_t n = std::min(st.classcap.size(), sn.classes.size());
1132 for (std::size_t r = 0; r < n; ++r)
1133 if (std::isfinite(st.classcap[r]) && st.classcap[r] > 0.0 &&
1134 st.classcap[r] < sn.classes[r].population)
1135 return solver + ": finite per-class capacity (classCap=" +
1136 capacity_str(st.classcap[r]) + " for class " + std::to_string(r + 1) +
1137 ") at station '" + st.name +
1138 "' is not supported by this solver, which has no representation of a "
1139 "finite buffer and would return the unconstrained answer. " +
1140 capacity_fallback_advice(std::isinf(sn.classes[r].population));
1141 }
1142 return std::string();
1143}
1144
1145/** Does any station buffer BIND? The gate's own question, asked without raising. */
1146template <class T>
1148 return !binding_capacity_reason(std::string("solver"), sn).empty();
1149}
1150
1151/**
1152 * NetworkSolver.checkBindingCapacity (NetworkSolver.m:1172-1228): the shared
1153 * structural gate for finite station capacity (setCapacity) and finite
1154 * per-class buffers (classCap), used by the product-form solvers.
1155 *
1156 * There is no LINE_QN_FEATURE_LIST enumerator for plain capacity -- it is a
1157 * NUMBER on a station, not a construct -- so `feature_gate` above cannot see
1158 * it, and a product-form solver has no representation of a finite buffer.
1159 * Without this check the solve returns the UNCONSTRAINED answer (QLen=4 where
1160 * the M/M/1/2 value is 0.8525), which is a wrong number rather than a refusal.
1161 *
1162 * The test reads the STATION-level cap/classcap the user set, never the derived
1163 * `sn.cap`/`sn.classcap`: refresh_capacity gives every closed model a finite
1164 * derived classcap (the chain population), so an sn-level test would reject
1165 * every closed model.
1166 *
1167 * Only a capacity that can actually BIND is refused. A closed model whose
1168 * station capacity is at least the total population can never block a job, so
1169 * the declaration is a no-op and the product-form answer stays exact -- a
1170 * common idiom is setCapacity(N) on a station of an N-job closed model. The
1171 * population is infinite for an open class, so any finite capacity an open
1172 * class reaches binds.
1173 *
1174 * Cache models are exempt: a Cache sets classcap=1 on the retrieval queues it
1175 * builds, and MVA/NC solve those through their cache analyzers rather than as a
1176 * buffer constraint.
1177 */
1178template <class T>
1179void check_binding_capacity(const std::string& solver, const NetworkStruct<T>& sn) {
1180 const std::string reason = binding_capacity_reason(solver, sn);
1181 if (!reason.empty()) throw UnsupportedError(ErrorKind{"FiniteCapacity"}, reason);
1182}
1183
1184} // namespace qn
1185} // namespace line
1186
1187#endif // LINE_LANG_QN_FEATURE_SET_H
A refusal: the feature, method or analysis is not covered: LINE:unsupported:<kind>.
Definition error.h:117
UnsupportedError(const std::string &what)
Definition error.h:119
A subset of the registry: MATLAB's SolverFeatureSet, whose list is a flag per field.
FeatureSet & set(Feature f)
FeatureSet & set(std::initializer_list< Feature > fs)
std::vector< Feature > list() const
The features held, in registry order.
FeatureSet & unset(Feature f)
bool has(Feature f) const
A network plus its refreshed NetworkStruct.
The exception types the port throws.
#define LINE_QN_FEATURE_LIST(X)
SolverFeatureSet.fields, in its order, as an X-list.
Definition feature_set.h:80
#define LINE_QN_FEATURE_ENUM(id)
#define LINE_QN_FEATURE_NAME(id)
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
Definition lang_types.h:465
@ REPLY
completes a synchronous call, releasing a held server
Definition lang_types.h:181
@ NEGATIVE
removes a batch of jobs (Gelenbe's negative customer)
Definition lang_types.h:182
@ CATASTROPHE
removes EVERY job at the station
Definition lang_types.h:183
@ CYCLIC
fixed cyclic order (or the polling table)
Definition lang_types.h:405
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
Definition lang_types.h:430
@ NONE
no visit timer
Definition lang_types.h:413
DepartureDiscipline
When a Place releases a served token, MATLAB DepartureDiscipline.
Definition lang_types.h:499
@ RANDOM
uniform over waiting AND in-service jobs
Definition lang_types.h:188
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
Definition lang_types.h:524
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
Definition lang_types.h:419
Feature feature_of_server_section(SchedStrategy s)
The SERVER section a Queue gets for a discipline, MATLAB Queue.m:79-108.
FeatureSet used_lang_features(const NetworkStruct< T > &sn)
Feature feature_generalization(Feature f)
The registry name a specialization falls back to when it is not declared.
Feature
One language feature.
void check_binding_capacity(const std::string &solver, const NetworkStruct< T > &sn)
NetworkSolver.checkBindingCapacity (NetworkSolver.m:1172-1228): the shared structural gate for finite...
std::string feature_phrase(Feature f)
A human-readable phrase for the reason string, e.g.
std::string capacity_str(double v)
g for a capacity, so the message reads 2 and not 2.000000.
bool has_binding_capacity(const NetworkStruct< T > &sn)
getUsedLangFeatures: the features the MODEL uses.
Feature feature_of_process(ProcessType p)
The feature name of a distribution, MATLAB serviceProcess{r}{3}.name.
Feature feature_of_routing(RoutingStrategy r)
RoutingStrategy.toFeature.
Feature feature_of_replacement(ReplacementStrategy s)
ReplacementStrategy.toFeature.
UnsupportedError feature_refusal(const SupportResult &r)
The refusal a failed gate raises: LINE:unsupported:<kind>, where the kind is the FIRST missing featur...
SupportResult feature_set_supports(const std::string &solver, const FeatureSet &declared, const FeatureSet &used)
SolverFeatureSet.supports: is every feature the model uses declared?
std::string capacity_fallback_advice(bool is_open_class)
Which solvers to point at when a finite capacity is refused.
void feature_gate(const std::string &solver, const FeatureSet &declared, const NetworkStruct< T > &sn, const std::string &requested_method="", const std::string &resolved_method="")
runAnalyzerChecks: refuse a model the solver does not declare, by name.
constexpr std::size_t feature_count()
The number of registered features, MATLAB numel(SolverFeatureSet.fields).
Feature feature_of_sched(SchedStrategy s)
SchedStrategy.toFeature.
const char * feature_name(Feature f)
The canonical registry name, byte for byte the MATLAB field name.
std::string binding_capacity_reason(const std::string &solver, const NetworkStruct< T > &sn)
The refusal check_binding_capacity raises, as a string, or empty when no buffer binds.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
A queueing network and its refreshed NetworkStruct.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
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.
double population
infinite for an open class
A node of the network.
std::vector< RoutingStrategy > routing
sn.routing, per class.
One station of the network.
std::vector< Distrib< T > > orbit_impatience
Queue.setOrbitImpatience(class, dist): abandonment from the RETRIAL ORBIT, which is a different popul...
double cap
Station capacity in Kendall's K, as setCapacity sets it.
std::vector< BalkingParam > balking
std::vector< std::size_t > server_parallelism
Queue.setServerParallelism(class, n): the servers a job seizes for the whole of its service,...
SchedStrategy sched
T orbit_join_of(std::size_t r) const
orbit_join[r] with the default 1 for a missing slot (0-based r).
CdScaling< T > jdscaling
sn.jdscaling for this station: MATLAB's Station.ljdScaling, the JOINT dependence map eta_i(n),...
std::vector< T > lldscaling
sn.lldscaling for this station: the multiplier at population 1, 2, ... Empty when the station is not ...
std::vector< lang::ImpatienceType > impatience
lang::PollingOrder polling_order
std::vector< std::size_t > polling_table
The polling extensions (Queue.setPollingTable, setPollingOrder, setPollingTimer).
CdScaling< T > cdscaling
sn.cdscaling for this station: the class-dependence map, empty when unset.
std::vector< double > classcap
Per-class buffer from setChainCapacity; infinite where unset.
std::vector< lang::DepartureDiscipline > departure_discipline
Place.departureDiscipline, per class.
lang::PollingTimer polling_timer_scope
T orbit_search_of(std::size_t r) const
orbit_search[r] with the default 0 for a missing slot (0-based r).
std::vector< ServerType > server_types
T orbit_persist_of(std::size_t r) const
orbit_persist[r] with the default 1 for a missing slot (0-based r).
The outcome of the gate: the verdict, the offending features, the message.
std::vector< Feature > missing
used but not declared, in registry order
std::string reason
empty when ok