5#ifndef LINE_LANG_QN_CTMC_BLOCKS_H
6#define LINE_LANG_QN_CTMC_BLOCKS_H
60 return 3 *
sn.nclasses + 1;
66 if (ind == 0 || ind >
sn.nvars.size())
return 0;
68 return sn.nvars[ind - 1].size() > c ?
sn.nvars[ind - 1][c] : 0;
87 std::map<std::size_t, SetupLaw<T>>
setup;
88 std::map<std::size_t, SetupLaw<T>>
delay;
105 return p == ProcessType::EXP || p == ProcessType::ERLANG || p == ProcessType::HYPEREXP ||
106 p == ProcessType::PH || p == ProcessType::APH || p == ProcessType::COXIAN ||
107 p == ProcessType::COX2 || p == ProcessType::MAP || p == ProcessType::MMPP2 ||
108 p == ProcessType::ME || p == ProcessType::RAP;
113 const std::string& cls) {
116 "SolverCTMC needs a Markovian " + what +
" law at " + node +
" for class " + cls +
120 const std::size_t n = d.
D0.rows();
122 for (std::size_t k = 0; k < n; ++k) {
124 for (std::size_t j = 0; j < n; ++j) s += d.
D0(k, j);
144 if (ind == 0 || ind >
sn.nodes.size())
return info;
145 const std::size_t ist =
sn.nodes[ind - 1].station;
146 if (ist == 0)
return info;
147 const typename std::map<std::size_t, SetupDelayOffParam<T>>::const_iterator it =
148 sn.setupparam.find(ist);
149 if (it ==
sn.setupparam.end())
return info;
151 const std::size_t R =
sn.nclasses;
152 std::vector<std::size_t> cls;
153 for (std::size_t r = 1; r <= R; ++r)
157 if (cls.empty())
return info;
158 const std::string& node =
sn.nodes[ind - 1].name;
160 for (std::size_t x = 0; x < cls.size(); ++x) {
162 sn.classes[cls[x] - 1].name);
165 info.
setup[cls[x]] = law;
167 for (std::size_t x = 0; x < cls.size(); ++x) {
169 sn.classes[cls[x] - 1].name);
172 info.
delay[cls[x]] = law;
174 const double c =
sn.stations[ist - 1].nservers;
176 info.
c = std::isfinite(c) && c > 0 ?
static_cast<std::size_t
>(c + 0.5) : 0;
204 if (ind == 0 || ind >
sn.nodes.size())
return a;
205 const std::size_t ist =
sn.nodes[ind - 1].station;
206 if (ist == 0)
return a;
207 const typename std::map<std::size_t, RetrialParam<T>>::const_iterator it =
208 sn.retrialparam.find(ist);
209 if (it ==
sn.retrialparam.end())
return a;
211 for (std::size_t r = 0; r < rp.
retrial_proc.size() && r <
sn.nclasses; ++r)
239 std::vector<std::vector<std::size_t>>& out,
240 std::vector<std::size_t> head = std::vector<std::size_t>()) {
242 head.push_back(total);
246 for (std::size_t first = total + 1; first-- > 0;) {
247 std::vector<std::size_t> h = head;
259 if (ind == 0 || ind >
sn.nodes.size())
return std::vector<double>();
260 const std::size_t ist =
sn.nodes[ind - 1].station;
261 if (ist == 0)
return std::vector<double>();
262 const std::vector<std::size_t>& sp =
sn.stations[ist - 1].server_parallelism;
263 std::vector<double> par(
sn.nclasses, 1.0);
265 for (std::size_t r = 0; r < sp.size() && r <
sn.nclasses; ++r) {
266 par[r] = sp[r] > 1 ?
static_cast<double>(sp[r]) : 1.0;
267 if (sp[r] > 1) any =
true;
269 return any ? par : std::vector<double>();
288 const std::size_t R = in.nclasses;
290 std::map<std::size_t, std::size_t> width;
291 for (std::size_t ind = 1; ind <= in.nodes.size(); ++ind) {
292 const std::size_t ist = in.nodes[ind - 1].station;
293 if (ist == 0)
continue;
295 const std::string& node = in.nodes[ind - 1].name;
301 if (st.
sched != SchedStrategy::FCFS)
303 "SolverCTMC serves setup and delay-off only under FCFS; " + node +
" is " +
305 if (!std::isfinite(c))
307 "Setup and delay-off need a finite number of servers at " + node +
".");
313 std::vector<bool> isreply(R,
false);
314 if (in.replyblock.size() >= ind)
315 for (std::size_t r = 1; r <= R && r <= in.syncreply.size(); ++r) {
316 const std::size_t s = in.syncreply[r - 1];
317 if (s >= 1 && s <= R && in.replyblock[ind - 1].size() >= r &&
318 in.replyblock[ind - 1][r - 1])
319 isreply[s - 1] =
true;
321 for (std::size_t r = 1; r <= R; ++r) {
322 const bool served = !in.disabled[ist - 1][r - 1] &&
323 !in.service[ist - 1][r - 1].disabled &&
324 in.service[ist - 1][r - 1].D0.rows() > 0;
325 if (served && !si.
setup.count(r) && !isreply[r - 1])
327 "Class " + in.classes[r - 1].name +
" is served at " + node +
328 " without a setup and delay-off law, while other classes have one; "
329 "SolverCTMC needs one per served class.");
332 if (in.has_breakdown_node(ind))
333 clash =
"server breakdowns";
334 else if (ind <= in.isbasblocking.size() && in.isbasblocking[ind - 1])
335 clash =
"true BAS blocking";
336 else if (!in.ctmcpool.empty() && in.ctmcpool.count(ind))
337 clash =
"heterogeneous server pools";
339 const typename std::map<std::size_t, RetrialParam<T>>::const_iterator rit =
340 in.retrialparam.find(ist);
341 if (rit != in.retrialparam.end())
342 for (std::size_t r = 0; r < rit->second.retrial_proc.size(); ++r)
343 if (!rit->second.retrial_proc[r].disabled) clash =
"retrials";
345 for (std::size_t r = 1; r <= R; ++r) {
348 in.mapc_of(ist, r) !=
nullptr)
349 clash =
"a non-renewal (MAP) service";
354 "SolverCTMC does not combine setup and delay-off with " + clash +
" at " +
355 node +
". Use SolverLDES.");
356 width[ind] = si.
width;
365 if (in.has_breakdown_node(ind) ||
366 (ind <= in.isbasblocking.size() && in.isbasblocking[ind - 1]))
368 "SolverCTMC does not combine a finite maxAttempts with " +
369 std::string(in.has_breakdown_node(ind) ?
"server breakdowns"
370 :
"true BAS blocking") +
371 " at " + node +
": both keep a trailing block in the station state. Use "
379 if (st.
sched != SchedStrategy::FCFS)
381 "SolverCTMC serves server parallelism only under FCFS; " + node +
" is " +
383 if (!std::isfinite(c))
385 "Server parallelism needs a finite number of servers at " + node +
".");
386 for (std::size_t r = 0; r < par.size(); ++r)
389 "A class at " + node +
" seizes more servers than the " +
390 std::to_string(
static_cast<long>(c)) +
" it has.");
393 "SolverCTMC does not combine server parallelism with setup and delay-off at " +
394 node +
". Use SolverLDES.");
398 if (width.empty())
return false;
400 for (std::map<std::size_t, std::size_t>::const_iterator it = width.begin(); it != width.end();
402 std::vector<std::size_t>& nv = out.
nvars[it->first - 1];
403 if (nv.size() <= col) nv.resize(col + 1, 0);
404 nv[col] = it->second;
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::vector< std::vector< std::size_t > > nvars
sn.nvars, (nnodes x 3R+1): the LOCAL VARIABLE columns each node appends to its state,...
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
const char * sched_to_text(SchedStrategy s)
const char * process_to_text(ProcessType p)
The MATLAB ProcessType name, as sn.procid prints it.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
SetupLaw< T > phase_law(const lang::Distrib< T > &d, const std::string &what, const std::string &node, const std::string &cls)
bool is_phase_type(lang::ProcessType p)
The laws a server-state block takes, python _ph: every CONTINUOUS family with a (D0,...
SetupInfo< T > setup_info(const NetworkStruct< T > &sn, std::size_t ind)
The ACTIVE setup/delay-off block of node ind: the layout, when SolverCTMC appended it.
void attempt_compositions(std::size_t total, std::size_t parts, std::vector< std::vector< std::size_t > > &out, std::vector< std::size_t > head=std::vector< std::size_t >())
Every vector of parts nonnegative integers summing to total, in the order of python compositions: the...
AttemptsLayout attempts_layout(const NetworkStruct< T > &sn, std::size_t ind)
The finite-attempt retrial of node ind as the model declares it, active or not.
SetupInfo< T > setup_layout(const NetworkStruct< T > &sn, std::size_t ind)
The setup/delay-off layout of node ind as the model declares it, whether or not the block is active.
bool ctmc_station_blocks(const NetworkStruct< T > &in, NetworkStruct< T > &out, bool &reachable)
Prepare the copy SolverCTMC solves: validate the setup/delay-off, finite-attempt and server-paralleli...
std::size_t ctmc_tail_col(const NetworkStruct< T > &sn)
The 0-based nvars column that holds the CTMC station block's width.
std::vector< double > parallelism_of(const NetworkStruct< T > &sn, std::size_t ind)
Per-class server degrees n_r (all >= 1) of node ind, or empty when every class seizes one server (pyt...
AttemptsLayout attempts_info(const NetworkStruct< T > &sn, std::size_t ind)
The ACTIVE attempt block of node ind: the layout, when SolverCTMC appended it.
std::size_t ctmc_tail_width(const NetworkStruct< T > &sn, std::size_t ind)
Width of the CTMC station block of node ind (1-based), 0 when it has none.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
A MAP as the pair of matrices (D0, D1).
A finite-attempt retrial station (python attempts_info).
std::size_t M
maxAttempts, the number of attempt levels
std::size_t ist
1-based station
std::size_t cls
1-based retrial class
The parameters of a retrial station: MATLAB sn.retrialProc and friends.
std::vector< int > max_attempts
0 = unbounded
std::vector< lang::Distrib< T > > retrial_proc
retrial_proc[r] is the class-r retrial process; empty = not a retrial class.
Setup and delay-off of a station that powers down when it falls idle.
std::vector< lang::Distrib< T > > setup
per class, disabled = not declared
std::vector< lang::Distrib< T > > delayoff
per class
The setup/delay-off layout of one station (python setup_info).
std::map< std::size_t, SetupLaw< T > > setup
keyed by 1-based class
std::map< std::size_t, SetupLaw< T > > delay
keyed by 1-based class
std::size_t ist
1-based station
std::size_t c
server count
std::size_t width
1 + setup phases + delay-off phases
One setup or delay-off law in phase-type form, and its offset in the block.
Matrix< T > S
sub-generator (D0)
std::vector< T > exit
exit rates -S e
std::vector< T > alpha
initial phase vector
std::size_t off
offset of phase 0 inside the block
One station of the network.
double nservers
may be infinite (a Delay, or an inf-scheduled task)