5#ifndef LINE_LANG_QN_NETWORK_STRUCT_H
6#define LINE_LANG_QN_NETWORK_STRUCT_H
82using lang::GlobalConstants;
101 std::vector<std::vector<std::size_t>>
auxall;
131 std::map<std::size_t, std::vector<std::vector<std::size_t>>>
auxmatrix;
132 std::map<std::size_t, std::vector<std::size_t>>
required;
141 std::map<std::size_t, std::size_t>
quorum;
303 if (m >= a.size())
return v;
305 for (std::size_t p = 0; p < a[m].rows(); ++p) {
308 for (std::size_t r = 0; r < a[m].cols(); ++r) {
310 if (!std::isfinite(x))
continue;
314 v[p] = any || a[m].cols() == 0
330 if (m >= a.size())
return v;
331 const double inf = std::numeric_limits<double>::infinity();
333 for (std::size_t p = 0; p < a[m].rows(); ++p) {
335 for (std::size_t r = 0; r < a[m].cols(); ++r) {
337 if (std::isfinite(x) && x < best) best = x;
347 for (
int w = 0; w < 3; ++w)
348 for (std::size_t m = 0; m < all[w]->size(); ++m) {
349 std::size_t touched = 0;
350 for (std::size_t r = 0; r < (*all[w])[m].cols(); ++r) {
352 for (std::size_t p = 0; p < (*all[w])[m].rows() && !any; ++p) {
355 any = w == 1 ? (std::isfinite(v) && v > 0.0) : v > 0.0;
359 if (touched > 1)
return true;
367 for (
int w = 0; w < 3; ++w)
368 for (std::size_t m = 0; m < all[w]->size(); ++m)
369 for (std::size_t r = 0; r < (*all[w])[m].cols(); ++r)
370 for (std::size_t p = 0; p < (*all[w])[m].rows(); ++p) {
372 if (w == 1 ? (std::isfinite(v) && v > 0.0) : v > 0.0)
return r + 1;
379 std::vector<lang::TimingStrategy>
timing;
388 std::vector<std::function<T(
const std::vector<T>&)>>
firingdep;
404 std::function<double(
double)>
fun;
414 std::function<double(
const std::vector<double>&)>
fun;
430 static const std::vector<FluidArc> none;
434 static const std::vector<FluidGuard> none;
438 static const std::vector<FluidArc> none;
441 const std::vector<FluidDep>&
fluid_deps(std::size_t m)
const {
442 static const std::vector<FluidDep> none;
446 static const std::vector<FluidFlowDep> none;
451 for (std::size_t m = 0; m <
nmodes; ++m)
494 std::vector<lang::Distrib<T>>
setup;
498 for (std::size_t r =
setup.size(); r > 0; --r)
499 if (!
setup[r - 1].disabled) {
603 std::vector<std::vector<Matrix<T>>>
accost;
643 std::vector<std::size_t>& rc_items,
644 std::vector<std::size_t>& rc_orig) {
652 rc_items.push_back(k + 1);
653 rc_orig.push_back(c + 1);
657 std::vector<std::size_t> ord(rc_list.size());
658 for (std::size_t i = 0; i < ord.size(); ++i) ord[i] = i;
659 std::stable_sort(ord.begin(), ord.end(),
660 [&](std::size_t a, std::size_t b) { return rc_list[a] < rc_list[b]; });
661 std::vector<std::size_t> l(rc_list.size()), it(rc_list.size()), oc(rc_list.size());
662 for (std::size_t i = 0; i < ord.size(); ++i) {
663 l[i] = rc_list[ord[i]];
664 it[i] = rc_items[ord[i]];
665 oc[i] = rc_orig[ord[i]];
692 double cap = std::numeric_limits<double>::infinity();
942 double fluidcap = std::numeric_limits<double>::infinity();
984 double deadline = std::numeric_limits<double>::infinity();
1014 std::vector<std::vector<std::size_t>>
pools;
1015 std::vector<std::vector<std::size_t>>
off,
len;
1016 std::vector<std::vector<std::vector<T>>>
alpha;
1017 std::vector<std::vector<std::vector<T>>>
exit;
1018 std::vector<std::vector<Matrix<T>>>
D0;
1022 std::vector<std::vector<std::size_t>>
perms;
1024 std::size_t
perm_index(
const std::vector<std::size_t>& order)
const {
1025 for (std::size_t p = 0; p <
perms.size(); ++p)
1026 if (
perms[p] == order)
return p + 1;
1047 std::vector<std::pair<std::size_t, std::size_t>>
pairs;
1064 "Class \"" + classname +
"\" is closed, but reneging" + where +
1065 " removes a waiting job from the network, which would change a closed population. Reneging "
1066 "is defined for open classes only; model the abandonment as a routing (e.g. a probabilistic "
1067 "exit back to the reference station) or use an open class.");
1137 if (i >=
stations.size() ||
stations[i].nodetype != NodeType::Place)
return false;
1138 for (std::size_t r = 0; r <
service[i].size(); ++r)
1145 if (ind == 0 || ind >
nodes.size())
return false;
1146 const std::size_t st =
nodes[ind - 1].station;
1147 return st > 0 && st <=
stations.size() &&
stations[st - 1].nodetype == NodeType::Place &&
1153 if (s.nodetype == NodeType::Place && s.fluid)
return true;
1155 if (tp.second.has_fluid_arcs())
return true;
1182 std::vector<std::pair<std::size_t, std::size_t>>
fj;
1270 const typename std::map<std::size_t, ForkParam<T> >::const_iterator it =
1289 std::function<T(
const std::vector<T>&)>
fn;
1326 std::vector<std::vector<double>>
cap;
1359 if (ind == 0 || ind >
nodes.size())
return false;
1360 const std::size_t ist =
nodes[ind - 1].station;
1474 std::vector<std::vector<std::size_t>>
nvars;
1586 if (ist == 0 || ist >
stations.size())
return pp;
1587 const typename std::map<std::size_t, PollingParam>::const_iterator it =
1623 std::size_t l)
const {
1625 const std::size_t R = polled.size();
1626 std::size_t src = 0;
1629 if (l > R || !polled[l - 1])
return nullptr;
1631 }
else if (!pp.
table.empty()) {
1632 const std::size_t M = pp.
table.size();
1633 const std::size_t pr = (l + M - 2) % M + 1;
1637 src = pp.
table[pr - 1];
1639 if (l > R || !polled[l - 1])
return nullptr;
1640 std::vector<std::size_t> pl;
1641 for (std::size_t r = 1; r <= R; ++r)
1642 if (polled[r - 1]) pl.push_back(r);
1644 while (pl[jj] != l) ++jj;
1645 src = pl[(jj + pl.size() - 1) % pl.size()];
1648 if (src == 0 || src > pp.
switchover.size())
return nullptr;
1651 if (d->
disabled || d->
type == ProcessType::IMMEDIATE)
return nullptr;
1671 std::vector<const lang::Distrib<T>*> legs(L,
nullptr);
1672 for (std::size_t l = 1; l <= L; ++l) {
1674 anysw = anysw || legs[l - 1] !=
nullptr;
1676 bool repeats =
false;
1677 if (!ld && !pp.
table.empty()) {
1678 std::vector<std::size_t> u = pp.
table;
1679 std::sort(u.begin(), u.end());
1680 repeats = std::unique(u.begin(), u.end()) != u.end();
1682 bool distinct =
false;
1685 for (std::size_t l = 0; l < L && !distinct; ++l) {
1686 if (legs[l] ==
nullptr)
continue;
1687 if (first ==
nullptr) { first = legs[l];
continue; }
1692 if (anysw || repeats) w += 1;
1695 if (distinct) w += 1;
1699 for (
bool b : polled) w += b ? 1 : 0;
1707 if (a.
D0.rows() != b.
D0.rows() || a.
D0.cols() != b.
D0.cols())
return true;
1708 for (std::size_t i = 0; i < a.
D0.rows(); ++i)
1709 for (std::size_t j = 0; j < a.
D0.cols(); ++j)
1710 if (a.
D0(i, j) != b.
D0(i, j) || a.
D1(i, j) != b.
D1(i, j))
return true;
1726 std::vector<bool> polled(R,
true);
1727 for (std::size_t r = 1; r <= R; ++r)
1731 polled[r - 1] =
false;
1743 for (std::size_t r = 0; r < polled.size() && r < pp.
switchover.size(); ++r) {
1744 if (!polled[r])
continue;
1777 if (ind == 0 || ind >
nvars.size())
return 0;
1779 for (std::size_t j = 0; j <
nvars[ind - 1].size(); ++j) w +=
nvars[ind - 1][j];
1790 std::vector<double> v;
1819 std::vector<double> v(
nodes.size(), std::nan(
""));
1829 std::vector<double> v(
nstations, std::nan(
""));
1832 if (nd >= 1 && nd <= nsf.size()) v[ist - 1] = nsf[nd - 1];
1842 if (nd >= 1 && nd <=
nodes.size() &&
nodes[nd - 1].station != 0)
1843 v[k] =
static_cast<double>(
nodes[nd - 1].station);
1858 const std::size_t I =
nodes.size();
1861 for (
const auto& kv :
P) {
1863 if (B.
rows() < I || B.
cols() < I)
continue;
1864 for (std::size_t a = 0; a < I; ++a)
1865 for (std::size_t b = 0; b < I; ++b)
1866 if (B(a, b) > zero &&
1867 !(
nodes[a].nodetype == NodeType::Sink &&
nodes[b].nodetype == NodeType::Source))
1879 const std::size_t I =
nodes.size();
1881 for (std::size_t ind = 0; ind < I; ++ind) {
1882 if (
nodes[ind].nodetype == NodeType::Cache) m(ind, 1) = 1.0;
1884 if (rs == RoutingStrategy::RROBIN || rs == RoutingStrategy::WRROBIN || rs == RoutingStrategy::JSQ ||
1885 rs == RoutingStrategy::SQ || rs == RoutingStrategy::SDR)
1893 std::vector<double> v(
nodes.size(), 0.0);
1894 for (std::size_t ind = 1; ind <=
nodes.size(); ++ind)
1901 std::vector<bool> v(
nclasses,
false);
1918 if (
stations[i].nodetype == NodeType::Join)
1919 m(i, r) =
static_cast<double>(
static_cast<int>(ProcessType::IMMEDIATE));
1923 m(i, r) =
static_cast<double>(
static_cast<int>(
service[i][r].type));
1930 bool proc_is_empty(std::size_t i, std::size_t r)
const {
1936 bool proc_is_nan(std::size_t i, std::size_t r)
const {
1937 return service[i][r].disabled && !proc_is_empty(i, r);
1940 std::vector<Matrix<T>> proc_blocks(std::size_t i, std::size_t r)
const {
1942 std::vector<Matrix<T>> b;
1946 for (
const Matrix<T>& Dk : d.
Dmark) b.push_back(Dk);
1970 if (proc_is_empty(i, r) || d.
type == ProcessType::NHPP || d.
type == ProcessType::NNPP)
1973 m(i, r) =
static_cast<double>(proc_blocks(i, r)[0].rows());
1986 for (std::size_t i = 0; i < m.
rows(); ++i)
1987 for (std::size_t r = 0; r < m.
cols(); ++r) {
1988 if (
stations[i].nodetype != NodeType::Join && m(i, r) < 1.0) m(i, r) = 1.0;
1989 if (
markidx_of(i + 1, r + 1) > 1) m(i, r) = 1.0;
1998 for (std::size_t i = 0; i < sz.
rows(); ++i)
1999 for (std::size_t r = 0; r < sz.
cols(); ++r) m(i, r + 1) = m(i, r) + sz(i, r);
2009 std::vector<std::vector<std::vector<double>>>
mu()
const {
return rate_cells(
true); }
2012 std::vector<std::vector<std::vector<double>>>
phi()
const {
return rate_cells(
false); }
2020 std::vector<std::vector<std::vector<double>>>
pie()
const {
2021 std::vector<std::vector<std::vector<double>>> out(
nstations, std::vector<std::vector<double>>(
nclasses));
2026 d.
type == ProcessType::NNPP) {
2027 out[i][r] = {std::nan(
"")};
2030 const std::vector<Matrix<T>> b = proc_blocks(i, r);
2046 const auto pies =
pie();
2051 d.
type == ProcessType::NNPP)
2061 using LstHandle = std::function<std::complex<double>(
const std::complex<double>&)>;
2071 std::vector<std::vector<LstHandle>>
lst()
const {
2072 std::vector<std::vector<LstHandle>> out(
nstations, std::vector<LstHandle>(
nclasses));
2077 if (nt == NodeType::Fork || nt == NodeType::Join)
continue;
2079 if (nt != NodeType::Source)
2080 out[i][r] = [](
const std::complex<double>&) {
return std::complex<double>(std::nan(
""), 0.0); };
2083 out[i][r] = [d](
const std::complex<double>& s) -> std::complex<double> {
2087 if (s.imag() != 0.0)
2089 "sn.lst: a complex argument needs transcendental arithmetic; solve in double");
2090 return std::complex<double>(
2099 std::vector<std::vector<std::vector<double>>> rate_cells(
bool want_mu)
const {
2100 std::vector<std::vector<std::vector<double>>> out(
nstations, std::vector<std::vector<double>>(
nclasses));
2104 if (proc_is_empty(i, r))
continue;
2106 out[i][r] = {std::nan(
"")};
2107 }
else if (d.
type == ProcessType::NHPP || d.
type == ProcessType::NNPP ||
2108 d.
type == ProcessType::DMAP) {
2109 out[i][r] = {want_mu ? num_traits<T>::to_double(d.
rate()) : 1.0};
2112 out[i][r].push_back(num_traits<T>::to_double(x));
2122 return service[ist - 1][r - 1].type;
2142 std::size_t
phases_of(std::size_t ist, std::size_t r)
const {
2175 classes[r - 1].name +
"; set it with setQuantum.");
2178 case ProcessType::EXP:
2179 case ProcessType::ERLANG:
2180 case ProcessType::HYPEREXP:
2181 case ProcessType::PH:
2182 case ProcessType::APH:
2183 case ProcessType::COXIAN:
2184 case ProcessType::COX2:
2185 return d.D0.rows() > 0 ? d.D0.rows() : 1;
2200 const std::size_t p =
phases_of(ist, r);
2201 return p > 0 ? p : 1;
2213 if (ist == 0 || ist >
stations.size())
return 0;
2214 const std::vector<std::size_t>&
mc =
stations[ist - 1].marked_classes;
2215 for (std::size_t k = 0; k <
mc.size(); ++k)
2216 if (
mc[k] == r)
return k + 1;
2225 if (ist == 0 || ist >
stations.size())
return 0;
2226 const std::vector<std::size_t>&
mc =
stations[ist - 1].marked_classes;
2227 return mc.empty() ? 0 :
mc[0];
2231 if (n.nodetype == NodeType::Fork)
return true;
2246 if (rs == RoutingStrategy::SDR)
return true;
2257 if (rs == RoutingStrategy::SDR || rs == RoutingStrategy::JSQ || rs == RoutingStrategy::SQ)
2277 std::vector<std::size_t>
rr_outlinks(std::size_t ind, std::size_t r)
const {
2278 std::vector<std::size_t> out;
2280 const std::size_t K =
classes.size(), I =
nodes.size();
2281 for (std::size_t j = 1; j <= I; ++j) {
2282 bool linked =
false;
2283 for (std::size_t s = 1; s <= K && !linked; ++s)
2284 if (
get_route(r, s, ind, j) > zero) linked =
true;
2285 if (linked) out.push_back(j);
2292 const std::vector<std::size_t> ol =
rr_outlinks(ind, r);
2293 const std::map<std::size_t, double>* w =
2294 (ind <=
nodes.size() &&
nodes[ind - 1].routing_weights.size() >= r)
2295 ? &
nodes[ind - 1].routing_weights[r - 1]
2297 std::vector<std::size_t> cycle;
2298 for (std::size_t d = 0; d < ol.size(); ++d) {
2301 const std::map<std::size_t, double>::const_iterator it = w->find(ol[d]);
2302 if (it != w->end() && it->second > 0.0)
2303 reps = std::lround(it->second) < 1 ? 1 : std::lround(it->second);
2305 for (
long q = 0; q < reps; ++q) cycle.push_back(ol[d]);
2312 if (
ctmcmapc.empty())
return nullptr;
2313 const auto it =
ctmcmapc.find(std::make_pair(ist, r));
2314 return it ==
ctmcmapc.end() ? nullptr : &it->second;
2319 std::size_t slot = 0;
2320 for (std::size_t j = 0; j + 1 < r && j <
nvars[ind - 1].size(); ++j) slot +=
nvars[ind - 1][j];
2334 const std::size_t R =
classes.size();
2335 if (ind == 0 || ind >
nodes.size() || r == 0 || r > R)
return 0;
2336 const std::vector<RoutingStrategy>& rt_i =
nodes[ind - 1].routing;
2337 if (rt_i.size() < r)
return 0;
2338 if (rt_i[r - 1] != RoutingStrategy::RROBIN && rt_i[r - 1] != RoutingStrategy::WRROBIN)
2340 if (
nvars.size() < ind)
return 0;
2341 std::size_t slot = 0;
2342 for (std::size_t j = 0; j < R + r && j <
nvars[ind - 1].size(); ++j)
2343 slot +=
nvars[ind - 1][j];
2353 std::size_t
rr_dest(std::size_t ind, std::size_t r,
const std::vector<T>& varrow)
const {
2355 if (slot == 0 || slot > varrow.size())
return 0;
2357 if (
nodes[ind - 1].routing[r - 1] == RoutingStrategy::RROBIN)
2358 return v > 0 ?
static_cast<std::size_t
>(v) : 0;
2360 if (v < 1 ||
static_cast<std::size_t
>(v) > cycle.size())
return 0;
2361 return cycle[
static_cast<std::size_t
>(v) - 1];
2370 void rr_advance(std::size_t ind, std::size_t r, std::vector<T>& varrow)
const {
2372 if (slot == 0 || slot > varrow.size())
return;
2373 if (
nodes[ind - 1].routing[r - 1] == RoutingStrategy::RROBIN) {
2374 const std::vector<std::size_t> ol =
rr_outlinks(ind, r);
2375 if (ol.empty())
return;
2377 std::size_t idx = ol.size();
2378 for (std::size_t d = 0; d < ol.size(); ++d)
2379 if (
static_cast<long>(ol[d]) == cur) { idx = d;
break; }
2380 const std::size_t nxt = (idx + 1 < ol.size()) ? idx + 1 : 0;
2385 if (cycle.empty())
return;
2387 const long nxt = (pos < 1 || static_cast<std::size_t>(pos) >= cycle.size()) ? 1 : pos + 1;
2395 if (rs == RoutingStrategy::RROBIN || rs == RoutingStrategy::WRROBIN)
return true;
2419 bool declared =
false;
2420 for (
const std::vector<bool>& row :
immfeed) {
2426 if (declared)
break;
2428 if (!declared)
return false;
2433 for (std::size_t ist = 1; ist <=
immfeed.size(); ++ist) {
2435 if (ind == 0 || ind >
nodes.size())
continue;
2437 if (isf == 0)
continue;
2438 for (std::size_t r = 1; r <=
immfeed[ist - 1].size() && r <= R; ++r) {
2439 if (!
immfeed[ist - 1][r - 1])
continue;
2440 const std::size_t col = (isf - 1) * R + (r - 1);
2441 if (col >=
rt.
cols())
continue;
2442 for (std::size_t sc = 0; sc < R; ++sc) {
2443 const std::size_t row = (isf - 1) * R + sc;
2470 throw InputError(
"network: a station is not a stateful node");
2482 nodes.push_back(nd);
2496 nodes.push_back(nd);
2499 return nodes.size();
2510 service[station - 1][cls - 1] = d;
2514 void set_route(std::size_t r, std::size_t s, std::size_t i, std::size_t j,
const T& p) {
2515 auto key = std::make_pair(r, s);
2516 auto it =
P.find(key);
2521 it->second(i - 1, j - 1) = p;
2537 auto key = std::make_pair(r, s);
2538 auto it =
Peff.find(key);
2539 if (it ==
Peff.end())
2542 if (it->second.rows() !=
nodes.size()) {
2544 for (std::size_t a = 0; a < it->second.rows(); ++a)
2545 for (std::size_t b = 0; b < it->second.cols(); ++b) g(a, b) = it->second(a, b);
2548 it->second(i - 1, j - 1) = p;
2559 T
get_route(std::size_t r, std::size_t s, std::size_t i, std::size_t j)
const {
2560 auto it =
P.find(std::make_pair(r, s));
2562 return it->second(i - 1, j - 1);
2566 T
route_eff(std::size_t r, std::size_t s, std::size_t i, std::size_t j)
const {
2568 auto it =
Peff.find(std::make_pair(r, s));
2570 return it->second(i - 1, j - 1);
2617 for (std::size_t i = 0; i <
stations.size(); ++i)
2618 for (std::size_t r = 0; r <
stations[i].impatience.size() && r <
classes.size(); ++r)
2620 std::isfinite(
classes[r].population))
2630 if (ind == 0 || ind >
replyblock.size())
return false;
2631 for (std::size_t k = 0; k <
syncreply.size(); ++k)
2649 if (ind == 0 || ind >
nodes.size())
return true;
2651 if (nt != NodeType::Queue && nt != NodeType::Delay)
return true;
2652 const std::size_t sti =
nodes[ind - 1].station;
2653 if (sti == 0 || sti >
stations.size())
return true;
2654 if (!
stations[sti - 1].server_types.empty())
return true;
2655 if (
procid(sti, r + 1) != ProcessType::DISABLED)
return true;
2673 std::vector<std::vector<bool>> reached;
2674 if (N == 0 || K == 0)
return reached;
2676 reached.assign(N, std::vector<bool>(K,
false));
2677 std::vector<std::vector<bool>> seed(N, std::vector<bool>(K,
false));
2678 for (std::size_t i = 0; i <
stations.size(); ++i) {
2679 if (
stations[i].nodetype != NodeType::Source)
continue;
2681 if (ind == 0 || ind > N)
continue;
2682 for (std::size_t r = 0; r < K; ++r)
2683 if (
procid(i + 1, r + 1) != ProcessType::DISABLED) seed[ind - 1][r] =
true;
2685 for (std::size_t r = 0; r < K && r <
classes.size(); ++r) {
2686 const double pop =
classes[r].population;
2687 if (!std::isfinite(pop) || pop <= 0.0)
continue;
2689 if (ind == 0 || ind > N)
continue;
2690 seed[ind - 1][r] =
true;
2692 std::vector<std::pair<std::size_t, std::size_t>> stack;
2693 for (std::size_t i = 0; i < N; ++i)
2694 for (std::size_t r = 0; r < K; ++r)
2696 reached[i][r] =
true;
2697 stack.push_back(std::make_pair(i, r));
2699 while (!stack.empty()) {
2700 const std::size_t i = stack.back().first;
2701 const std::size_t r = stack.back().second;
2704 if (nt == NodeType::Sink)
continue;
2705 if (nt == NodeType::Source && !seed[i][r])
continue;
2707 const std::size_t row = i * K + r;
2708 for (std::size_t col = 0; col < N * K; ++col) {
2712 const std::size_t j = col / K, sIdx = col % K;
2713 if (!reached[j][sIdx]) {
2714 reached[j][sIdx] =
true;
2715 stack.push_back(std::make_pair(j, sIdx));
2763 for (std::size_t i = 0; i <
nstations; ++i) {
2765 if (nt != NodeType::Queue && nt != NodeType::Delay)
continue;
2766 for (std::size_t r = 0; r <
classes.size() && r <
issignal.size(); ++r)
2767 if (
issignal[r] &&
procid(i + 1, r + 1) == ProcessType::DISABLED)
2777 for (std::size_t ind = 0; ind <
nodes.size(); ++ind) {
2779 if (nt == NodeType::Cache || nt == NodeType::Place ||
2780 nt == NodeType::Transition || nt == NodeType::Fork ||
2781 nt == NodeType::Join)
2786 if (reached.empty())
return;
2787 for (std::size_t i = 0; i <
nstations; ++i) {
2789 if (nt != NodeType::Queue && nt != NodeType::Delay)
continue;
2793 if (!
stations[i].server_types.empty())
continue;
2795 if (ind == 0)
continue;
2796 for (std::size_t r = 0; r < K; ++r) {
2797 if (
procid(i + 1, r + 1) != ProcessType::DISABLED)
continue;
2803 if (ind - 1 >= reached.size() || r >= reached[ind - 1].size())
continue;
2804 if (!reached[ind - 1][r])
continue;
2805 const std::string kind = (nt == NodeType::Delay) ?
"Delay" :
"Queue";
2807 "' has no service configured for job class '" +
2809 "', but the class is routed to it. Jobs would arrive and "
2810 "never leave. Configure a service for that class, or route "
2827 immfeed.assign(M, std::vector<bool>(R,
false));
2828 for (std::size_t i = 0; i < M; ++i)
2829 for (std::size_t r = 0; r < R; ++r) {
2830 const bool station_has =
2848 if (ind == 0 || ind >
nodes.size() ||
nodes[ind - 1].stateful)
return;
2849 nodes[ind - 1].stateful =
true;
2868 for (std::size_t ind = 1; ind <=
nodes.size(); ++ind) {
2872 for (std::size_t r = 0; r < nd.
routing.size(); ++r)
2873 if (nd.
routing[r] == RoutingStrategy::RROBIN ||
2874 nd.
routing[r] == RoutingStrategy::WRROBIN ||
2875 nd.
routing[r] == RoutingStrategy::JSQ || nd.
routing[r] == RoutingStrategy::SQ)
2892 const std::size_t R =
classes.size();
2897 nvars.assign(
nodes.size(), std::vector<std::size_t>(3 * R + 1, 0));
2898 for (std::size_t ind = 1; ind <=
nodes.size(); ++ind) {
2899 const std::size_t ist =
nodes[ind - 1].station;
2903 for (std::size_t r = 1; r <= R; ++r) {
2905 if (pt == ProcessType::MAP || pt == ProcessType::MMPP2)
2906 nvars[ind - 1][r - 1] += 1;
2910 const std::vector<RoutingStrategy>& rt_i =
nodes[ind - 1].routing;
2911 for (std::size_t r = 1; r <= R && r <= rt_i.size(); ++r)
2912 if (rt_i[r - 1] == RoutingStrategy::RROBIN ||
2913 rt_i[r - 1] == RoutingStrategy::WRROBIN)
2914 nvars[ind - 1][R + r - 1] += 1;
2923 if (ist != 0 &&
stations[ist - 1].sched == SchedStrategy::POLLING) {
2933 if (ist != 0 &&
stations[ist - 1].sched == SchedStrategy::RR) {
2936 nvars[ind - 1][2 * R] = w;
2939 for (std::size_t r = 1; r <= R; ++r)
2942 nvars[ind - 1][2 * R + r] = 1;
2951 if (
stations[ist - 1].sched == SchedStrategy::POLLING)
2953 "Server breakdowns are not supported at a polling station (" +
2954 nodes[ind - 1].name +
2955 "): the polling controller and the breakdown status share one "
2956 "local-state column.");
2957 if (
stations[ist - 1].sched == SchedStrategy::RR)
2959 "Server breakdowns are not supported at a round-robin station (" +
2960 nodes[ind - 1].name +
2961 "): the quantum phases of the jobs in service and the breakdown status "
2962 "share one local-state column.");
2963 for (std::size_t r = 1; r <= R; ++r)
2967 "Server breakdowns are not supported at station '" +
2968 nodes[ind - 1].name +
2969 "', which also holds servers for a synchronous reply: the reply "
2970 "counters would trail the breakdown status the service handlers read");
2971 nvars[ind - 1][2 * R] = 1;
2973 const typename std::map<std::size_t, CacheParam<T>>::const_iterator ci =
2980 for (std::size_t u = 0; u < ci->second.itemcap.size(); ++u)
2981 if (ci->second.itemcap[u] > 0)
2982 w +=
static_cast<std::size_t
>(ci->second.itemcap[u]);
2983 if (ci->second.retrieval_capacity > 0) {
2984 w += ci->second.nitems;
2985 std::vector<std::size_t> rcl, rci, rco;
2989 nvars[ind - 1][2 * R] = w;
3011 const std::size_t R =
classes.size(), N =
nodes.size();
3013 for (std::size_t r = 0; r < R && r <
syncreply.size(); ++r)
3016 replyblock.assign(N, std::vector<bool>(R,
false));
3017 for (std::size_t r = 1; r <= R; ++r) {
3020 if (s < 1 || s > R)
continue;
3021 for (std::size_t ind = 1; ind <= N; ++ind) {
3022 const std::size_t ist =
nodes[ind - 1].station;
3024 if (
stations[ist - 1].sched == SchedStrategy::INF)
continue;
3025 bool arrives_here =
false;
3026 for (std::size_t i = 1; i <= N && !arrives_here; ++i)
3027 for (std::size_t q = 1; q <= R; ++q)
3030 rtnodes((i - 1) * R + q - 1, (ind - 1) * R + s - 1)) > 0) {
3031 arrives_here =
true;
3034 if (!arrives_here)
continue;
3035 if (
stations[ist - 1].sched != SchedStrategy::FCFS)
3037 "network '" +
name +
3038 "': synchronous calls (REPLY signals) are supported only at FCFS "
3041 "' uses another discipline. A held server is encoded as a per-class "
3042 "counter, which is exact only where servers are interchangeable (FCFS) "
3043 "or unlimited (INF); the other disciplines are not yet encoded rather than "
3044 "infeasible. Set this station to FCFS or INF, or simulate the layered model "
3045 "directly with SolverLDES.");
3066 const std::size_t R =
classes.size();
3067 const std::size_t N =
nodes.size();
3068 std::vector<std::size_t> out;
3070 std::vector<bool> seen(N + 1,
false);
3071 std::vector<std::size_t> frontier(1, ind);
3073 while (!frontier.empty()) {
3074 const std::size_t i = frontier.back();
3075 frontier.pop_back();
3076 for (std::size_t j = 1; j <= N; ++j) {
3077 if (seen[j])
continue;
3078 bool linked =
false;
3079 for (std::size_t r = 0; r < R && !linked; ++r)
3080 for (std::size_t s = 0; s < R && !linked; ++s)
3082 rtnodes((i - 1) * R + r, (j - 1) * R + s)) > 0)
3084 if (!linked)
continue;
3086 if (
nodes[j - 1].station != 0) {
3089 frontier.push_back(j);
3101 const std::size_t R =
classes.size();
3102 const std::size_t N =
nodes.size();
3106 for (std::size_t ind = 1; ind <= N; ++ind) {
3107 std::vector<std::vector<bool>> destmask;
3109 for (std::size_t j = 0; j < destmask.size(); ++j)
3110 for (std::size_t r = 0; r < R; ++r)
3112 const std::size_t ist =
nodes[ind - 1].station;
3118 "station '" +
nodes[ind - 1].name +
3119 "' combines server breakdowns with true-BAS blocking: the breakdown status "
3120 "and the BAS blocked marker share one local-state column. Remove the BAS drop "
3121 "rule or the breakdown");
3122 if (
stations[ist - 1].sched == SchedStrategy::POLLING)
3124 "true BAS blocking is not supported at the polling station '" +
3125 nodes[ind - 1].name +
3126 "': the polling controller and the BAS blocked marker share one local-state "
3127 "column. Use a non-polling discipline at the blocking station, or remove the "
3129 if (
stations[ist - 1].sched == SchedStrategy::RR)
3131 "True BAS blocking is not supported at a round-robin station (" +
3132 nodes[ind - 1].name +
3133 "): the quantum phases of the jobs in service and the BAS blocked marker "
3134 "share one local-state column.");
3135 for (std::size_t r = 1; r <= R; ++r)
3139 "true BAS blocking is not supported at station '" +
nodes[ind - 1].name +
3140 "', which also holds servers for a synchronous reply: fromMarginal appends "
3141 "the reply counters AFTER the blocked marker, so the marker would no "
3142 "longer be the trailing column the departure handler reads");
3154 bool bas_declares(std::size_t ind, std::vector<std::vector<bool>>& destmask)
const {
3155 const std::size_t R =
classes.size();
3156 destmask.assign(
stations.size(), std::vector<bool>(R,
false));
3157 if (
droprule.empty() || ind == 0 || ind >
nodes.size())
return false;
3158 const std::size_t ist =
nodes[ind - 1].station;
3159 if (ist == 0)
return false;
3161 if (nt == NodeType::Source || nt == NodeType::Cache)
return false;
3163 bool declares =
false;
3164 for (std::size_t r = 1; r <= R; ++r) {
3165 const bool here_bas =
droprule.size() >= ist &&
droprule[ist - 1].size() >= r &&
3166 droprule[ist - 1][r - 1] == DropStrategy::BAS;
3167 for (std::size_t d = 0; d < dests.size(); ++d) {
3168 const std::size_t jst =
nodes[dests[d] - 1].station;
3169 if (jst == 0 ||
nodes[dests[d] - 1].nodetype == NodeType::Source)
continue;
3180 const double dcap =
stations[jst - 1].cap;
3181 if (!std::isfinite(dcap) || !(dcap > 0))
continue;
3182 const bool there_bas =
3184 droprule[jst - 1][r - 1] == DropStrategy::BAS;
3185 if (!here_bas && !there_bas)
continue;
3190 destmask[jst - 1][r - 1] =
true;
3205 std::size_t
bas_code(std::size_t r, std::size_t jst, std::size_t s)
const {
3206 const std::size_t R =
classes.size();
3207 return 1 + (r - 1) + R * ((s - 1) + R * (jst - 1));
3210 void bas_decode(std::size_t code, std::size_t& r, std::size_t& jst, std::size_t& s)
const {
3211 const std::size_t R =
classes.size();
3212 std::size_t c = code - 1;
3225 std::vector<std::size_t> codes;
3226 std::vector<std::vector<bool>> destmask;
3228 const std::size_t R =
classes.size();
3230 if (isf == 0)
return codes;
3231 const std::vector<double> nj =
njobs();
3233 for (std::size_t r = 0; r < nj.size(); ++r) total += nj[r];
3234 for (std::size_t jst = 1; jst <=
stations.size(); ++jst) {
3236 if (jsf == 0)
continue;
3237 if (jst <=
cap.size() && std::isfinite(total) &&
cap[jst - 1] >= total)
continue;
3238 for (std::size_t s = 1; s <= R; ++s) {
3239 if (!destmask[jst - 1][s - 1])
continue;
3240 for (std::size_t r = 1; r <= R; ++r) {
3241 const std::size_t i = (isf - 1) * R + (r - 1), j = (jsf - 1) * R + (s - 1);
3243 codes.push_back(
bas_code(r, jst, s));
3247 std::sort(codes.begin(), codes.end());
3248 codes.erase(std::unique(codes.begin(), codes.end()), codes.end());
3252 static std::size_t
bas_ncols(
const std::vector<std::size_t>& codes) {
3253 return codes.empty() ? 1 : codes.size();
3257 if (ist == 0 || ist >
stations.size())
return false;
3258 if (
stations[ist - 1].sched == SchedStrategy::INF)
return false;
3259 return stations[ist - 1].nservers <= 1;
3278 for (std::size_t i = 0; i <
stations.size(); ++i) {
3280 if (st.
sched == SchedStrategy::DPS || st.
sched == SchedStrategy::GPS) {
3285 if (st.
sched == SchedStrategy::SEPT || st.
sched == SchedStrategy::LEPT) {
3287 std::vector<double> means;
3288 for (std::size_t r = 0; r <
classes.size(); ++r)
3290 std::vector<double> sorted = means;
3291 std::sort(sorted.begin(), sorted.end());
3292 sorted.erase(std::unique(sorted.begin(), sorted.end()), sorted.end());
3293 if (st.
sched == SchedStrategy::LEPT)
3294 std::reverse(sorted.begin(), sorted.end());
3296 for (std::size_t r = 0; r <
classes.size(); ++r)
3297 for (std::size_t k = 0; k < sorted.size(); ++k)
3298 if (sorted[k] == means[r])
3336 const std::size_t K =
classes.size(), I =
nodes.size();
3338 bool trivial =
true;
3341 if (rs != RoutingStrategy::PROB && rs != RoutingStrategy::DISABLED) trivial =
false;
3348 bool has_cs =
false;
3350 if (nd.nodetype == NodeType::ClassSwitch) has_cs =
true;
3353 const bool has_cache = !
nodeparam.empty();
3354 if (trivial && !has_cs && !has_cache)
return;
3356 for (
const auto& kv :
P)
Peff[kv.first] = kv.second;
3360 std::vector<char> conn(I * I, 0);
3361 for (
const auto& kv :
P) {
3363 if (M.
rows() < I || M.
cols() < I)
continue;
3364 for (std::size_t a = 0; a < I; ++a)
3365 for (std::size_t b = 0; b < I; ++b)
3366 if (M(a, b) > zero) conn[a * I + b] = 1;
3368 auto eff_at = [&](std::size_t r, std::size_t s) ->
Matrix<T>& {
3369 auto key = std::make_pair(r, s);
3370 auto it =
Peff.find(key);
3371 if (it ==
Peff.end())
3373 if (it->second.rows() != I) {
3375 for (std::size_t a = 0; a < it->second.rows(); ++a)
3376 for (std::size_t b = 0; b < it->second.cols(); ++b) g(a, b) = it->second(a, b);
3382 for (std::size_t i = 1; i <= I; ++i) {
3384 for (std::size_t r = 1; r <= K; ++r) {
3386 nd.
routing.size() >= r ? nd.
routing[r - 1] : RoutingStrategy::PROB;
3387 if (rs == RoutingStrategy::PROB || rs == RoutingStrategy::DISABLED)
continue;
3388 if (rs != RoutingStrategy::RAND && rs != RoutingStrategy::RROBIN &&
3389 rs != RoutingStrategy::JSQ && rs != RoutingStrategy::SQ &&
3390 rs != RoutingStrategy::WRROBIN && rs != RoutingStrategy::SDR)
3393 "' has no routing-matrix expansion in this port");
3409 const bool open_class = !std::isfinite(
3411 const bool from_source = nd.
nodetype == NodeType::Source;
3412 const bool from_sink = nd.
nodetype == NodeType::Sink;
3413 if (!open_class && (from_source || from_sink))
continue;
3414 std::vector<std::pair<std::size_t, std::size_t>> dest;
3415 for (std::size_t j = 1; j <= I; ++j) {
3416 if (!open_class &&
nodes[j - 1].nodetype == NodeType::Sink)
continue;
3417 if (conn[(i - 1) * I + (j - 1)]) dest.emplace_back(j, r);
3419 if (dest.empty())
continue;
3424 std::vector<T> share(dest.size(),
3427 if (rs == RoutingStrategy::WRROBIN) {
3428 const std::map<std::size_t, double>* w =
3431 std::vector<double> raw(dest.size(), 0.0);
3433 for (std::size_t d = 0; d < dest.size(); ++d) {
3434 const std::map<std::size_t, double>::const_iterator it =
3435 w->find(dest[d].first);
3436 raw[d] = (it == w->end()) ? 0.0 : it->second;
3440 for (std::size_t d = 0; d < dest.size(); ++d)
3445 for (std::size_t s = 1; s <= K; ++s) {
3446 if (
Peff.find(std::make_pair(r, s)) ==
Peff.end())
continue;
3448 for (std::size_t j = 1; j <= I; ++j) B(i - 1, j - 1) = zero;
3450 for (std::size_t d = 0; d < dest.size(); ++d)
3451 eff_at(r, dest[d].second)(i - 1, dest[d].first - 1) = share[d];
3457 const std::size_t cs = kv.first;
3459 if (C.
rows() != K || C.
cols() != K)
3460 throw InputError(
"network: the class-switch matrix of node '" +
3461 nodes[cs - 1].
name +
"' is not (nclasses x nclasses)");
3476 std::vector<std::vector<T>> diag(K, std::vector<T>(I, zero));
3477 for (std::size_t s = 1; s <= K; ++s) {
3478 if (!
Peff.empty() &&
Peff.find(std::make_pair(s, s)) ==
Peff.end())
continue;
3479 for (std::size_t j = 1; j <= I; ++j)
3480 diag[s - 1][j - 1] =
3481 Peff.empty() ?
get_route(s, s, cs, j) : eff_at(s, s)(cs - 1, j - 1);
3484 for (std::size_t r = 1; r <= K; ++r)
3485 for (std::size_t s = 1; s <= K; ++s) {
3486 if (
Peff.find(std::make_pair(r, s)) ==
Peff.end())
continue;
3488 for (std::size_t j = 1; j <= I; ++j) B(cs - 1, j - 1) = zero;
3490 for (std::size_t r = 1; r <= K; ++r)
3491 for (std::size_t s = 1; s <= K; ++s) {
3492 if (!(C(r - 1, s - 1) > zero))
continue;
3494 for (std::size_t j = 1; j <= I; ++j)
3495 if (diag[s - 1][j - 1] > zero)
3496 B(cs - 1, j - 1) = T(diag[s - 1][j - 1] * C(r - 1, s - 1));
3510 const std::size_t ci = kv.first;
3512 for (std::size_t r = 0; r < cp.
hitclass.size() && r < K; ++r) {
3515 for (std::size_t s = 1; s <= K; ++s) {
3517 for (std::size_t j = 1; j <= I; ++j) B(ci - 1, j - 1) = zero;
3519 eff_at(r + 1, cp.
hitclass[r])(ci - 1, ci - 1) = half;
3521 eff_at(r + 1, cp.
missclass[r])(ci - 1, ci - 1) = half;
3538 const std::size_t I =
nodes.size();
3539 if (joinNode == 0 || joinNode > I)
return 0;
3540 std::size_t forkNode = 0;
3541 for (std::size_t a = 0; a <
fj.size(); ++a)
3542 if (
fj[a].second == joinNode) {
3543 forkNode =
fj[a].first;
3547 std::vector<bool> seen(I + 1,
false);
3548 std::size_t deg = 0;
3549 for (
typename std::map<std::pair<std::size_t, std::size_t>,
Matrix<T> >::const_iterator
3551 it !=
P.end(); ++it) {
3552 if (it->second.rows() < I || it->second.cols() < I)
continue;
3553 for (std::size_t b = 1; b <= I; ++b) {
3554 if (seen[b])
continue;
3555 const T v = (forkNode != 0) ? it->second(forkNode - 1, b - 1)
3556 : it->second(b - 1, joinNode - 1);
3563 if (forkNode == 0 || forkNode > I)
return deg;
3577 const std::size_t lo = (r != 0 && r <= fol.
cols()) ? r - 1 : 0;
3578 const std::size_t hi = (r != 0 && r <= fol.
cols()) ? r - 1 : fol.
cols() - 1;
3580 for (std::size_t c = lo; c <= hi && c < fol.
cols(); ++c) {
3582 for (std::size_t d = 0; d < fol.
rows(); ++d) {
3584 if (!(link > 0.0))
continue;
3588 if (acc > best) best = acc;
3590 if (best > 0.0)
return static_cast<std::size_t
>(best + 0.5);
3593 double w =
nodes[forkNode - 1].tasks_per_link;
3594 if (!(w >= 1.0)) w = 1.0;
3595 return deg *
static_cast<std::size_t
>(w + 0.5);
3606 std::vector<std::size_t> out;
3607 for (
typename std::map<std::size_t, JoinDecl>::const_iterator it =
joindecl.begin();
3610 if (it->second.quorum <= 0.0)
continue;
3612 const std::size_t k =
static_cast<std::size_t
>(it->second.quorum + 0.5);
3613 if (n == 0 || k < n) out.push_back(it->first);
3648 const double inf = std::numeric_limits<double>::infinity();
3650 classcap.assign(M, std::vector<double>(K, inf));
3651 droprule.assign(M, std::vector<DropStrategy>(K, DropStrategy::WAITQ));
3652 std::vector<std::vector<double>> chaincap(M, std::vector<double>(std::max(
nchains, K), inf));
3660 std::vector<char> quorum_class(K + 1, 0);
3664 for (std::size_t x = 0; x < qj.size(); ++x)
3665 for (
typename std::map<std::pair<std::size_t, std::size_t>,
3667 it !=
P.end(); ++it) {
3668 if (it->second.rows() <
nodes.size() || qj[x] >
nodes.size())
continue;
3669 for (std::size_t a = 1; a <=
nodes.size(); ++a)
3670 if (it->second(a - 1, qj[x] - 1) > zero) {
3671 if (it->first.first <= K) quorum_class[it->first.first] = 1;
3672 if (it->first.second <= K) quorum_class[it->first.second] = 1;
3684 double fork_task_factor = 1.0;
3685 for (std::size_t i = 0; i <
nodes.size(); ++i) {
3686 if (
nodes[i].nodetype != NodeType::Fork)
continue;
3687 const double w =
nodes[i].tasks_per_link;
3688 if (w >= 1.0 && std::isfinite(w)) fork_task_factor *= std::floor(w + 0.5);
3691 for (std::size_t c = 0; c <
nchains; ++c) {
3692 double chain_cap = 0.0;
3694 bool quorum =
false;
3695 for (std::size_t r :
inchain[c]) {
3696 if (std::isinf(
classes[r - 1].population)) open =
true;
3697 else chain_cap +=
classes[r - 1].population;
3698 if (r <= K && quorum_class[r]) quorum =
true;
3702 bool spawn_fed =
false;
3703 for (std::size_t q = 0; q < K && !spawn_fed; ++q)
3704 for (std::size_t r :
inchain[c])
3705 if (
classes[q].spawn == r) spawn_fed =
true;
3706 chain_cap *= fork_task_factor;
3707 if (open || quorum || spawn_fed) chain_cap = inf;
3708 for (std::size_t r :
inchain[c])
3709 for (std::size_t i = 0; i < M; ++i) {
3712 if (st.
nodetype != NodeType::Source) {
3713 const bool cap_finite = st.
cap >= 0.0 && !std::isinf(st.
cap);
3714 const bool classcap_finite = st.
classcap.size() >= r &&
3718 st.
droprule[r - 1] ==
static_cast<int>(DropStrategy::WAITQ) &&
3719 std::isinf(
classes[r - 1].population) &&
3720 (cap_finite || classcap_finite))
3722 "station '" + st.
name +
"' declares setDropRule(WAITQ) for the "
3723 "open class '" +
classes[r - 1].name +
"' at a finite capacity: "
3724 "LINE does not implement waiting-room blocking for an open "
3725 "arrival at a plain finite buffer. Use DropStrategy.DROP for a "
3726 "loss station, or BAS / BBS / RSRD for blocking between "
3730 }
else if (std::isinf(st.
cap)) {
3731 droprule[i][r - 1] = DropStrategy::WAITQ;
3732 }
else if (!std::isinf(
classes[r - 1].population)) {
3733 droprule[i][r - 1] = DropStrategy::WAITQ;
3735 droprule[i][r - 1] = DropStrategy::DROP;
3741 chaincap[i][c] = 0.0;
3744 chaincap[i][c] = chain_cap;
3751 for (std::size_t i = 0; i < M; ++i) {
3756 double sc = 0.0, scl = 0.0;
3757 for (std::size_t c = 0; c < chaincap[i].size(); ++c) sc += chaincap[i][c];
3758 for (std::size_t r = 0; r < K; ++r) scl +=
classcap[i][r];
3759 cap[i] = std::min(sc, scl);
3773 const std::size_t K =
classes.size(), I =
nodes.size();
3774 std::vector<std::size_t> all(K);
3775 for (std::size_t r = 0; r < K; ++r) all[r] = r + 1;
3779 for (std::size_t a = 0; a < I; ++a)
3780 for (std::size_t b = 0; b < I; ++b)
rtnodes(a * K + r - 1, b * K + s - 1) = M(a, b);
3797 const std::size_t K =
classes.size();
3798 std::size_t cidx = 0;
3800 const std::size_t ci = kv.first;
3802 for (std::size_t r = 0; r < cp.
hitclass.size() && r < K; ++r) {
3814 for (std::size_t c = 0; c <
nchains; ++c) {
3832 for (std::size_t i = 0; i <
nstations; ++i)
3833 for (std::size_t r = 0; r <
nclasses; ++r) {
3835 if (
stations[i].nodetype == NodeType::Join) {
3838 std::numeric_limits<double>::infinity());
3850 const std::size_t mk =
markidx_of(i + 1, r + 1);
3851 if (mk > 0 && mk <= d.
Dmark.size()) {
3856 scv(i, r) = ms.second;
3882 for (std::size_t a = 0; a < m.
D0.rows(); ++a)
3883 for (std::size_t b = 0; b < m.
D0.cols(); ++b)
3884 m.
D0(a, b) += T(d.
D1(a, b) - m.
D1(a, b));
3904 std::vector<std::vector<bool>> cs(K, std::vector<bool>(K,
false));
3905 for (std::size_t r = 0; r < K; ++r) cs[r][r] =
true;
3906 for (
const auto& kv : (
Peff.empty() ?
P :
Peff)) {
3908 for (std::size_t a = 0; a < kv.second.rows() && !any; ++a)
3909 for (std::size_t b = 0; b < kv.second.cols() && !any; ++b)
3910 if (kv.second(a, b) > zero) any =
true;
3911 if (any) cs[kv.first.first - 1][kv.first.second - 1] =
true;
3921 for (std::size_t r = 0; r < K && r < C.
rows(); ++r)
3922 for (std::size_t s = 0; s < K && s < C.
cols(); ++s)
3923 if (C(r, s) > zero) cs[r][s] =
true;
3931 for (std::size_t r = 0; r < cp.
hitclass.size() && r < K; ++r) {
3945 for (std::size_t r = 0; r < row.size() && r < K; ++r)
3946 if (row[r] != 0) cs[r][row[r] - 1] =
true;
3949 std::vector<std::size_t> comp(K, K);
3950 std::size_t ncomp = 0;
3951 for (std::size_t r = 0; r < K; ++r) {
3952 if (comp[r] != K)
continue;
3953 std::vector<std::size_t> stack{r};
3955 while (!stack.empty()) {
3956 const std::size_t v = stack.back();
3958 for (std::size_t w = 0; w < K; ++w)
3959 if (comp[w] == K && (cs[v][w] || cs[w][v])) {
3971 for (std::size_t r = 0; r < K; ++r) {
3972 chains[comp[r]][r] =
true;
3973 inchain[comp[r]].push_back(r + 1);
3978 for (std::size_t c = 0; c <
nchains; ++c)
3979 for (std::size_t k :
inchain[c])
3982 for (std::size_t c = 0; c <
nchains; ++c) {
3984 for (std::size_t k :
inchain[c])
3985 if (
classes[k - 1].refstat != rs)
3986 throw InputError(
"network '" +
name +
"': classes within a chain have different "
3987 "reference stations");
3996 for (std::size_t c = 0; c <
nchains; ++c) {
4031 for (
auto& kv :
P) {
4032 if (kv.second.rows() <
nodes.size())
continue;
4033 kv.second(
sinkNode - 1, src - 1) = zero;
4035 for (
auto& kv :
Peff) {
4036 if (kv.second.rows() <
nodes.size())
continue;
4037 kv.second(
sinkNode - 1, src - 1) = zero;
4039 for (std::size_t c = 0; c <
nchains; ++c) {
4041 for (std::size_t k :
inchain[c])
4042 if (std::isinf(
classes[k - 1].population)) open =
true;
4043 if (!open)
continue;
4045 for (std::size_t k :
inchain[c])
4049 for (std::size_t s :
inchain[c]) {
4056 if (!(p > zero))
continue;
4064 std::vector<std::size_t> v(
nodes.size());
4065 for (std::size_t i = 0; i <
nodes.size(); ++i) v[i] = i + 1;
4087 std::vector<std::size_t>
chain_seeds(std::size_t c,
const std::vector<std::size_t>& sel)
const {
4088 const std::vector<std::size_t>& ic =
inchain[c];
4089 const std::size_t refst =
classes[ic[0] - 1].refstat;
4091 std::vector<std::size_t> seeds;
4092 std::size_t refpos = sel.size();
4093 for (std::size_t a = 0; a < sel.size(); ++a)
4094 if (sel[a] == refnode) refpos = a;
4095 if (refpos == sel.size())
return seeds;
4096 for (std::size_t x = 0; x < ic.size(); ++x) {
4102 const bool dis = refst - 1 <
disabled.size() && ic[x] - 1 <
disabled[refst - 1].size() &&
4106 held = !dis && std::isfinite(rate) && rate > 0;
4108 if (held) seeds.push_back(refpos * ic.size() + x);
4119 const std::vector<std::size_t>& sel)
const {
4120 std::vector<std::pair<std::size_t, std::size_t>> edges;
4121 const std::size_t nIC = ic.size();
4123 const std::vector<std::vector<std::size_t>>& rc = kv.second.retrieval_classes;
4124 if (rc.empty())
continue;
4125 std::size_t pos = sel.size();
4126 for (std::size_t a = 0; a < sel.size(); ++a)
4127 if (sel[a] == kv.first) pos = a;
4128 if (pos == sel.size())
continue;
4129 for (std::size_t x = 0; x < nIC; ++x)
4130 for (
const std::vector<std::size_t>& row : rc) {
4131 if (ic[x] - 1 >= row.size() || row[ic[x] - 1] == 0)
continue;
4132 for (std::size_t y = 0; y < nIC; ++y)
4133 if (ic[y] == row[ic[x] - 1]) edges.emplace_back(pos * nIC + x, pos * nIC + y);
4143 const std::vector<std::pair<std::size_t, std::size_t>>& edges) {
4144 const std::size_t n =
P.rows();
4145 if (seeds.empty())
return std::vector<bool>(n,
true);
4146 std::vector<std::vector<std::size_t>> extra(n);
4147 for (
const std::pair<std::size_t, std::size_t>& e : edges)
4148 if (e.first < n && e.second < n) extra[e.first].push_back(e.second);
4149 std::vector<bool> reach(n,
false);
4150 std::vector<std::size_t> frontier;
4151 for (std::size_t sd : seeds)
4152 if (sd < n && !reach[sd]) {
4154 frontier.push_back(sd);
4156 while (!frontier.empty()) {
4157 std::vector<std::size_t> nxt;
4158 for (std::size_t row : frontier) {
4159 for (std::size_t col = 0; col < n; ++col) {
4161 if (!reach[col] && v != 0.0) {
4166 for (std::size_t col : extra[row])
4180 const std::vector<std::size_t>& ic =
inchain[c];
4181 const std::size_t nIC = ic.size();
4182 const std::size_t dim = sel.size() * nIC;
4189 std::vector<std::size_t> cpos(
nclasses + 1, nIC);
4190 for (std::size_t x = 0; x < nIC; ++x) cpos[ic[x]] = x;
4193 const std::size_t x = cpos[r], y = cpos[s];
4194 if (x == nIC || y == nIC)
return;
4195 for (std::size_t a = 0; a < sel.size(); ++a)
4196 for (std::size_t b = 0; b < sel.size(); ++b)
4197 Pc(a * nIC + x, b * nIC + y) = M(sel[a] - 1, sel[b] - 1);
4223 std::vector<bool> served(dim,
true);
4225 for (std::size_t a = 0; a < sel.size(); ++a) {
4226 const std::size_t sti =
nodes[sel[a] - 1].station;
4227 if (sti == 0 || sti >
stations.size())
continue;
4229 if (nt == NodeType::Place || nt == NodeType::Transition)
continue;
4230 if (!
stations[sti - 1].server_types.empty())
continue;
4231 if (sti >
disabled.size())
continue;
4238 for (std::size_t x = 0; x < nIC; ++x)
4240 served[a * nIC + x] =
false;
4242 for (std::size_t row = 0; row < dim; ++row)
4244 for (std::size_t col = 0; col < dim; ++col) Pc(row, col) = zero;
4245 for (std::size_t col = 0; col < dim; ++col)
4247 for (std::size_t row = 0; row < dim; ++row) Pc(row, col) = zero;
4253 std::vector<std::size_t> visited;
4254 std::vector<T> rowsum(dim, zero);
4255 for (std::size_t row = 0; row < dim; ++row) {
4257 for (std::size_t col = 0; col < dim; ++col) s += Pc(row, col);
4259 if (s > zero && reach[row]) visited.push_back(row);
4261 bool oversum =
false;
4263 for (std::size_t row = 0; row < dim; ++row) {
4267 for (std::size_t col = 0; col < dim; ++col)
4268 Pc(row, col) = T(Pc(row, col) / rowsum[row]);
4298 bool reducible =
false;
4299 if (!fork && !visited.empty()) {
4300 Matrix<T> Pv0(visited.size(), visited.size(), zero);
4301 for (std::size_t a = 0; a < visited.size(); ++a)
4302 for (std::size_t b = 0; b < visited.size(); ++b) Pv0(a, b) = Pc(visited[a], visited[b]);
4304 std::size_t nrec = 0;
4307 reducible = (nrec > 1) && mc::detail::weak_components(Pv0).size() == 1;
4316 std::vector<std::size_t> nconn(sel.size(), 0);
4317 std::vector<std::vector<bool>> conn(sel.size(), std::vector<bool>(sel.size(),
false));
4318 for (std::size_t a = 0; a < sel.size(); ++a)
4319 for (std::size_t b = 0; b < sel.size(); ++b) {
4321 for (std::size_t x = 0; x < nIC && !cbit; ++x)
4322 for (std::size_t y = 0; y < nIC && !cbit; ++y)
4323 if (Pc(a * nIC + x, b * nIC + y) > zero) cbit =
true;
4325 if (cbit) ++nconn[a];
4327 for (std::size_t a = 0; a < sel.size(); ++a) {
4328 if (nconn[a] == 0)
continue;
4329 for (std::size_t x = 0; x < nIC; ++x) {
4331 for (std::size_t col = 0; col < dim; ++col) outsum += Pc(a * nIC + x, col);
4332 if (outsum > zero)
continue;
4335 for (std::size_t b = 0; b < sel.size(); ++b)
4336 if (conn[a][b]) Pc(a * nIC + x, b * nIC + x) = p;
4348 for (std::size_t row = 0; row < dim; ++row)
4350 for (std::size_t col = 0; col < dim; ++col) Pc(row, col) = zero;
4351 for (std::size_t col = 0; col < dim; ++col)
4353 for (std::size_t row = 0; row < dim; ++row) Pc(row, col) = zero;
4355 for (std::size_t row = 0; row < dim; ++row) {
4357 for (std::size_t col = 0; col < dim; ++col) s += Pc(row, col);
4358 if (s > zero && reach[row]) visited.push_back(row);
4362 std::vector<T> alpha(dim, zero);
4363 if (!visited.empty()) {
4364 Matrix<T> Pv(visited.size(), visited.size(), zero);
4365 for (std::size_t a = 0; a < visited.size(); ++a)
4366 for (std::size_t b = 0; b < visited.size(); ++b)
4367 Pv(a, b) = Pc(visited[a], visited[b]);
4374 bool allzero =
true, hasnan =
false;
4375 for (
const T& x : av) {
4376 if (x != zero) allzero =
false;
4379 if (allzero || hasnan) ok =
false;
4380 }
catch (
const Error&) {
4388 for (std::size_t a = 0; a < visited.size(); ++a) alpha[visited[a]] = av[a];
4408 for (std::size_t a = 0; a < visited.size(); ++a)
4409 if (!scc.
recurrent[scc.
scc[a] - 1]) alpha[visited[a]] = zero;
4413 if (fork && oversum) {
4414 for (std::size_t idx = 0; idx < dim; ++idx) {
4416 const std::size_t nd = sel[idx / nIC];
4417 if (!complement &&
nodes[nd - 1].nodetype == NodeType::Join) {
4424 const std::size_t r = ic[idx % nIC];
4425 std::size_t nsrc = 0;
4426 for (std::size_t src = 1; src <=
nodes.size(); ++src)
4427 for (std::size_t q = 1; q <=
nclasses; ++q)
4439 for (std::size_t a = 0; a < sel.size(); ++a)
4440 for (std::size_t x = 0; x < nIC; ++x) out(a, ic[x] - 1) = alpha[a * nIC + x];
4443 const std::size_t rstat =
classes[ic[0] - 1].refstat;
4445 std::size_t refrow = sel.size();
4446 for (std::size_t a = 0; a < sel.size(); ++a)
4447 if (sel[a] == refnode) refrow = a;
4448 if (refrow < sel.size()) {
4450 for (std::size_t x = 0; x < nIC; ++x) norm += out(refrow, ic[x] - 1);
4452 for (std::size_t a = 0; a < sel.size(); ++a)
4453 for (std::size_t x = 0; x < nIC; ++x)
4454 out(a, ic[x] - 1) = T(out(a, ic[x] - 1) / norm);
4456 for (std::size_t a = 0; a < sel.size(); ++a)
4457 for (std::size_t x = 0; x < nIC; ++x)
4458 if (out(a, ic[x] - 1) < zero) out(a, ic[x] - 1) = T(-out(a, ic[x] - 1));
4472 const std::vector<std::size_t>& ic, std::size_t refnode)
const {
4474 const std::size_t nIC = ic.size();
4475 const std::size_t dim = Pc_in.
rows();
4478 for (std::size_t row = 0; row < dim; ++row) {
4480 std::size_t nnan = 0;
4481 for (std::size_t col = 0; col < dim; ++col) {
4484 else nonnan = T(nonnan + Pc(row, col));
4486 if (nnan == 0)
continue;
4489 for (std::size_t col = 0; col < dim; ++col) {
4491 if (v != v) Pc(row, col) = fill;
4504 std::vector<bool> served(dim,
true);
4505 for (std::size_t a = 0; a < sel.size(); ++a) {
4506 const std::size_t sti =
nodes[sel[a] - 1].station;
4507 if (sti == 0 || sti >
stations.size())
continue;
4509 if (nt == NodeType::Place || nt == NodeType::Transition)
continue;
4510 if (!
stations[sti - 1].server_types.empty())
continue;
4511 if (sti >
disabled.size())
continue;
4512 for (std::size_t x = 0; x < nIC; ++x)
4514 served[a * nIC + x] =
false;
4516 for (std::size_t row = 0; row < dim; ++row)
4518 for (std::size_t col = 0; col < dim; ++col) Pc(row, col) = zero;
4519 for (std::size_t col = 0; col < dim; ++col)
4521 for (std::size_t row = 0; row < dim; ++row) Pc(row, col) = zero;
4524 for (std::size_t c = 0; c <
nchains; ++c)
4525 if (
inchain[c] == ic) chain = c;
4526 const std::vector<bool> reach =
4529 std::vector<std::size_t> visited;
4530 for (std::size_t row = 0; row < dim; ++row) {
4532 for (std::size_t col = 0; col < dim; ++col) s += Pc(row, col);
4533 if (s > zero && reach[row]) visited.push_back(row);
4535 std::vector<T> alpha(dim, zero);
4536 if (!visited.empty()) {
4537 Matrix<T> Pv(visited.size(), visited.size(), zero);
4538 for (std::size_t a = 0; a < visited.size(); ++a)
4539 for (std::size_t b = 0; b < visited.size(); ++b) Pv(a, b) = Pc(visited[a], visited[b]);
4545 bool allzero =
true, hasnan =
false;
4546 for (
const T& x : av) {
4547 if (x != zero) allzero =
false;
4550 if (allzero || hasnan) ok =
false;
4551 }
catch (
const Error&) {
4555 for (std::size_t a = 0; a < visited.size(); ++a) alpha[visited[a]] = av[a];
4558 for (std::size_t a = 0; a < sel.size(); ++a)
4559 for (std::size_t x = 0; x < nIC; ++x) out(a, ic[x] - 1) = alpha[a * nIC + x];
4560 std::size_t refrow = sel.size();
4561 for (std::size_t a = 0; a < sel.size(); ++a)
4562 if (sel[a] == refnode) refrow = a;
4563 if (refrow < sel.size()) {
4565 for (std::size_t x = 0; x < nIC; ++x) norm += out(refrow, ic[x] - 1);
4567 for (std::size_t a = 0; a < sel.size(); ++a)
4568 for (std::size_t x = 0; x < nIC; ++x)
4569 out(a, ic[x] - 1) = T(out(a, ic[x] - 1) / norm);
4571 for (std::size_t a = 0; a < sel.size(); ++a)
4572 for (std::size_t x = 0; x < nIC; ++x)
4573 if (out(a, ic[x] - 1) < zero) out(a, ic[x] - 1) = T(-out(a, ic[x] - 1));
4589 if (nd.nodetype == NodeType::Fork)
4591 "route_eff visit path");
4592 std::vector<std::size_t> keep;
4593 keep.reserve(M * K);
4594 for (std::size_t p = 0; p < M; ++p) {
4596 for (std::size_t r = 0; r < K; ++r) keep.push_back(base + r);
4600 std::vector<std::size_t> allnodes(I);
4601 for (std::size_t a = 0; a < I; ++a) allnodes[a] = a + 1;
4604 for (std::size_t c = 0; c <
nchains; ++c) {
4605 const std::vector<std::size_t>& ic =
inchain[c];
4606 const std::size_t nIC = ic.size();
4609 for (std::size_t a = 0; a < M; ++a)
4610 for (std::size_t x = 0; x < nIC; ++x)
4611 for (std::size_t b = 0; b < M; ++b)
4612 for (std::size_t y = 0; y < nIC; ++y)
4613 Ps(a * nIC + x, b * nIC + y) =
rt(a * K + (ic[x] - 1), b * K + (ic[y] - 1));
4614 const std::size_t rstat =
classes[ic[0] - 1].refstat;
4621 for (std::size_t a = 0; a < I; ++a)
4622 for (std::size_t x = 0; x < nIC; ++x)
4623 for (std::size_t b = 0; b < I; ++b)
4624 for (std::size_t y = 0; y < nIC; ++y)
4625 Pn(a * nIC + x, b * nIC + y) =
4626 rtnodes(a * K + (ic[x] - 1), b * K + (ic[y] - 1));
4640 const std::size_t nIC = ic.size();
4641 const std::size_t I =
nodes.size();
4643 std::vector<std::size_t> pos(
classes.size() + 1, 0);
4644 for (std::size_t x = 0; x < nIC; ++x) pos[ic[x]] = x + 1;
4646 if (r >= pos.size() || s >= pos.size() || pos[r] == 0 || pos[s] == 0)
return;
4647 const std::size_t x = pos[r] - 1, y = pos[s] - 1;
4648 for (std::size_t a = 0; a < I; ++a)
4649 for (std::size_t b = 0; b < I; ++b) full(a * nIC + x, b * nIC + y) = M(a, b);
4660 const std::map<std::pair<std::size_t, std::size_t>,
Matrix<T>>& src =
Peff.empty() ?
P :
Peff;
4661 for (
const auto& kv : src)
4662 if (kv.second.rows() >=
nodes.size() && kv.second.cols() >=
nodes.size())
4663 f(kv.first.first, kv.first.second, kv.second);
4682 const std::size_t I =
nodes.size();
4683 std::vector<std::size_t> keep, drop;
4684 for (std::size_t a = 0; a < I; ++a) {
4685 const bool st =
nodes[a].stateful;
4686 for (std::size_t x = 0; x < nIC; ++x) (st ? keep : drop).push_back(a * nIC + x);
4688 if (drop.empty())
return full;
4693 std::vector<char> isdrop(full.
rows(), 0), seen(full.
rows(), 0);
4694 for (std::size_t d : drop) isdrop[d] = 1;
4695 std::vector<std::size_t> stack;
4696 for (std::size_t k : keep)
4697 for (std::size_t d : drop)
4698 if (!seen[d] && full(k, d) != zero) { seen[d] = 1; stack.push_back(d); }
4699 while (!stack.empty()) {
4700 const std::size_t u = stack.back();
4702 for (std::size_t d : drop)
4703 if (!seen[d] && full(u, d) != zero) { seen[d] = 1; stack.push_back(d); }
4705 std::vector<std::size_t> reach;
4706 for (std::size_t d : drop)
4707 if (seen[d]) reach.push_back(d);
4711 Matrix<T> S(keep.size(), keep.size(), zero);
4712 for (std::size_t a = 0; a < keep.size(); ++a)
4713 for (std::size_t b = 0; b < keep.size(); ++b) S(a, b) = full(keep[a], keep[b]);
4717 const std::size_t nk = keep.size(), nd = drop.size();
4718 Matrix<T> P11(nk, nk, zero), P12(nk, nd, zero), P21(nd, nk, zero), A(nd, nd, zero);
4719 for (std::size_t a = 0; a < nk; ++a) {
4720 for (std::size_t b = 0; b < nk; ++b) P11(a, b) = full(keep[a], keep[b]);
4721 for (std::size_t b = 0; b < nd; ++b) P12(a, b) = full(keep[a], drop[b]);
4723 for (std::size_t a = 0; a < nd; ++a) {
4724 for (std::size_t b = 0; b < nk; ++b) P21(a, b) = full(drop[a], keep[b]);
4725 for (std::size_t b = 0; b < nd; ++b)
4726 A(a, b) = T((a == b ? one : zero) - full(drop[a], drop[b]));
4730 std::vector<std::size_t> piv(nd);
4731 for (std::size_t i = 0; i < nd; ++i) piv[i] = i;
4732 for (std::size_t col = 0; col < nd; ++col) {
4733 std::size_t best = col;
4735 for (std::size_t r2 = col + 1; r2 < nd; ++r2) {
4737 if (v > bv) { bv = v; best = r2; }
4740 for (std::size_t b = 0; b < nd; ++b) std::swap(A(col, b), A(best, b));
4741 for (std::size_t b = 0; b < nk; ++b) std::swap(X(col, b), X(best, b));
4743 if (A(col, col) == zero)
4746 std::vector<std::size_t> nzA, nzX;
4747 for (std::size_t b = 0; b < nd; ++b)
4748 if (A(col, b) != zero) nzA.push_back(b);
4749 for (std::size_t b = 0; b < nk; ++b)
4750 if (X(col, b) != zero) nzX.push_back(b);
4751 for (std::size_t r2 = 0; r2 < nd; ++r2) {
4752 if (r2 == col)
continue;
4753 const T f = T(A(r2, col) / A(col, col));
4754 if (f == zero)
continue;
4755 for (std::size_t b : nzA) A(r2, b) = T(A(r2, b) - f * A(col, b));
4756 for (std::size_t b : nzX) X(r2, b) = T(X(r2, b) - f * X(col, b));
4759 for (std::size_t r2 = 0; r2 < nd; ++r2)
4760 for (std::size_t b = 0; b < nk; ++b) X(r2, b) = T(X(r2, b) / A(r2, r2));
4764 std::vector<T> acc(nk, zero);
4765 for (std::size_t a = 0; a < nk; ++a) {
4766 std::fill(acc.begin(), acc.end(), zero);
4767 for (std::size_t m = 0; m < nd; ++m) {
4768 const T w = P12(a, m);
4769 if (w == zero)
continue;
4770 for (std::size_t b = 0; b < nk; ++b) acc[b] += w * X(m, b);
4772 for (std::size_t b = 0; b < nk; ++b) S(a, b) = T(S(a, b) + acc[b]);
4781 if (std::isinf(c.population))
return true;
4793 if (!std::isinf(c.population))
return false;
4799 if (std::isfinite(s.nservers) && s.nservers > 1.0)
return true;
4805 if (std::isfinite(c.population) && c.population != std::floor(c.population + 0.5))
4814 if (c.prio > 0)
return true;
4827 if (
classes.empty())
return false;
4829 if (c.prio !=
classes.front().prio)
return true;
4845 case SchedStrategy::HOL:
4846 case SchedStrategy::PSPRIO:
4847 case SchedStrategy::DPSPRIO:
4848 case SchedStrategy::GPSPRIO:
4849 case SchedStrategy::LCFSPRIO:
4850 case SchedStrategy::LCFSPRPRIO:
4851 case SchedStrategy::LCFSPIPRIO:
4852 case SchedStrategy::FCFSPRPRIO:
4853 case SchedStrategy::FCFSPIPRIO:
4854 case SchedStrategy::SRPTPRIO:
4877 std::size_t count = 0;
4879 if (
stations[i].sched == strategy) ++count;
4885 for (std::size_t i = 0; i <
nstations; ++i) {
4886 if (
stations[i].sched != SchedStrategy::FCFS)
continue;
4889 for (std::size_t r = 0; r <
nclasses; ++r) {
4892 lo = hi =
rates(i, r);
4909 if (!(s.sched == SchedStrategy::INF || s.sched == SchedStrategy::PS ||
4910 s.sched == SchedStrategy::FCFS || s.sched == SchedStrategy::LCFSPR ||
4911 s.sched == SchedStrategy::LCFS || s.sched == SchedStrategy::EXT))
4923 for (std::size_t i = 0; i <
nstations; ++i) {
4924 if (
stations[i].sched != SchedStrategy::FCFS)
continue;
4925 for (std::size_t r = 0; r <
nclasses; ++r) {
4927 if (std::isinf(v) || !(v > 0.0))
continue;
4941 double k = std::numeric_limits<double>::infinity();
4942 if (
cap[ist - 1] >= 0.0) k = std::min(k,
cap[ist - 1]);
4944 bool anyServed =
false;
4945 for (std::size_t r = 0; r <
nclasses; ++r)
4950 if (anyServed) k = std::min(k, ccap);
4954 double reachable = 0.0;
4955 for (std::size_t r = 0; r <
nclasses; ++r)
4957 return (k >= reachable) ? std::numeric_limits<double>::infinity() : k;
4963 for (std::size_t k = 0; k <
classes.size(); ++k)
4964 if (std::isfinite(
classes[k].population))
return false;
4965 std::size_t nq = 0, nsrc = 0, nsink = 0, qnode = 0, snode = 0;
4966 for (std::size_t a = 0; a <
nodes.size(); ++a) {
4967 switch (
nodes[a].nodetype) {
4968 case NodeType::Queue: ++nq; qnode = a + 1;
break;
4969 case NodeType::Source: ++nsrc; snode = a + 1;
break;
4970 case NodeType::Sink: ++nsink;
break;
4971 default:
return false;
4974 if (nq != 1 || nsrc != 1 || nsink != 1)
return false;
4975 const std::size_t qist =
nodes[qnode - 1].station;
4976 const std::size_t sist =
nodes[snode - 1].station;
4977 if (qist == 0 || sist == 0)
return false;
4978 if (
stations[qist - 1].nservers != 1.0)
return false;
4980 droprule[qist - 1][0] != DropStrategy::DROP)
4982 if (!(qist <=
cap.size()) || !std::isfinite(
cap[qist - 1]) || !(
cap[qist - 1] > 0.0))
5004 if (!
regions.empty())
return true;
5005 for (std::size_t a = 0; a <
nodes.size(); ++a)
5006 if (
nodes[a].nodetype == NodeType::Cache)
return false;
5008 for (std::size_t ist = 1; ist <=
stations.size(); ++ist)
5017 if (rs == RoutingStrategy::RROBIN || rs == RoutingStrategy::WRROBIN ||
5018 rs == RoutingStrategy::JSQ || rs == RoutingStrategy::SQ || rs == RoutingStrategy::SDR)
5054 if (!(s.sched == SchedStrategy::INF || s.sched == SchedStrategy::PS ||
5055 s.sched == SchedStrategy::FCFS || s.sched == SchedStrategy::LCFSPR ||
5056 s.sched == SchedStrategy::EXT))
5059 for (std::size_t i = 0; i <
nstations; ++i) {
5060 if (
stations[i].sched != SchedStrategy::FCFS)
continue;
5061 for (std::size_t r = 0; r <
nclasses; ++r) {
5064 if (!std::isinf(v) && v > 0.0 &&
5068 if (!check_means ||
visits.empty())
continue;
5070 double stmin = 0.0, stmax = 0.0;
5071 bool anyserved =
false;
5072 for (std::size_t c = 0; c <
nchains && c <
visits.size(); ++c) {
5073 double num = 0.0, den = 0.0;
5074 for (std::size_t r = 0; r <
nclasses; ++r) {
5085 const double st = num / den;
5090 stmin = std::min(stmin, st);
5091 stmax = std::max(stmax, st);
5107 for (std::size_t a = 0; a < B.
rows(); ++a)
5108 for (std::size_t b = 0; b < B.
cols(); ++b) g(a, b) = B(a, b);
5116 if (std::isfinite(c.population)) s += c.population;
5139 const std::size_t R =
sn.nclasses;
5143 if (st.
sched != SchedStrategy::PAS)
return Matrix<T>(R, R, zero);
5145 for (std::size_t r = 0; r < R; ++r) g(r, r) = zero;
5154 for (std::size_t a = 0; a < g.
rows(); ++a)
5155 for (std::size_t b = 0; b < g.
cols(); ++b)
5156 if (g(a, b) != zero)
return false;
5179 if (qist) *qist = 0;
5181 if (std::isfinite(c.
population))
return false;
5182 if (
sn.nodes.size() != 3)
return false;
5183 std::size_t nq = 0, nsrc = 0, nsink = 0, qnode = 0, snode = 0;
5184 for (std::size_t a = 0; a <
sn.nodes.size(); ++a) {
5185 switch (
sn.nodes[a].nodetype) {
5186 case NodeType::Queue: ++nq; qnode = a + 1;
break;
5187 case NodeType::Source: ++nsrc; snode = a + 1;
break;
5188 case NodeType::Sink: ++nsink;
break;
5189 default:
return false;
5192 if (nq != 1 || nsrc != 1 || nsink != 1)
return false;
5193 const std::size_t q =
sn.nodes[qnode - 1].station;
5194 const std::size_t src =
sn.nodes[snode - 1].station;
5195 if (q == 0 || src == 0)
return false;
5197 if (st.
sched != SchedStrategy::OI && st.
sched != SchedStrategy::PAS)
return false;
5200 bool finite = q <=
sn.cap.size() && std::isfinite(
sn.cap[q - 1]);
5201 if (!finite && q <=
sn.classcap.size())
5202 for (
double cc :
sn.classcap[q - 1])
5203 if (std::isfinite(cc)) finite =
true;
5204 if (!finite)
return false;
5211 for (std::size_t r = 0; r <
sn.nclasses; ++r) {
5212 if (!(
sn.rates(src - 1, r) > zero))
continue;
5213 if (q <=
sn.droprule.size() && r <
sn.droprule[q - 1].size()) {
5215 if (d != DropStrategy::DROP && d != DropStrategy::WAITQ)
return false;
5217 std::size_t chain = 0;
5218 for (std::size_t c = 0; c <
sn.nchains; ++c)
5219 if (
sn.chains[c][r]) chain = c + 1;
5220 if (chain == 0 || chain >
sn.visits.size())
return false;
5225 if (!(vs > 0.0) || std::fabs(vq / vs - 1.0) > 1e-9)
5228 if (qist) *qist = q;
Base error for the multiprecision C++ port.
NumericError(const std::string &what)
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
void set_route(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
P{r,s}(i,j) = p, with 1-based NODE and class indices.
std::size_t sourceIdx
1-based station index of the Source, 0 = none
Matrix< double > phases() const
sn.phases (M x K), as refreshProcessRepresentations.m leaves it: 0 for a disabled pair,...
bool has_multi_class_heter_fcfs() const
bool has_distinct_priorities() const
Whether the classes carry more than one priority level.
std::size_t nvars_of(std::size_t ind) const
Total local-variable width of node ind (1-based).
pfqn::SdrStruct sdr_nodes
Node-indexed twin of sdr.
std::size_t add_class(const JobClass &cl)
Add a class and grow the service table.
T get_route(std::size_t r, std::size_t s, std::size_t i, std::size_t j) const
P{r,s}(i,j), AS THE USER SET IT.
std::vector< Matrix< T > > nodevisits
(nchains) each (nnodes x nclasses)
void refresh_rates()
Port of MNetwork.refreshRates: lower each service process onto a rate and an SCV.
std::vector< double > node_to_stateful() const
sn.nodeToStateful (1 x N): the stateful index of each node, NaN when it is not stateful.
bool has_fluid_places() const
sn_has_fluid_places: does the net hold a fluid place, or a transition declaring a fluid arc?
std::function< std::complex< double >(const std::complex< double > &)> LstHandle
One LST handle: E[exp(-sX)] at a complex argument.
std::vector< std::size_t > chain_seeds(std::size_t c, const std::vector< std::size_t > &sel) const
Port of the per-chain body of sn_refresh_visits, over an arbitrary node subset – the stateful nodes f...
Matrix< T > chain_visits(std::size_t c, const std::vector< std::size_t > &sel, bool complement, bool fork) const
std::size_t stateful_index(std::size_t ind) const
1-based stateful index of node ind, 0 when the node is not stateful.
void refresh_cacheqn_actual_visits(const Matrix< T > &hitprob, const Matrix< T > &missprob)
Re-resolve the cache read self-switch from the offered 1/2-1/2 to the ACTUAL hit/miss probabilities t...
std::vector< std::vector< std::vector< double > > > pie() const
sn.pie (M x K cells): the phase an arriving job enters, map_pie of sn.proc{i}{r} (the Erlang conversi...
bool has_immediate_feedback() const
Whether immediate feedback is EFFECTIVE anywhere in the model.
bool has_class_switching() const
std::vector< lang::RemovalPolicy > signalrempolicy
bool has_rtfun_routing() const
True when some routing must be re-read at every state from rt_state: SDR, and the JSQ and SQ(d) dispa...
std::vector< std::vector< bool > > immfeed
sn.immfeed: (nstations x nclasses) IMMEDIATE FEEDBACK, the reference's refreshStruct field.
const ForkParam< T > * fork_param_of(std::size_t node) const
The fork's override block, or null when it declares none.
std::size_t stateful_of_station(std::size_t st) const
std::vector< std::size_t > downstream_stations(std::size_t ind) const
The nodes directly downstream of ind, walking THROUGH stateless nodes and stopping at the first stati...
std::size_t nof_nodes() const
std::size_t polling_width(std::size_t ist) const
The controller width, pinfo.width: [pos, swk, ctr, src, tht, trt_1..R] with each column materialized ...
std::size_t nof_stateful() const
std::size_t polling_nlegs(const PollingParam &pp) const
Number of controller legs: the table length, else R.
bool has_rr_routing() const
Whether ANY (node, class) pair dispatches round-robin.
Matrix< double > phaseshift() const
sn.phaseshift (M x K+1) = [0, cumsum(phasessz, 2)].
std::map< std::pair< std::size_t, std::size_t >, Matrix< T > > P
P[(r,s)] is an (nnodes x nnodes) block; absent means all zero.
std::size_t phases_of(std::size_t ist, std::size_t r) const
sn.phases(i,r): the order of the process representation.
std::map< std::size_t, TransitionParam< T > > transparam
Transition (SPN) parameters, keyed by 1-based node index.
void check_closed_reneging() const
Refuses RENEGING declared for a class of finite population at any station (closed_reneging_refusal).
std::size_t mark_carrier_of(std::size_t ist) const
The CARRIER of station i's marked arrival: the class of mark 1, whose phase block holds the one modul...
std::vector< std::vector< bool > > replyblock
sn.replyblock (nnodes x nclasses) and sn.syncreply (nclasses).
std::vector< std::size_t > all_nodes() const
Every node index, 1-based, for the node-level visit computation.
bool bas_declares(std::size_t ind, std::vector< std::vector< bool > > &destmask) const
declaresBlockedMarker for node ind (1-based): true when it is the BLOCKING side of a true-BAS relatio...
std::vector< std::vector< bool > > isbasdestination
sn.isbasdestination, (nstations x nclasses): true where a refusal at this station must BLOCK an upstr...
bool is_mm1k_loss() const
Implementation of api::sn_is_mm1k_loss; that free function delegates here.
void for_each_route_block(F f) const
Visit every (r, s) block of the routing in force, the one route_eff reads: Peff when the expansion ra...
bool has_sdr_routing() const
MATLAB's any(sn.isstatedep(:,3)) NARROWED TO THE ONE STRATEGY THIS PORT EVALUATES PER STATE: Krzesins...
std::vector< Reward > reward
std::vector< std::size_t > stateful_nodes
1-based node indices, ascending
Matrix< double > phasessz() const
sn.phasessz (M x K) = max(phases, 1), with MATLAB's two exceptions: a Join keeps its 0 and a non-carr...
bool sched_has_priority_aware() const
Whether some station runs a discipline that READS the class priorities.
const lang::Distrib< T > * polling_leg(std::size_t ist, const PollingParam &pp, std::size_t l) const
The switchover law of leg l (1-based) of station ist's controller, as State.pollingInfo resolves it,...
std::vector< bool > iscatastrophe() const
sn.iscatastrophe (K x 1): true where class r is a catastrophe signal.
bool holds_reply_for(std::size_t ind, std::size_t r) const
True when node ind (1-based) holds a server across a synchronous call whose reply class is r (1-based...
void refresh_replyblock()
sn.replyblock, DERIVED from sn.syncreply and the routing.
std::vector< std::vector< Distrib< T > > > service
service[i][r], 0-based station and class; a disabled entry marks a pair never visited.
void refresh_chains()
Port of MNetwork.refreshChains followed by sn_refresh_visits.
std::vector< std::vector< bool > > csmask
(nclasses x nclasses) class r can switch into s, diagonal set
void refresh_capacity()
Port of MNetwork.refreshCapacity.
std::vector< std::vector< bool > > chains
(nchains x nclasses)
void apply_sink_closure()
Route every open chain from the Sink back into the Source, as the tail of MATLAB's getRoutingMatrix d...
std::vector< std::size_t > refclass
(nchains) 1-based class, 0 = none
std::vector< bool > polling_polled(std::size_t ist) const
The buffers a polling server at station ist actually visits, as State.pollingInfo builds pinfo....
int gdscalingcutoff
sn.gdscalingcutoff: the per-slot OPEN-class truncation used when gdscaling is materialized onto the J...
std::map< std::size_t, SetupDelayOffParam< T > > setupparam
Setup / delay-off, keyed by 1-based STATION index.
std::map< std::size_t, BreakdownParam< T > > breakdownparam
Server breakdown / repair, keyed by 1-based STATION index.
bool has_exponential_fcfs() const
BCMP type 1 asks the FCFS service to be exponential.
void check_service_reachable() const
bool has_breakdown() const
Any station at all, the guard every solver gate needs first.
static bool polling_leg_differs(const lang::Distrib< T > &a, const lang::Distrib< T > &b)
True when two timed legs are not the same law (distinctLaws).
GdScaling< T > gdscaling
sn.gdscaling: the network-level globally state-dependent (Whittle) rate scaling phi(n).
std::vector< bool > fjauxclass
sn.fjauxclass: (nclasses+1, 1-based) true where the class is an MMT AUXILIARY OPEN class,...
std::vector< std::vector< std::size_t > > nvars
sn.nvars, (nnodes x 3R+1): the LOCAL VARIABLE columns each node appends to its state,...
bool has_service_law(std::size_t i, std::size_t r) const
Does (station i, class r) have a service law an analyzer may convert?
std::vector< std::vector< bool > > disabled
Matrix< T > visits_from_block(const Matrix< T > &Pc_in, const std::vector< std::size_t > &sel, const std::vector< std::size_t > &ic, std::size_t refnode) const
The visit ratios of one chain from an already-formed chain routing block Pc (dim = sel....
pfqn::SdrStruct sdr
Krzesinski (1987) product-form state-dependent routing, in 0-based STATION indices; empty unless a no...
std::vector< std::vector< bool > > reached_node_classes() const
The (node, class) pairs a job can actually ARRIVE at, 0-based on both axes.
void refresh_sched_param()
Port of MNetwork.refreshScheduling's schedparam half.
std::map< std::size_t, FjJoinParam > fjjoinparam
sn.nodeparam{j}.fj for each Join node: the tag matrix and the required sibling multiplicity after_eve...
std::vector< std::vector< LstHandle > > lst() const
sn.lst (M x K handles), refreshLST.m: the Laplace-Stieltjes transform of each law,...
bool serves_class(std::size_t ind, std::size_t r) const
Whether a job of class r (0-based) can LEAVE node ind (1-based) again.
double total_jobs() const
Total population, as MATLAB's getNumberOfJobs summed.
Matrix< T > rt
sn.rt and sn.rtnodes: the class-expanded routing.
void fill_signal_services()
Refuses a class that is ROUTED TO a station which cannot serve it.
const CtmcMapc< T > * mapc_of(std::size_t ist, std::size_t r) const
The pair form of class r (1-based) at station ist (1-based), or null when there is none.
std::map< std::size_t, RetrialParam< T > > retrialparam
Retrial parameters, keyed by 1-based STATION index.
void promote_stateful(std::size_t ind)
Make node ind stateful, keeping stateful_nodes ascending.
std::vector< bool > issignal
The G-network signal declaration, per CLASS.
void grow_routing()
Grow every routing block to the current node count.
std::map< std::size_t, CacheParam< T > > nodeparam
Cache parameters by 1-based NODE index; only Cache nodes have an entry.
Matrix< double > procid() const
sn.procid (M x K): the ProcessType id of each (station, class) pair, as refreshProcessTypes....
void grow_block(Matrix< T > &B) const
std::size_t map_var_slot(std::size_t ind, std::size_t r) const
0-based column of class r's MAP memory inside node ind's local-variable block.
bool has_priorities() const
std::size_t add_node(const std::string &nm, NodeType ty, bool stateful)
Add a non-station node (a Fork, a Router).
std::map< std::size_t, PasParam > pasparam
static std::size_t bas_ncols(const std::vector< std::size_t > &codes)
Width of the held-job block: one counter per code, at least one column.
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::map< std::pair< std::size_t, std::size_t >, CtmcMapc< T > > ctmcmapc
MAP services in CTMC pair form, keyed by (1-based station, 1-based class).
std::vector< JobClass > classes
void rr_advance(std::size_t ind, std::size_t r, std::vector< T > &varrow) const
Advance the pointer of (ind, r) in VARROW by one position, cyclically.
std::vector< bool > isbasblocking
sn.isbasblocking, per NODE: true where the node is the BLOCKING (upstream) side of a true-BAS relatio...
bool has_product_form_not_het_fcfs(bool check_means=true) const
Port of sn_has_product_form_not_het_fcfs: LCFS is excluded, and at FCFS the service must be exponenti...
std::size_t sinkNode
1-based NODE index of the Sink, 0 = none (it is not a station)
std::size_t nregions() const
sn.nregions: the number of finite capacity regions.
Matrix< double > isph() const
sn.isph (M x K): true where sn.proc{i}{r} with sn.pie{i}{r} admits a phase-type reading (sn_is_phaset...
std::vector< std::vector< std::vector< double > > > mu() const
sn.mu (M x K cells): the total outgoing rate of each phase, MATLAB's getServiceRates/getSourceRates.
Matrix< double > connmatrix() const
sn.connmatrix (N x N): 1 where some class routes node i to node j with positive probability.
std::map< std::size_t, JoinDecl > joindecl
std::vector< std::size_t > signaltarget
std::vector< std::vector< std::vector< double > > > phi() const
sn.phi (M x K cells): the completion probability of each phase; 1 where mu is a single rate.
void bas_decode(std::size_t code, std::size_t &r, std::size_t &jst, std::size_t &s) const
Inverse of bas_code: 1-based (r, jst, s) for a code >= 1.
void refresh_local_vars()
Port of MNetwork.refreshLocalVars: the per-node local-variable widths.
ProcessType procid(std::size_t ist, std::size_t r) const
sn.procid(i,r): the process type of a (station, class) pair.
std::size_t rr_dest(std::size_t ind, std::size_t r, const std::vector< T > &varrow) const
The destination node the pointer in VARROW names, or 0 when (ind, r) does not dispatch round-robin or...
PollingParam effective_polling(std::size_t ist) const
The polling controller of station ist, from whichever API declared it.
std::vector< T > gdscalingpeak
sn.gdscalingpeak: the declared (nstations x nclasses) peak of gdscaling, row-major,...
std::size_t rr_var_slot(std::size_t ind, std::size_t r) const
1-BASED index of the pointer of (ind, r) INSIDE the node's local-variable block, or 0 when that pair ...
void refresh_bas_blocking()
Port of refreshLocalVars' true-BAS block and its declaresBlockedMarker helper: which nodes carry the ...
std::vector< Station< T > > stations
stations[k-1] is the k-th station
std::vector< std::size_t > rr_outlinks(std::size_t ind, std::size_t r) const
ROUND-ROBIN DISPATCH, the state that makes it deterministic.
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
void refresh_struct()
The whole chain, in MATLAB's refreshStruct order.
T route_eff(std::size_t r, std::size_t s, std::size_t i, std::size_t j) const
The routing actually in force: the expansion when there is one, else P.
bool is_queueing_place(std::size_t i) const
Is station i (0-based) a QUEUEING PLACE, i.e.
void set_service(std::size_t station, std::size_t cls, const Distrib< T > &d)
std::vector< std::size_t > syncreply
std::map< std::pair< std::size_t, std::size_t >, Matrix< T > > Peff
The routing after refresh_routing() has expanded the non-PROB strategies and folded the class switche...
std::vector< std::vector< std::size_t > > inchain
1-based class indices per chain
Matrix< double > isstatedep() const
sn.isstatedep (N x 3): column 1 the input section (never set by the reference), column 2 state-depend...
std::size_t node_of_station(std::size_t st) const
1-based node index of station st, 0 when the map has no entry.
std::vector< std::size_t > bas_marker_codes(std::size_t ind) const
Sorted held-job codes of the blocking node ind: one per (r, jst, s) the routing sends from class r at...
bool bas_single_server(std::size_t ist) const
A non-INF station with at most one server holds at most one job in total.
bool has_multi_server() const
void da_recompute_visits_from_rtnodes()
Recompute rt, visits and nodevisits after the caller has rewritten rtnodes in place – the cacheqn dri...
std::vector< NodeDef > nodes
every node, in creation order
std::vector< std::vector< double > > classcap
bool has_sd_routing() const
sn_has_sd_routing: RROBIN, WRROBIN, JSQ, SQ or SDR at some node.
std::vector< std::size_t > rr_weighted_outlinks(std::size_t ind, std::size_t r) const
The WRROBIN cycle: each outlink repeated by its weight, weight 0 once.
bool polling_has_timed_switchover(std::size_t ist, const PollingParam &pp) const
True when some POLLED buffer of station ist declares a non-immediate switchover, i....
std::map< std::size_t, Matrix< T > > csmatrix
The class-switch matrix of a ClassSwitch node, by 1-based NODE index.
std::vector< double > njobs() const
sn.njobs: the population of each class, infinite for an open one.
std::vector< std::pair< std::size_t, std::size_t > > chain_retrieval_edges(const std::vector< std::size_t > &ic, const std::vector< std::size_t > &sel) const
sn_refresh_visits.m retrievalEdges: extra [from, to] chain-block positions for a retrieval cache,...
bool has_breakdown_node(std::size_t ind) const
sn.hasbreakdown(ind): does the NODE's server break down?
std::vector< double > hasbreakdown() const
sn.hasbreakdown (N x 1): 1 where the node's server is subject to breakdowns.
void refresh_router_stateful()
A Router that DISPATCHES (round-robin, JSQ or SQ(d)) holds state, so it must survive the stochastic c...
bool is_open_model() const
sn_is_open_model: EVERY class is open, which is not has_open_classes.
bool has_open_classes() const
bool sched_is_product_form() const
std::vector< std::vector< DropStrategy > > droprule
std::size_t bas_code(std::size_t r, std::size_t jst, std::size_t s) const
TRUE-BAS HELD-JOB CODES (BUG-110).
std::string log_path
Network.setLogPath / getLogPath: the directory every Logger writes into, and the logPath attribute of...
bool has_blocking() const
Some station can REFUSE a job: its own buffer BINDS, or a finite capacity region caps a set of statio...
void refresh_rt()
sn.rt and sn.rtnodes: the class-expanded routing matrices.
bool priorities_ignored() const
Priorities were declared and no station will read them.
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
double buffer_size(std::size_t ist) const
Kendall's K of station IST (1-based), +inf when unbounded.
std::map< std::size_t, std::vector< T > > initmarking
The DECLARED initial state of a stateful node, by 1-based node index.
std::pair< T, T > mark_marginal_moments(const Distrib< T > &d, std::size_t mk) const
Mean and SCV of ONE MARK'S MARGINAL MAP, MarkedMAP.toMAPs(k).
std::vector< double > station_to_stateful() const
sn.stationToStateful (1 x M): the stateful index of each station.
std::map< std::size_t, std::vector< T > > stateprior
bool has_homogeneous_scheduling(SchedStrategy strategy) const
Port of sn_has_homogeneous_scheduling: true when EVERY station uses strategy, the reference's length(...
std::map< std::size_t, CtmcPool< T > > ctmcpool
Heterogeneous server pools rewritten for the CTMC, by 1-based NODE index.
double nclosedjobs() const
sn.nclosedjobs: the total population of the closed classes.
std::vector< std::pair< std::size_t, std::size_t > > fj
fj(f,j): the Join node j that closes the Fork node f, 1-based.
std::size_t nof_stations() const
void set_route_effective(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
Write into the routing the consumers actually read.
std::size_t join_siblings(std::size_t joinNode, std::size_t r=0) const
The number of siblings the fork-join pair ending at Join node joinNode (1-based) emits per parent job...
std::vector< double > stateful_to_station() const
sn.statefulToStation (1 x S): the station index of each stateful node, NaN when it is not a station.
std::size_t phasessz_of(std::size_t ist, std::size_t r) const
bool has_product_form() const
sn_has_product_form, conjunct for conjunct.
std::vector< lang::SignalType > signaltype
std::vector< std::size_t > fjclassmap
sn.fjclassmap: the ORIGINAL class of each auxiliary sibling class, 0 for an original class.
std::map< std::size_t, PollingParam > pollingparam
bool is_fluid_node(std::size_t ind) const
Is 1-based node ind a FLUID place (Place.setFluid, MATLAB sn.fluid(ind))?
std::vector< std::size_t > quorum_joins() const
The 1-based Join nodes that fire on a STRICT quorum, i.e.
bool has_fractional_populations() const
std::map< std::size_t, Matrix< T > > statespace
std::size_t markidx_of(std::size_t ist, std::size_t r) const
sn.markidx(i,r): the 1-based MARK that class r carries in station i's marked arrival process,...
std::size_t rr_quantum_phases(std::size_t ist, std::size_t r) const
sn.phasessz(i,r) = max(sn.phases(i,r),1): THE WIDTH of class r's phase block in a state row,...
Matrix< T > stoch_comp_stateful(const Matrix< T > &full, std::size_t nIC) const
The stochastic complement of a NODE-level routing block over the stateful nodes, S = P11 + P12 (I - P...
std::size_t add_station(const Station< T > &st)
Add a station, which is also a node, and grow the service table.
std::vector< std::vector< T > > signalremdist
Matrix< T > station_routing(const std::vector< std::size_t > &ic) const
The chain-restricted routing over the STATEFUL nodes: the node-level routing with the non-stateful no...
bool isfjaugmented
sn.isfjaugmented: this struct came out of fj_tag, so its Fork nodes are STATEFUL and its Join nodes c...
std::vector< std::size_t > station_to_node
(nstations) 1-based node index
static std::vector< bool > chain_reachable(const Matrix< T > &P, const std::vector< std::size_t > &seeds, const std::vector< std::pair< std::size_t, std::size_t > > &edges)
sn_refresh_visits.m chainReachable: states reachable from the seeds along nonzero entries and the ext...
void refresh_routing()
Port of the part of MNetwork.refreshRoutingMatrix this port reaches: the expansion of a routing STRAT...
std::vector< Region > regions
std::size_t nof_classes() const
void refresh_immfeed()
Port of the sn.immfeed block of @@MNetwork/refreshStruct.m.
std::map< std::size_t, ForkParam< T > > forkparam
Variable forking levels, by 1-based Fork node; absent on a plain fork.
static std::string plural(long n, const std::string &singular, const std::string &plural_form)
Count with an agreeing noun, e.g.
static void compiling(const std::string &name)
Announce the compilation of a model structure.
static void compile_detail(const char *fmt,...)
One stage line of a structure compile: silenced inside a Quiet scope, and inside an open run,...
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
Equilibrium distribution of a discrete-time Markov chain, and stochastic complementation.
Limiting distribution of a discrete-time Markov chain whose transition matrix may be reducible.
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
int dispatch(const Options &in, bool allow_server, bool no_args)
Everything main did, with the arguments already in hand.
Running progress log of a LINE solver run (the "solver console").
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
bool sn_is_phasetype(const std::vector< Matrix< T > > &maps, const std::vector< T > &pie)
Whether a (D0, D1, ...) list is a valid phase-type / MAP representation.
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.
BalkingStrategy
Balking rules, with the values of MATLAB BalkingStrategy.
@ CATASTROPHE
removes EVERY job at the station
PollingOrder
Visit-order rules of a polling server, with the values of MATLAB PollingOrder.
@ CYCLIC
fixed cyclic order (or the polling table)
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.
@ GLOBAL
a timed token: per-class target rotation timers
T dist_lst(const Distrib< T > &d, const T &s)
sn.lst: the Laplace-Stieltjes transform E[exp(-sX)].
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)
@ EXHAUSTIVE
serve until the queue empties
@ GLIMITED
serve at most K of the jobs present at the polling instant
JobClassType
Job class kinds, with the values of MATLAB JobClassType.
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
std::function< std::vector< T >(const std::vector< T > &)> GdScaling
A globally state-dependent scaling, sn.gdscaling.
bool process_is_markovian(ProcessType p)
ProcessType.isMarkovian: true when sn.proc carries an exact matrix representation of the law,...
std::function< std::vector< T >(const std::vector< T > &)> CdScaling
A class-dependent scaling map, sn.cdscaling.
const char * routing_to_text(RoutingStrategy r)
NodeType
Node kinds, with the values of MATLAB NodeType.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
T map_mean(const Map< T > &m)
Mean inter-arrival time, 1/lambda.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
T map_scv(const Map< T > &m)
Squared coefficient of variation.
ReducibleResult< T > dtmc_solve_reducible(const Matrix< T > &P, const std::vector< T > &pin, double zeroColTol=1e-12)
Limiting distribution of a discrete-time Markov chain whose transition matrix may be reducible.
Matrix< T > dtmc_stochcomp(const Matrix< T > &P, const std::vector< std::size_t > &keep)
Stochastic complement of a DTMC partition, a port of matlab/lib/kpctoolbox/mc/dtmc_stochcomp....
SccResult stronglyconncomp(const Matrix< T > &A)
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
std::vector< T > dtmc_solve(const Matrix< T > &P)
Stationary distribution of a stochastic matrix P.
void cache_retrieval_class_map(const CacheParam< T > &cp, std::vector< std::size_t > &rc_list, std::vector< std::size_t > &rc_items, std::vector< std::size_t > &rc_orig)
Port of State.cacheRetrievalClassMap: the canonical order of a cache's retrieval classes,...
Matrix< T > station_swap_graph(const NetworkStruct< T > &sn, std::size_t ist)
The swap graph of a PAS / OI station, with the defaults refreshLocalVars.m installs applied.
bool is_oi_loss(const NetworkStruct< T > &sn, std::size_t *qist=nullptr)
Port of sn_is_oi_loss.m: an open Source -> Queue -> Sink system (any number of classes,...
bool station_swap_graph_is_zero(const NetworkStruct< T > &sn, std::size_t ist)
True when the station's materialized swap graph is entirely zero.
const char * routing_to_text(RoutingStrategy r)
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....
Conservation laws of a layered queueing network, enumerated from its structure.
Number-type abstraction for the templated API port.
Product-form state-dependent routing.
Whether a (D0, D1, ...) list is a valid phase-type / MAP representation.
Strongly connected components of a directed graph, and which of them are recurrent (closed under the ...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
The DECLARED join rule of a Join node, by 1-based node index.
The pass-and-swap / order-independent parameters of a PAS station, keyed by station index (Dorsman an...
The polling controller of a POLLING station, keyed by station index.
FINITE CAPACITY REGIONS, MATLAB's refreshRegions output.
sn.reward: the user-declared reward functions, MATLAB's model.setReward(name, fn).
std::vector< T > mu_vec() const
Phase rates, MATLAB's getMu: the total outgoing rate of each phase.
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
std::vector< Matrix< T > > Dmark
MMAP per-class D1 blocks / BMAP per-batch-size blocks; empty otherwise.
T rate() const
The rate MATLAB's refreshRates would store: 1/mean, with the Immediate singleton short-circuited to i...
std::vector< T > phi_vec() const
Completion probabilities, MATLAB's getPhi: (D1 e) .
std::size_t phases() const
The order of the representation, MATLAB's sn.phases.
A MAP as the pair of matrices (D0, D1).
std::vector< bool > recurrent
recurrent[c-1] is true when component c has no edge leaving it.
std::vector< std::size_t > scc
Component index of each state, 1-based as in MATLAB (0 is never used).
Topology and coefficients of a state-dependent routing subnetwork.
Server breakdown and repair of a station whose server fails and is repaired.
T failure_rate
sn.breakdownMu: 1 / mean failure time
T down_rate_of(std::size_t cls_1based) const
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).
T qlru
q-LRU admission probability; 1 admits every miss (plain LRU).
std::vector< Popularity > preadkind
per class, parallel to pread
std::vector< T > initstate
The DECLARED initial contents of the cache, as the reference dumps the node's state row: the per-clas...
std::vector< int > itemsize
Per-item storage cost (size) and per-list cap on the total cost of the resident items (ton21cache Sec...
std::vector< int > costcap
std::map< std::size_t, std::vector< std::size_t > > retrieval_queues
read class(0-based)->nodes
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
long max_pending_retrieval
Truncation level of block B: how many secondary requests may be merged onto the in-flight fetches of ...
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
lang::ReplacementStrategy replacestrat
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
CTMC pair form of a MAP service at an FCFS station, written by ctmc::ctmc_mapc on the solver's privat...
Matrix< T > V
landing law (-D0)^-1 D1
std::size_t p
phases of the original MAP
std::vector< std::pair< std::size_t, std::size_t > > pairs
0-based (i,j), i-major, V(i,j) > 0
std::vector< T > done
completion rate D1(i,j)/V(i,j)
bool single
c = 1: carried phase, no pairs
CTMC bookkeeping of a heterogeneous-server station, written by ctmc::ctmc_pools on the solver's priva...
std::vector< std::vector< std::size_t > > len
offset and length of block k of class r
std::vector< std::vector< std::vector< T > > > alpha
entry vector of block k of class r
std::vector< std::vector< std::vector< T > > > exit
exit rates of block k of class r
std::vector< std::vector< bool > > compat
compat[t-1][r-1]
std::vector< double > count
servers per pool
std::vector< std::size_t > alfsorder
pools by ascending class count (ALFS)
std::vector< std::vector< Matrix< T > > > D0
D0 of block k of class r.
std::vector< std::vector< std::size_t > > pools
pools[r-1]: compatible pools of r, ascending
lang::HeteroSchedPolicy policy
bool rotate
ALIS/FAIRNESS order is part of the state.
std::vector< std::vector< std::size_t > > off
std::size_t perm_index(const std::vector< std::size_t > &order) const
1-based index of order in perms, 0 when absent.
std::vector< std::vector< double > > fsfrate
fsfrate[t-1][r-1] = 1/mean (FSF)
std::vector< std::vector< std::size_t > > perms
every pool order, identity first
bool has_map() const
True when the type carries a (D0,D1) pair of its own.
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
std::vector< Matrix< T > > Dmark
MMAP per-class D1 blocks / BMAP per-batch-size blocks; empty otherwise.
static Distrib disabled_dist()
static Distrib immediate()
The point mass at zero.
sn.nodeparam{j}.fj: what a Join node needs to fire on identity.
std::vector< std::size_t > origclasses
std::map< std::size_t, std::size_t > quorum
QUORUM joins (JoinStrategy.PARTIAL), keyed by original class: the join fires on the first quorum[r] o...
std::map< std::size_t, std::vector< std::vector< std::size_t > > > auxmatrix
std::map< std::size_t, std::size_t > debtoff
std::map< std::size_t, std::vector< std::size_t > > required
One fork firing synchronization: sn.fjsync{k}.
std::size_t fork
1-based Fork node
std::vector< std::size_t > weightlink
Per-branch tasksPerLink, EMPTY when every branch carries weight.
std::size_t weight
tasksPerLink: siblings emitted per branch
std::vector< std::size_t > branchheads
1-based node per branch
std::size_t join
1-based Join node that closes it
std::size_t cls
1-based ORIGINAL class being forked
std::vector< std::vector< std::size_t > > auxall
(B x T) every auxiliary class of this (fork, class), for the tag scan.
std::vector< std::size_t > auxclasses
the tag's auxiliary class per branch
std::size_t tag
1-based tag this entry allocates
Variable forking levels, the twin of MATLAB sn.nodeparam{f}.fanOutLink / .fanOutProb / ....
std::vector< std::vector< lang::Distrib< T > > > fan_out_dist
static constexpr double Immediate
Rate of an Immediate distribution; its mean is 1/Immediate = 1e-8.
static constexpr double FineTol
static constexpr double Zero
static constexpr double CoarseTol
One job class of the network.
std::size_t refstat
1-based reference station
bool completes
Whether passage through the reference station is a COMPLETION.
double deadline
sn.classdeadline(r): the soft deadline EDD and EDF order by, and the tardiness JMT reports.
int attr_kind
LayeredNetworkElement of the element it stands for.
std::size_t attr_idx
index of that element
double population
infinite for an open class
bool immfeed
Class-level immediate feedback, ORed with the station's own setting into sn.immfeed.
std::size_t spawn
sn.classspawn(r): the 1-based class injected at the SAME station on every completion of this class,...
bool self_looping
A SelfLoopingClass: a closed class that perpetually cycles at its reference station.
bool is_ref_class
marks the chain's reference class
lang::JoinStrategy strategy
double quorum
0 = every sibling
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 > > timer
std::vector< lang::Distrib< T > > table_sw
std::vector< std::size_t > table
The extensions, as the Station fields of the same names.
std::vector< lang::Distrib< T > > switchover
lang::PollingTimer timer_scope
std::vector< T > lincon_b
Matrix< T > lincon_A
optional linear constraint A n <= b
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
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,...
A Logger node's trace configuration, MATLAB's Logger properties and sn.nodeparam{ind}...
std::string file_name
base name, no directory
std::string file_path
directory, MATLAB's model.getLogPath
std::vector< int > routing_param
The scalar parameter of a parameterized dispatcher, per class: the d of a power-of-d (SQ) choice.
std::vector< std::map< std::size_t, double > > routing_weights
The per-destination weights of a WRROBIN dispatcher, per class: a map from 1-based destination NODE i...
bool queue_object
Declared as a Queue although its INF discipline makes nodetype Delay (Network::add_queue).
std::vector< RoutingStrategy > routing
sn.routing, per class.
double tasks_per_link
Fork.output.tasksPerLink == MATLAB sn.nodeparam{f}.fanOut: how many tasks a fork emits per outgoing l...
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).
Setup and delay-off of a station that powers down when it falls idle.
bool last(lang::Distrib< T > &su, lang::Distrib< T > &doff) const
The pair the solvers use: the last class that declares one.
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.
lang::BalkingStrategy strategy
std::vector< BalkingThreshold > thresholds
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...
std::vector< bool > compatible
per class; empty = every class
std::vector< Distrib< T > > service
per class
One station of the network.
std::vector< Distrib< T > > orbit_impatience
Queue.setOrbitImpatience(class, dist): abandonment from the RETRIAL ORBIT, which is a different popul...
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 ...
T orbit_join_of(std::size_t r) const
orbit_join[r] with the default 1 for a missing slot (0-based r).
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< std::size_t > marked_classes
Source.markedClasses: the 1-based class of each mark of an MMAP arrival.
std::vector< T > lldscaling
sn.lldscaling for this station: the multiplier at population 1, 2, ... Empty when the station is not ...
std::vector< lang::ImpatienceType > impatience
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).
lang::HeteroSchedPolicy hetero_policy
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
bool fluid
Place.setFluid (MATLAB sn.fluid): the place holds a continuous LEVEL rather than tokens,...
std::vector< T > orbit_search
Queue.setOrbitalSearch(class, theta), MATLAB sn.orbitSearchProb: on a service completion at a retrial...
lang::PollingTimer polling_timer_scope
T orbit_search_of(std::size_t r) const
orbit_search[r] with the default 0 for a missing slot (0-based r).
std::vector< T > orbit_persist
std::vector< bool > immfeed
Node-level immediate feedback, per class; empty when the station sets none.
std::vector< ServerType > server_types
std::size_t attr_idx
LQN element this station stands for.
long polling_order_threshold
T orbit_persist_of(std::size_t r) const
orbit_persist[r] with the default 1 for a missing slot (0-based r).
One fluid arc of a mode: node is the 1-based fluid place, value a rate or an impulse.
A fluid rate dependence: the firing rate is multiplied by fun(level(node)).
std::function< double(double)> fun
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,...
const std::vector< FluidArc > & fluid_rates(std::size_t m) const
static std::vector< T > inhibit_total(const std::vector< Matrix< T > > &a, std::size_t m)
The inhibiting THRESHOLD of one mode per place, class blind.
std::vector< std::vector< FluidDep > > fluiddep
static std::vector< T > arc_total(const std::vector< Matrix< T > > &a, std::size_t m)
The arcs of one mode summed over classes, for a consumer that is class blind BECAUSE THE NET IS SINGL...
bool is_multiclass() const
True when any mode's arcs touch more than one class.
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
bool has_fluid_arcs() const
Transition.hasFluidArcs: any mode declares a fluid rate, guard, impulse, rate or flow dependence.
std::vector< double > nmodeservers
servers per mode, may be infinite
const std::vector< FluidArc > & fluid_impulses(std::size_t m) const
std::vector< T > fireweight
weight among simultaneously enabled modes
std::size_t single_class() const
The one class every arc of every mode touches, 1-based; 0 when none does.
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.
const std::vector< FluidDep > & fluid_deps(std::size_t m) const
const std::vector< FluidFlowDep > & fluid_flow_deps(std::size_t m) const
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).
const std::vector< FluidGuard > & fluid_guards(std::size_t m) const
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