5#ifndef LINE_IO_MAP2RENV_H
6#define LINE_IO_MAP2RENV_H
55 std::vector<api::SnMapModulation<T>>
mods;
66 std::size_t max_stages = 64) {
71 "map2renv: the model declares no MAP, MMPP2 or MMAP process, so it has no "
72 "random-environment image");
74 const std::size_t P = mods.size();
75 std::vector<std::size_t> orders(P);
76 std::size_t nstages = 1;
77 for (std::size_t p = 0; p < P; ++p) {
78 orders[p] = mods[p].order;
81 if (nstages > max_stages)
82 throw InputError(
"map2renv: the random-environment image of this model has " +
83 std::to_string(nstages) +
84 " stages, above the max_stages cap of " + std::to_string(max_stages) +
85 "; reduce the order of the modulating processes or raise the cap");
88 std::vector<std::vector<std::size_t>> phase_of(nstages, std::vector<std::size_t>(P, 0));
89 for (std::size_t s = 0; s < nstages; ++s) {
91 for (std::size_t p = 0; p < P; ++p) {
92 phase_of[s][p] = rem % orders[p];
98 for (std::size_t s = 0; s < nstages; ++s) {
99 std::string nm =
"Phase";
100 for (std::size_t p = 0; p < P; ++p) nm +=
"_" + std::to_string(phase_of[s][p] + 1);
106 for (std::size_t p = 0; p < P; ++p) {
107 for (std::size_t c = 0; c < mods[p].classes.size(); ++c) {
108 const std::size_t r = mods[p].classes[c];
111 for (std::size_t j = 0; j < D1.
cols(); ++j) rate += D1(phase_of[s][p], j);
112 if (mods[p].arrival) {
122 "map2renv: phase " + std::to_string(phase_of[s][p] + 1) +
123 " of the service process of class " + std::to_string(r) +
124 " at station " + std::to_string(mods[p].ist) +
125 " has zero completion rate: the station never empties while the "
126 "environment sits in that stage, so the stage has no steady state "
127 "and the random-environment image is not defined; model the "
128 "stalled server as a breakdown stage instead");
134 envModel.
set_stage(s, nm,
"item", stage);
139 for (std::size_t s = 0; s < nstages; ++s) {
140 std::size_t stride = 1;
141 for (std::size_t p = 0; p < P; ++p) {
144 for (std::size_t a = 0; a < Qp.
rows(); ++a)
145 for (std::size_t b = 0; b < Qp.
cols(); ++b) Qp(a, b) += D1(a, b);
146 const std::size_t k = phase_of[s][p];
147 for (std::size_t l = 0; l < orders[p]; ++l) {
148 if (l == k)
continue;
151 const std::size_t t =
static_cast<std::size_t
>(
152 static_cast<std::ptrdiff_t
>(s) +
153 (
static_cast<std::ptrdiff_t
>(l) -
static_cast<std::ptrdiff_t
>(k)) *
154 static_cast<std::ptrdiff_t
>(stride));
164 if (info !=
nullptr) {
165 info->nstages = nstages;
166 info->orders = orders;
167 info->is_mmpp =
true;
169 if (!m.is_mmpp) info->is_mmpp =
false;
184 return map2renv(base, info, max_stages);
void init()
Port of Environment.init().
void set_stage(std::size_t e, const std::string &nm, const std::string &type, const qn::NetworkStruct< T > &model)
addStage: name the stage and give it its network.
void add_transition(std::size_t e, std::size_t h, const lang::Distrib< T > &d, const ResetMarginal &reset=ResetMarginal())
addTransition: enable e -> h with a distribution and a reset policy.
A network plus its refreshed NetworkStruct.
void refresh_struct()
The whole chain, in MATLAB's refreshStruct order.
void set_service(std::size_t station, std::size_t cls, const Distrib< T > &d)
A random environment: a port of matlab/src/lang/Environment.m, restricted to what SolverENV reads out...
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
std::vector< SnMapModulation< T > > sn_map_modulation(const qn::NetworkStruct< T > &sn)
env::Environment< T > map2renv(const qn::NetworkStruct< T > &base, Map2RenvInfo< T > *info=nullptr, std::size_t max_stages=64)
env::Environment< T > mapqn2renv(const qn::NetworkStruct< T > &base, Map2RenvInfo< T > *info=nullptr, std::size_t max_stages=64)
Retained name for the transformation now implemented by map2renv, which generalizes it from a single ...
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Port of matlab/src/api/sn/sn_map_modulation.m.
One modulating process: which station and classes it drives, and its blocks.
The INFO output of map2renv: how the stage set was assembled.
bool is_mmpp
True when every process was an MMPP, so the image is exact in structure.
std::vector< api::SnMapModulation< T > > mods
The modulation records themselves.
std::vector< std::size_t > orders
Phase order of each modulated process.
static Distrib exp_rate(const T &r)
static constexpr double Zero