849 const std::string& method =
opt.method;
873 if (method.compare(0, 5,
"spnlp") != 0) {
874 for (std::size_t i = 0; i < L.
nodes.size(); ++i)
877 "solver_ba_analyzer: Method '" + method +
"' is parameterized by demands and a "
878 "population, which the marking of a Petri net is not. Use "
879 "'spnlp2.upper'/'spnlp2.lower' or the 'spnlp1.upper'/'spnlp1.lower' pair on this model.");
884 if ((method ==
"aba.upper" || method ==
"aba.lower" || method ==
"bjb.upper" ||
885 method ==
"bjb.lower") && detail::ba_is_open_aba_bjb(L, method))
886 return detail::ba_open_aba_bjb(L, method);
892 if (method ==
"auto.upper" || method ==
"auto.lower") {
893 const bool up = method ==
"auto.upper";
894 const detail::ScDemands<T> sc = detail::ba_sc_demands(L);
895 static const char*
const cand_up[] = {
"aba.upper",
"bjb.upper",
"pb.upper",
"gb.upper",
896 "sb.upper",
"mw.upper",
"ssd.upper",
"cub.upper"};
897 static const char*
const cand_lo[] = {
"aba.lower",
"bjb.lower",
"pb.lower",
898 "gb.lower",
"sb.lower",
"mw.lower",
899 "ssd.lower",
"mbjb.lower",
"ldac.lower"};
900 const char*
const* cand = up ? cand_up : cand_lo;
901 const std::size_t ncand = up ?
sizeof(cand_up) /
sizeof(*cand_up)
902 :
sizeof(cand_lo) /
sizeof(*cand_lo);
905 for (std::size_t ci = 0; ci < ncand; ++ci) {
911 }
catch (
const std::exception&) {
914 if (r.
X.empty())
continue;
917 if (!have || (up && Xc < Xbest) || (!up && Xc > Xbest)) {
924 "' found no feasible bound for this model");
925 return detail::ba_fill(L, sc.V, sc.N, Xbest, sc.Z, sc.D, up);
930 const bool single_class_family =
931 method ==
"aba.upper" || method ==
"aba.lower" || method ==
"bjb.upper" ||
932 method ==
"bjb.lower" || method ==
"pb.upper" || method ==
"pb.lower" ||
933 method ==
"sb.upper" || method ==
"sb.lower" || method ==
"gb.upper" ||
934 method ==
"gb.lower";
936 if (single_class_family) {
937 const detail::ScDemands<T> sc = detail::ba_sc_demands(L);
938 const std::vector<T>& V = sc.V;
939 const std::vector<T>& D = sc.D;
943 const detail::DemandStats<T> st = detail::ba_demand_stats(D);
945 if (method ==
"aba.upper") {
946 const T X = detail::ba_min(T(one / st.max), T(Nt / T(Z + st.sum)));
947 return detail::ba_fill_xc(L, V, N, X, T(Z + Nt * st.sum),
true);
949 if (method ==
"aba.lower") {
950 const T X = T(Nt / T(Z + Nt * st.sum));
951 return detail::ba_fill_xc(L, V, N, X, T(Z + st.sum),
false);
958 const T xup1 = detail::ba_min(T(one / st.max), T(Nm1 / T(Z + st.sum)));
959 const T xlo1 = T(Nm1 / T(Z + Nm1 * st.sum));
960 if (method ==
"bjb.upper") {
961 const T C = T(Z + st.sum + st.max * T(Nm1 - Z * xlo1));
962 const T X = detail::ba_min(
963 T(one / st.max), T(Nt / T(Z + st.sum + st.mean * T(Nm1 - Z * xup1))));
964 return detail::ba_fill_xc(L, V, N, X, C,
true);
966 if (method ==
"bjb.lower") {
967 const T C = T(Z + st.sum + st.mean * T(Nm1 - Z * xup1));
968 const T X = T(Nt / T(Z + st.sum + st.max * T(Nm1 - Z * xlo1)));
969 return detail::ba_fill_xc(L, V, N, X, C,
false);
971 if (method ==
"pb.upper" || method ==
"pb.lower") {
972 T d2 = zero, dN = zero, dNm1 = zero;
973 for (
const T& d : D) {
976 dNm1 +=
num_pow_int(d,
static_cast<unsigned>(N - 1));
978 const T Dpb2 = T(d2 / st.sum);
979 const T DpbN = T(dN / dNm1);
980 if (method ==
"pb.upper") {
981 const T C = T(Z + st.sum + DpbN * T(Nm1 - Z * xlo1));
982 const T X = detail::ba_min(
983 T(one / st.max), T(Nt / T(Z + st.sum + Dpb2 * T(Nm1 - Z * xup1))));
984 return detail::ba_fill_xc(L, V, N, X, C,
true);
986 const T C = T(Z + st.sum + Dpb2 * T(Nm1 - Z * xup1));
987 const T X = T(Nt / T(Z + st.sum + DpbN * T(Nm1 - Z * xlo1)));
988 return detail::ba_fill_xc(L, V, N, X, C,
false);
990 if (method ==
"sb.upper" || method ==
"sb.lower") {
994 for (std::size_t i = 0; i < L.
nstations; ++i)
995 if (detail::ba_is_delay(L, i))
997 "' does not support infinite-server stations");
998 T A1 = zero, A2 = zero, A3 = zero;
999 for (
const T& d : D) {
1004 if (method ==
"sb.upper") {
1005 const T C = T(Z + A1 + Nm1 * T(T(A1 * A2 + A3) / T(A1 * A1 + A2)));
1006 const T X = detail::ba_min(T(one / st.max), T(Nt / C));
1010 return detail::ba_fill_xc(L, V, N, X, C,
false);
1015 "solver_ba_analyzer: method 'sb.lower' needs an (N-1)-st root and is "
1016 "unavailable in exact arithmetic");
1020 for (
const T& d : D) AN +=
num_pow_int(d,
static_cast<unsigned>(N));
1023 const T root = pow(T(AN / A1), T(one / Nm1));
1024 const T C = T(Z + A1 + Nm1 * root);
1025 return detail::ba_fill_xc(L, V, N, T(Nt / C), C,
false);
1031 "' solve a quadratic and are unavailable in exact arithmetic");
1033 const bool up = (method ==
"gb.upper");
1036 const T X = up ? detail::ba_min(T(one / st.max), Xup) : Xlo;
1037 const T C = T(Nt / (up ? Xlo : Xup));
1042 const T Xden = up ? Xlo : Xup;
1049 for (std::size_t i = 0; i < L.
nstations; ++i) {
1050 s.
Tp(i, 0) = T(V[i] * X);
1051 if (detail::ba_is_delay(L, i)) {
1052 s.
R(i, 0) = T(one / L.
rates(i, 0));
1053 s.
Q(i, 0) = T(X * s.
R(i, 0));
1056 s.
R(i, 0) = T(T(s.
Q(i, 0) / Xden) / V[i]);
1059 s.
U(i, 0) = detail::ba_is_delay(L, i) ? s.
Q(i, 0) : T(s.
Tp(i, 0) / L.
rates(i, 0));
1068 if (method ==
"lr.upper" || method ==
"lr.lower") {
1072 const detail::ScDemands<T> sc = detail::ba_sc_demands(L);
1073 for (std::size_t i = 0; i < L.
nstations; ++i)
1074 if (detail::ba_is_delay(L, i))
1076 "' does not support delay (infinite-server) stations");
1077 const bool up = (method ==
"lr.upper");
1079 const std::vector<T>& V = sc.V;
1082 par.
M =
static_cast<int>(M);
1085 par.
N =
static_cast<int>(sc.N);
1088 for (std::size_t i = 0; i < M; ++i) {
1096 if (totV == zero)
throw NumericError(
ErrorKind{
"Degenerate"},
"solver_ba_analyzer: the visit ratios are all zero");
1097 for (std::size_t i = 0; i < M; ++i)
1098 for (std::size_t j = 0; j < M; ++j) par.
r(i, j) = T(V[j] / totV);
1101 std::vector<T> U(M, zero);
1102 for (std::size_t ti = 0; ti < M; ++ti) {
1107 "' linear program did not solve (" + r.
status +
")");
1115 for (std::size_t i = 0; i < M; ++i) {
1116 if (V[i] == zero)
continue;
1117 const T cand = T(U[i] * L.
rates(i, 0) / V[i]);
1118 if (!any || cand < X) {
1127 BaSolution<T> s = detail::ba_fill(L, V, sc.N, X, zero, sc.D, up);
1128 for (std::size_t i = 0; i < M; ++i) s.
U(i, 0) = U[i];
1129 s.
lG = std::numeric_limits<double>::quiet_NaN();
1133 if (method ==
"mapamva.upper" || method ==
"mapamva.lower") {
1149 const detail::ScDemands<T> sc = detail::ba_sc_demands(L);
1150 for (std::size_t i = 0; i < L.
nstations; ++i)
1151 if (detail::ba_is_delay(L, i))
1153 "solver_ba_analyzer: method '" + method +
1154 "' does not support delay (infinite-server) stations: the MAP-AMVA program "
1155 "of Casale-Smirni (DSN 2009) is written for a network of queues and the "
1156 "paper names the delay extension as open work. Use a QRF method, which "
1157 "carries the load-dependent rate law");
1158 const bool up = (method ==
"mapamva.upper");
1160 const std::vector<T>& V = sc.V;
1165 std::vector<std::pair<Matrix<T>,
Matrix<T>>> MAPs(M);
1166 std::vector<int> kph(M, 1);
1167 for (std::size_t i = 0; i < M; ++i) {
1169 if (m.
D0.rows() == 0) {
1174 MAPs[i] = std::make_pair(m.
D0, m.
D1);
1175 kph[i] =
static_cast<int>(m.
D0.rows());
1178 std::vector<std::size_t> phased;
1179 for (std::size_t i = 0; i < M; ++i)
1180 if (kph[i] > 1) phased.push_back(i);
1181 if (phased.size() > 1) {
1183 for (std::size_t j = 0; j < phased.size(); ++j)
1184 names += (j ?
", " :
"") + std::to_string(phased[j] + 1);
1186 "solver_ba_analyzer: method '" + method +
1187 "' carries phases at ONE station: the LP gives queue M the (D0,D1) pair and "
1188 "every other queue a scalar rate. Stations " + names +
" are all "
1189 "non-exponential. Use a QRF method, whose q carries a phase at every station");
1194 const std::size_t map_idx = phased.empty() ? M - 1 : phased.front();
1195 std::vector<std::size_t>
perm;
1197 for (std::size_t i = 0; i < M; ++i)
1198 if (i != map_idx)
perm.push_back(i);
1199 perm.push_back(map_idx);
1200 const int K = kph[map_idx];
1201 const std::size_t Ks =
static_cast<std::size_t
>(K);
1204 par.
M =
static_cast<int>(M);
1205 par.
N =
static_cast<int>(sc.N);
1207 par.
muM.resize(M - 1);
1208 for (std::size_t a = 0; a + 1 < M; ++a) par.
muM[a] = L.
rates(
perm[a], 0);
1216 for (std::size_t a = 0; a < Ks; ++a)
1217 for (std::size_t b = 0; b < Ks; ++b) {
1218 par.
muMAP(a, b) = MAPs[map_idx].second(a, b);
1219 par.
v(a, b) = (a == b) ? zero : MAPs[map_idx].first(a, b);
1222 for (std::size_t a = 0; a < M; ++a)
1223 for (std::size_t b = 0; b < M; ++b) par.
r(a, b) = L.
rt(
perm[a],
perm[b]);
1225 std::vector<T> Vp(M, zero), Sp(M, zero);
1226 for (std::size_t a = 0; a < M; ++a) {
1227 const std::size_t i =
perm[a];
1230 mi.
D0 = MAPs[i].first;
1231 mi.
D1 = MAPs[i].second;
1241 std::vector<T> umax(M, zero), umin(M, zero), qbnd(M, zero);
1242 for (std::size_t a = 0; a < M; ++a) {
1243 const int ti =
static_cast<int>(a);
1252 if (!ru.
ok || !rl.
ok || !rq.
ok)
1254 "' linear program did not solve (" +
1266 T x_up = zero, x_lo = zero;
1267 for (std::size_t a = 0; a < M; ++a) {
1268 const T load = T(Vp[a] * Sp[a]);
1269 if (load <= zero)
continue;
1270 const T cu = T(umax[a] / load), cl = T(umin[a] / load);
1276 if (cu < x_up) x_up = cu;
1277 if (cl > x_lo) x_lo = cl;
1282 "' found no station with both a positive visit ratio and a "
1283 "positive mean service time");
1284 const T xb = up ? x_up : x_lo;
1285 const T xopp = up ? x_lo : x_up;
1293 for (std::size_t a = 0; a < M; ++a) {
1294 const std::size_t i =
perm[a];
1295 s.
U(i, 0) = up ? umax[a] : umin[a];
1296 s.
Q(i, 0) = qbnd[a];
1297 s.
Tp(i, 0) = T(Vp[a] * xb);
1298 s.
R(i, 0) = (xopp > zero && Vp[a] > zero) ? T(qbnd[a] / (Vp[a] * xopp)) : zero;
1304 s.
C.assign(1, xopp > zero
1312 if (method ==
"mw.upper" || method ==
"mw.lower") {
1316 const detail::ChainView<T> v = detail::ba_chain_view(L);
1318 Matrix<T> Vq(Kq, C, zero), Sq(Kq, C, zero);
1319 std::vector<pfqn::MwrbbSched> schedq(Kq);
1320 for (std::size_t k = 0; k < Kq; ++k) {
1321 const std::size_t i = v.qstat[k];
1322 schedq[k] = detail::mwrbb_disc_code(L.
stations[i].sched);
1323 for (std::size_t c = 0; c < C; ++c) {
1324 Vq(k, c) = v.d.Vchain(i, c);
1325 Sq(k, c) = v.d.STchain(i, c);
1330 std::vector<int> prioc(C, 0);
1331 for (std::size_t c = 0; c < C; ++c) {
1336 for (std::size_t r : L.
inchain[c]) p = std::min(p, L.
classes[r - 1].prio);
1341 const bool up = (method ==
"mw.upper");
1342 const std::vector<T>& Xchain = up ? b.
Xup : b.
Xlo;
1343 Matrix<T> Tchain(M, C, zero), Uchain(M, C, zero), Qchain(M, C, zero);
1344 for (std::size_t c = 0; c < C; ++c)
1345 for (std::size_t i = 0; i < M; ++i) {
1346 Tchain(i, c) = T(Xchain[c] * v.d.Vchain(i, c));
1347 Uchain(i, c) = T(Xchain[c] * v.d.Lchain(i, c));
1349 Qchain = detail::ba_chain_qfill(Uchain, Xchain, v.d.Lchain, v.Nv, v.isdelay, up);
1351 L, v.d, Qchain, Uchain,
Matrix<T>(), Tchain, Xchain);
1359 s.
lG = std::numeric_limits<double>::quiet_NaN();
1366 if (method ==
"looping.upper" || method ==
"looping.lower") {
1367 const detail::ChainView<T> v = detail::ba_chain_view(L);
1370 for (std::size_t k = 0; k < Kq; ++k)
1371 for (std::size_t c = 0; c < C; ++c) Lq(k, c) = v.d.Lchain(v.qstat[k], c);
1373 const bool up = (method ==
"looping.upper");
1374 const std::vector<T>& Xchain = up ? b.
Xup : b.
Xlo;
1375 Matrix<T> Tchain(M, C, zero), Uchain(M, C, zero), Qchain(M, C, zero);
1376 for (std::size_t c = 0; c < C; ++c)
1377 for (std::size_t i = 0; i < M; ++i) {
1378 Tchain(i, c) = T(Xchain[c] * v.d.Vchain(i, c));
1379 Uchain(i, c) = T(Xchain[c] * v.d.Lchain(i, c));
1381 Qchain = detail::ba_chain_qfill(Uchain, Xchain, v.d.Lchain, v.Nv, v.isdelay, up);
1383 L, v.d, Qchain, Uchain,
Matrix<T>(), Tchain, Xchain);
1391 s.
lG = std::numeric_limits<double>::quiet_NaN();
1399 if (method ==
"bpt.lower") {
1408 if (method ==
"bgt.upper") {
1417 if (method ==
"snc.upper") {
1423 if (method ==
"cub.upper" || method ==
"mbjb.lower") {
1424 const detail::ChainView<T> v = detail::ba_chain_view(L);
1427 for (std::size_t k = 0; k < Kq; ++k)
1428 for (std::size_t c = 0; c < C; ++c) Lq(k, c) = v.d.Lchain(v.qstat[k], c);
1430 const bool up = (method ==
"cub.upper");
1431 const std::vector<T>& Xchain = up ? b.
Xub : b.
Xlb;
1432 Matrix<T> Tchain(M, C, zero), Uchain(M, C, zero), Qchain(M, C, zero);
1433 for (std::size_t c = 0; c < C; ++c)
1434 for (std::size_t i = 0; i < M; ++i) {
1435 Tchain(i, c) = T(Xchain[c] * v.d.Vchain(i, c));
1436 Uchain(i, c) = T(Xchain[c] * v.d.Lchain(i, c));
1438 Qchain = detail::ba_chain_qfill(Uchain, Xchain, v.d.Lchain, v.Nv, v.isdelay, up);
1440 L, v.d, Qchain, Uchain,
Matrix<T>(), Tchain, Xchain);
1448 s.
lG = std::numeric_limits<double>::quiet_NaN();
1455 if (method ==
"harel.upper" || method ==
"harel.lower") {
1456 const detail::ScDemands<T> sch = detail::ba_sc_demands(L);
1457 if (!(sch.Z == zero))
1459 "' does not support think times (infinite-server stations)");
1460 const int Nh =
static_cast<int>(sch.N);
1461 const int maxUB = Nh < 7 ? Nh : 7;
1463 const bool uph = method ==
"harel.upper";
1467 for (
const T& d : sch.D)
1468 if (d > dmax) dmax = d;
1470 const T ext = maxUB >= 2 ? b.
UB[
static_cast<std::size_t
>(maxUB)] : b.
TH[1];
1471 Xb = ext < cap ? ext : cap;
1473 return detail::ba_fill(L, sch.V, sch.N, Xb, sch.Z, sch.D, uph);
1477 const bool hier = method ==
"pbh.upper" || method ==
"pbh.lower" || method ==
"cbh.upper" ||
1478 method ==
"cbh.lower" || method ==
"bjbh.upper" || method ==
"bjbh.lower" ||
1479 method ==
"ssd.upper" ||
1480 method ==
"ssd.lower" || method ==
"sib.upper" || method ==
"sib.lower" ||
1481 method ==
"scb.upper" || method ==
"scb.lower" ||
1482 method ==
"ldac.lower" || method ==
"kriz.upper" || method ==
"kriz.lower" ||
1483 method ==
"ibjb.upper" || method ==
"ibjb.lower" ||
1484 method ==
"ldsy.upper" || method ==
"ldsy.lower";
1488 const detail::ScDemands<T> sc = detail::ba_sc_demands(L);
1489 const bool up = method.size() > 6 && method.compare(method.size() - 6, 6,
".upper") == 0;
1491 const int lvl =
opt.level;
1496 if (method ==
"ssd.upper" || method ==
"ssd.lower") {
1497 std::vector<T> cvec;
1498 for (std::size_t i = 0; i < L.
nstations; ++i)
1499 if (!detail::ba_is_delay(L, i))
1502 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1504 if (method ==
"ldac.lower") {
1508 const std::vector<T> cz(sc.D.size(), zero);
1513 "solver_ba_analyzer: method 'ldac.lower' requires the asymptotic regime N >= "
1515 return detail::ba_fill(L, sc.V, sc.N, b.
Xlo, sc.Z, sc.D,
false);
1517 if (method ==
"scb.upper" || method ==
"scb.lower") {
1524 if (!(sc.Z == zero))
1526 "' supports Z=0 (no delay station) only; Theorem 3 rests on "
1527 "the delay-free balanced-network throughput");
1529 return detail::ba_fill(L, sc.V, sc.N, up ? b.Xhi : b.Xlo, sc.Z, sc.D, up);
1531 if (method ==
"pbh.upper" || method ==
"pbh.lower") {
1533 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1535 if (method ==
"bjbh.upper" || method ==
"bjbh.lower") {
1537 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1539 if (method ==
"cbh.upper" || method ==
"cbh.lower") {
1541 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1543 if (method ==
"ibjb.upper" || method ==
"ibjb.lower") {
1546 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1548 if (method ==
"ldsy.upper" || method ==
"ldsy.lower") {
1551 const Matrix<T> mu = detail::ba_sc_ld_mu(L, sc.N);
1553 return detail::ba_ld_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, mu, up);
1560 "' solves a quadratic and is unavailable in exact arithmetic");
1562 if (method ==
"kriz.upper" || method ==
"kriz.lower") {
1566 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);
1569 return detail::ba_fill(L, sc.V, sc.N, up ? b.
Xhi : b.
Xlo, sc.Z, sc.D, up);