5#ifndef LINE_API_INFER_SN_SET_SERVICE_COC_H
6#define LINE_API_INFER_SN_SET_SERVICE_COC_H
53inline bool map_hyperexp_fit(
double mean,
double scv,
double p,
double* mu1_out,
double* mu2_out,
55 const double E2 = (1.0 + scv) * mean * mean;
56 const double Delta = -4.0 * p * mean * mean + 4.0 * p * p * mean * mean + 2.0 * E2 * p -
58 const double den = E2 * p - 2.0 * mean * mean;
59 auto feasible = [](
double mu1,
double mu2,
double pp) {
60 return std::isfinite(mu1) && std::isfinite(mu2) && mu1 > 0.0 && mu2 > 0.0 &&
61 pp >= 0.0 && pp <= 1.0;
63 if (Delta >= 0.0 && den != 0.0) {
64 double mu2 = (-2.0 * mean + 2.0 * p * mean + std::sqrt(Delta)) / den;
65 double mu1 = mu2 * p / (p - 1.0 + mean * mu2);
66 if (feasible(mu1, mu2, p)) {
72 mu2 = (-2.0 * mean + 2.0 * p * mean - std::sqrt(Delta)) / den;
73 mu1 = mu2 * p / (p - 1.0 + mean * mu2);
74 if (feasible(mu1, mu2, p)) {
81 if (p > 1e-6)
return map_hyperexp_fit(mean, scv, p / 10.0, mu1_out, mu2_out, p_out);
100 const T& rate,
const T& scv) {
101 if (stationIdx == 0 || stationIdx >
sn.nstations)
102 throw InputError(
"sn_set_service_coc: station index out of range");
103 if (classIdx == 0 || classIdx >
sn.nclasses)
104 throw InputError(
"sn_set_service_coc: class index out of range");
105 const std::size_t i = stationIdx - 1, r = classIdx - 1;
106 sn.rates(i, r) = rate;
110 if (std::isnan(rd) || rd <= 0.0 || std::isinf(rd))
return;
113 const T meanVal = T(one / rate);
115 if (std::isnan(sd) || std::fabs(sd - 1.0) < 1e-10) {
117 }
else if (sd < 1.0) {
118 const double kd = std::ceil(1.0 / sd);
119 const std::size_t k =
static_cast<std::size_t
>(kd < 1.0 ? 1.0 : kd);
123 double mu1 = 0.0, mu2 = 0.0, p = 0.99;
132 sn.set_service(stationIdx, classIdx, d);
133 if (i <
sn.disabled.size() && r <
sn.disabled[i].size())
sn.disabled[i][r] =
false;
A network plus its refreshed NetworkStruct.
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
void sn_set_service_coc(qn::NetworkStruct< T > &sn, std::size_t stationIdx, std::size_t classIdx, const T &rate, const T &scv)
Set the service process of (stationIdx, classIdx) from a rate and an SCV, the reference's sn_set_serv...
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
static Distrib hyperexp(const T &p, const T &lambda1, const T &lambda2)
HyperExp(p, lambda1, lambda2): phase i chosen with probability p_i.
static Distrib erlang(const T &phase_rate, std::size_t r)
Erlang(alpha, r): r phases of rate alpha, as MATLAB's Erlang(phaseRate, nphases).
static Distrib exp_mean(const T &m)