5#ifndef LINE_SOLVERS_AUTO_SOLVER_AUTO_H
6#define LINE_SOLVERS_AUTO_SOLVER_AUTO_H
213 return token.empty() || token ==
"default" || token ==
"auto" || token ==
"heur" ||
214 token ==
"sim" || token ==
"exact" || token ==
"fast" ||
219 if (token.empty() || token ==
"default" || token ==
"auto" || token ==
"heur")
225 throw InputError(
"SolverAUTO: '" + token +
"' is not a selection intent");
234 if (name ==
"mam")
return "mam";
235 if (name ==
"ag")
return "ag";
236 if (name ==
"mva")
return "mva";
237 if (name ==
"nc")
return "nc";
238 if (name ==
"fluid" || name ==
"fld")
return "fld";
239 if (name ==
"jmt")
return "jmt";
240 if (name ==
"ssa")
return "ssa";
241 if (name ==
"ctmc")
return "ctmc";
242 if (name ==
"ldes" || name ==
"des")
return "ldes";
243 if (name ==
"ba")
return "ba";
244 if (name ==
"env")
return "env";
245 if (name ==
"ln")
return "ln";
246 if (name ==
"lqns" || name ==
"lqsim")
return "lqns";
247 if (name ==
"qns")
return "lqns";
248 if (name ==
"uq")
return "uq";
269 const std::string token = raw.empty() ? std::string(
"default") : raw;
275 if (token ==
"bound") {
286 const std::size_t dot = token.find(
'.');
287 const std::string head = dot == std::string::npos ? token : token.substr(0, dot);
288 const std::string rest = dot == std::string::npos ? std::string() : token.substr(dot + 1);
290 const std::string fam =
294 "SolverAUTO: '" + token +
295 "' is neither a selection intent (default, heur, exact, sim, fast, accurate, "
297 "nor a method family (mva, nc, ctmc, fld, mam, ag, ba, ssa, ldes, jmt, ln, "
298 "env, lqns, uq). A bare algorithm name must be qualified by its family here, as in "
299 "'nc.comom': resolving it needs the per-family method registry "
300 "(listValidMethods) that this port does not carry");
303 t.
submethod = rest.empty() ? std::string(
"default") : rest;
347 bool has_open =
false, has_closed =
false;
349 if (std::isinf(c.
population)) has_open =
true;
350 else has_closed =
true;
352 t.
is_open = has_open && !has_closed;
354 t.
is_mixed = has_open && has_closed;
361 for (std::size_t i = 1; i <=
sn.nstations && !t.
has_map; ++i)
362 for (std::size_t r = 1; r <=
sn.nclasses; ++r) {
363 const ProcessType p =
sn.procid(i, r);
364 if (p == ProcessType::MAP || p == ProcessType::MMPP2) {
372 bool preempt =
false, psprio =
false, hol =
false;
374 if (s.
sched == SchedStrategy::FCFSPRPRIO || s.
sched == SchedStrategy::FCFSPIPRIO ||
375 s.
sched == SchedStrategy::LCFSPRPRIO || s.
sched == SchedStrategy::LCFSPIPRIO)
377 if (s.
sched == SchedStrategy::PSPRIO || s.
sched == SchedStrategy::DPSPRIO ||
378 s.
sched == SchedStrategy::GPSPRIO)
380 if (s.
sched == SchedStrategy::HOL || s.
sched == SchedStrategy::LCFSPRIO ||
381 s.
sched == SchedStrategy::SRPTPRIO)
384 if (preempt) t.
prio =
"preempt";
385 else if (psprio) t.
prio =
"ps";
386 else if (hol) t.
prio =
"hol";
441 const std::string method = token.empty() ? std::string(
"default") : token;
466 if (!
sn.has_product_form()) {
473 if (st.
sched == SchedStrategy::OI || st.
sched == SchedStrategy::PAS) oi =
true;
474 if (!oi)
return false;
499 bool has_place =
false;
501 if (nd.
nodetype == NodeType::Place) has_place =
true;
502 else if (nd.
nodetype != NodeType::Transition && nd.
nodetype != NodeType::Source &&
506 if (!has_place)
return false;
528 std::vector<AutoSolver> skipped;
529 for (std::size_t k = 0; k < order.size(); ++k) {
531 skipped.push_back(order[k]);
537 out.
method = (token ==
"default") ? std::string() : token;
552 std::vector<AutoSolver> out;
553 for (std::size_t i = 0; i <
sizeof(kSlots) /
sizeof(*kSlots); ++i)
555 out.push_back(kSlots[i]);
572inline std::vector<AutoSolver> avg_order(
const AutoTraits& t,
bool homogeneous_inf) {
580 if (t.prio ==
"preempt")
597inline UnsupportedError no_solver(
const std::string& what,
598 const std::vector<AutoSolver>& skipped) {
599 std::string msg =
"SolverAUTO: no solver supports this model" + what;
600 if (!skipped.empty()) {
601 msg +=
" (the ranking preferred ";
602 for (std::size_t i = 0; i < skipped.size(); ++i) {
606 msg +=
", which this port does not build)";
639 const std::vector<AutoSolver> exact_order =
646 const std::vector<AutoSolver> order =
647 detail::avg_order(t,
sn.has_homogeneous_scheduling(SchedStrategy::INF));
656 throw detail::no_solver(
"", pool);
670inline bool in_list(
const std::string& m,
const char*
const* tab, std::size_t n) {
671 for (std::size_t i = 0; i < n; ++i)
672 if (m == tab[i])
return true;
677inline bool is_avg_method(
const std::string& m) {
678 static const char* kAvg[] = {
679 "getAvgChainTable",
"getAvgTputTable",
"getAvgRespTTable",
"getAvgUtilTable",
680 "getAvgSysTable",
"getAvgNodeTable",
"getAvgTable",
"getAvgTableLayered",
"getAvg",
681 "getAvgChain",
"getAvgSys",
"getAvgNode",
"getAvgNodeChain",
"getAvgArvRChain",
682 "getAvgQLenChain",
"getAvgUtilChain",
"getAvgRespTChain",
"getAvgTputChain",
683 "getAvgSysRespT",
"getAvgSysTput",
"getAvgQLen",
"getAvgUtil",
"getAvgRespT",
684 "getAvgResidT",
"getAvgWaitT",
"getAvgTput",
"getAvgArvR",
"getAvgQLenTable",
685 "getAvgResidTChain",
"getAvgNodeQLenChain",
"getAvgNodeUtilChain",
686 "getAvgNodeRespTChain",
"getAvgNodeResidTChain",
"getAvgNodeTputChain",
687 "getAvgNodeArvRChain",
"getAvgNodeChainTable",
"getResults",
"hasResults",
688 "getAvgHandles",
"getTranHandles",
"getAvgQLenHandles",
"getAvgUtilHandles",
689 "getAvgRespTHandles",
"getAvgTputHandles",
"getAvgArvRHandles",
"getAvgResidTHandles",
690 "getMethodFeatureSet",
"supportsModelMethod",
"isStochasticMethod",
"libraries",
691 "showLibraryAttribution",
"citations"};
692 return in_list(m, kAvg,
sizeof(kAvg) /
sizeof(*kAvg));
696inline bool is_ensemble_method(
const std::string& m) {
697 static const char* kEns[] = {
"getEnsembleAvg",
"getEnsembleAvgTables",
"getSolver",
698 "setSolver",
"getNumberOfModels",
"getIteration",
699 "get_state",
"set_state",
"update_solver"};
700 return in_list(m, kEns,
sizeof(kEns) /
sizeof(*kEns));
703inline bool is_cdf_method(
const std::string& m) {
704 return m ==
"getCdfRespT" || m ==
"getCdfPassT" || m ==
"getPerctRespT";
707inline bool is_tran_prob_method(
const std::string& m) {
708 return m ==
"getTranProb" || m ==
"getTranProbSys" || m ==
"getTranProbAggr" ||
709 m ==
"getTranProbSysAggr";
712inline bool is_prob_method(
const std::string& m) {
713 return m ==
"getProb" || m ==
"getProbAggr" || m ==
"getProbSys" || m ==
"getProbSysAggr" ||
714 m ==
"getProbMarg" || m ==
"getProbNormConstAggr";
717inline bool is_sample_method(
const std::string& m) {
return m ==
"sample" || m ==
"sampleSys"; }
719inline bool is_sample_aggr_method(
const std::string& m) {
720 return m ==
"sampleAggr" || m ==
"sampleSysAggr";
723inline bool is_cache_metric_method(
const std::string& m) {
724 static const char* kTab[] = {
"getAvgCacheTable",
"getAvgCacheT",
"getAvgItemTable",
725 "getAvgItemT",
"cacheAvgT",
"itemAvgT",
"aCaT",
"aIT"};
726 return in_list(m, kTab,
sizeof(kTab) /
sizeof(*kTab));
729inline bool is_loss_metric_method(
const std::string& m) {
730 static const char* kTab[] = {
"getAvgLossTable",
"getAvgLossT",
"getAvgRegionLossTable",
731 "getAvgRegionLossT",
"lossAvgT",
"regionLossAvgT",
733 return in_list(m, kTab,
sizeof(kTab) /
sizeof(*kTab));
736inline bool is_orbit_metric_method(
const std::string& m) {
737 static const char* kTab[] = {
"getAvgOrbitTable",
"getAvgOrbitT",
"getAvgOrbit",
"orbitAvgT",
739 return in_list(m, kTab,
sizeof(kTab) /
sizeof(*kTab));
742inline bool is_moment_method(
const std::string& m) {
743 static const char* kTab[] = {
"getMomentTable",
"getMomentChainTable",
"getMomentStationTable",
744 "getMomentT",
"getMomentChainT",
"getMomentStationT",
745 "momentT",
"momentChainT",
"momentStationT",
747 return in_list(m, kTab,
sizeof(kTab) /
sizeof(*kTab));
750inline bool is_sens_method(
const std::string& m) {
751 static const char* kTab[] = {
"getSensitivityTable",
"getSensitivityT",
"sensitivityT",
"sT",
752 "supportsExactSensitivity"};
753 return in_list(m, kTab,
sizeof(kTab) /
sizeof(*kTab));
768 if (detail::is_ensemble_method(method))
770 "' is only available for LayeredNetwork models");
772 std::vector<AutoSolver> order;
773 if (method ==
"getTranAvg") {
775 }
else if (detail::is_cdf_method(method)) {
778 if (
sn.has_homogeneous_scheduling(SchedStrategy::FCFS) &&
sn.has_product_form())
782 }
else if (method ==
"getTranCdfPassT" || method ==
"getTranCdfRespT") {
784 }
else if (detail::is_tran_prob_method(method)) {
786 }
else if (detail::is_sample_method(method)) {
788 }
else if (detail::is_sample_aggr_method(method)) {
790 }
else if (detail::is_prob_method(method)) {
791 if (
sn.has_product_form())
795 }
else if (detail::is_cache_metric_method(method)) {
798 }
else if (detail::is_loss_metric_method(method)) {
800 }
else if (detail::is_orbit_metric_method(method)) {
802 }
else if (detail::is_moment_method(method)) {
804 }
else if (detail::is_sens_method(method)) {
821 std::vector<AutoSolver> order;
822 if (detail::is_tran_prob_method(method) || detail::is_cdf_method(method) ||
823 method ==
"getTranCdfPassT" || method ==
"getTranCdfRespT" || method ==
"getTranAvg") {
825 }
else if (detail::is_sample_method(method) || detail::is_sample_aggr_method(method)) {
828 }
else if (detail::is_prob_method(method)) {
838 bool any_open =
false;
840 if (std::isinf(c.
population)) any_open =
true;
842 order.erase(std::remove(order.begin(), order.end(),
AutoSolver::CTMC), order.end());
848 throw detail::no_solver(
" exactly for method '" + method +
849 "'; use the default heuristic for the approximation",
856 const std::vector<AutoSolver> order =
857 detail::is_sample_method(method)
862 throw detail::no_solver(
" by simulation", order);
880 sn, std::string(), out))
887 sn, std::string(), out))
908 const std::string& method,
AutoMode mode) {
910 std::vector<AutoSolver> out(1, chosen.
solver);
912 for (std::size_t i = 0; i < cand.size(); ++i)
913 if (std::find(out.begin(), out.end(), cand[i]) == out.end()) out.push_back(cand[i]);
928inline bool layered_ranked(
const std::vector<AutoLayered>& order,
AutoLayeredChoice& out) {
929 std::vector<AutoLayered> skipped;
930 for (std::size_t k = 0; k < order.size(); ++k) {
932 skipped.push_back(order[k]);
956 std::vector<AutoLayered> order;
963 }
else if (method ==
"getTranAvg" || detail::is_cdf_method(method) ||
964 method ==
"getTranCdfPassT" || method ==
"getTranCdfRespT") {
966 }
else if (detail::is_sample_method(method) || detail::is_sample_aggr_method(method)) {
968 }
else if (detail::is_prob_method(method) || detail::is_tran_prob_method(method)) {
970 }
else if (detail::is_ensemble_method(method)) {
973 }
else if (has_cache_task) {
986 for (std::size_t i = 0; i < order.size(); ++i)
990 if (detail::layered_ranked(order, out))
return out;
992 "SolverAUTO: no LayeredNetwork solver in this port serves method '" + method +
993 "'; the reference's ranking is served by SolverLQNS, which shells out to an external "
994 "binary this port does not wrap");
1019 std::vector<AutoEnv> order;
1025 std::vector<AutoEnv> skipped;
1026 for (std::size_t k = 0; k < order.size(); ++k) {
1028 skipped.push_back(order[k]);
1033 out.
retry.push_back(order[k]);
1035 for (std::size_t j = 0; j < 3; ++j)
1037 out.
retry.push_back(slots[j]);
1041 "SolverAUTO: no Environment stage solver in this port serves method '" + method +
"'");
UnsupportedError(const std::string &what)
A subset of the registry: MATLAB's SolverFeatureSet, whose list is a flag per field.
A network plus its refreshed NetworkStruct.
Worst-case log-size of the CTMC state space induced by a NetworkStruct.
The exception types the port throws.
Where the LDES engine is, and whether this machine can run it.
Is a usable lqns installed on this machine?
bool auto_ispn_preferred(const qn::NetworkStruct< T > &sn)
True for a pure stochastic Petri net with an open class: every node is a Place, a Transition,...
bool auto_supports(AutoSolver s, const qn::NetworkStruct< T > &sn, const std::string &token)
Solver.supports(model) for a candidate slot, tightened by the two method-level rules a flat feature s...
bool auto_layered_is_available(AutoLayered s)
Every LN layer engine the ranking names is one --layer-solver takes (mva, nc, fluid,...
AutoEnvChoice auto_choose_env_solver(const std::string &method, AutoMode mode=AutoMode::HEUR)
The Environment arm of chooseSolverHeur / chooseSolverExact / chooseSolverSim.
AutoSolver
The Network candidate slots, in the reference's slot order (SolverAUTO.m:41-50), which is also the or...
bool auto_ctmc_is_tractable(const qn::NetworkStruct< T > &sn, double cutoff=-1.0)
double auto_ctmc_state_space_logsize(const qn::NetworkStruct< T > &sn, double cutoff=-1.0)
Worst-case log-size of the CTMC state space induced by sn: the SAME estimator SolverCTMC's memory gat...
AutoChoice auto_choose_solver_exact(const qn::NetworkStruct< T > &sn, const std::string &method)
chooseSolverExact: the ranking restricted to solvers that answer exactly.
AutoSolver auto_choose_solver(const qn::NetworkStruct< T > &sn, const std::string &method)
The heuristic Network arm, by getter name.
std::string auto_family_alias(const std::string &name)
SolverAUTO.familyAlias: the canonical family of a method name, or "" when the method name names none.
AutoTraits auto_traits(const qn::NetworkStruct< T > &sn)
bool auto_solver_is_available(AutoSolver s)
True when this port has an engine behind the slot at all.
bool auto_is_selection_intent(const std::string &token)
SolverAUTO.selectionIntents, less 'bound'.
const double kAutoExactPopulationMax
Population at or below which an exact solver is preferred (EXACT_POPULATION_MAX).
AutoSolver auto_choose_avg_solver(const qn::NetworkStruct< T > &sn)
AutoChoice auto_choose_avg_solver_ex(const qn::NetworkStruct< T > &sn)
chooseAvgSolverHeur, the Network arm: exact first at small populations, then the trait-keyed ranking,...
AutoLayeredChoice auto_choose_layered_solver(const std::string &method, bool has_cache_task, AutoMode mode=AutoMode::HEUR)
chooseLayeredSolver plus the LayeredNetwork arm of chooseAvgSolverHeur.
AutoMode auto_mode_of_token(const std::string &token)
const char * auto_env_stage_solver(AutoEnv s)
The EnvOptions::stage_solver (and --stage-solver) name of a candidate ensemble.
const double kAutoCtmcStateCap
The cap reachable_space_generator enforces (solver_ctmc.h, maxst).
AutoChoice auto_choose_solver_sim(const qn::NetworkStruct< T > &sn, const std::string &method)
chooseSolverSim: the ranking restricted to simulators.
bool auto_env_is_available(AutoEnv)
All three candidate ensembles are built here (EnvOptions::stage_solver = fluid, mva,...
const char * auto_solver_name(AutoSolver s)
AutoToken auto_resolve_token(const std::string &raw, const qn::NetworkStruct< T > &sn)
resolveMethodToken with its third arm: an intent, a family[.submethod], or else a BARE method name,...
std::vector< AutoSolver > auto_candidates(const qn::NetworkStruct< T > &sn)
The candidate pool in slot order, filtered by supports: what the delegate retries through after the c...
std::vector< AutoSolver > auto_proposed_solvers(const qn::NetworkStruct< T > &sn, const std::string &method, AutoMode mode)
delegate's proposed order: the chosen solver, then every feasible candidate in slot order.
AutoChoice auto_choose_solver_mode(const qn::NetworkStruct< T > &sn, const std::string &method, AutoMode mode)
chooseSolver: the selection mode picks the ranking, and every mode but the two learned ones keeps the...
const char * auto_env_name(AutoEnv s)
AutoChoice auto_choose_solver_heur(const qn::NetworkStruct< T > &sn, const std::string &method)
chooseNetworkSolver in chooseSolverHeur.m: the getter names the metric family, the family names a ran...
bool auto_ranked(const std::vector< AutoSolver > &order, const qn::NetworkStruct< T > &sn, const std::string &token, AutoChoice &out)
chooseSolverRanked: the first slot in ORDER that exists and accepts the model.
AutoEnv
The Environment candidate slots (SolverAUTO.m:58-60).
AutoLayered
The LayeredNetwork candidate slots (SolverAUTO.m:52-56).
AutoMode
The selection intents of SolverAUTO.selectionIntents, less 'bound'.
const char * auto_layered_name(AutoLayered s)
The layered names are the CLI's own tokens, because that is what the choice is spent on: ln....
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
NodeType
Node kinds, with the values of MATLAB NodeType.
bool ldes_is_available()
True when this machine can run the engine at all, by either image.
bool lqns_is_available()
True when lqns is installed AND is a release this port speaks.
double ctmc_state_space_logsize(const qn::NetworkStruct< T > &sn, const CtmcSizeOptions &opt=CtmcSizeOptions())
Worst-case log state-space size of sn.
FeatureSet ldes_feature_set(const std::string &)
SolverLDES.getFeatureSet, transcribed WHOLE.
FeatureSet fluid_feature_set(const std::string &method)
FeatureSet ssa_feature_set(const std::string &method)
FeatureSet used_lang_features(const NetworkStruct< T > &sn)
FeatureSet nc_feature_set(const std::string &method)
SolverNC.getFeatureSet, 48 names, transcribed unchanged.
FeatureSet fluid_class_feature_set()
SolverFLD.getFeatureSet, transcribed, MINUS what the requested method cannot evaluate – the port of @...
FeatureSet ctmc_feature_set(const std::string &method)
SolverCTMC.getFeatureSet, the reference's 104 MATLAB names in full.
SupportResult feature_set_supports(const std::string &solver, const FeatureSet &declared, const FeatureSet &used)
SolverFeatureSet.supports: is every feature the model uses declared?
FeatureSet mam_feature_set(const std::string &method)
SolverMAM.getFeatureSet, the union of its four setTrue calls: 55 MATLAB names, WIDENED for 'default'/...
FeatureSet mva_feature_set(const std::string &raw_method)
SolverMVA.getFeatureSet, plus getMethodFeatureSet's per-method deltas.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
The DECLARED side of the gate: one feature set per solver.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
What a ranking resolved to, and what it had to skip to get there.
std::string method
The method the choice was gated on: "" for the default, "exact".
std::vector< AutoSolver > skipped
Slots that outranked solver and have no engine in this port.
std::vector< AutoEnv > retry
delegate.m's proposed list: the chosen ensemble, then every candidate in slot order (MVA,...
std::vector< AutoEnv > skipped
std::vector< AutoLayered > skipped
resolveMethodToken, minus the unqualified-algorithm-name arm.
std::string submethod
the method handed to the family, "default" when bare
std::string family
empty when is_intent
The structural traits the rankings are keyed on.
std::string prio
"none", "preempt", "ps" or "hol", in the reference's own precedence.
Options the estimator reads; only the cutoff matters.
double cutoff
< 0 or non-finite = not given, take the solver default
One job class of the network.
double population
infinite for an open class
One station of the network.