5#ifndef LINE_SOLVERS_WRAPPERS_LDES_LDES_WARM_START_H
6#define LINE_SOLVERS_WRAPPERS_LDES_LDES_WARM_START_H
67 const std::size_t M =
sn.nstations, K =
sn.nclasses;
68 if (QN.rows() != M || QN.cols() != K)
69 throw InputError(
"warm_start_placement_from_qlen: QN must be (nstations x nclasses)");
71 for (std::size_t r = 0; r < K; ++r) {
72 const double njobs =
sn.classes[r].population;
73 const bool closed = std::isfinite(njobs);
74 std::vector<double> floors(M, 0.0), fracs(M, -1.0);
75 std::vector<bool> eligible(M,
false);
76 for (std::size_t i = 0; i < M; ++i) {
78 if (!eligible[i])
continue;
81 floors[i] = std::floor(m);
82 fracs[i] = m - floors[i];
84 floors[i] = std::round(m);
88 if (!closed)
continue;
90 for (std::size_t i = 0; i < M; ++i) placed += floors[i];
91 long residual = std::lround(njobs) - std::lround(placed);
92 while (residual > 0) {
95 for (std::size_t i = 1; i < M; ++i)
96 if (fracs[i] > fracs[bi]) bi = i;
97 if (fracs[bi] < 0.0) {
100 std::size_t ref =
sn.classes[r].refstat;
102 if (ref >= 1 && ref <= M && eligible[ref - 1]) at = ref - 1;
103 for (std::size_t i = 0; at == M && i < M; ++i)
104 if (eligible[i]) at = i;
106 throw InputError(
"warm_start_placement_from_qlen: closed class '" +
107 sn.classes[r].name +
"' has no Queue or Delay to start at");
108 P(at, r) +=
static_cast<double>(residual);
133 "warm_start_placement_from_ctmc: a fork-join model is solved on its tag-augmented "
134 "chain; warm-start it from a mean-value solver instead");
135 const std::size_t M =
sn.nstations, K =
sn.nclasses;
137 std::map<std::vector<long>,
double> aggr;
138 for (std::size_t s = 0; s < SSq.
rows(); ++s) {
140 if (p < 1e-14) p = 0.0;
141 std::vector<long> key(M * K);
142 for (std::size_t c = 0; c < M * K; ++c)
147 throw InputError(
"warm_start_placement_from_ctmc: the chain has no states");
149 std::map<std::vector<long>,
double>::const_iterator best = aggr.begin();
150 for (std::map<std::vector<long>,
double>::const_iterator it = aggr.begin(); it != aggr.end();
152 if (it->second > best->second) best = it;
154 for (std::size_t i = 0; i < M; ++i) {
156 for (std::size_t r = 0; r < K; ++r) P(i, r) = static_cast<double>(best->first[i * K + r]);
168 for (std::size_t i = 0; i < P.
rows(); ++i)
169 for (std::size_t r = 0; r < P.
cols(); ++r) o.
init_sol.push_back(P(i, r));
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
The exception types the port throws.
The option and result records of SolverLDES, the discrete-event simulator.
Dense matrix and non-owning view.
CtmcSolution< T > solver_ctmc_analyzer(const NetworkStruct< T > &sn_in, const CtmcOptions &opt)
Port of solver_ctmc_analyzer.m plus the fork-join wrapper of @@SolverCTMC/runAnalyzer....
Matrix< T > ctmc_state_space_aggr(const NetworkStruct< T > &sn, const std::vector< NetState< T > > &space)
Port of StateSpaceAggr: the per-(station, class) job counts of every state, as an (nstates x nstation...
NodeType
Node kinds, with the values of MATLAB NodeType.
bool is_service_station(const qn::NetworkStruct< T > &sn, std::size_t i)
Matrix< double > warm_start_placement_from_qlen(const qn::NetworkStruct< T > &sn, const Matrix< T > &QN)
Port of placementFromMeanQLen: an integer placement from mean queue lengths.
Matrix< double > warm_start_placement_from_ctmc(const qn::NetworkStruct< T > &sn, const ctmc::CtmcOptions &opt)
Port of placementFromCtmcSteadyState: the mode of the aggregate stationary law.
void init_from_placement(LdesOptions &o, const Matrix< double > &P)
Port of initFromSolver's last step: the placement becomes init_sol, STATION-MAJOR (reshape(placement'...
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Port of solver_ctmc.m: the infinitesimal generator of a queueing network, assembled from the enumerat...
Port of solver_ctmc_analyzer.m and the parts of @@SolverCTMC/runAnalyzer.m that surround one solve: t...
The SolverCTMC knobs this port honours.
Everything one CTMC solve produces.
std::vector< std::size_t > fjclassmap
fjclassmap when the model was fork-join, empty otherwise: the ORIGINAL class of each auxiliary siblin...
std::vector< T > pi
stationary distribution over chain.space
The knobs of one LDES run.
double warmupfrac
–warmupfrac, only for tranfilter=fixed
std::string tranfilter
–tranfilter: mser5 | fixed | none
std::vector< double > init_sol
–initsol, the warm-start placement as a STATION-MAJOR vector [st0_cl0, st0_cl1, .....