5#ifndef LINE_SOLVERS_NC_SOLVER_NC_DT_H
6#define LINE_SOLVERS_NC_SOLVER_NC_DT_H
103 std::vector<T> alpha(N, one);
104 const std::vector<T>& lld =
sn.stations[ist].lldscaling;
105 if (lld.empty())
return alpha;
107 for (std::size_t k = 0; k < lld.size(); ++k) {
108 if (!(lld[k] == one)) { varies =
true;
break; }
110 if (!varies)
return alpha;
113 for (std::size_t n = 0; n < N; ++n) {
114 alpha[n] = (n < lld.size()) ? lld[n] : lld[lld.size() - 1];
123 const std::vector<T>& lld =
sn.stations[ist].lldscaling;
124 for (std::size_t k = 0; k < lld.size(); ++k) {
125 if (!(lld[k] == one))
return true;
132std::size_t dt_capacity(
const qn::NetworkStruct<T>& sn, std::size_t ist, std::size_t r) {
133 double cap = sn.stations[ist].cap;
134 if (!sn.classcap.empty() && ist < sn.classcap.size() && r < sn.classcap[ist].size()) {
135 const double cc = sn.classcap[ist][r];
136 if (cc < cap) cap = cc;
138 if (!std::isfinite(cap) || cap <= 0)
return 0;
139 return static_cast<std::size_t
>(cap);
147std::vector<std::size_t> dt_cycle_order(
const qn::NetworkStruct<T>& sn) {
148 const std::size_t M = sn.nstations, R = sn.nclasses;
150 const Matrix<T>& rtst = rt.rtst;
151 const double tol = 1e-8, coarse = 1e-3;
153 std::vector<std::size_t> succ(M, 0);
154 for (std::size_t i = 0; i < M; ++i) {
156 for (std::size_t j = 0; j < M; ++j) {
158 for (std::size_t r = 0; r < R; ++r) {
159 for (std::size_t s = 0; s < R; ++s) {
160 w += num_traits<T>::to_double(rtst(i * R + r, j * R + s));
164 if (std::fabs(w -
static_cast<double>(R)) > coarse && std::fabs(w - 1.0) > coarse) {
165 return std::vector<std::size_t>();
167 if (tgt >= 0)
return std::vector<std::size_t>();
168 tgt =
static_cast<long>(j);
171 if (tgt < 0 ||
static_cast<std::size_t
>(tgt) == i)
return std::vector<std::size_t>();
172 succ[i] =
static_cast<std::size_t
>(tgt);
175 std::vector<bool> visited(M,
false);
176 std::vector<std::size_t> order;
178 for (std::size_t k = 0; k < M; ++k) {
179 if (visited[cur])
return std::vector<std::size_t>();
181 order.push_back(cur);
184 if (cur != 0)
return std::vector<std::size_t>();
185 for (std::size_t i = 0; i < M; ++i) {
186 if (!visited[i])
return std::vector<std::size_t>();
200 if (std::abs(slot_length - 1.0) > 1e-8) {
202 std::snprintf(buf,
sizeof(buf),
"%g", slot_length);
203 dt.
reason = std::string(
"the slot length is ") + buf +
204 ", but a Bernoulli server needs the unit slot: a Geometric steps in whole "
205 "time units, so on any other lattice it is not a one-slot geometric server "
206 "(SolverMAM and SolverLDES accept other lattices)";
209 const std::size_t M =
sn.nstations, R =
sn.nclasses;
213 for (std::size_t i = 0; i < M; ++i) {
214 for (std::size_t r = 0; r < R; ++r) {
215 const T rate =
sn.rates(i, r);
217 if (
sn.procid(i + 1, r + 1) != qn::ProcessType::GEOMETRIC) {
218 dt.
reason =
"a station serves a class with a non-Geometric process; a "
219 "discrete-time model needs Geometric service and interarrival times";
225 for (std::size_t i = 0; i < M; ++i) {
226 if (
sn.stations[i].cdscaling ||
sn.stations[i].jdscaling) {
227 dt.
reason =
"class- or joint-dependent scaling is not covered by the discrete-time "
233 const std::vector<double> njobs =
sn.njobs();
234 bool is_open =
false;
235 for (std::size_t r = 0; r < njobs.size(); ++r) {
236 if (std::isinf(njobs[r])) { is_open =
true;
break; }
241 dt.
reason =
"the discrete-time single-node route handles one open class";
244 std::size_t src = 0, nsrc = 0, ist = 0, nq = 0;
245 for (std::size_t i = 0; i < M; ++i) {
246 if (
sn.stations[i].sched == qn::SchedStrategy::EXT) { src = i; ++nsrc; }
247 else { ist = i; ++nq; }
250 dt.
reason =
"an open discrete-time model needs exactly one Source";
254 dt.
reason =
"the discrete-time single-node route handles one queueing station";
257 if (
sn.stations[ist].sched != qn::SchedStrategy::FCFS) {
258 dt.
reason =
"a Bernoulli server is a FCFS station";
261 if (std::isfinite(
sn.stations[ist].nservers) &&
sn.stations[ist].nservers != 1.0) {
262 dt.
reason =
"a Bernoulli server is a single-server station; use load dependence for "
263 "the multiserver approximation of example 2.10";
266 const T b =
sn.rates(src, 0), p =
sn.rates(ist, 0);
267 if (!(b > zero) || b > one) {
268 dt.
reason =
"the source arrival probability must lie in (0,1]";
271 if (!(p > zero) || p > one) {
272 dt.
reason =
"the service probability must lie in (0,1]";
275 const std::size_t cap = detail::dt_capacity(
sn, ist, 0);
276 const bool has_lld = detail::dt_has_lld(
sn, ist);
277 if (cap == 0 && has_lld) {
278 dt.
reason =
"a load-dependent Bernoulli server needs a finite capacity to bound the "
282 if (cap == 0 && !(b < p)) {
283 dt.
reason =
"an unbounded discrete-time queue needs an arrival probability below the "
284 "service probability";
290 const std::vector<T> alpha = detail::dt_lld_vector(
sn, ist, cap);
292 for (std::size_t n = 0; n < cap; ++n) {
295 dt.
reason =
"load dependence must keep the service probability inside (0,1]";
300 dt.
kind =
"bernoulli1";
309 for (std::size_t r = 0; r < njobs.size(); ++r) {
310 if (std::isfinite(njobs[r])) Ntot += njobs[r];
312 if (Ntot <= 0 || Ntot != std::floor(Ntot)) {
313 dt.
reason =
"the closed population must be a positive integer";
316 const std::size_t N =
static_cast<std::size_t
>(Ntot);
318 std::vector<T> p(M, zero);
319 for (std::size_t i = 0; i < M; ++i) {
320 if (
sn.stations[i].sched != qn::SchedStrategy::FCFS) {
321 dt.
reason =
"a cycle of Bernoulli servers is FCFS throughout";
324 if (std::isfinite(
sn.stations[i].nservers) &&
sn.stations[i].nservers != 1.0) {
325 dt.
reason =
"a multiserver node inside a cycle of geometrical queues has no product "
330 T lo = zero, hi = zero;
331 for (std::size_t r = 0; r < R; ++r) {
332 const T v =
sn.rates(i, r);
334 if (!seen) { lo = v; hi = v; seen =
true; }
335 else {
if (v < lo) lo = v;
if (v > hi) hi = v; }
339 dt.
reason =
"a station of the cycle serves no class";
343 dt.
reason =
"a station has a class-dependent service probability; the discrete-time "
344 "cycle needs one Bernoulli server per node";
348 if (!(p[i] > zero) || !(p[i] < one)) {
349 dt.
reason =
"the product form of theorem 3.2 needs every service probability in (0,1)";
354 const std::vector<std::size_t> order = detail::dt_cycle_order(
sn);
356 dt.
reason =
"the stations do not form a single deterministic cycle; discrete-time FCFS "
357 "networks of other topologies have no product form";
361 dt.
service.assign(M, std::vector<T>(N, zero));
362 for (std::size_t k = 0; k < M; ++k) {
363 const std::vector<T> alpha = detail::dt_lld_vector(
sn, order[k], N);
364 for (std::size_t n = 0; n < N; ++n) {
365 dt.
service[k][n] = p[order[k]] * alpha[n];
367 dt.
reason =
"load dependence must keep every service probability inside (0,1]";
393 const std::size_t M =
sn.nstations, K =
sn.nclasses;
402 out.
sol.C.assign(K, zero);
403 out.
sol.X.assign(K, zero);
406 if (dt.
kind ==
"bernoulli1") {
407 out.
sol.method =
"dt.bernoulli1";
419 if (ratio > 0 && ratio < 1) {
420 const std::size_t need =
static_cast<std::size_t
>(std::ceil(std::log(1e-18)
422 if (need > L) L = need;
424 if (L > 100000) L = 100000;
438 }
else if (dt.
kind ==
"cycle") {
440 bool state_independent =
true;
441 for (std::size_t k = 0; k < dt.
service.size() && state_independent; ++k) {
442 for (std::size_t n = 1; n < dt.
service[k].size(); ++n) {
443 if (!(dt.
service[k][n] == dt.
service[k][0])) { state_independent =
false;
break; }
446 std::vector<T> Qs(M, zero), Us(M, zero), Ts(M, zero);
447 if (state_independent) {
450 out.
sol.method =
"dt.cycle";
452 for (std::size_t k = 0; k < M; ++k) p[k] = dt.
service[k][0];
454 const T x =
nc.throughput();
455 for (std::size_t k = 0; k < M; ++k) {
456 const T q = one - p[k];
457 T ratio = one, tail = zero;
458 for (std::size_t n = 1; n <= N; ++n) {
459 ratio = ratio * q / p[k];
460 tail = tail + ratio / q *
nc.G1[N - n + 1] /
nc.G;
462 Qs[dt.
order[k]] = tail;
463 Us[dt.
order[k]] = x / p[k];
468 out.
sol.method =
"dt.cycleld";
470 for (std::size_t k = 0; k < M; ++k) {
471 const std::vector<T> marg =
nc.marginal(k);
472 T q = zero, t = zero;
473 for (std::size_t n = 0; n <= N; ++n) {
475 if (n >= 1) t = t + marg[n] * dt.
service[k][n - 1];
478 Us[dt.
order[k]] = one - marg[0];
484 const std::vector<double> njobs =
sn.njobs();
485 for (std::size_t i = 0; i < M; ++i) {
486 for (std::size_t r = 0; r < K; ++r) {
488 std::isfinite(njobs[r]) ? njobs[r] /
static_cast<double>(N) : 0.0);
489 out.
sol.Q(i, r) = Qs[i] * share;
490 out.
sol.U(i, r) = Us[i] * share;
491 out.
sol.Tp(i, r) = Ts[i] * share;
492 if (out.
sol.Tp(i, r) > zero) {
493 out.
sol.R(i, r) = out.
sol.Q(i, r) / out.
sol.Tp(i, r);
497 for (std::size_t r = 0; r < K; ++r) {
498 const std::size_t ref =
sn.classes[r].refstat;
499 if (ref >= 1 && ref <= M) out.
sol.X[r] = out.
sol.Tp(ref - 1, r);
500 if (out.
sol.X[r] > zero && std::isfinite(njobs[r])) {
505 throw InputError(
"solver_nc_dt: a discrete time scale was requested but the model is "
506 "not a discrete-time product-form model: " + dt.
reason);
A network plus its refreshed NetworkStruct.
Normalizing constants of a discrete-time closed cycle of Bernoulli servers.
State dependent Bernoulli server on a discrete time scale.
The exception types the port throws.
SnRtStations< T > sn_rt_stations(const qn::NetworkStruct< T > &sn)
DtNcLdResult< T > dpfqn_ncld(const std::vector< std::vector< T > > &P, std::size_t N)
Theorem 3.2 for a cycle whose service probabilities depend on the local queue length.
DtNcResult< T > dpfqn_nc(const std::vector< T > &p, std::size_t N)
Propositions 3.18 and 3.19 for a cycle with state independent service probabilities.
Bernoulli1InfiniteResult< T > dqsys_bernoulli1(const T &b, const T &p)
dqsys_bernoulli1(b, p) with the reference's default L = Inf.
NcSolution< T > solver_nc_dt(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Exact discrete-time analysis of sn.
DtModel< T > nc_is_dt_model(const qn::NetworkStruct< T > &sn, double slot_length=1.0)
Classify sn against the two discrete-time product-form families.
SlottedRequest slotted_request(std::string timescale, bool slotted, double slotlength)
Resolves timescale (empty reads as "auto"), slotted and slotlength as they come from options....
Conservation laws of a layered queueing network, enumerated from its structure.
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
Port of matlab/src/api/sn/sn_rt_stations.m.
Constants of the state dependent cycle, in one common scale.
Constants of the state independent cycle, in one common scale.
Steady-state quantities of a finite-buffer Bernoulli server.
T throughput
carried departures per slot
T normConst
H of theorem 2.3.
T meanSojournTime
in slots, by Little's law
Classification of a model against the discrete-time product form.
std::vector< std::vector< T > > service
p_j(n), [cycle position][n-1]
std::vector< T > service_single
p(n), n = 1..L (bernoulli1)
std::size_t station
0-based queueing station (bernoulli1)
std::size_t capacity
0 means unbounded
T arrival_prob
offered b (bernoulli1)
std::string reason
why not, when kind is "none"
std::string kind
"bernoulli1", "cycle" or "none"
std::size_t source
0-based Source station (bernoulli1)
std::vector< std::size_t > order
stations in cycle order
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
mva::MvaSolution< T > sol
Controls, defaulting to SolverOptions('NC') in the reference.