5#ifndef LINE_SOLVERS_LDES_LDES_GETAVG_H
6#define LINE_SOLVERS_LDES_LDES_GETAVG_H
51 bool any_open =
false;
52 for (std::size_t k = 0; k < K; ++k)
53 if (std::isinf(L.
classes[k].population)) any_open =
true;
54 if (!any_open)
return;
55 const double dinf = std::numeric_limits<double>::infinity();
56 std::vector<bool> sat(M,
false);
57 for (std::size_t i = 0; i < M; ++i) {
58 const double c = L.
stations[i].nservers;
59 if (std::isinf(c) || c <= 0.0)
continue;
60 if (L.
stations[i].nodetype == line::qn::NodeType::Source)
continue;
61 bool exempt = (i < L.
cap.size() && std::isfinite(L.
cap[i]) && L.
cap[i] >= 0.0);
64 if (!exempt && i < L.
classcap.size())
65 for (std::size_t k = 0; k < L.
classcap[i].size() && k < K; ++k)
66 if (std::isinf(L.
classes[k].population) && std::isfinite(L.
classcap[i][k]) &&
72 for (
const auto& rg : L.
regions)
73 if (i < rg.members.size() && rg.members[i]) { exempt =
true;
break; }
78 for (std::size_t k = 0; k < K; ++k)
82 for (
double v : L.
stations[i].lldscaling)
83 if (!std::isnan(v) && !std::isinf(v) && v > lldpeak) lldpeak = v;
84 std::vector<double> rho(K, 0.0);
85 double rho_open = 0.0, rho_tot = 0.0;
86 bool has_open =
false;
87 for (std::size_t k = 0; k < K; ++k) {
88 const double rate = L.
rates(i, k), t = r.
TN(i, k);
89 if (rate > 0.0 && t > 0.0) {
90 rho[k] = t / (c * lldpeak * rate);
92 if (std::isinf(L.
classes[k].population)) {
98 if (!(has_open && rho_open >= 1.0 && rho_tot > 0.0))
continue;
100 for (std::size_t k = 0; k < K; ++k) {
101 const bool open = std::isinf(L.
classes[k].population);
103 r.
UN(i, k) = open ? rho[k] / rho_open : 0.0;
115 for (std::size_t ch = 0; ch < L.
nchains; ++ch) {
116 std::vector<std::size_t> inchain;
119 for (std::size_t k = 0; k < K; ++k) {
120 if (!L.
chains[ch][k])
continue;
121 inchain.push_back(k);
122 if (std::isinf(L.
classes[k].population)) open =
true;
123 else pop += L.
classes[k].population;
125 if (open || inchain.empty() || ch >= L.
visits.size())
continue;
126 std::vector<std::vector<double>> vsat(M, std::vector<double>(inchain.size(), 0.0));
128 for (std::size_t i = 0; i < M; ++i) {
129 if (!sat[i])
continue;
131 for (std::size_t j = 0; j < inchain.size(); ++j) {
132 vsat[i][j] = L.
visits[ch](isf, inchain[j]);
136 if (!(vtot > 0.0))
continue;
137 for (std::size_t i = 0; i < M; ++i)
138 for (std::size_t j = 0; j < inchain.size(); ++j) {
139 const std::size_t k = inchain[j];
140 const double t = vsat[i][j] > 0.0 ? dinf : 0.0;
144 if (r.
QN.
rows() == M && r.
QN.
cols() == K) r.
QN(i, k) = pop * vsat[i][j] / vtot;
162 for (std::size_t c = 0; c < L.
nchains; ++c)
163 for (std::size_t i = 0; i < M; ++i) {
165 for (std::size_t k = 0; k < K; ++k) V(i, k) += L.
visits[c](sf - 1, k);
169 for (std::size_t i = 0; i < M; ++i)
170 for (std::size_t k = 0; k < K; ++k) {
171 const bool is_place = L.
stations[i].nodetype == line::qn::NodeType::Place;
172 if ((L.
disabled[i][k] && !is_place) || !(RN(i, k) > 0.0))
continue;
173 if (RN(i, k) < fine) {
178 for (std::size_t cc = 0; cc < L.
nchains; ++cc)
179 if (L.
chains[cc][k]) c = cc;
181 const std::size_t rs = L.
classes[k].refstat;
186 for (std::size_t r : L.
inchain[c]) den += V(rs - 1, r - 1);
188 if (den > 0.0) WN(i, k) = RN(i, k) * V(i, k) / den;
190 for (std::size_t i = 0; i < M; ++i)
191 for (std::size_t k = 0; k < K; ++k)
192 if (WN(i, k) < 10.0 * fine) WN(i, k) = 0.0;
219 for (std::size_t i = 0; i < r.
RN.
rows(); ++i)
220 for (std::size_t k = 0; k < r.
RN.
cols(); ++k) {
221 const double rn = r.
RN(i, k), wn = r.
WN(i, k);
222 if (rn > 0.0 && std::isfinite(rn) && std::isfinite(wn)) r.
WNCI(i, k) = r.
RNCI(i, k) * (wn / rn);
A network plus its refreshed NetworkStruct.
std::size_t stateful_of_station(std::size_t st) const
std::vector< std::vector< bool > > chains
(nchains x nclasses)
std::vector< std::size_t > refclass
(nchains) 1-based class, 0 = none
std::vector< std::vector< bool > > disabled
Matrix< double > procid() const
sn.procid (M x K): the ProcessType id of each (station, class) pair, as refreshProcessTypes....
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< std::vector< std::size_t > > inchain
1-based class indices per chain
std::vector< std::vector< double > > classcap
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
std::vector< Region > regions
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
The option and result records of SolverLDES, the discrete-event simulator.
Dense matrix and non-owning view.
bool process_is_batch(ProcessType p)
True when an EVENT of this process releases (or, as a service process, completes) a BATCH of jobs who...
ImpatienceType
Impatience kinds, with the values of MATLAB ImpatienceType.
line::Matrix< double > ldes_residt_from_respt(const line::qn::NetworkStruct< double > &L, const line::Matrix< double > &RN)
The per-JOB residence time the reference document carries as WN: snGetResidTFromRespT,...
void ldes_apply_getavg(const line::qn::NetworkStruct< double > &sn, LdesResult &r)
getAvg applied to an engine result in place: WN becomes the per-job residence time and AN/WN are re-d...
void ldes_cap_unstable_open_stations(const line::qn::NetworkStruct< double > &L, LdesResult &r)
The instability cap the reference document carries: LdesCLI writes after solver.getAvg(),...
void sn_arvr_state_dependent_balance(const qn::NetworkStruct< T > &L, Matrix< T > &AN, const Matrix< T > &TN, Matrix< T > *WN)
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Arrival rates at stations fed by a JSQ or SQ(d) dispatcher, from flow balance.
static constexpr double FineTol
One ldes-result document, parsed.