8#ifndef LINE_API_MAM_QBD_SETUPDELAYOFF_MMK_H
9#define LINE_API_MAM_QBD_SETUPDELAYOFF_MMK_H
42SetupDelayoffMMk<T> setupdelayoff_mmk_solve(
int k,
int nmax,
const std::function<T(
int)>& lam,
43 const T& mu,
const T& alpharate,
const T& alphascv,
44 const T& betarate,
const T& betascv,
double& ptop) {
47 const int na =
static_cast<int>(Ta.
rows());
48 std::vector<T> ta(na, zero);
49 for (
int i = 0; i < na; ++i) {
51 for (
int j = 0; j < na; ++j) s += Ta(i, j);
55 const int nb =
static_cast<int>(Tb.
rows());
56 std::vector<T> tb(nb, zero);
57 for (
int i = 0; i < nb; ++i) {
59 for (
int j = 0; j < nb; ++j) s += Tb(i, j);
64 const int L = 3 + na + nb;
65 std::vector<std::vector<int>> states;
66 std::map<std::vector<int>, std::size_t> index;
67 states.push_back(std::vector<int>(L, 0));
73 std::vector<Arc> arcs;
74 std::vector<std::pair<std::vector<int>, T>> out;
75 auto emit = [&](
const std::vector<int>& st,
const T& rate,
int i1,
int dv1,
int i2,
int dv2) {
76 std::vector<int> x = st;
78 if (i2 >= 0) x[i2] += dv2;
79 out.emplace_back(x, rate);
81 for (std::size_t head = 0; head < states.size(); ++head) {
82 const std::vector<int> st = states[head];
84 const int q = st[0], b = st[1], a = st[2];
85 int ssum = 0, dsum = 0;
86 for (
int i = 0; i < na; ++i) ssum += st[3 + i];
87 for (
int j = 0; j < nb; ++j) dsum += st[3 + na + j];
88 const int off = k - b - a - ssum - dsum;
90 const T l = n < nmax ? lam(n) : zero;
93 emit(st, l, 2, -1, 1, 1);
94 }
else if (dsum > 0) {
95 for (
int j = 0; j < nb; ++j)
96 if (st[3 + na + j] > 0)
98 3 + na + j, -1, 1, 1);
100 emit(st, l, 0, 1, 3, 1);
102 emit(st, l, 0, 1, -1, 0);
107 if (q > 0) emit(st, rb, 0, -1, -1, 0);
108 else emit(st, rb, 1, -1, 3 + na, 1);
110 for (
int i = 0; i < na; ++i) {
111 const int si = st[3 + i];
112 if (si <= 0)
continue;
113 for (
int i2 = 0; i2 < na; ++i2)
118 std::vector<int> x = st;
129 for (
int j = 0; j < nb; ++j) {
130 const int dj = st[3 + na + j];
131 if (dj <= 0)
continue;
132 for (
int j2 = 0; j2 < nb; ++j2)
138 for (
const auto& o : out) {
139 auto it = index.find(o.first);
141 if (it == index.end()) {
144 states.push_back(o.first);
148 arcs.push_back(Arc{head, to, o.second});
151 const std::size_t m = states.size();
153 for (
const Arc& arc : arcs) {
154 Q(arc.from, arc.to) += arc.rate;
155 Q(arc.from, arc.from) -= arc.rate;
164 if (total <= 0)
return res;
166 T QN = zero, B = zero;
167 for (std::size_t i = 0; i < m; ++i) {
169 const T p = T(pi[i] / norm);
226 const T& alpharate,
const T& alphascv,
227 const T& betarate,
const T& betascv) {
229 "qbd_setupdelayoff_mmk requires transcendental arithmetic");
232 throw InputError(
"qbd_setupdelayoff_mmk needs k >= 1 servers and a positive service rate");
237 if (std::isfinite(N)) {
238 const int pop =
static_cast<int>(std::llround(N));
239 if (pop <= 0)
return res;
243 const std::function<T(
int)> lam = [pop, Z](
int n) {
246 return detail::setupdelayoff_mmk_solve<T>(k, pop, lam, mu, alpharate, alphascv, betarate,
251 throw InputError(
"qbd_setupdelayoff_mmk: the open queue is unstable, arrival rate " +
255 const std::function<T(
int)> lam = [rate](int) {
return rate; };
256 int nmax = 2 * k + 32;
258 res = detail::setupdelayoff_mmk_solve<T>(k, nmax, lam, mu, alpharate, alphascv, betarate,
Steady-state distribution of a continuous-time Markov chain.
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Dense matrix and non-owning view.
Matrix< T > coxian_phase_subgen(const T &rate, const T &scv)
Sub-generator of the canonical Coxian form with the given RATE and SCV, entered at phase 1 (the coxia...
SetupDelayoffMMk< T > qbd_setupdelayoff_mmk(int k, double N, const T &arv, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean number present and throughput of a k-SERVER queue whose servers each pay a setup when woken from...
std::vector< T > ctmc_solve(const Matrix< T > &Qin)
Steady-state distribution of a continuous-time Markov chain.
Conservation laws of a layered queueing network, enumerated from its structure.
Number-type abstraction for the templated API port.
Mean queue length of an M/M/1 queue with a setup delay and a delayed-off period, solved as a QBD.
static constexpr double FineTol
static constexpr double Zero
Mean number present and throughput of the setup/delayed-off pool.
T QN
mean number at the station: queued, waiting for a setup or in service
T XN
throughput of the station