5#ifndef LINE_SOLVERS_NC_SOLVER_OI_OPEN_CDFRESPT_H
6#define LINE_SOLVERS_NC_SOLVER_OI_OPEN_CDFRESPT_H
62 std::vector<std::vector<Matrix<T> > >
RD;
69inline double oi_open_erlang_c(
double a,
double c) {
70 if (a <= 0.0)
return 0.0;
71 const int ci =
static_cast<int>(c);
72 std::vector<double> logterms(
static_cast<std::size_t
>(ci));
73 double mx = -std::numeric_limits<double>::infinity();
74 for (
int k = 0; k < ci; ++k) {
75 logterms[
static_cast<std::size_t
>(k)] = k * std::log(a) - std::lgamma(k + 1.0);
76 mx = std::max(mx, logterms[
static_cast<std::size_t
>(k)]);
78 const double lastlog = c * std::log(a) - std::lgamma(c + 1.0) - std::log(1.0 - a / c);
79 mx = std::max(mx, lastlog);
80 double S = std::exp(lastlog - mx);
81 for (
double lt : logterms) S += std::exp(lt - mx);
82 return std::exp(lastlog - mx) / S;
101 "solver_oi_open_cdfrespt: the sojourn-time laws are evaluated by a matrix "
102 "exponential on a logarithmic time grid; this backend has no transcendental "
106 const std::size_t M =
sn.nstations, K =
sn.nclasses;
110 "solver_oi_open_cdfrespt serves open networks only.");
115 "getCdfRespT has no exact law for the order-independent LOSS queue; use SolverCTMC "
120 std::vector<std::vector<mam::Map<T> > > laws(M, std::vector<
mam::Map<T> >(K));
121 for (std::size_t i = 0; i < M; ++i) {
123 if (st.
nodetype == qn::NodeType::Source)
continue;
124 const std::string name = st.
name;
125 if (st.
sched == SchedStrategy::OI || st.
sched == SchedStrategy::PAS) {
126 std::vector<T> li(K, zero);
127 for (std::size_t r = 0; r < K; ++r) li[r] = L(i, r);
132 if (ph.
why ==
"unstable")
133 msg =
"station '" + name +
"' is unstable, so it has no stationary response time.";
134 else if (ph.
why ==
"not support-only")
135 msg =
"the rate of OI station '" + name +
136 "' depends on how many jobs of a class are present; the exact "
137 "response-time law (Gardner, Righter 2020) needs a collaborative server "
138 "pool, whose rate depends only on which classes are present.";
139 else if (ph.
why ==
"not nested")
140 msg =
"two classes at OI station '" + name +
141 "' share some but not all servers; the exact response-time law "
142 "(Gardner, Righter 2020) needs a NESTED compatibility structure.";
143 else if (ph.
why ==
"not a pool")
144 msg =
"the rate of OI station '" + name +
145 "' is not the rate of a nested collaborative server pool, which the "
146 "exact response-time law (Gardner, Righter 2020) requires.";
148 msg =
"OI station '" + name +
"' has more than 16 classes with traffic.";
150 "getCdfRespT: " + msg +
151 " Use SolverCTMC, SolverSSA or SolverLDES for this model.");
153 for (std::size_t r = 0; r < K; ++r)
154 if (L(i, r) > zero) laws[i][r] = ph.
PH[r];
155 }
else if (st.
sched == SchedStrategy::INF) {
156 for (std::size_t r = 0; r < K; ++r)
158 }
else if (st.
sched == SchedStrategy::FCFS) {
160 std::size_t rpos = K;
161 for (std::size_t r = 0; r < K; ++r) {
162 if (!(L(i, r) > zero))
continue;
163 if (rpos == K) rpos = r;
165 if (!std::isfinite(rate) || !(rate > 0.0))
continue;
166 const T rho = T(L(i, r) /
sn.rates(i, r));
170 if (!std::isfinite(c) || c <= 0.0) c = 1.0;
173 "getCdfRespT: station '" + name +
174 "' is unstable, so it has no stationary response time.");
175 if (rpos == K)
continue;
176 const T mu =
sn.rates(i, rpos);
180 const T gap = T(cT * mu - a * mu);
183 law.
D0(0, 0) = T(-gap);
185 law.
D0(1, 1) = T(-mu);
187 const T alpha[2] = {PC, T(one - PC)};
189 for (std::size_t p = 0; p < 2; ++p) {
190 const T ex = T(-(law.
D0(p, 0) + law.
D0(p, 1)));
191 for (std::size_t q = 0; q < 2; ++q) law.
D1(p, q) = T(ex * alpha[q]);
193 for (std::size_t r = rpos; r < K; ++r)
194 if (L(i, r) > zero) laws[i][r] = law;
197 "getCdfRespT on an open order-independent network supports OI, INF and FCFS "
199 ". Use SolverCTMC, SolverSSA or SolverLDES for this model.");
204 for (std::size_t i = 0; i < M; ++i)
205 for (std::size_t r = 0; r < K; ++r)
206 if (laws[i][r].order() > 0)
210 if (!(Tm > 0.0))
return out;
211 const std::size_t npts = 100;
212 const double lo = std::log10(Tm) - 2.0;
213 out.
tset.assign(npts, zero);
214 for (std::size_t j = 0; j < npts; ++j) {
215 const double e = lo + 3.0 *
static_cast<double>(j) /
static_cast<double>(npts - 1);
218 for (std::size_t i = 0; i < M; ++i)
219 for (std::size_t r = 0; r < K; ++r) {
220 if (laws[i][r].order() == 0)
continue;
223 for (std::size_t j = 0; j < npts; ++j) {
225 A(j, 1) = out.
tset[j];
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Cumulative distribution of the inter-arrival time of a MAP.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
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.
const char * sched_to_text(SchedStrategy s)
T map_mean(const Map< T > &m)
Mean inter-arrival time, 1/lambda.
std::vector< T > map_cdf(const Map< T > &m, const std::vector< T > &points)
Cumulative distribution of the inter-arrival time at the given points.
OiOpenTraffic< T > oi_open_traffic(const qn::NetworkStruct< T > &sn)
Port of oi_open_traffic.m: the station traffic of an OPEN network.
std::string nc_oi_refusal(const qn::NetworkStruct< T > &sn, const std::string &route="oi")
Port of nc_oi_refusal.m: may the order-independent route ROUTE run on this model?
OiOpenCdfRespT< T > solver_oi_open_cdfrespt(const qn::NetworkStruct< T > &sn, double tol)
Port of solver_oi_open_cdfrespt.m.
OiResptResult< T > pfqn_oi_respt(const std::vector< T > &lambda, const std::function< T(const std::vector< int > &)> &mu, const OiMixedOptions &opt=OiMixedOptions())
Per-class phase-type sojourn laws of an open nested-pool OI station.
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,...
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Exact per-class sojourn-time distribution at an OPEN order-independent (OI) station whose rate is tha...
Exact analysis of an OPEN queueing network mixing order-independent (OI) stations with BCMP product-f...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
A MAP as the pair of matrices (D0, D1).
Return value of solver_oi_open_cdfrespt: RD{ist,r} = [F(t) t] and the shared grid.
std::vector< std::vector< Matrix< T > > > RD
The tuning fields of pfqn_oi_mixed / pfqn_oi_open (OPTIONS in the reference).
double tol
relative tolerance of the 'oi.trunc' branch
Return value of pfqn_oi_respt, mirroring [PH, ok, why].
bool ok
false when the theorem does not apply
std::string why
the reason when ok is false
std::vector< mam::Map< T > > PH
(R) PH[i] is the sojourn time of class i as a renewal MAP (D1 = -D0 * 1 * alpha), for every class wit...
One job class of the network.
double population
infinite for an open class
One station of the network.
double nservers
may be infinite (a Delay, or an inf-scheduled task)