5#ifndef LINE_LANG_QN_NETWORK_BUILDER_H
6#define LINE_LANG_QN_NETWORK_BUILDER_H
65 void set(std::size_t r, std::size_t s, std::size_t i, std::size_t j,
const T& p) {
68 void set(std::size_t i, std::size_t j,
const T& p) {
set(1, 1, i, j, p); }
78 for (
const auto& kv : block.entries)
79 set(cls, cls, kv.first.i, kv.first.j, kv.second);
82 T
get(std::size_t r, std::size_t s, std::size_t i, std::size_t j)
const {
89 Key(std::size_t r_, std::size_t s_, std::size_t i_, std::size_t j_)
90 :
r(r_),
s(s_),
i(i_),
j(j_) {}
92 if (
r != o.
r)
return r < o.
r;
93 if (
s != o.
s)
return s < o.
s;
94 if (
i != o.
i)
return i < o.
i;
113 explicit Network(
const std::string& nm) { sn_.name = nm; }
135 st.
nodetype = (sched == SchedStrategy::INF) ? NodeType::Delay : NodeType::Queue;
137 st.
nservers = (sched == SchedStrategy::INF)
138 ? std::numeric_limits<double>::infinity()
140 const std::size_t ist = sn_.add_station(st);
141 sn_.nodes[sn_.station_to_node[ist - 1] - 1].queue_object =
true;
142 init_node(sn_.station_to_node[ist - 1]);
143 return sn_.station_to_node[ist - 1];
151 st.
sched = SchedStrategy::INF;
152 st.
nservers = std::numeric_limits<double>::infinity();
153 const std::size_t ist = sn_.add_station(st);
154 init_node(sn_.station_to_node[ist - 1]);
155 return sn_.station_to_node[ist - 1];
165 if (sn_.sourceIdx != 0)
166 throw InputError(
ErrorKind{
"Model"},
"Network '" + sn_.
name +
"' already has a Source; a network holds at most one. "
167 "Give every open class its arrival process on that Source.");
170 st.nodetype = NodeType::Source;
171 st.sched = SchedStrategy::EXT;
173 const std::size_t ist = sn_.add_station(st);
175 init_node(sn_.station_to_node[ist - 1]);
176 return sn_.station_to_node[ist - 1];
181 if (sn_.sinkNode != 0)
throw InputError(
ErrorKind{
"Model"},
"Network '" + sn_.
name +
"' already has a Sink; a network holds at most one. Route every open class to that Sink.");
182 const std::size_t nd = sn_.add_node(nm, NodeType::Sink,
false);
190 const std::size_t nd = sn_.add_node(nm, NodeType::Router,
false);
204 std::size_t
add_logger(
const std::string& nm,
const std::string& log_file = std::string()) {
205 const std::size_t nd = sn_.add_node(nm, NodeType::Logger,
false);
209 std::string base = log_file;
210 const std::size_t slash = base.find_last_of(
'/');
211 if (slash != std::string::npos) base = base.substr(slash + 1);
212 sn_.nodes[nd - 1].logger.file_name = base;
226 if (C.
rows() != sn_.classes.size() || C.
cols() != sn_.classes.size())
228 "': the matrix must be (nclasses x nclasses); declare the classes "
230 const std::size_t nd = sn_.add_node(nm, NodeType::ClassSwitch,
false);
231 sn_.csmatrix[nd] = C;
252 const std::size_t nd = sn_.add_node(nm, NodeType::ClassSwitch,
false);
260 if (node == 0 || node > sn_.nodes.size())
261 throw InputError(
"set_class_switch_matrix: node index is out of range");
262 if (sn_.nodes[node - 1].nodetype != NodeType::ClassSwitch)
263 throw InputError(
"set_class_switch_matrix: node '" + sn_.nodes[node - 1].name +
264 "' is not a ClassSwitch");
265 if (C.
rows() != sn_.classes.size() || C.
cols() != sn_.classes.size())
266 throw InputError(
"set_class_switch_matrix: the matrix of '" +
267 sn_.nodes[node - 1].name +
268 "' must be (nclasses x nclasses)");
269 sn_.csmatrix[node] = C;
274 std::size_t
add_fork(
const std::string& nm,
double tasks_per_link = 1.0) {
275 const std::size_t nd = sn_.add_node(nm, NodeType::Fork,
false);
276 sn_.nodes[nd - 1].tasks_per_link = tasks_per_link;
303 double tasks, std::size_t dest_node = 0) {
305 ov.kind = ForkOverride::TASKS;
310 record_fork_override(ov);
316 std::size_t dest_node = 0) {
318 throw InputError(
"set_fork_tasks_per_link_dist: the jobs-per-link "
319 "distribution must be a DiscreteSampler");
321 ov.kind = ForkOverride::DIST;
326 record_fork_override(ov);
331 std::size_t dest_node,
double prob) {
332 if (prob < 0.0 || prob > 1.0)
333 throw InputError(
"set_fork_branch_probability: a branch activation "
334 "probability must lie in [0,1]");
336 ov.kind = ForkOverride::PROB;
341 record_fork_override(ov);
348 std::size_t
add_join(
const std::string& nm, std::size_t fork_node) {
366 st.
sched = SchedStrategy::INF;
367 st.
nservers = std::numeric_limits<double>::infinity();
368 const std::size_t ist = sn_.add_station(st);
369 const std::size_t nd = sn_.station_to_node[ist - 1];
375 void bind_join(std::size_t join_node, std::size_t fork_node) {
376 if (join_node == 0 || join_node > sn_.nodes.size() ||
377 sn_.nodes[join_node - 1].nodetype != NodeType::Join)
378 throw InputError(
"bind_join: the node being bound is not a Join");
379 if (fork_node == 0 || fork_node > sn_.nodes.size() ||
380 sn_.nodes[fork_node - 1].nodetype != NodeType::Fork)
381 throw InputError(
"Join '" + sn_.nodes[join_node - 1].name +
382 "': the node it closes is not a Fork");
383 sn_.fj.emplace_back(fork_node, join_node);
420 st.
nservers = (sched == SchedStrategy::INF)
421 ? std::numeric_limits<double>::infinity()
423 const std::size_t ist = sn_.add_station(st);
424 init_node(sn_.station_to_node[ist - 1]);
425 return sn_.station_to_node[ist - 1];
439 throw InputError(
"add_transition: a transition needs at least one mode");
442 "add_transition: enabling and firing must have one entry per mode");
443 const std::size_t nd = sn_.add_node(nm, NodeType::Transition,
true);
444 sn_.transparam[nd] = par;
463 const std::size_t nd = sn_.add_node(nm, NodeType::Transition,
true);
476 std::size_t
add_mode(std::size_t node,
const std::string& nm) {
485 tp.
firingdep.push_back(std::function<T(
const std::vector<T>&)>());
502 mode_param(node, mode,
"set_mode_distribution").firingproc[mode - 1] = d;
507 mode_param(node, mode,
"set_mode_timing").timing[mode - 1] = ts;
512 mode_param(node, mode,
"set_mode_servers").nmodeservers[mode - 1] = n;
517 mode_param(node, mode,
"set_firing_priority").firingprio[mode - 1] = prio;
522 mode_param(node, mode,
"set_firing_weight").fireweight[mode - 1] = w;
527 const std::function<T(
const std::vector<T>&)>& g) {
528 mode_param(node, mode,
"set_mode_firing_dependence").firingdep[mode - 1] = g;
537 fluid_place_arg(place,
"set_mode_fluid_rate");
538 if (!std::isfinite(rate))
539 throw InputError(
"set_mode_fluid_rate: the fluid rate must be a finite scalar");
540 set_fluid_row(tp.
fluidrate[mode - 1], place, rate);
548 const std::string& op,
double threshold) {
550 fluid_place_arg(place,
"set_mode_fluid_guard");
551 std::vector<typename TransitionParam<T>::FluidGuard>& g = tp.
fluidguard[mode - 1];
552 for (std::size_t k = g.size(); k-- > 0;)
553 if (g[k].node == place) g.erase(g.begin() +
static_cast<std::ptrdiff_t
>(k));
554 if (op.empty())
return;
556 if (op ==
">=") sgn = 1;
557 else if (op ==
"<=") sgn = -1;
558 else throw InputError(
"set_mode_fluid_guard: the fluid guard operator must be '>=' or '<='");
559 if (!std::isfinite(threshold) || threshold < 0.0)
561 "set_mode_fluid_guard: the fluid guard threshold must be a finite non-negative scalar");
575 fluid_place_arg(place,
"set_mode_fluid_impulse");
576 if (!std::isfinite(delta))
577 throw InputError(
"set_mode_fluid_impulse: the fluid impulse must be a finite scalar");
587 const std::function<
double(
double)>& h) {
589 fluid_place_arg(place,
"set_mode_fluid_dependence");
590 std::vector<typename TransitionParam<T>::FluidDep>& d = tp.
fluiddep[mode - 1];
591 for (std::size_t k = d.size(); k-- > 0;)
592 if (d[k].node == place) d.erase(d.begin() +
static_cast<std::ptrdiff_t
>(k));
596 "set_mode_fluid_dependence: fluid rate dependence is not supported for IMMEDIATE modes");
599 "set_mode_fluid_dependence: fluid rate dependence is supported only for exponentially "
600 "distributed (memoryless) firing; set an Exp distribution on the mode first");
614 const std::function<
double(
const std::vector<double>&)>& phi,
615 const std::vector<std::size_t>& read = std::vector<std::size_t>()) {
617 fluid_place_arg(place,
"set_mode_fluid_flow_dependence");
618 std::vector<typename TransitionParam<T>::FluidFlowDep>& d = tp.
fluidflowdep[mode - 1];
619 for (std::size_t k = d.size(); k-- > 0;)
620 if (d[k].node == place) d.erase(d.begin() +
static_cast<std::ptrdiff_t
>(k));
625 for (std::size_t q : read) {
626 if (q == 0 || q > sn_.nodes.size() || sn_.nodes[q - 1].nodetype != NodeType::Place)
627 throw InputError(
"set_mode_fluid_flow_dependence: the places a fluid flow dependence reads must be "
629 fd.
read.push_back(q);
631 std::sort(fd.
read.begin(), fd.
read.end());
646 std::size_t place,
const T& tokens) {
647 arc_target(node, mode, cls, place,
true,
"set_enabling_conditions");
648 pending_arcs_[node].enab.push_back(TransitionArc(mode, place, cls, tokens));
657 std::size_t place,
const T& tokens) {
658 arc_target(node, mode, cls, place,
true,
"set_inhibiting_conditions");
659 pending_arcs_[node].inhib.push_back(TransitionArc(mode, place, cls, tokens));
668 std::size_t dest,
const T& tokens) {
669 arc_target(node, mode, cls, dest,
false,
"set_firing_outcome");
670 pending_arcs_[node].fire.push_back(TransitionArc(mode, dest, cls, tokens));
680 int max_attempts = 0) {
681 if (node == 0 || node > sn_.nodes.size())
682 throw InputError(
"set_retrial: node index is out of range");
683 const std::size_t ist = sn_.nodes[node - 1].station;
684 if (ist == 0)
throw InputError(
"set_retrial: node is not a station");
689 const std::size_t K = sn_.classes.size();
690 if (cls == 0 || cls > K)
691 throw InputError(
"set_retrial: class index is out of range");
705 set_drop_rule(node, cls, max_attempts > 0 ? DropStrategy::RETRIAL_WITH_LIMIT
706 : DropStrategy::RETRIAL);
722 bool size_buffer =
true) {
723 if (node == 0 || node > sn_.nodes.size())
724 throw InputError(
"set_orbit_policy: node index is out of range");
725 const std::size_t ist = sn_.nodes[node - 1].station;
726 typename std::map<std::size_t, RetrialParam<T> >::iterator it = sn_.retrialparam.find(ist);
727 if (ist == 0 || it == sn_.retrialparam.end() || cls == 0 ||
728 cls > it->second.retrial_proc.size() || it->second.retrial_proc[cls - 1].disabled)
729 throw InputError(
"set_orbit_policy: the class has no retrial declared at this station");
730 if (policy != 1 && policy != 2)
731 throw InputError(
"set_orbit_policy: the policy must be 1 (LINEAR) or 2 (CONSTANT)");
733 throw InputError(
"set_orbit_policy: max_orbit must be -1 (unbounded) or non-negative");
734 it->second.policy[cls - 1] = policy;
735 it->second.max_orbit[cls - 1] = max_orbit;
739 st.
cap = max_orbit < 0 ? std::numeric_limits<double>::infinity()
750 Station<T>& st = station_ref(node, cls,
"set_patience");
762 Station<T>& st = station_ref(node, cls,
"set_orbit_impatience");
769 Station<T>& st = station_ref(node, cls,
"set_batch_reject");
785 Station<T>& st = station_ref(node, cls,
"set_orbit_persistence");
788 if (!std::isfinite(p) || p < 0.0 || p > 1.0)
789 throw InputError(
"Orbit join probability must be in [0, 1].");
790 if (!std::isfinite(q) || q < 0.0 || q > 1.0)
791 throw InputError(
"Orbit persistence probability must be in [0, 1].");
792 if ((p < 1.0 || q < 1.0) && std::isfinite(sn_.classes[cls - 1].population))
794 "Non-persistent retrial customers leave the network, which a closed class cannot do; "
795 "use an open class.");
810 Station<T>& st = station_ref(node, cls,
"set_orbital_search");
812 if (!std::isfinite(th) || th < 0.0 || th > 1.0)
813 throw InputError(
"Orbital search probability must be in [0, 1].");
815 for (std::size_t r = 0; r < st.
orbit_search.size(); ++r)
817 if (total > 1.0 + 1e-12)
818 throw InputError(
"Orbital search probabilities over the classes must sum to at most 1.");
830 Station<T>& st = station_ref(node, cls,
"set_balking");
832 st.
balking[cls - 1].strategy = strategy;
833 st.
balking[cls - 1].thresholds = thresholds;
838 const std::size_t ist = station_of(node,
"add_server_type");
839 sn_.stations[ist - 1].server_types.push_back(stype);
842 for (
const auto& pool : sn_.stations[ist - 1].server_types) total += pool.count;
843 sn_.stations[ist - 1].nservers = total;
852 Station<T>& st = station_ref(node, cls,
"set_server_parallelism");
854 throw InputError(
"set_server_parallelism: parallelism must be a positive integer");
858 "set_server_parallelism: parallelism " + std::to_string(n) +
" exceeds the " +
859 std::to_string(
static_cast<long long>(st.
nservers)) +
" servers of station '" +
860 sn_.nodes[node - 1].name +
"', so a job of this class could never enter service");
868 sn_.stations[station_of(node,
"set_hetero_sched_policy") - 1].hetero_policy = policy;
876 Station<T>& st = station_ref(node, cls,
"set_arrival_batch");
880 bool zero_in_support =
false;
885 zero_in_support =
true;
888 zero_in_support = !dist.
params.empty() && dist.
params[0] < one;
891 for (
const T& x : dist.
trace) zero_in_support = zero_in_support || x < one;
897 throw InputError(
"set_arrival_batch: the batch-size law can return a value below one; a batch must carry "
898 "at least one job, so its support must be {1,2,...}");
900 throw InputError(
"set_arrival_batch: the batch-size law has mean below one; a batch must carry at least "
901 "one job, so its support must be {1,2,...}");
909 sn_.stations[station_of(node,
"set_marked_classes") - 1].marked_classes = classes;
915 Station<T>& st = station_ref(node, cls,
"set_departure_discipline");
922 if (node == 0 || node > sn_.nodes.size())
923 throw InputError(
"set_initial_marking: node index is out of range");
924 if (sn_.nodes[node - 1].nodetype != NodeType::Place)
925 throw InputError(
"set_initial_marking: only a Place carries an initial marking");
926 sn_.initmarking[node] = tokens;
935 place_station(node,
"set_place_fluid").fluid =
fluid;
940 if (std::isnan(cap) || cap <= 0.0)
941 throw InputError(
"set_fluid_capacity: the fluid capacity must be a positive scalar, or Inf "
942 "for an unbounded place");
943 place_station(node,
"set_fluid_capacity").fluidcap = cap;
948 if (!std::isfinite(level) || level < 0.0)
949 throw InputError(
"set_fluid_level: the initial fluid level must be a finite non-negative scalar");
950 place_station(node,
"set_fluid_level").fluidinit = level;
954 bool is_place_fluid(std::size_t node) {
return place_station(node,
"is_place_fluid").fluid; }
956 return place_station(node,
"get_fluid_capacity").fluidcap;
958 double get_fluid_level(std::size_t node) {
return place_station(node,
"get_fluid_level").fluidinit; }
962 const auto it = sn_.transparam.find(node);
963 return it != sn_.transparam.end() && it->second.has_fluid_arcs();
972 if (node == 0 || node > sn_.nodes.size())
973 throw InputError(
"set_state_prior: node index is out of range");
974 if (space.
rows() != prior.size())
976 "set_state_prior: the prior has one entry per ROW of the declared state space");
977 sn_.statespace[node] = space;
978 sn_.stateprior[node] = prior;
983 if (node == 0 || node > sn_.nodes.size())
984 throw InputError(
"set_join_strategy: node index is out of range");
985 if (sn_.nodes[node - 1].nodetype != NodeType::Join)
986 throw InputError(
"set_join_strategy: the node is not a Join");
990 sn_.joindecl[node] = jd;
995 const std::map<std::size_t, double>& weights) {
996 if (node == 0 || node > sn_.nodes.size())
997 throw InputError(
"set_routing_weights: node index is out of range");
998 std::vector<std::map<std::size_t, double>>& rw = sn_.nodes[node - 1].routing_weights;
999 if (rw.size() < sn_.classes.size()) rw.resize(sn_.classes.size());
1000 if (cls == 0 || cls > rw.size())
1001 throw InputError(
"set_routing_weights: class index is out of range");
1002 rw[cls - 1] = weights;
1007 if (node == 0 || node > sn_.nodes.size())
1008 throw InputError(
"set_routing_param: node index is out of range");
1009 std::vector<int>& rp = sn_.nodes[node - 1].routing_param;
1010 if (rp.size() < sn_.classes.size()) rp.resize(sn_.classes.size(), 0);
1011 if (cls == 0 || cls > rp.size())
1012 throw InputError(
"set_routing_param: class index is out of range");
1024 const std::size_t ist = station_of(node,
"set_setup_delayoff");
1025 const std::size_t K = sn_.classes.size();
1026 if (cls == 0 || cls > K)
1027 throw InputError(
"set_setup_delayoff: class index is out of range");
1029 if (sp.
setup.size() < K) {
1033 sp.
setup[cls - 1] = setup;
1053 const std::size_t ist = station_of(node,
"set_breakdown");
1056 "set_breakdown: both a failure and a repair time are required; a server that "
1057 "never recovers is an absorbing model, not a breakdown");
1060 if (!(fm > 0.0) || !(rm > 0.0))
1061 throw InputError(
"set_breakdown: the failure and repair times must have positive means");
1062 const std::size_t K = sn_.classes.size();
1069 for (std::size_t r = 0; r < K && r < down_service.size(); ++r) {
1074 "set_breakdown: station '" + sn_.stations[ist - 1].
name +
1075 "': the down-server service distribution must be exponential; a phase-type "
1076 "degraded service would need its own phase block in the joint chain");
1084 const std::size_t nd = sn_.add_node(nm, NodeType::Cache,
true);
1085 sn_.nodeparam[nd] = par;
1101 const std::vector<std::size_t>& read_classes,
1102 const std::vector<std::size_t>& hit_classes) {
1103 auto it = sn_.nodeparam.find(cache_node);
1104 if (it == sn_.nodeparam.end())
1105 throw InputError(
"setItemReadClasses: node is not a Cache");
1107 const std::size_t nitems = cp.
nitems;
1108 if (read_classes.size() != nitems)
1109 throw InputError(
"setItemReadClasses: pass exactly one read class per item");
1110 const std::vector<std::size_t> hit =
1111 per_item_classes(hit_classes, nitems,
"setItemReadClasses hit");
1112 const std::size_t K = sn_.classes.size();
1118 for (std::size_t i = 0; i < nitems; ++i) {
1121 cp.
pread[read_classes[i] - 1] = onehot;
1122 cp.
hitclass[read_classes[i] - 1] = hit[i];
1123 cp.
classitem[read_classes[i] - 1] = i + 1;
1125 cache_item_classes_[cache_node] = read_classes;
1133 void set_cache_read(std::size_t cache_node, std::size_t r,
const std::vector<T>& pmf) {
1134 CacheParam<T>& cp = cache_param_for_class(cache_node, r,
"set_read");
1135 if (pmf.size() != cp.
nitems)
1136 throw InputError(
"set_read: the popularity has " + std::to_string(pmf.size()) +
1137 " entries and the cache '" + sn_.nodes[cache_node - 1].name +
"' " +
1138 std::to_string(cp.
nitems) +
" items");
1139 cp.
pread[r - 1] = pmf;
1154 for (std::size_t k = 1; k <= n; ++k) h += std::pow(
double(k), -sv);
1155 for (std::size_t k = 1; k <= n; ++k)
1163 kind.
n = pmf.size();
1165 throw InputError(
"set_read: an item popularity is a Zipf or a DiscreteSampler over the item ranks");
1168 cache_param_for_class(cache_node, r,
"set_read").preadkind[r - 1] = kind;
1173 CacheParam<T>& cp = cache_param_for_class(cache_node, r,
"set_hit_class");
1174 check_class(h,
"set_hit_class");
1180 CacheParam<T>& cp = cache_param_for_class(cache_node, r,
"set_miss_class");
1181 check_class(m,
"set_miss_class");
1192 std::vector<std::size_t>
set_miss_cache(std::size_t cache_node, std::size_t next_cache,
1193 const std::vector<std::size_t>& hit_classes_at_next) {
1194 auto it = sn_.nodeparam.find(cache_node);
1195 auto itn = sn_.nodeparam.find(next_cache);
1196 if (it == sn_.nodeparam.end() || itn == sn_.nodeparam.end())
1197 throw InputError(
"setMissCache: both nodes must be Caches");
1198 if (it->second.nitems != itn->second.nitems)
1199 throw InputError(
"setMissCache: a cache network requires one common item set");
1200 auto self_it = cache_item_classes_.find(cache_node);
1201 if (self_it == cache_item_classes_.end())
1202 throw InputError(
"setMissCache: call setItemReadClasses on the source cache first");
1203 const std::vector<std::size_t> self_cls = self_it->second;
1204 const std::size_t nitems = it->second.nitems;
1205 const std::vector<std::size_t> hit =
1206 per_item_classes(hit_classes_at_next, nitems,
"setMissCache hit");
1208 std::vector<std::size_t> minted;
1209 minted.reserve(nitems);
1210 const bool closed = sn_.classes[self_cls[0] - 1].type == JobClassType::CLOSED;
1211 const std::size_t refstat = sn_.classes[self_cls[0] - 1].refstat;
1212 for (std::size_t i = 0; i < nitems; ++i) {
1215 cls =
add_closed_class(sn_.nodes[next_cache - 1].name +
"_item" + std::to_string(i + 1),
1216 0.0, sn_.station_to_node[refstat - 1]);
1218 cls =
add_open_class(sn_.nodes[next_cache - 1].name +
"_item" + std::to_string(i + 1));
1219 minted.push_back(cls);
1222 const std::size_t K = sn_.classes.size();
1223 for (std::size_t nd : {cache_node, next_cache}) {
1233 for (std::size_t i = 0; i < nitems; ++i) {
1236 dst.
pread[minted[i] - 1] = onehot;
1237 dst.
hitclass[minted[i] - 1] = hit[i];
1239 src.
missclass[self_cls[i] - 1] = minted[i];
1243 cache_miss_arcs_.push_back(CacheMissArc(minted[i], cache_node, next_cache));
1245 cache_item_classes_[next_cache] = minted;
1255 auto it = sn_.nodeparam.find(cache_node);
1256 if (it == sn_.nodeparam.end())
1257 throw InputError(
"setItemMissClass: node is not a Cache");
1258 auto self_it = cache_item_classes_.find(cache_node);
1259 if (self_it == cache_item_classes_.end())
1260 throw InputError(
"setItemMissClass: the cache has no per-item classes");
1261 const std::vector<std::size_t>& self_cls = self_it->second;
1262 const std::vector<std::size_t> miss =
1263 per_item_classes(miss_classes, self_cls.size(),
"setItemMissClass miss");
1265 cp.
missclass.resize(sn_.classes.size(), 0);
1266 for (std::size_t i = 0; i < self_cls.size(); ++i)
1267 cp.
missclass[self_cls[i] - 1] = miss[i];
1282 std::size_t miss_class,
const std::vector<std::size_t>& queue_nodes) {
1283 auto it = sn_.nodeparam.find(cache_node);
1284 if (it == sn_.nodeparam.end())
1285 throw InputError(
"setRetrievalSystem: node is not a Cache");
1287 if (queue_nodes.empty())
1288 throw InputError(
"setRetrievalSystem: the retrieval system has no stations");
1289 const std::size_t nitems = cp.
nitems;
1291 for (
int c : cp.
itemcap) totalcap += c;
1297 std::vector<Distrib<T> > svc;
1298 svc.reserve(queue_nodes.size());
1299 for (std::size_t q : queue_nodes) {
1300 const std::size_t st = station_of(q,
"setRetrievalSystem");
1301 const Distrib<T>& d = sn_.service[st - 1][read_class - 1];
1303 throw InputError(
"No service distribution for the read class at queue \"" +
1304 sn_.nodes[q - 1].name +
1305 "\"; call queue.setService(readClass, ...) before setRetrievalSystem.");
1309 cp.
retrieval_classes.assign(nitems, std::vector<std::size_t>(sn_.classes.size(), 0));
1310 const bool closed = sn_.classes[read_class - 1].type == JobClassType::CLOSED;
1311 const std::size_t refstat = sn_.classes[read_class - 1].refstat;
1312 for (std::size_t i = 0; i < nitems; ++i) {
1315 rc =
add_closed_class(sn_.classes[read_class - 1].name +
"_retrievalClass_" +
1316 std::to_string(i + 1),
1317 0.0, sn_.station_to_node[refstat - 1]);
1319 rc =
add_open_class(sn_.classes[read_class - 1].name +
"_retrievalClass_" +
1320 std::to_string(i + 1));
1321 for (std::size_t s = 0; s < queue_nodes.size(); ++s) {
1327 for (std::size_t k = 0; k < nitems; ++k)
1334 const std::size_t K = sn_.classes.size();
1341 cp.
pread[rc - 1] = onehot;
1348 std::size_t queue_node) {
1349 set_retrieval_system(cache_node, read_class, miss_class, std::vector<std::size_t>(1, queue_node));
1358 std::size_t item,
const T& rate) {
1368 std::size_t source_node, std::size_t dest_node,
const T& p) {
1369 const std::size_t rc = retrieval_class_of(cache_node, read_class, item);
1371 retrieval_routing_entries_.push_back(RetrievalRoutingEntry(rc, source_node, dest_node, p));
1376 std::size_t source_node, std::size_t dest_node,
const T& p) {
1387 if (!(njobs >= 0.0) || std::isinf(njobs))
1388 throw InputError(
"ClosedClass '" + nm +
"': the population must be finite");
1391 cl.
type = JobClassType::CLOSED;
1393 cl.
refstat = station_of(refstat_node,
"ClosedClass '" + nm +
"'");
1395 const std::size_t r = sn_.add_class(cl);
1396 grow_class_vectors();
1405 if (sn_.sourceIdx == 0)
1407 "': the model has no Source to reference; add one first");
1410 cl.
type = JobClassType::OPEN;
1411 cl.
population = std::numeric_limits<double>::infinity();
1414 const std::size_t r = sn_.add_class(cl);
1415 grow_class_vectors();
1428 std::size_t refstat_node,
int prio = 0) {
1430 sn_.classes[r - 1].self_looping =
true;
1436 class_ref(cls,
"set_reference_class").is_ref_class =
true;
1441 class_ref(cls,
"set_class_deadline").deadline = due;
1449 const std::size_t K = sn_.classes.size();
1450 if (spawn_cls == 0 || spawn_cls > K)
1451 throw InputError(
"set_class_spawn: the spawned class index is out of range");
1452 class_ref(cls,
"set_class_spawn").spawn = spawn_cls;
1466 const std::size_t K = sn_.classes.size();
1467 if (cls == 0 || cls > K)
throw InputError(
"set_class_patience: class index out of range");
1471 for (std::size_t ist = 0; ist < sn_.stations.size(); ++ist) {
1472 const std::size_t ind = sn_.station_to_node[ist];
1478 if (!st.
patience[cls - 1].disabled)
continue;
1496 const std::size_t K = sn_.classes.size();
1497 if (call_cls == 0 || call_cls > K || reply_cls == 0 || reply_cls > K)
1498 throw InputError(
"set_reply_signal_class: class index is out of range");
1500 if (sn_.syncreply.size() < K) sn_.syncreply.resize(K, 0);
1501 sn_.syncreply[call_cls - 1] = reply_cls;
1516 "Defective patience is not supported: the law never fires with probability "
1517 "pInf, and no solver models an infinite patience. Give the patient fraction its "
1518 "own class without patience, or set the inner law as the patience.");
1528 std::string(
"A Defective law is infinite with probability pInf, so its mean is Inf "
1529 "and it cannot be a ") + what +
" time. Use it as a lifetime or failure "
1530 "law, or MassAtOrigin for an atom at zero.");
1548 sn_.set_service(station_of(node,
"setService"), cls, dd);
1553 const std::size_t ist = station_of(node,
"setArrival");
1554 if (sn_.stations[ist - 1].nodetype != NodeType::Source)
1555 throw InputError(
"setArrival: node '" + sn_.nodes[node - 1].name +
"' is not a Source");
1562 sn_.set_service(ist, cls, dd);
1576 const std::size_t ist = station_of(node,
"setNumberOfServers");
1577 if (sn_.stations[ist - 1].sched == SchedStrategy::INF)
return;
1580 if (!(n >= 0.0))
throw InputError(
"setNumberOfServers: the server count must be >= 0");
1581 sn_.stations[ist - 1].nservers = n;
1584 if (std::isinf(n) && sn_.stations[ist - 1].nodetype == NodeType::Queue)
1585 sn_.stations[ist - 1].nodetype = NodeType::Delay;
1590 sn_.stations[station_of(node,
"setCapacity") - 1].cap = k;
1595 Station<T>& st = sn_.stations[station_of(node,
"setChainCapacity") - 1];
1596 st.
classcap.resize(sn_.classes.size(), std::numeric_limits<double>::infinity());
1609 Station<T>& st = sn_.stations[station_of(node,
"setImmediateFeedback") - 1];
1610 st.
immfeed.resize(sn_.classes.size(),
false);
1616 sn_.classes[cls - 1].immfeed =
true;
1621 Station<T>& st = sn_.stations[station_of(node,
"setDropRule") - 1];
1622 st.
droprule.resize(sn_.classes.size(), 0);
1623 st.
droprule[cls - 1] =
static_cast<int>(rule);
1642 std::size_t node,
const std::function<T(
const std::vector<std::size_t>&)>& muFun,
1644 const std::size_t ist = station_of(node,
"setServiceRateFunction");
1646 if (st.
sched != SchedStrategy::PAS && st.
sched != SchedStrategy::OI)
1648 "setServiceRateFunction is only applicable to PAS (pass-and-swap) and OI "
1649 "(order-independent) queues");
1650 if (!muFun)
throw InputError(
"setServiceRateFunction: the rate function is empty");
1661 for (std::size_t r = 1; r <= sn_.classes.size(); ++r) {
1662 const T rate_r = muFun(std::vector<std::size_t>{r});
1675 Station<T>& st = sn_.stations[station_of(node,
"setPollingType") - 1];
1676 if (st.
sched != SchedStrategy::POLLING)
1677 throw InputError(
"setPollingType is only applicable to a POLLING station");
1679 if (limited && par < 1)
1681 ?
"K-limited polling requires a parameter K >= 1"
1682 :
"G-limited polling requires a parameter K >= 1");
1695 Station<T>& st = sn_.stations[station_of(node,
"setPollingTable") - 1];
1696 if (st.
sched != SchedStrategy::POLLING)
1698 "setPollingTable can only be invoked on queues with SchedStrategy.POLLING.");
1699 const std::size_t R = sn_.classes.size();
1701 throw InputError(
ErrorKind{
"Argument"},
"The polling table must list class indices between 1 and " +
1702 std::to_string(R) +
".");
1703 for (std::size_t c : table)
1706 "The polling table must list class indices between 1 and " +
1707 std::to_string(R) +
".");
1710 "A polling table cannot be combined with a load-dependent polling order.");
1711 if (!swlegs.empty() && swlegs.size() != table.size())
1713 "setPollingTable needs one switchover entry per table position (" +
1714 std::to_string(table.size()) +
").");
1726 long threshold = -1) {
1727 Station<T>& st = sn_.stations[station_of(node,
"setPollingOrder") - 1];
1728 if (st.
sched != SchedStrategy::POLLING)
1730 "setPollingOrder can only be invoked on queues with SchedStrategy.POLLING.");
1733 "A load-dependent polling order cannot be combined with a polling table.");
1739 "The THRESHOLD polling order needs the priority class and the threshold L.");
1741 throw InputError(
ErrorKind{
"Argument"},
"The polling threshold L must be a non-negative integer.");
1754 Station<T>& st = sn_.stations[station_of(node,
"setPollingTimer") - 1];
1755 if (st.
sched != SchedStrategy::POLLING)
1757 "setPollingTimer can only be invoked on queues with SchedStrategy.POLLING.");
1758 const std::size_t R = sn_.classes.size();
1759 std::vector<Distrib<T>> tl;
1760 if (dists.size() == 1)
1761 tl.assign(R, dists[0]);
1762 else if (dists.size() == R)
1766 "setPollingTimer needs one distribution per class (" + std::to_string(R) +
").");
1770 throw InputError(
ErrorKind{
"Argument"},
"A polling timer must be a strictly positive distribution.");
1778 Station<T>& st = sn_.stations[station_of(node,
"setSwitchover") - 1];
1779 if (st.
sched != SchedStrategy::POLLING)
1780 throw InputError(
"setSwitchover is only applicable to a POLLING station");
1802 Station<T>& st = sn_.stations[station_of(node,
"setSwitchover") - 1];
1803 if (st.
sched == SchedStrategy::POLLING)
1805 "setSwitchover(fromClass, toClass, distrib) is not applicable to a POLLING "
1806 "station, whose switchover is the walk out of one buffer and is declared per "
1808 const std::size_t K = sn_.classes.size();
1809 if (from_cls == 0 || from_cls > K || to_cls == 0 || to_cls > K)
1810 throw InputError(
"setSwitchover: class index is out of range");
1824 Station<T>& st = sn_.stations[station_of(node,
"setQuantum") - 1];
1825 if (st.
sched != SchedStrategy::RR)
1826 throw InputError(
ErrorKind{
"Argument"},
"setQuantum can only be invoked on queues with SchedStrategy.RR.");
1829 "The RR quantum must be a non-degenerate time distribution (Exp, Erlang, "
1830 "HyperExp, APH, Coxian, PH, or Det for simulation).");
1831 const std::size_t K = sn_.classes.size();
1832 if (cls == 0 || cls > K)
throw InputError(
ErrorKind{
"Argument"},
"setQuantum: class index is out of range");
1841 for (std::size_t r = 1; r <= sn_.classes.size(); ++r)
set_quantum(node, r, q);
1846 Station<T>& st = sn_.stations[station_of(node,
"setSchedParam") - 1];
1862 sn_.stations[station_of(node,
"setLoadDependence") - 1].sched;
1866 "Load-dependence supported only for processor sharing (PS), discriminatory "
1867 "processor sharing (DPS) and first-come first-serve (FCFS) stations.");
1878 if (alpha.empty())
throw InputError(
"setLoadDependence: the scaling vector is empty");
1879 sn_.stations[station_of(node,
"setLoadDependence") - 1].lldscaling = alpha;
1900 const std::vector<T>& peak = std::vector<T>()) {
1901 Station<T>& st = sn_.stations[station_of(node,
"setClassDependence") - 1];
1902 const std::size_t K = sn_.classes.size();
1906 else if (peak.size() == 1)
1908 else if (peak.size() == K)
1912 "setClassDependence: peakRatePerClass must be a scalar or a vector of length "
1926 const std::vector<T>& peak) {
1927 Station<T>& st = sn_.stations[station_of(node,
"setJointDependence") - 1];
1928 const std::size_t K = sn_.classes.size();
1931 "setJointDependence: joint dependence requires an explicit peak rate; pass a "
1932 "scalar (identical peak for every class) or a per-class vector");
1934 if (peak.size() == 1)
1936 else if (peak.size() == K)
1940 "setJointDependence: peakRatePerClass must be a scalar or a vector of length "
1974 throw InputError(
"setGlobalDependence: the scaling must be a callable");
1975 const std::size_t M = sn_.stations.size(), K = sn_.classes.size();
1978 "setGlobalDependence: a global dependence requires an explicit peak rate; pass a "
1979 "scalar, one entry per station, or one entry per (station, class)");
1980 for (std::size_t i = 0; i < peak.size(); ++i)
1982 throw InputError(
"setGlobalDependence: peak must be positive");
1985 for (
int probe = 0; probe < 2; ++probe) {
1987 const std::vector<T> v = fun(n);
1988 if (v.size() != 1 && v.size() != M && v.size() != M * K)
1990 "setGlobalDependence: the handle must return a scalar, one entry per station, "
1991 "or one entry per (station, class)");
1992 for (std::size_t j = 0; j < v.size(); ++j)
1995 "setGlobalDependence: the handle must return finite nonnegative scalings");
1997 if (wire_cutoff < 1)
1998 throw InputError(
"setGlobalDependence: wireCutoff must be a positive integer");
1999 sn_.gdscaling = fun;
2000 sn_.gdscalingcutoff = wire_cutoff;
2001 if (peak.size() == 1)
2002 sn_.gdscalingpeak.assign(M * K, peak[0]);
2003 else if (peak.size() == M) {
2005 for (std::size_t i = 0; i < M; ++i)
2006 for (std::size_t r = 0; r < K; ++r) sn_.gdscalingpeak[i * K + r] = peak[i];
2007 }
else if (peak.size() == M * K)
2008 sn_.gdscalingpeak = peak;
2011 "setGlobalDependence: peak must be a scalar, one entry per station, or one entry "
2012 "per (station, class)");
2017 NodeDef& nd = sn_.nodes[node - 1];
2018 nd.
routing.resize(sn_.classes.size(), RoutingStrategy::PROB);
2049 const std::vector<std::vector<std::size_t>>& branches,
2050 const std::vector<std::size_t>& level,
2052 std::size_t cls = 0) {
2053 if (branches.size() < 2 || !branches[0].empty())
2054 throw InputError(
"set_state_dep_routing: branches[0] must be empty, branch index 1 "
2055 "denotes the complement M-V");
2056 const std::size_t B = branches.size();
2057 if (level.size() != B)
2058 throw InputError(
"set_state_dep_routing: level must have one entry per branch index, "
2059 "including the unused index 0");
2061 nodesdr.
entry = entry - 1;
2063 nodesdr.
branch.assign(B, std::vector<std::size_t>());
2066 for (std::size_t b = 1; b < B; ++b) {
2067 if (branches[b].empty())
2068 throw InputError(
"set_state_dep_routing: branch " + std::to_string(b + 1) +
2070 for (std::size_t k = 0; k < branches[b].size(); ++k)
2071 nodesdr.
branch[b].push_back(branches[b][k] - 1);
2072 nodesdr.
entryOf[b] = branches[b].front() - 1;
2075 nodesdr.
level = level;
2082 std::vector<std::size_t> node_to_station(sn_.nodes.size(), 0);
2083 std::vector<bool> is_station(sn_.nodes.size(),
false);
2084 for (std::size_t k = 0; k < sn_.station_to_node.size(); ++k) {
2085 node_to_station[sn_.station_to_node[k] - 1] = k;
2086 is_station[sn_.station_to_node[k] - 1] =
true;
2089 const std::vector<std::size_t>& n2s;
2090 const std::vector<bool>& isst;
2092 std::size_t operator()(std::size_t nd)
const {
2093 if (nd >= isst.size() || !isst[nd])
2094 throw InputError(
"set_state_dep_routing: node '" +
sn.nodes[nd].name +
2095 "' takes part in state-dependent routing but is not a "
2096 "station: the product form is over queue lengths, and a "
2097 "stateless node holds none");
2100 } to_station{node_to_station, is_station, sn_};
2105 for (std::size_t b = 1; b < B; ++b) {
2106 for (std::size_t k = 0; k < nodesdr.
branch[b].size(); ++k)
2113 sn_.sdr_nodes = nodesdr;
2115 const std::size_t K = sn_.classes.size();
2117 for (std::size_t r = 1; r <= K; ++r)
set_routing(entry, r, RoutingStrategy::SDR);
2138 for (std::size_t k = 0; k < nodes.size(); ++k) {
2139 if (nodes[k] == 0 || nodes[k] > sn_.nodes.size())
2140 throw InputError(
"serialRouting: the path names a node that does not exist");
2143 if (nodes.size() > 1 && sn_.nodes[nodes.back() - 1].nodetype != NodeType::Sink)
2156 for (
const auto& kv : Pm.
entries) {
2157 const auto& k = kv.first;
2158 if (k.r == 0 || k.r > sn_.classes.size() || k.s == 0 || k.s > sn_.classes.size())
2159 throw InputError(
"link: the routing matrix names a class that does not exist");
2160 if (k.i == 0 || k.i > sn_.nodes.size() || k.j == 0 || k.j > sn_.nodes.size())
2161 throw InputError(
"link: the routing matrix names a node that does not exist");
2175 const std::size_t K = sn_.classes.size();
2176 const std::size_t I = sn_.nodes.size();
2182 for (std::size_t a = 0; a < cache_miss_arcs_.size(); ++a) {
2183 const CacheMissArc&
mc = cache_miss_arcs_[a];
2184 P.set(
mc.cls,
mc.cls,
mc.from_node,
mc.to_node, one);
2189 for (std::size_t r = 1; r <= K; ++r) {
2190 if (!sn_.classes[r - 1].self_looping)
continue;
2191 for (
auto it = P.entries.begin(); it != P.entries.end();)
2192 it = it->first.r == r ? P.entries.erase(it) : std::next(it);
2193 const std::size_t ref = sn_.node_of_station(sn_.classes[r - 1].refstat);
2194 P.set(r, r, ref, ref, one);
2196 std::map<std::pair<std::size_t, std::size_t>, std::size_t> csid;
2197 for (std::size_t i = 1; i <= I; ++i)
2198 for (std::size_t j = 1; j <= I; ++j) {
2201 for (std::size_t r = 1; r <= K; ++r)
2202 for (std::size_t s = 1; s <= K; ++s) {
2203 const T p = P.get(r, s, i, j);
2205 C(r - 1, s - 1) = p;
2210 bool offdiag =
false;
2211 for (std::size_t r = 1; r <= K; ++r) {
2213 for (std::size_t s = 1; s <= K; ++s) S += C(r - 1, s - 1);
2215 for (std::size_t s = 1; s <= K; ++s) C(r - 1, s - 1) = T(C(r - 1, s - 1) / S);
2217 C(r - 1, r - 1) = one;
2219 for (std::size_t s = 1; s <= K; ++s)
2222 if (!offdiag)
continue;
2238 if (sn_.nodes[i - 1].nodetype == NodeType::Sink &&
2239 sn_.nodes[j - 1].nodetype == NodeType::Source)
2241 csid[std::make_pair(i, j)] =
2242 add_class_switch(
"CS_" + sn_.nodes[i - 1].name +
"_to_" + sn_.nodes[j - 1].name, C);
2247 for (
const auto& kv : csid) {
2248 const std::size_t i = kv.first.first, j = kv.first.second, c = kv.second;
2249 for (std::size_t r = 1; r <= K; ++r)
2250 for (std::size_t s = 1; s <= K; ++s) {
2251 const T p = P.get(r, s, i, j);
2253 P.set(r, r, i, c, T(P.get(r, r, i, c) + p));
2254 P.set(r, s, i, j, zero);
2255 P.set(s, s, c, j, one);
2258 for (
const auto& kv : P.entries) {
2259 const auto& k = kv.first;
2260 sn_.set_route(k.r, k.s, k.i, k.j, kv.second);
2266 for (
const auto& np : sn_.nodeparam) {
2267 const std::size_t ci = np.first;
2271 const std::size_t rd = rq.first + 1;
2272 std::vector<std::size_t> nodeset = rq.second;
2273 nodeset.push_back(ci);
2274 bool minted =
false;
2275 const std::size_t Inodes = sn_.nodes.size();
2276 for (std::size_t i = 0; i < cp.
nitems; ++i) {
2278 if (rc == 0)
continue;
2284 std::vector<bool> declared(nodeset.size(),
false);
2285 for (std::size_t si = 0; si < nodeset.size(); ++si)
2286 for (std::size_t b = 1; b <= Inodes && !declared[si]; ++b)
2288 declared[si] =
true;
2289 for (std::size_t si = 0; si < nodeset.size(); ++si) {
2290 if (declared[si])
continue;
2291 for (std::size_t b : nodeset) {
2292 const T p = Pm.
get(rd, rd, nodeset[si], b);
2294 sn_.set_route(rc, rc, nodeset[si], b, p);
2310 for (std::size_t a : nodeset)
2311 for (std::size_t b : nodeset)
2317 for (
const RetrievalRoutingEntry& e : retrieval_routing_entries_)
2318 sn_.set_route(e.cls, e.cls, e.from_node, e.to_node, e.p);
2343 const std::size_t Kc = sn_.classes.size(), Ic = sn_.nodes.size();
2344 for (std::size_t i = 1; i <= Ic; ++i) {
2345 NodeDef& nd = sn_.nodes[i - 1];
2346 nd.
routing.resize(Kc, RoutingStrategy::PROB);
2347 bool linked =
false;
2348 for (std::size_t j = 1; j <= Ic && !linked; ++j)
2349 for (std::size_t a = 1; a <= Kc && !linked; ++a)
2350 for (std::size_t b = 1; b <= Kc && !linked; ++b)
2352 if (!linked)
continue;
2353 for (std::size_t r = 1; r <= Kc; ++r) {
2354 if (nd.
routing[r - 1] != RoutingStrategy::PROB)
continue;
2355 if (sn_.classes[r - 1].self_looping)
continue;
2356 if (r <= sn_.issignal.size() && sn_.issignal[r - 1])
continue;
2357 bool routed =
false;
2358 for (std::size_t j = 1; j <= Ic && !routed; ++j)
2359 for (std::size_t s = 1; s <= Kc && !routed; ++s)
2361 if (!routed) nd.
routing[r - 1] = RoutingStrategy::RAND;
2370 routing_linked_ =
true;
2371 apply_fork_overrides();
2380 materialize_transitions();
2381 if (routing_installed()) apply_fork_overrides();
2383 sn_.refresh_struct();
2394 if (!violations.empty()) {
2396 for (
const auto& x : violations) msg +=
"\n " + x;
2397 std::cerr <<
"[LINE] Warning: The NetworkStruct of model " << sn_.name
2398 <<
" violates sn_contract:" << msg << std::endl;
2417 const std::function<T(
const std::vector<std::size_t>&)>& mu,
2418 const std::vector<std::vector<bool>>& swap_graph =
2419 std::vector<std::vector<bool>>()) {
2420 const std::size_t ist = station_of(node,
"set_pas");
2425 pp.
swap_graph.assign(sn_.classes.size(), std::vector<bool>(sn_.classes.size(),
false));
2426 sn_.pasparam[ist] = pp;
2432 for (std::size_t a = 0; a < R; ++a)
2433 for (std::size_t b = 0; b < pp.
swap_graph[a].size(); ++b)
2444 const std::function<T(
const std::vector<std::size_t>&)>& mu,
2448 const std::size_t R = sn_.classes.size();
2449 pp.
swap_graph.assign(R, std::vector<bool>(R,
false));
2450 for (std::size_t a = 0; a < R && a < swap_graph.
rows(); ++a)
2451 for (std::size_t b = 0; b < R && b < swap_graph.
cols(); ++b)
2453 sn_.pasparam[ist] = pp;
2465 std::size_t pk = 1) {
2466 const std::size_t ist = station_of(node,
"set_polling");
2467 if (sn_.stations[ist - 1].sched != SchedStrategy::POLLING)
2468 throw InputError(
"set_polling: the station is not POLLING-scheduled");
2473 if (pp.
switchover.size() < sn_.classes.size())
2475 sn_.pollingparam[ist] = pp;
2490 const std::size_t K = sn_.classes.size();
2491 if (node == 0 || node > sn_.nodes.size())
2492 throw InputError(
"set_sync_reply: node index is out of range");
2493 if (call_cls == 0 || call_cls > K || reply_cls == 0 || reply_cls > K)
2494 throw InputError(
"set_sync_reply: class index is out of range");
2495 const std::size_t ist = sn_.nodes[node - 1].station;
2496 if (ist == 0)
throw InputError(
"set_sync_reply: node is not a station");
2500 if (sn_.replyblock.size() < sn_.nodes.size()) sn_.replyblock.resize(sn_.nodes.size());
2501 for (std::vector<bool>& row : sn_.replyblock)
2502 if (row.size() < K) row.resize(K,
false);
2503 if (sn_.syncreply.size() < K) sn_.syncreply.resize(K, 0);
2504 sn_.replyblock[node - 1][call_cls - 1] =
true;
2505 sn_.syncreply[call_cls - 1] = reply_cls;
2528 const std::vector<double>& class_max_jobs,
2529 double global_max_jobs = -1.0,
2530 const std::vector<DropStrategy>& rule = std::vector<DropStrategy>(),
2531 const std::vector<double>& class_max_memory = std::vector<double>(),
2532 const std::vector<T>& class_size = std::vector<T>(),
2533 double global_max_memory = -1.0,
2534 const std::string& name = std::string()) {
2535 const std::size_t M = sn_.stations.size(), K = sn_.classes.size();
2538 rg.
cap.assign(M, std::vector<double>(K + 1, -1.0));
2539 rg.
maxmem.assign(M, -1.0);
2544 rg.
rule.assign(K, DropStrategy::WAITQ);
2547 for (std::size_t r = 0; r < K && r < rule.size(); ++r) rg.
rule[r] = rule[r];
2548 for (std::size_t r = 0; r < K && r < class_size.size(); ++r) rg.
size[r] = class_size[r];
2550 for (std::size_t j = 0; j < nodes.size(); ++j) {
2551 const std::size_t ist = station_of(nodes[j],
"addRegion");
2553 for (std::size_t r = 0; r < K; ++r) {
2559 if (r >= class_max_jobs.size()) {
2560 rg.
cap[ist - 1][r] = -1.0;
2563 double c = class_max_jobs[r];
2564 if (r < class_max_memory.size() && class_max_memory[r] != -1.0) {
2567 const double memjobs = std::floor(class_max_memory[r] / sz);
2568 c = c == -1.0 ? memjobs : std::min(c, memjobs);
2571 rg.
cap[ist - 1][r] = c;
2573 rg.
cap[ist - 1][K] = global_max_jobs;
2574 rg.
maxmem[ist - 1] = global_max_memory;
2576 sn_.regions.push_back(rg);
2577 return sn_.regions.size();
2586 if (region == 0 || region > sn_.regions.size())
2587 throw InputError(
"set_region_weights: region index is out of range");
2589 for (std::size_t r = 0; r < rg.
weight.size() && r < weight.size(); ++r)
2590 rg.
weight[r] = weight[r];
2595 if (region == 0 || region > sn_.regions.size())
2596 throw InputError(
"set_region_constraint: region index is out of range");
2597 if (A.
rows() != b.size())
2598 throw InputError(
"set_region_constraint: A and b disagree on the number of rows");
2599 sn_.regions[region - 1].lincon_A = A;
2600 sn_.regions[region - 1].lincon_b = b;
2612 const std::function<T(
const std::vector<T>&)>& fn,
2613 const std::string& kind = std::string(), std::size_t node = 0,
2614 std::size_t cls = 0) {
2615 for (std::size_t i = 0; i < sn_.reward.size(); ++i)
2616 if (sn_.reward[i].name == nm) {
2617 sn_.reward[i].fn = fn;
2618 sn_.reward[i].kind = kind;
2619 sn_.reward[i].node = node;
2620 sn_.reward[i].cls = cls;
2629 sn_.reward.push_back(rw);
2642 std::size_t target = 0,
2643 const std::vector<T>& remdist = std::vector<T>()) {
2644 const std::size_t K = sn_.classes.size();
2645 if (cls == 0 || cls > K)
throw InputError(
"set_signal: class index is out of range");
2646 if (target > K)
throw InputError(
"set_signal: target class index is out of range");
2648 if (sn_.issignal.size() < K) {
2649 sn_.issignal.resize(K,
false);
2651 sn_.signaltarget.resize(K, 0);
2653 sn_.signalremdist.resize(K, std::vector<T>());
2655 sn_.issignal[cls - 1] =
true;
2656 sn_.signaltype[cls - 1] = type;
2657 sn_.signaltarget[cls - 1] = target;
2658 sn_.signalrempolicy[cls - 1] = policy;
2659 sn_.signalremdist[cls - 1] = remdist;
2662 std::size_t
station_index(std::size_t node)
const {
return station_of(node,
"station_index"); }
2668 struct TransitionArc {
2669 std::size_t mode, node, cls;
2671 TransitionArc(std::size_t m, std::size_t n, std::size_t c,
const T& v)
2672 : mode(m), node(n), cls(c), count(v) {}
2676 struct TransitionArcs {
2677 std::vector<TransitionArc> enab, inhib, fire;
2688 std::map<std::size_t, TransitionArcs> pending_arcs_;
2691 TransitionParam<T>& declarative_transition(std::size_t node,
const char* what) {
2692 if (node == 0 || node > sn_.nodes.size())
2693 throw InputError(std::string(what) +
": node index is out of range");
2694 if (sn_.nodes[node - 1].nodetype != NodeType::Transition)
2695 throw InputError(std::string(what) +
": node '" + sn_.nodes[node - 1].name +
2696 "' is not a Transition");
2697 if (pending_arcs_.find(node) == pending_arcs_.end())
2698 throw InputError(std::string(what) +
": the Transition '" + sn_.nodes[node - 1].name +
2699 "' was created from a finished TransitionParam, so its modes are "
2700 "already fixed; create it as add_transition(name) to declare them "
2702 return sn_.transparam[node];
2706 TransitionParam<T>& mode_param(std::size_t node, std::size_t mode,
const char* what) {
2707 TransitionParam<T>& tp = declarative_transition(node, what);
2708 if (mode == 0 || mode > tp.nmodes)
2709 throw InputError(std::string(what) +
": the Transition '" + sn_.nodes[node - 1].name +
2710 "' has no mode " + std::to_string(mode));
2715 Station<T>& place_station(std::size_t node,
const char* what) {
2716 if (node == 0 || node > sn_.nodes.size())
2717 throw InputError(std::string(what) +
": node index is out of range");
2718 if (sn_.nodes[node - 1].nodetype != NodeType::Place)
2719 throw InputError(std::string(what) +
": node '" + sn_.nodes[node - 1].name +
2720 "' is not a Place");
2721 return sn_.stations[sn_.nodes[node - 1].station - 1];
2725 TransitionParam<T>& fluid_mode(std::size_t node, std::size_t mode,
const char* what) {
2726 TransitionParam<T>& tp = mode_param(node, mode, what);
2727 if (tp.fluidrate.size() < tp.nmodes) tp.fluidrate.resize(tp.nmodes);
2728 if (tp.fluidguard.size() < tp.nmodes) tp.fluidguard.resize(tp.nmodes);
2729 if (tp.fluidimpulse.size() < tp.nmodes) tp.fluidimpulse.resize(tp.nmodes);
2730 if (tp.fluiddep.size() < tp.nmodes) tp.fluiddep.resize(tp.nmodes);
2731 if (tp.fluidflowdep.size() < tp.nmodes) tp.fluidflowdep.resize(tp.nmodes);
2736 void fluid_place_arg(std::size_t place,
const char* what)
const {
2737 if (place == 0 || place > sn_.nodes.size() || sn_.nodes[place - 1].nodetype != NodeType::Place)
2738 throw InputError(std::string(what) +
": a fluid arc must name a Place");
2742 static void set_fluid_row(std::vector<
typename TransitionParam<T>::FluidArc>& a, std::size_t place,
2744 for (std::size_t k = a.size(); k-- > 0;)
2745 if (a[k].node == place) a.erase(a.begin() +
static_cast<std::ptrdiff_t
>(k));
2746 if (val == 0.0)
return;
2747 typename TransitionParam<T>::FluidArc fa;
2754 void arc_target(std::size_t node, std::size_t mode, std::size_t cls, std::size_t target,
2755 bool must_be_place,
const char* what) {
2756 mode_param(node, mode, what);
2757 if (cls == 0 || cls > sn_.classes.size())
2759 ": class index is out of range; declare the job class before the "
2760 "arcs that move its tokens");
2761 if (target == 0 || target > sn_.nodes.size())
2762 throw InputError(std::string(what) +
": the node the arc names is out of range");
2763 if (must_be_place && sn_.nodes[target - 1].nodetype != NodeType::Place)
2764 throw InputError(std::string(what) +
": '" + sn_.nodes[target - 1].name +
2765 "' is not a Place, and only a Place holds the tokens a mode tests");
2769 static void fill_arcs(std::vector<Matrix<T> >& dst,
const std::vector<TransitionArc>& arcs) {
2770 for (std::size_t a = 0; a < arcs.size(); ++a)
2771 dst[arcs[a].mode - 1](arcs[a].node - 1, arcs[a].cls - 1) = arcs[a].count;
2782 static void normalize_arcs(std::vector<Matrix<T> >& a, std::size_t N, std::size_t K,
2783 bool inhibitor,
const std::string& nm,
const char* what) {
2784 for (std::size_t m = 0; m < a.size(); ++m) {
2785 if (a[m].rows() == N && a[m].cols() == K)
continue;
2786 if (a[m].rows() > N || a[m].cols() > K)
2788 "the Transition '" + nm +
"' has an " + what +
" matrix of " +
2789 std::to_string(a[m].rows()) +
"x" + std::to_string(a[m].cols()) +
2790 " against a model of " + std::to_string(N) +
" nodes and " +
2791 std::to_string(K) +
" classes; an arc matrix is read row by row against "
2792 "the marking, so a wider one is read past its end");
2793 Matrix<T> grown(N, K, inhibitor ? no_inhibitor() : num_traits<T>::from_int(0));
2794 for (std::size_t q = 0; q < a[m].rows(); ++q)
2795 for (std::size_t r = 0; r < a[m].cols(); ++r) grown(q, r) = a[m](q, r);
2808 static T no_inhibitor() {
2809 return num_traits<T>::from_double(std::numeric_limits<double>::infinity());
2821 void materialize_transitions() {
2822 if (sn_.transparam.empty())
return;
2823 const std::size_t N = sn_.nodes.size(), K = sn_.classes.size();
2824 const T
zero = num_traits<T>::from_int(0);
2825 for (
typename std::map<std::size_t, TransitionParam<T> >::iterator it =
2826 sn_.transparam.begin();
2827 it != sn_.transparam.end(); ++it) {
2828 TransitionParam<T>& tp = it->second;
2829 const std::string& nm = sn_.nodes[it->first - 1].name;
2830 if (pending_arcs_.find(it->first) == pending_arcs_.end()) {
2831 normalize_arcs(tp.enabling, N, K,
false, nm,
"enabling");
2832 normalize_arcs(tp.inhibiting, N, K,
true, nm,
"inhibiting");
2833 normalize_arcs(tp.firing, N, K,
false, nm,
"firing");
2837 throw InputError(
"Network '" + sn_.name +
"': the Transition '" + nm +
2838 "' has no mode, and every transition needs at least one");
2839 const TransitionArcs& pa = pending_arcs_[it->first];
2840 tp.enabling.assign(tp.nmodes, Matrix<T>(N, K, zero));
2841 tp.inhibiting.assign(tp.nmodes, Matrix<T>(N, K, no_inhibitor()));
2842 tp.firing.assign(tp.nmodes, Matrix<T>(N, K, zero));
2843 fill_arcs(tp.enabling, pa.enab);
2844 fill_arcs(tp.inhibiting, pa.inhib);
2845 fill_arcs(tp.firing, pa.fire);
2849 for (std::size_t m = 0; m < tp.nmodes; ++m)
2850 tp.firingphases[m] =
2855 resolve_fluid_flow_reads();
2863 void resolve_fluid_flow_reads() {
2864 for (
typename std::map<std::size_t, TransitionParam<T> >::iterator it = sn_.transparam.begin();
2865 it != sn_.transparam.end(); ++it) {
2866 TransitionParam<T>& tp = it->second;
2867 for (std::size_t m = 0; m < tp.fluidflowdep.size(); ++m) {
2868 for (
typename TransitionParam<T>::FluidFlowDep& fd : tp.fluidflowdep[m]) {
2869 if (fd.read_given)
continue;
2871 if (m >= tp.enabling.size())
continue;
2872 const Matrix<T>& en = tp.enabling[m];
2873 for (std::size_t q = 0; q < en.rows(); ++q)
2874 for (std::size_t r = 0; r < en.cols(); ++r)
2875 if (num_traits<T>::to_double(en(q, r)) > 0.0) {
2876 fd.read.push_back(q + 1);
2885 std::map<std::size_t, std::vector<std::size_t> > cache_item_classes_;
2888 struct CacheMissArc {
2889 std::size_t cls, from_node, to_node;
2890 CacheMissArc(std::size_t c, std::size_t f, std::size_t t)
2891 : cls(c), from_node(f), to_node(t) {}
2893 std::vector<CacheMissArc> cache_miss_arcs_;
2896 struct RetrievalRoutingEntry {
2897 std::size_t cls, from_node, to_node;
2899 RetrievalRoutingEntry(std::size_t c, std::size_t f, std::size_t t,
const T& q)
2900 : cls(c), from_node(f), to_node(t), p(q) {}
2902 std::vector<RetrievalRoutingEntry> retrieval_routing_entries_;
2905 std::size_t retrieval_class_of(std::size_t cache_node, std::size_t read_class, std::size_t item)
const {
2906 const auto it = sn_.nodeparam.find(cache_node);
2908 if (it != sn_.nodeparam.end() && item >= 1 && item <= it->second.retrieval_classes.size() &&
2909 read_class >= 1 && read_class <= it->second.retrieval_classes[item - 1].size())
2910 rc = it->second.retrieval_classes[item - 1][read_class - 1];
2912 throw InputError(
"No retrieval class defined for the given class/item; call setRetrievalSystem first.");
2917 CacheParam<T>& cache_param_for_class(std::size_t cache_node, std::size_t r,
const char* who) {
2918 auto it = sn_.nodeparam.find(cache_node);
2919 if (cache_node == 0 || cache_node > sn_.nodes.size() || it == sn_.nodeparam.end() ||
2920 sn_.nodes[cache_node - 1].nodetype != NodeType::Cache)
2921 throw InputError(std::string(who) +
": node is not a Cache");
2922 check_class(r, who);
2923 CacheParam<T>& cp = it->second;
2924 const std::size_t K = sn_.classes.size();
2925 if (cp.pread.size() < K) cp.pread.resize(K);
2926 if (cp.preadkind.size() < K) cp.preadkind.resize(K);
2927 if (cp.hitclass.size() < K) cp.hitclass.resize(K, 0);
2928 if (cp.missclass.size() < K) cp.missclass.resize(K, 0);
2929 if (cp.classitem.size() < K) cp.classitem.resize(K, 0);
2934 void check_class(std::size_t r,
const char* who)
const {
2935 if (r == 0 || r > sn_.classes.size())
2936 throw InputError(std::string(who) +
": class index " + std::to_string(r) +
2937 " names no declared class; create the class before passing it");
2941 static std::vector<std::size_t> per_item_classes(
const std::vector<std::size_t>& spec,
2942 std::size_t nitems,
const char* what) {
2943 if (spec.size() == nitems)
return spec;
2944 if (spec.size() == 1)
return std::vector<std::size_t>(nitems, spec[0]);
2946 ": pass one class per item or a single class shared by all");
2950 JobClass& class_ref(std::size_t cls,
const char* what) {
2951 if (cls == 0 || cls > sn_.classes.size())
2952 throw InputError(std::string(what) +
": class index is out of range");
2953 return sn_.classes[cls - 1];
2956 void init_node(std::size_t nd) {
2957 sn_.nodes[nd - 1].routing.assign(sn_.classes.size(), RoutingStrategy::PROB);
2961 void grow_class_vectors() {
2962 const std::size_t K = sn_.classes.size();
2963 for (NodeDef& nd : sn_.nodes) nd.routing.resize(K, RoutingStrategy::PROB);
2964 for (Station<T>& st : sn_.stations) {
2965 if (!st.classcap.empty())
2966 st.classcap.resize(K, std::numeric_limits<double>::infinity());
2967 if (!st.droprule.empty()) st.droprule.resize(K, 0);
2968 if (!st.schedparam.empty()) st.schedparam.resize(K, num_traits<T>::from_int(1));
2973 Station<T>& station_ref(std::size_t node, std::size_t cls,
const char* what) {
2974 const std::size_t ist = station_of(node, what);
2975 if (cls == 0 || cls > sn_.classes.size())
2976 throw InputError(std::string(what) +
": class index is out of range");
2977 return sn_.stations[ist - 1];
2988 void grow_class_slot(std::vector<V>& v, std::size_t cls,
const V& fill) {
2989 const std::size_t K = sn_.classes.size();
2990 if (v.size() < K) v.resize(K < cls ? cls : K, fill);
2993 std::size_t station_of(std::size_t node,
const std::string& what)
const {
2994 if (node == 0 || node > sn_.nodes.size())
2995 throw InputError(what +
": node index " + std::to_string(node) +
" does not exist");
2996 const std::size_t ist = sn_.nodes[node - 1].station;
2998 throw InputError(what +
": node '" + sn_.nodes[node - 1].name +
2999 "' is not a station (it serves no jobs)");
3004 struct ForkOverride {
3005 enum Kind { TASKS, DIST, PROB };
3007 std::size_t fork = 0, cls = 0, dest = 0;
3009 lang::Distrib<T> dist;
3011 std::vector<ForkOverride> fork_overrides_;
3013 bool routing_linked_ =
false;
3022 void record_fork_override(
const ForkOverride& ov) {
3023 if (ov.fork == 0 || ov.fork > sn_.nodes.size() ||
3024 sn_.nodes[ov.fork - 1].nodetype != NodeType::Fork)
3025 throw InputError(
"the node given is not a Fork of this model");
3026 if (ov.cls == 0 || ov.cls > sn_.classes.size())
3027 throw InputError(
"a fork override names a class that does not exist");
3028 fork_overrides_.push_back(ov);
3029 if (routing_installed()) apply_fork_override(ov);
3040 bool routing_installed()
const {
return routing_linked_; }
3043 void apply_fork_overrides() {
3044 for (std::size_t i = 0; i < fork_overrides_.size(); ++i)
3045 apply_fork_override(fork_overrides_[i]);
3048 void apply_fork_override(
const ForkOverride& ov) {
3049 qn::ForkParam<T>& f = fork_param(ov.fork);
3050 const std::vector<std::size_t> dests = fork_dests(ov.fork, ov.dest);
3051 for (std::size_t x = 0; x < dests.size(); ++x) {
3052 const std::size_t k = dests[x];
3054 case ForkOverride::TASKS:
3055 f.fan_out_link(k - 1, ov.cls - 1) = num_traits<T>::from_double(ov.value);
3057 case ForkOverride::DIST:
3058 f.fan_out_dist[k - 1][ov.cls - 1] = ov.dist;
3061 f.fan_out_link(k - 1, ov.cls - 1) = ov.dist.mean;
3063 case ForkOverride::PROB:
3064 f.fan_out_prob(k - 1, ov.cls - 1) = num_traits<T>::from_double(ov.value);
3068 refresh_fork_scalar(sn_.nodes[ov.fork - 1], f);
3080 qn::ForkParam<T>& fork_param(std::size_t fork_node) {
3081 if (fork_node == 0 || fork_node > sn_.nodes.size() ||
3082 sn_.nodes[fork_node - 1].nodetype != NodeType::Fork)
3083 throw InputError(
"the node given is not a Fork of this model");
3084 qn::ForkParam<T>& f = sn_.forkparam[fork_node];
3085 const std::size_t I = sn_.nodes.size(), K = sn_.classes.size();
3086 if (f.fan_out_link.rows() == I && f.fan_out_link.cols() == K)
return f;
3087 const T
zero = num_traits<T>::from_int(0);
3090 f.fan_out_dist.assign(I, std::vector<lang::Distrib<T> >(K));
3091 const T tpl = num_traits<T>::from_double(sn_.nodes[fork_node - 1].tasks_per_link);
3092 const T one = num_traits<T>::from_int(1);
3093 for (std::size_t k = 1; k <= I; ++k)
3094 for (std::size_t r = 1; r <= K; ++r)
3095 if (fork_links_to(fork_node, k, r)) {
3096 f.fan_out_link(k - 1, r - 1) = tpl;
3097 f.fan_out_prob(k - 1, r - 1) = one;
3111 void refresh_fork_scalar(qn::NodeDef& nd,
const qn::ForkParam<T>& f) {
3113 std::size_t cnt = 0;
3114 for (std::size_t k = 0; k < f.fan_out_link.rows(); ++k)
3115 for (std::size_t r = 0; r < f.fan_out_link.cols(); ++r) {
3116 if (num_traits<T>::to_double(f.fan_out_prob(k, r)) == 0.0)
continue;
3117 acc += num_traits<T>::to_double(f.fan_out_link(k, r)) *
3118 num_traits<T>::to_double(f.fan_out_prob(k, r));
3121 if (cnt > 0) nd.tasks_per_link = acc /
static_cast<double>(cnt);
3138 bool fork_links_to(std::size_t fork_node, std::size_t k, std::size_t r)
const {
3139 const std::size_t K = sn_.classes.size();
3140 for (std::size_t s = 1; s <= K; ++s)
3141 if (num_traits<T>::to_double(sn_.route_eff(r, s, fork_node, k)) != 0.0)
return true;
3151 std::vector<std::size_t> fork_dests(std::size_t fork_node, std::size_t dest_node)
const {
3152 std::vector<std::size_t> out;
3153 const std::size_t I = sn_.nodes.size(), K = sn_.classes.size();
3154 if (dest_node != 0) {
3156 throw InputError(
"a fork override names a node that does not exist");
3157 out.push_back(dest_node);
3160 for (std::size_t k = 1; k <= I; ++k)
3161 for (std::size_t r = 1; r <= K; ++r)
3162 if (fork_links_to(fork_node, k, r)) { out.push_back(k);
break; }
3164 throw InputError(
"a fork override was set on '" + sn_.nodes[fork_node - 1].name +
3165 "', which links nowhere yet: call link() before the override");
3176 void validate()
const {
3177 if (sn_.classes.empty())
throw InputError(
"Network '" + sn_.name +
"': it has no classes");
3178 if (sn_.stations.empty())
3179 throw InputError(
"Network '" + sn_.name +
"': it has no stations");
3195 const std::size_t K = sn_.classes.size();
3196 const T
zero = num_traits<T>::from_int(0);
3197 std::vector<std::vector<bool>> switches(K, std::vector<bool>(K,
false));
3198 for (std::size_t r = 0; r < K; ++r)
3199 for (std::size_t sc = 0; sc < K; ++sc) {
3200 if (r == sc)
continue;
3201 for (std::size_t i = 1; i <= sn_.nodes.size() && !switches[r][sc]; ++i)
3202 for (std::size_t j = 1; j <= sn_.nodes.size(); ++j)
3203 if (sn_.get_route(r + 1, sc + 1, i, j) > zero) {
3204 switches[r][sc] =
true;
3208 for (
const auto& kv : sn_.csmatrix) {
3209 const Matrix<T>& C = kv.second;
3210 for (std::size_t r = 0; r < K && r < C.rows(); ++r)
3211 for (std::size_t sc = 0; sc < K && sc < C.cols(); ++sc)
3212 if (r != sc && C(r, sc) > zero) switches[r][sc] =
true;
3214 for (
const auto& kv : sn_.nodeparam) {
3215 const CacheParam<T>& cp = kv.second;
3216 for (std::size_t r = 0; r < K; ++r) {
3217 if (r < cp.hitclass.size() && cp.hitclass[r] >= 1 && cp.hitclass[r] <= K)
3218 switches[r][cp.hitclass[r] - 1] =
true;
3219 if (r < cp.missclass.size() && cp.missclass[r] >= 1 && cp.missclass[r] <= K)
3220 switches[r][cp.missclass[r] - 1] =
true;
3222 for (
const auto& row : cp.retrieval_classes)
3223 for (std::size_t r = 0; r < K && r < row.size(); ++r)
3224 if (row[r] >= 1 && row[r] <= K) switches[r][row[r] - 1] =
true;
3230 for (std::size_t r = 0; r < K; ++r)
3231 if (sn_.classes[r].spawn >= 1 && sn_.classes[r].spawn <= K)
3232 switches[r][sn_.classes[r].spawn - 1] =
true;
3233 for (std::size_t r = 0; r < sn_.classes.size(); ++r) {
3237 bool switched_into =
false;
3238 for (std::size_t q = 0; q < K; ++q)
3239 if (switches[q][r]) switched_into =
true;
3240 bool served =
false;
3241 for (std::size_t i = 0; i < sn_.stations.size(); ++i)
3242 if (!sn_.service[i][r].disabled) served =
true;
3248 for (std::size_t nd = 0; nd < sn_.nodes.size(); ++nd)
3249 if (sn_.nodes[nd].nodetype == NodeType::Transition) petri =
true;
3250 if (!served && !switched_into && !petri)
3251 throw InputError(
"Network '" + sn_.name +
"': class '" + sn_.classes[r].name +
3252 "' has no service process at any station");
3281 for (std::size_t i = 0; i < sn_.nodes.size(); ++i) {
3282 if (sn_.nodes[i].nodetype != NodeType::Fork)
continue;
3283 bool closed =
false;
3284 for (
const auto& fjp : sn_.fj)
3285 if (fjp.first == i + 1) closed =
true;
3286 if (closed)
continue;
3290 std::vector<bool> seen(sn_.nodes.size(),
false);
3291 std::vector<std::size_t>
stack(1, i + 1);
3293 bool departs =
false;
3294 while (!
stack.empty() && !departs) {
3295 const std::size_t u =
stack.back();
3297 for (std::size_t v = 1; v <= sn_.nodes.size() && !departs; ++v) {
3298 if (seen[v - 1])
continue;
3300 for (std::size_t r = 1; r <= K && !edge; ++r)
3301 for (std::size_t s = 1; s <= K; ++s)
3302 if (sn_.get_route(r, s, u, v) > zero) {
3306 if (!edge)
continue;
3307 if (sn_.nodes[v - 1].nodetype == NodeType::Sink) {
3316 throw InputError(
"Network '" + sn_.name +
"': the Fork '" + sn_.nodes[i].name +
3317 "' is not closed by a Join and no Sink is reachable from it, "
3318 "so its siblings can neither merge nor depart");
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
void set_service_rate_function(std::size_t node, const std::function< T(const std::vector< std::size_t > &)> &muFun, const Matrix< T > &swap_graph=Matrix< T >())
Queue.setServiceRateFunction(muFun): the TOTAL service rate of a PAS or OI station as a function of t...
void set_drop_rule(std::size_t node, std::size_t cls, DropStrategy rule)
void set_state_prior(std::size_t node, const Matrix< T > &space, const std::vector< T > &prior)
StatefulNode.setStatePrior(space, prior): a distribution over the rows of a DECLARED state space.
void set_departure_discipline(std::size_t node, std::size_t cls, lang::DepartureDiscipline rule)
Place.setDepartureDiscipline(class, rule).
std::size_t add_logger(const std::string &nm, const std::string &log_file=std::string())
A Logger node: a pass-through that records every job crossing it.
void set_global_dependence(const GdScaling< T > &fun, const std::vector< T > &peak, int wire_cutoff)
As above, with an explicit per-slot OPEN-class truncation used when phi is materialized onto the JSON...
void set_load_dependence(std::size_t node, const std::vector< T > &alpha)
station.setLoadDependence(alpha): the rate multiplier at population 1, 2, ... The vector is indexed f...
void set_mode_fluid_impulse(std::size_t node, std::size_t mode, std::size_t place, double delta)
Transition.setFluidImpulse(mode, place, delta): every firing of the mode moves the level of the fluid...
void set_class_capacity(std::size_t node, std::size_t cls, double k)
std::size_t add_source(const std::string &nm)
The external arrival station.
std::size_t add_fork(const std::string &nm, double tasks_per_link=1.0)
A Fork node.
void bind_join(std::size_t join_node, std::size_t fork_node)
void set_enabling_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setEnablingConditions(mode, class, place, tokens): how many class-r tokens the mode needs ...
void set_arrival_batch(std::size_t node, std::size_t cls, const Distrib< T > &dist)
Source.setArrivalBatch(class, dist): the batch-size law released at each arrival epoch.
void set_item_routing_prob(std::size_t cache_node, std::size_t read_class, std::size_t item, std::size_t source_node, std::size_t dest_node, const T &p)
Short alias of set_item_routing_probability (Cache.setItemRoutingProb).
double get_fluid_level(std::size_t node)
std::size_t add_open_class(const std::string &nm, int prio=0)
void set_cache_read(std::size_t cache_node, std::size_t r, const std::vector< T > &pmf)
Cache.setRead(jobclass, popularity): class r (1-based) reads the cache, drawing items from the pmf pm...
static void refuse_defective(const Distrib< T > &d, const char *what)
MATLAB Queue.setService / Source.setArrival: a Defective law has an infinite mean,...
void set_mode_timing(std::size_t node, std::size_t mode, lang::TimingStrategy ts)
Transition.setTimingStrategy(mode, strategy): TIMED or IMMEDIATE.
std::size_t add_place(const std::string &nm, SchedStrategy sched)
A Place whose EMBEDDED QUEUE is served under sched: the QUEUEING PLACE of a queueing Petri net,...
Network(const std::string &nm)
void set_firing_weight(std::size_t node, std::size_t mode, const T &w)
Transition.setFiringWeights(mode, weight): the share among tied modes.
void set_class_patience(std::size_t cls, const Distrib< T > &dist, lang::ImpatienceType kind=lang::ImpatienceType::RENEGING)
JobClass.setPatience(kind, dist): the CLASS-WIDE abandonment law.
void set_cache_miss_class(std::size_t cache_node, std::size_t r, std::size_t m)
Cache.setMissClass(jobclass, missclass): a class-r read that misses leaves as class m.
std::size_t add_delay(const std::string &nm)
An infinite-server station (a Delay, MATLAB's Delay / DelayStation).
void set_orbital_search(std::size_t node, std::size_t cls, const T &prob)
Queue.setOrbitalSearch(class, prob): orbital search (Artalejo, Joshua and Krishnamoorthy 2002).
void set_class_spawn(std::size_t cls, std::size_t spawn_cls)
JobClass.spawnClass (sn.classspawn): the class injected at the same station on every completion of cl...
void set_polling_timer(std::size_t node, const std::vector< Distrib< T > > &dists, lang::PollingTimer scope=lang::PollingTimer::LOCAL, bool preemptive=false)
Queue.setPollingTimer(dist, scope, preemptive): a visit timer per class (one law for all classes,...
void set_mode_fluid_dependence(std::size_t node, std::size_t mode, std::size_t place, const std::function< double(double)> &h)
Transition.setFluidRateDependence(mode, place, h): the firing rate of a TIMED, exponential mode is mu...
void set_region_constraint(std::size_t region, const Matrix< T > &A, const std::vector< T > &b)
The optional linear constraint A n <= b a region may carry beyond its caps.
RoutingMatrix< T > init_routing_matrix() const
An empty routing matrix, MATLAB's model.initRoutingMatrix.
std::vector< std::size_t > set_miss_cache(std::size_t cache_node, std::size_t next_cache, const std::vector< std::size_t > &hit_classes_at_next)
Cache.setMissCache(readClass, nextCache, hitClassAtNext): send this cache's misses to next_cache pres...
void set_class_immediate_feedback(std::size_t cls)
jobclass.setImmediateFeedback(): the same property, class-wide.
void set_retrieval_system(std::size_t cache_node, std::size_t read_class, std::size_t miss_class, std::size_t queue_node)
Cache.setRetrievalSystem(readClass, missClass, queue) with a single Queue, as the reference accepts.
void set_mode_distribution(std::size_t node, std::size_t mode, const Distrib< T > &d)
Transition.setDistribution(mode, dist): the mode's firing law.
void set_polling(std::size_t node, lang::PollingType ptype, const std::vector< Distrib< T > > &switchover=std::vector< Distrib< T > >(), std::size_t pk=1)
Queue.setPollingType(...): the polling discipline of a POLLING station and the switchover walks betwe...
bool is_place_fluid(std::size_t node)
Place.isFluid(), getFluidCapacity() and getFluidLevel().
std::size_t add_router(const std::string &nm)
A stateless routing node.
void set_initial_marking(std::size_t node, const std::vector< T > &tokens)
Place.setState(marking): the initial token count of the place, per class.
void set_mode_fluid_rate(std::size_t node, std::size_t mode, std::size_t place, double rate)
Transition.setFluidRate(mode, place, rate): the FSPN flow of a TIMED mode into (rate > 0) or out of (...
void set_inhibiting_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setInhibitingConditions(mode, class, place, tokens): the class-r count at place that BLOCK...
void set_orbit_persistence(std::size_t node, std::size_t cls, const T &join_prob, const T &persist_prob=num_traits< T >::from_int(1))
Queue.setOrbitPersistence(class, joinProb, persistProb): non-persistent retrial customers (Phung-Duc ...
void set_number_of_servers(std::size_t node, double n)
RoutingMatrix< T > serial_routing(const std::vector< std::size_t > &nodes) const
model.serialRouting(nodes): a unit-probability path through nodes.
void set_joint_dependence(std::size_t node, const CdScaling< T > &fun, const std::vector< T > &peak)
station.setJointDependence(eta, peakRatePerClass): MATLAB's Station.ljdScaling / ljdScalingPeak.
bool has_fluid_arcs(std::size_t node) const
Transition.hasFluidArcs(): any mode declares a flow, guard, impulse or fluid rate dependence.
void set_fork_tasks_per_link(std::size_t fork_node, std::size_t jobclass, double tasks, std::size_t dest_node=0)
Variable forking levels on an existing Fork, the twin of MATLAB Fork.setTasksPerLink(jobclass,...
void set_patience(std::size_t node, std::size_t cls, const Distrib< T > &dist, lang::ImpatienceType kind=lang::ImpatienceType::RENEGING)
Queue.setPatience(class, dist, type): the abandonment timer of a job WAITING at the station,...
void set_mode_firing_dependence(std::size_t node, std::size_t mode, const std::function< T(const std::vector< T > &)> &g)
Transition.setFiringRateDependence(mode, g): g(marking) scales the rate.
void set_item_service_rate(std::size_t queue_node, std::size_t cache_node, std::size_t read_class, std::size_t item, const T &rate)
queue.setItemServiceRate(cache, readClass, item, rate) (Queue.m): override, at queue_node,...
void set_reply_signal_class(std::size_t call_cls, std::size_t reply_cls)
JobClass.setReplySignalClass(reply) (sn.syncreply), plus the sn.replyblock the state layer needs.
void set_class_completes(std::size_t cls, bool flag)
jobclass.completes = flag: whether a passage through the reference station counts as a completion.
std::size_t add_queue(const std::string &nm, SchedStrategy sched=SchedStrategy::FCFS)
A queueing station.
void set_class_switch_matrix(std::size_t node, const Matrix< T > &C)
Install the switching matrix of a ClassSwitch created without one.
void set_routing(std::size_t node, std::size_t cls, RoutingStrategy rs)
node.setRouting(class, strategy).
std::size_t add_transition(const std::string &nm)
A Transition with NO modes yet: Transition(model, name) as MATLAB, the JAR and Python spell it,...
void set_join_strategy(std::size_t node, lang::JoinStrategy strategy, double quorum=0.0)
Join.setStrategy(...): STD waits for every sibling, PARTIAL for a quorum.
void set_fork_branch_probability(std::size_t fork_node, std::size_t jobclass, std::size_t dest_node, double prob)
A branch that fires only with probability prob.
void set_item_routing_probability(std::size_t cache_node, std::size_t read_class, std::size_t item, std::size_t source_node, std::size_t dest_node, const T &p)
Cache.setItemRoutingProbability(readClass, item, source, dest, p): the probability of routing the ret...
std::size_t add_cache(const std::string &nm, const CacheParam< T > &par)
A Cache node with its item population, list capacities and popularity.
void set_cache_read(std::size_t cache_node, std::size_t r, const lang::Distrib< T > &d)
Cache.setRead(jobclass, Zipf(s, n)) or DiscreteSampler(p): the law is expanded to its pmf,...
void set_reward(const std::string &nm, const std::function< T(const std::vector< T > &)> &fn, const std::string &kind=std::string(), std::size_t node=0, std::size_t cls=0)
model.setReward(name, fn): a named reward evaluated on the AGGREGATE state row, the per-(station,...
void set_fluid_capacity(std::size_t node, double cap)
Place.setFluidCapacity(B): the level ceiling of a fluid place, Inf when unbounded.
std::size_t add_mode(std::size_t node, const std::string &nm)
Transition.addMode(name): a new firing mode, returning its 1-based index.
std::size_t add_self_looping_class(const std::string &nm, double njobs, std::size_t refstat_node, int prio=0)
SelfLoopingClass(model, name, njobs, refstat, prio): a closed class whose jobs perpetually cycle at t...
void set_marked_classes(std::size_t node, const std::vector< std::size_t > &classes)
Source.markedClasses: the 1-based class carried by each mark of an MMAP.
std::size_t add_closed_class(const std::string &nm, double njobs, std::size_t refstat_node, int prio=0)
void set_sched_param(std::size_t node, std::size_t cls, const T &weight)
The DPS / GPS weight of a class at a station.
std::size_t add_class_switch(const std::string &nm, const Matrix< T > &C)
A ClassSwitch node carrying the (nclasses x nclasses) switching matrix.
void set_fork_tasks_per_link_dist(std::size_t fork_node, std::size_t jobclass, const lang::Distrib< T > &dist, std::size_t dest_node=0)
A random jobs-per-link degree, redrawn per link and per forked job.
void set_firing_priority(std::size_t node, std::size_t mode, double prio)
Transition.setFiringPriorities(mode, priority).
std::vector< std::vector< bool > > get_class_switching_mask()
model.getClassSwitchingMask(): entry (r-1, s-1) is true if some node can switch class r into s.
std::size_t add_sink(const std::string &nm)
The external departure node.
const NetworkStruct< T > & get_struct()
The refreshed struct, MATLAB's model.getStruct().
std::size_t add_class_switch(const std::string &nm)
A ClassSwitch node whose matrix is installed LATER, by set_class_switch_matrix.
void set_batch_reject(std::size_t node, std::size_t cls, const T &p)
Queue.setBatchRejectProbability(class, p).
void set_polling_order(std::size_t node, lang::PollingOrder order, std::size_t prioclass=0, long threshold=-1)
Queue.setPollingOrder(order, prioclass, L): the visit-order rule.
void set_class_dependence(std::size_t node, const CdScaling< T > &fun, const std::vector< T > &peak=std::vector< T >())
station.setClassDependence(beta, peakRatePerClass).
void set_fluid_level(std::size_t node, double level)
Place.setFluidLevel(x0): the initial level of a fluid place.
void set_state_dep_routing(std::size_t entry, std::size_t departure, const std::vector< std::vector< std::size_t > > &branches, const std::vector< std::size_t > &level, const std::vector< double > &C, const Matrix< double > &d, std::size_t cls=0)
node.setStateDepRouting(class, departure, branches, level, C, d).
std::size_t add_place(const std::string &nm)
A Place: an SPN token container.
void set_routing_weights(std::size_t node, std::size_t cls, const std::map< std::size_t, double > &weights)
The per-destination weights of a WRROBIN dispatcher, per (node, class).
void set_mode_fluid_flow_dependence(std::size_t node, std::size_t mode, std::size_t place, const std::function< double(const std::vector< double > &)> &phi, const std::vector< std::size_t > &read=std::vector< std::size_t >())
Transition.setFluidFlowDependence(mode, place, phi, readPlaces): the flow of the mode into or out of ...
void set_item_miss_class(std::size_t cache_node, const std::vector< std::size_t > &miss_classes)
Cache.setItemMissClass(readClass, missClasses): terminate a cache network, every per-item class of th...
void set_log_path(const std::string &path)
Network.setLogPath: the directory every Logger of this model writes into.
void set_capacity(std::size_t node, double k)
station.setCapacity(k), the K of Kendall's notation.
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
void set_switchover(std::size_t node, std::size_t cls, const Distrib< T > &so)
Queue.setSwitchover(jobclass, distrib): the switchover time of a class.
void set_cache_hit_class(std::size_t cache_node, std::size_t r, std::size_t h)
Cache.setHitClass(jobclass, hitclass): a class-r read that hits leaves as class h.
void set_place_fluid(std::size_t node, bool fluid)
Place.setFluid(flag): the place holds one real level in [0, fluid capacity] instead of tokens,...
void set_immediate_feedback(std::size_t node, std::size_t cls)
queue.setImmediateFeedback(class): a completing job of that class is fed straight back into service,...
static void refuse_defective_patience(const Distrib< double > &d)
void set_balking(std::size_t node, std::size_t cls, lang::BalkingStrategy strategy, const std::vector< typename Station< T >::BalkingThreshold > &thresholds)
Queue.setBalking(class, strategy, thresholds): an arrival that refuses to JOIN, on the state it finds...
void set_polling_table(std::size_t node, const std::vector< std::size_t > &table, const std::vector< Distrib< T > > &swlegs=std::vector< Distrib< T > >())
Queue.setPollingTable(table, swlegs): the visit sequence of a POLLING station (1-based classes,...
void add_server_type(std::size_t node, const typename Station< T >::ServerType &stype)
Queue.addServerType(...): one heterogeneous server pool of the station.
void set_quantum(std::size_t node, std::size_t cls, const Distrib< T > &q)
Queue.setQuantum(jobclass, distrib): the time slice of a class at a round-robin station.
void set_setup_delayoff(std::size_t node, std::size_t cls, const Distrib< T > &setup, const Distrib< T > &delayoff)
Queue.setDelayOff(class, setupTime, delayoffTime): the station powers down after sitting idle for the...
void set_retrieval_system(std::size_t cache_node, std::size_t read_class, std::size_t miss_class, const std::vector< std::size_t > &queue_nodes)
Cache.setRetrievalSystem(readClass, missClass, queues): a delayed-hit cache whose misses are fetched ...
void set_class_deadline(std::size_t cls, double due)
JobClass.deadline: the soft deadline EDD, EDF and JMT's tardiness use.
void link(const RoutingMatrix< T > &Pm)
model.link(P): install the routing.
void set_routing_param(std::size_t node, std::size_t cls, int d)
The d of a power-of-d (SQ) dispatcher, per (node, class).
void set_retrial(std::size_t node, std::size_t cls, const Distrib< T > &proc, const T &rate, int max_attempts=0)
Queue.setRetrial(...): a station with an ORBIT instead of a waiting line.
void set_service(std::size_t node, std::size_t cls, const Distrib< double > &d)
void set_reference_class(std::size_t cls)
JobClass.setReferenceClass(true): sn.refclass(c) picks this class.
void pas_mirror(std::size_t ist, const std::function< double(const std::vector< std::size_t > &)> &mu, const Matrix< double > &swap_graph)
std::size_t add_join_unbound(const std::string &nm)
void set_hetero_sched_policy(std::size_t node, lang::HeteroSchedPolicy policy)
Queue.setHeteroSchedPolicy(...): how the server pools are picked among.
void set_limited_load_dependence(std::size_t node, const std::vector< double > &alpha)
std::size_t add_join(const std::string &nm, std::size_t fork_node)
A Join node, which IS a station: it serves at an infinite rate, and the synchronisation delay is supp...
void set_breakdown(std::size_t node, const Distrib< T > &failure, const Distrib< T > &repair, const std::vector< Distrib< T > > &down_service=std::vector< Distrib< T > >())
Queue.setBreakdown(failure, repair, downService): the server alternates up and down on the two clocks...
void set_pas(std::size_t node, const std::function< T(const std::vector< std::size_t > &)> &mu, const std::vector< std::vector< bool > > &swap_graph=std::vector< std::vector< bool > >())
Queue.setService(@(c) ...) for a pass-and-swap / order-independent station: the total service rate mu...
void set_item_read_classes(std::size_t cache_node, const std::vector< std::size_t > &read_classes, const std::vector< std::size_t > &hit_classes)
Cache.setItemReadClasses(readClasses, hitClasses): declare that read_classes[i] is the request stream...
void set_mode_servers(std::size_t node, std::size_t mode, double n)
Transition.setNumberOfServers(mode, n); GlobalConstants::MaxInt is infinite.
void set_switchover(std::size_t node, std::size_t from_cls, std::size_t to_cls, const Distrib< T > &so)
Queue.setSwitchover(fromClass, toClass, distrib): the walk between two CLASSES at an ordinary station...
void set_firing_outcome(std::size_t node, std::size_t mode, std::size_t cls, std::size_t dest, const T &tokens)
Transition.setFiringOutcome(mode, class, node, tokens): the class-r tokens the firing deposits.
std::size_t add_transition(const std::string &nm, const TransitionParam< T > &par)
A Transition: the firing rules of an SPN, as Transition in MATLAB.
void set_orbit_impatience(std::size_t node, std::size_t cls, const Distrib< T > &dist)
Queue.setOrbitImpatience(class, dist): abandonment from the retrial orbit.
void set_sync_reply(std::size_t node, std::size_t call_cls, std::size_t reply_cls)
Declare a SYNCHRONOUS call: a job of call_cls leaving node keeps its server until a job of the REPLY ...
void set_signal(std::size_t cls, lang::SignalType type, lang::RemovalPolicy policy=lang::RemovalPolicy::RANDOM, std::size_t target=0, const std::vector< double > &remdist=std::vector< double >())
void set_global_dependence(const GdScaling< T > &fun, const std::vector< T > &peak)
model.setGlobalDependence(phi, peak): MATLAB's Network.gdScaling.
void set_server_parallelism(std::size_t node, std::size_t cls, std::size_t n)
Queue.setServerParallelism(class, n): the servers a job seizes for the whole of its service.
std::size_t station_index(std::size_t node) const
void set_orbit_policy(std::size_t node, std::size_t cls, int policy, int max_orbit, bool size_buffer=true)
The policy and bound of Queue.setOrbit(class, dist, policy, maxOrbit) on a class already declared by ...
void set_region_weights(std::size_t region, const std::vector< T > &weight)
FiniteCapacityRegion.setClassWeight: the per-class weight the region's global cap counts a job agains...
void set_quantum(std::size_t node, const Distrib< T > &q)
Queue.setQuantum(distrib): the same time slice for every class.
void set_arrival(std::size_t node, std::size_t cls, const Distrib< T > &d)
source.setArrival(class, dist): the same table, at the Source.
std::size_t add_region(const std::vector< std::size_t > &nodes, const std::vector< double > &class_max_jobs, double global_max_jobs=-1.0, const std::vector< DropStrategy > &rule=std::vector< DropStrategy >(), const std::vector< double > &class_max_memory=std::vector< double >(), const std::vector< T > &class_size=std::vector< T >(), double global_max_memory=-1.0, const std::string &name=std::string())
FiniteCapacityRegion(model, nodes): a cap on the jobs held ACROSS a set of stations.
void set_mode_fluid_guard(std::size_t node, std::size_t mode, std::size_t place, const std::string &op, double threshold)
Transition.setFluidGuard(mode, place, op, threshold): the mode is enabled only while the level of the...
double get_fluid_capacity(std::size_t node)
void set_polling_type(std::size_t node, lang::PollingType rule, int par=0)
Queue.setPollingType(rule, par): the polling discipline of a POLLING station, identical across all cl...
The routing matrix a model script fills in, MATLAB's P cell array.
void set(std::size_t cls, const RoutingMatrix< T > &block)
P.set(class, Network.serialRouting(...)): install a one-class block.
T get(std::size_t r, std::size_t s, std::size_t i, std::size_t j) const
void set(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
void set(std::size_t i, std::size_t j, const T &p)
std::map< Key, double > entries
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The exception types the port throws.
Dense matrix and non-owning view.
std::vector< std::string > sn_validate_contract(const SnFieldViews &views, bool error=false)
The contract violations of a field view; with error true, throws InternalError with id LINE:internal:...
void sn_fj_nodevisits_mmt(qn::NetworkStruct< T > &sn)
Rewrite sn.nodevisits with the MMT correction.
bool sn_validate_requested()
True when get_struct should validate: debug verbosity, or LINE_VALIDATE_SN=1.
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
TimingStrategy
SPN transition timing, with the values of MATLAB TimingStrategy.
@ IMMEDIATE
fires with zero delay, resolved by weight and priority
@ TIMED
fires after its firing distribution elapses
BalkingStrategy
Balking rules, with the values of MATLAB BalkingStrategy.
SignalType
G-network signal classes, with the values of MATLAB SignalType.
@ REPLY
completes a synchronous call, releasing a held server
@ NEGATIVE
removes a batch of jobs (Gelenbe's negative customer)
PollingOrder
Visit-order rules of a polling server, with the values of MATLAB PollingOrder.
@ THRESHOLD
a priority buffer above its threshold, else SKIPEMPTY
@ CYCLIC
fixed cyclic order (or the polling table)
void prior_refresh_moments(Distrib< T > &d)
Write the mixture moments onto a Prior, the counterpart of dist_refresh_moments for the Markovian fam...
JoinStrategy
Join rules, with the values of MATLAB JoinStrategy.
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
PollingTimer
Visit-timer scopes of a polling server, with the values of MATLAB PollingTimer.
@ LOCAL
a timer per visit, drawn at the polling instant
DepartureDiscipline
When a Place releases a served token, MATLAB DepartureDiscipline.
RemovalPolicy
Which job a negative signal removes, with the values of MATLAB RemovalPolicy.
@ RANDOM
uniform over waiting AND in-service jobs
HeteroSchedPolicy
How a heterogeneous station picks among its server types, MATLAB HeteroSchedPolicy.
PollingType
Polling service disciplines, with the values of MATLAB PollingType.
@ KLIMITED
serve at most K per visit (K in pollingPar)
@ GLIMITED
serve at most K of the jobs present at the polling instant
std::function< std::vector< T >(const std::vector< T > &)> GdScaling
A globally state-dependent scaling, sn.gdscaling.
std::function< std::vector< T >(const std::vector< T > &)> CdScaling
A class-dependent scaling map, sn.cdscaling.
void dist_refresh_moments(Distrib< T > &d)
Fill in the first two moments of a distribution given by its matrices.
NodeType
Node kinds, with the values of MATLAB NodeType.
ImpatienceType
Impatience kinds, with the values of MATLAB ImpatienceType.
SdrCoeff pfqn_sdrcoeff(const SdrStruct &sdr)
Validates an SDR structure and returns its derived coefficients.
void closed_reneging_refusal(const std::string &classname, const std::string &where)
Refuses RENEGING on a class of finite population (LINE:input:Model; MATLAB closedRenegingRefusal....
std::vector< Frame > & stack()
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Prior: parameter uncertainty as a weighted set of alternative models.
Post-MMT node visits of a fork-join model.
Check a NetworkStruct against its contract (sn_contract.h): the C++ twin of MATLAB's sn_validate.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
std::vector< T > params
Constructor arguments, in MATLAB getParam order.
std::vector< T > trace
Replayer / Trace samples; empty for every other type.
Topology and coefficients of a state-dependent routing subnetwork.
std::vector< std::size_t > departureOf
departureOf[b] is the departure centre d(b) of branch b.
std::vector< std::size_t > entryOf
entryOf[b] is the entry centre e(b) of branch b.
std::vector< std::size_t > level
level[b] is the unique t with B_b in V_t - V_{t+1}; level[0] is unused.
Matrix< double > d
Coefficients d_tb of eq.
std::vector< double > C
Coefficients C_t of eq.
std::size_t departure
Departure centre d of Q(V,V); may equal entry.
std::vector< std::vector< std::size_t > > branch
branch[b] holds the centres of branch b, b >= 1; branch[0] is unused.
std::size_t entry
Entry centre e of Q(V,V).
Server breakdown and repair of a station whose server fails and is repaired.
T failure_rate
sn.breakdownMu: 1 / mean failure time
lang::Distrib< T > repair
time to repair of a down server
lang::Distrib< T > failure
time to failure of an up server
T repair_rate
sn.repairMu: 1 / mean repair time
std::vector< T > down_service_rates
sn.downServiceRates(ist, :): per class, 0 = no service while down.
The popularity LAW each class declared, beside the pmf it expands to.
std::size_t n
support size of a Zipf or a DiscreteSampler
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
int retrieval_capacity
Delayed-hit retrieval system (Cache.setRetrievalSystem).
std::vector< Popularity > preadkind
per class, parallel to pread
std::map< std::size_t, std::vector< std::size_t > > retrieval_queues
read class(0-based)->nodes
std::vector< std::vector< std::size_t > > retrieval_classes
(nitems x nclasses), 1-based
std::vector< int > itemcap
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
std::vector< std::size_t > classitem
Item read by each per-item class of a cache network (MATLAB Cache.setItemReadClasses,...
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN
static Distrib exp_rate(const T &r)
static Distrib disabled_dist()
static Distrib immediate()
The point mass at zero.
One job class of the network.
std::size_t refstat
1-based reference station
double population
infinite for an open class
The DECLARED join rule of a Join node, by 1-based node index.
lang::JoinStrategy strategy
double quorum
0 = every sibling
The pass-and-swap / order-independent parameters of a PAS station, keyed by station index (Dorsman an...
std::function< T(const std::vector< std::size_t > &)> svc_rate_fun
std::vector< std::vector< bool > > swap_graph
The polling controller of a POLLING station, keyed by station index.
std::size_t pk
the K of K-LIMITED
std::vector< lang::Distrib< T > > switchover
FINITE CAPACITY REGIONS, MATLAB's refreshRegions output.
std::vector< std::vector< double > > cap
(nstations x nclasses+1), -1 = unbounded
std::string name
The region's declared name, as the wire carries it; a generated one otherwise.
std::vector< double > maxmem
per member station, -1 = unbounded
std::vector< DropStrategy > rule
per class
std::vector< T > size
per class; size is the memory footprint
std::vector< bool > members
membership, independent of the caps
sn.reward: the user-declared reward functions, MATLAB's model.setReward(name, fn).
std::function< T(const std::vector< T > &)> fn
std::string kind
The DECLARATIVE form the reward was built from, when it was: the template name (QLen,...
std::vector< RoutingStrategy > routing
sn.routing, per class.
The parameters of a retrial station: MATLAB sn.retrialProc and friends.
std::vector< int > max_attempts
0 = unbounded
std::vector< T > retrial_rate
mu_r, the per-class orbit retry rate
std::vector< lang::Distrib< T > > retrial_proc
retrial_proc[r] is the class-r retrial process; empty = not a retrial class.
std::vector< int > max_orbit
MATLAB sn.orbitMaxJobs: -1 = unbounded.
std::vector< int > policy
MATLAB sn.retrialPolicy: 1 = LINEAR (per-job clocks), 2 = CONSTANT (one clock per orbit).
Key(std::size_t r_, std::size_t s_, std::size_t i_, std::size_t j_)
bool operator<(const Key &o) const
Setup and delay-off of a station that powers down when it falls idle.
std::vector< lang::Distrib< T > > setup
per class, disabled = not declared
std::vector< lang::Distrib< T > > delayoff
per class
Per class; strategy == NONE is a class that declares no balking.
One balking threshold: with min_jobs <= n <= max_jobs at the station, an arriving job of the class re...
A heterogeneous server pool: count servers that serve only compatible classes, each with its own serv...
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...
bool polling_timer_preempt
double cap
Station capacity in Kendall's K, as setCapacity sets it.
std::vector< T > jdscalingpeak
sn.jdscalingpeak for this station: the declared peak joint-dependent scaling per class.
std::vector< BalkingParam > balking
std::function< T(const std::vector< std::size_t > &)> svc_rate_fun
sn.nodeparam{ind}.svcRateFun for a PAS / OI station: the TOTAL service rate as a function of the orde...
std::vector< T > batch_reject
Queue.setBatchRejectProbability: per-class rejection of a whole batch.
std::vector< Distrib< T > > patience
Queue.setPatience(class, dist): the abandonment timer of a WAITING job, with impatience[r] naming whi...
std::vector< std::size_t > server_parallelism
Queue.setServerParallelism(class, n): the servers a job seizes for the whole of its service,...
std::vector< Distrib< T > > quantum
Queue.setQuantum(class, distrib): the per-class time slice of a round-robin (SchedStrategy::RR) stati...
std::vector< int > droprule
Per-class blocking rule as an INT, with 0 meaning "not set".
std::vector< T > orbit_join
Queue.setOrbitPersistence(class, p, q), MATLAB sn.orbitJoinProb and sn.orbitPersistProb: a fresh arri...
std::vector< Distrib< T > > polling_timer
std::vector< std::vector< Distrib< T > > > switchover_pair
Queue.setSwitchover(fromClass, toClass, distrib): the walk the server takes when it turns from servin...
std::vector< Distrib< T > > polling_table_sw
double nservers
may be infinite (a Delay, or an inf-scheduled task)
std::size_t polling_order_class
std::vector< lang::PollingType > polling_type
Polling parameters for a POLLING station, MATLAB's pollingType, switchoverTime and pollingPar on the ...
Matrix< T > swap_graph
sn.nodeparam{ind}.swapGraph: which class a departing job promotes the jobs behind it into.
CdScaling< T > jdscaling
sn.jdscaling for this station: MATLAB's Station.ljdScaling, the JOINT dependence map eta_i(n),...
std::vector< T > cdscalingpeak
sn.cdscalingpeak for this station: the DECLARED peak rate scaling per class, empty when the station i...
std::vector< lang::ImpatienceType > impatience
std::vector< T > schedparam
sn.schedparam, per class: the DPS / GPS weight, or the SEPT / LEPT rank.
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.
std::vector< Distrib< T > > arrival_batch
Source.setArrivalBatch(class, dist): the batch-size law released at each arrival epoch.
std::vector< Distrib< T > > switchover
std::vector< T > orbit_search
Queue.setOrbitalSearch(class, theta), MATLAB sn.orbitSearchProb: on a service completion at a retrial...
lang::PollingTimer polling_timer_scope
std::vector< T > orbit_persist
std::vector< bool > immfeed
Node-level immediate feedback, per class; empty when the station sets none.
long polling_order_threshold
A fluid rate dependence: the firing rate is multiplied by fun(level(node)).
A marking-dependent fluid flow (setFluidFlowDependence): the flow of the mode on fluid place node is ...
std::vector< std::size_t > read
std::function< double(const std::vector< double > &)> fun
A fluid guard: the mode is enabled only while level(node) >= thr (sgn = +1) or <= thr (sgn = -1).
The parameters of a Transition node: MATLAB sn.nodeparam{ind} for an SPN transition,...
std::vector< std::vector< FluidDep > > fluiddep
std::vector< double > firingprio
firing priority per mode
std::vector< std::vector< FluidGuard > > fluidguard
std::vector< std::vector< FluidFlowDep > > fluidflowdep
std::vector< lang::TimingStrategy > timing
immediate or timed
std::vector< std::string > modenames
std::vector< std::vector< FluidArc > > fluidimpulse
std::vector< lang::Distrib< T > > firingproc
firing distribution per mode
std::vector< double > nmodeservers
servers per mode, may be infinite
std::vector< T > fireweight
weight among simultaneously enabled modes
std::vector< Matrix< T > > firing
firing[m](p,r): class-r tokens mode m moves to/from place p when it fires.
std::vector< Matrix< T > > enabling
enabling[m](p,r): class-r tokens of place p (0-based node) mode m needs.
std::vector< std::function< T(const std::vector< T > &)> > firingdep
Marking-dependent firing-rate multiplier g_m(marking); an empty entry is the unit multiplier.
std::vector< Matrix< T > > inhibiting
inhibiting[m](p,r): class-r tokens of p that BLOCK mode m (Inf = never).
std::vector< std::vector< FluidArc > > fluidrate
FSPN arcs per mode, MATLAB sn.transparam{ind}.fluidrate/fluidguard/fluidimpulse/fluiddep.
std::vector< std::size_t > firingphases
phase count per mode, 0 when non-Markovian