184 const std::string& method,
const T& atol,
const NcOptions& nopt) {
185 const std::size_t M = D.
rows();
186 const std::size_t R = D.
cols();
187 if (N.size() != R)
throw InputError(
"pfqn_ncldmx: D and N disagree on the class count");
188 if (lambda.size() != R)
189 throw InputError(
"pfqn_ncldmx: lambda and D disagree on the class count");
190 if (mu.
rows() != M)
throw InputError(
"pfqn_ncldmx: mu and D disagree on the station count");
195 std::vector<std::size_t> openCl, closedCl;
196 for (std::size_t r = 0; r < R; ++r) (N[r] < 0 ? openCl : closedCl).push_back(r);
197 for (std::size_t r : closedCl)
198 if (lambda[r] != zero)
199 throw InputError(
"pfqn_ncldmx: an arrival rate is specified on a closed class");
201 std::vector<int> Nc(closedCl.size(), 0);
203 for (std::size_t a = 0; a < closedCl.size(); ++a) {
204 Nc[a] = N[closedCl[a]];
207 std::size_t width =
static_cast<std::size_t
>(Kc > 0 ? Kc : 1);
220 const std::size_t padCols = (mu.
cols() > width ? mu.
cols() : width) + 1;
222 for (std::size_t i = 0; i < M; ++i)
223 for (std::size_t k = 0; k < padCols; ++k)
224 mup(i, k) = mu.
cols() == 0 ? one : mu(i, k < mu.
cols() ? k : mu.
cols() - 1);
226 std::vector<T> lambdao(R, zero);
227 for (std::size_t r : openCl) lambdao[r] = lambda[r];
240 bool openDiverges =
false;
241 for (std::size_t i = 0; i < M; ++i)
242 if (ec.
E(i, 0) <= zero) { openDiverges =
true;
break; }
244 res.
lGopen = std::numeric_limits<double>::infinity();
251 for (std::size_t i = 0; i < M; ++i) res.
Gopen *= ec.
E(i, 0);
255 for (std::size_t i = 0; i < M; ++i) res.
Gopen *= ec.
E(i, 0);
267 std::vector<bool> sat(M,
false);
268 for (std::size_t i = 0; i < M; ++i) sat[i] = ec.
E(i, 0) <= zero;
269 std::vector<std::size_t> stuckCl, keptCl;
270 for (std::size_t r : closedCl) {
273 for (std::size_t i = 0; i < M && !stuck; ++i) stuck = sat[i] && D(i, r) > zero;
274 (stuck ? stuckCl : keptCl).push_back(r);
276 if (!stuckCl.empty()) {
278 Nc.assign(closedCl.size(), 0);
280 for (std::size_t a = 0; a < closedCl.size(); ++a) {
281 Nc[a] = N[closedCl[a]];
284 width =
static_cast<std::size_t
>(Kc > 0 ? Kc : 1);
287 for (std::size_t i = 0; i < M; ++i)
289 for (std::size_t k = 0; k < ec.
EC.cols(); ++k) ec.
EC(i, k) = one;
294 for (std::size_t i = 0; i < M; ++i)
295 for (std::size_t a = 0; a < closedCl.size(); ++a) Dc(i, a) = D(i, closedCl[a]);
297 for (std::size_t i = 0; i < Zc.
rows(); ++i)
298 for (std::size_t a = 0; a < closedCl.size(); ++a) Zc(i, a) = Z(i, closedCl[a]);
301 for (std::size_t i = 0; i < M; ++i)
302 for (std::size_t k = 0; k < width; ++k) {
303 if (ec.
EC(i, k) == zero)
305 muEff(i, k) = one / ec.
EC(i, k);
318 const std::size_t C = closedCl.size();
319 res.
XN.assign(R, zero);
321 for (std::size_t r : openCl) res.
XN[r] = lambda[r];
322 for (std::size_t r : stuckCl) {
324 for (std::size_t i = 0; i < M; ++i)
325 if (sat[i]) Dsum += D(i, r);
326 for (std::size_t i = 0; i < M; ++i)
330 std::vector<double> lGr(C > 0 ? C : 1, 0.0);
332 for (std::size_t a = 0; a < C; ++a) {
333 if (Nc[a] <= 0)
continue;
334 std::vector<int> Ncr = Nc;
336 lGr[a] = detail::ncldmx_lg(Dc, Ncr, Zc, muEff, method, atol, nopt);
341 for (std::size_t i = 0; i < M; ++i) {
342 bool anyDemand =
false;
343 for (std::size_t a = 0; a < C; ++a)
344 if (Dc(i, a) > zero) { anyDemand =
true;
break; }
345 if (!anyDemand)
continue;
348 for (std::size_t k = 0; k < muhat.
cols(); ++k) muhatRow(0, k) = muhat(i, k);
351 const Matrix<T> Dminus = detail::ncldmx_drop_row(Dc, i);
352 const Matrix<T> muminus = detail::ncldmx_drop_row(muEff, i);
354 for (std::size_t i2 = 0; i2 < M; ++i2)
355 for (std::size_t a = 0; a < C; ++a) DcPlus(i2, a) = Dc(i2, a);
356 for (std::size_t a = 0; a < C; ++a) DcPlus(M, a) = Dc(i, a);
358 for (std::size_t i2 = 0; i2 < M; ++i2)
359 for (std::size_t k = 0; k < muhat.
cols(); ++k) muhatPlus(i2, k) = muhat(i2, k);
360 for (std::size_t k = 0; k < muhat.
cols() && k < fnc.
mu.cols(); ++k)
361 muhatPlus(M, k) = fnc.
mu(0, k);
362 for (std::size_t a = 0; a < C; ++a) {
363 if (Nc[a] <= 0 || !(Dc(i, a) > zero))
continue;
364 std::vector<int> Ncr = Nc;
366 const double lGhat = detail::ncldmx_lg(Dc, Ncr, Zc, muhat, method, atol, nopt);
367 const double lGhatf =
368 detail::ncldmx_lg(DcPlus, Ncr, Zc, muhatPlus, method, atol, nopt);
369 const double lGminus =
370 detail::ncldmx_lg(Dminus, Ncr, Zc, muminus, method, atol, nopt);
372 (std::exp(lGhatf - lGhat) - 1.0) + cshift * (std::exp(lGminus - lGhat) - 1.0);
382 if (!openCl.empty()) {
383 for (std::size_t i = 0; i < M; ++i) {
387 for (std::size_t r : openCl) {
388 if (!(D(i, r) > zero))
continue;
393 "pfqn_ncldmx: an open class saturates a station; its mean queue length is unbounded");
398 for (std::size_t a = 0; a < C; ++a)
400 const std::size_t b = detail::ncldmx_lld_level(mup, i);
401 const std::size_t bcap = b < ec.
EC.cols() ? b : ec.
EC.cols();
403 double acc = ECinf * (Qtot + 1.0);
405 const Matrix<T> Dminus = detail::ncldmx_drop_row(Dc, i);
406 const Matrix<T> muminus = detail::ncldmx_drop_row(muEff, i);
408 for (std::size_t a = 0; a < C; ++a) Drow(0, a) = Dc(i, a);
409 for (std::size_t k = 0; k < muEff.
cols(); ++k) murow(0, k) = muEff(i, k);
411 for (std::size_t n = 0; n + 2 <= b; ++n) {
413 if (delta == 0.0)
continue;
423 Pn = n == 0 ? 1.0 : 0.0;
425 std::vector<std::vector<int> > ks;
426 std::vector<int> cur(C, 0);
428 detail::ncldmx_compositions(
static_cast<int>(n), Nc, 0, cur, ks);
430 ks.push_back(std::vector<int>());
431 for (std::size_t t = 0; t < ks.size(); ++t) {
432 std::vector<int> rest(C, 0);
433 for (std::size_t a = 0; a < C; ++a) rest[a] = Nc[a] - ks[t][a];
434 const double lF = n == 0 ? 0.0
435 : detail::ncldmx_lg(Drow, ks[t], Zzero, murow,
438 detail::ncldmx_lg(Dminus, rest, Zc, muminus, method, atol, nopt);
439 Pn += std::exp(lF + lGbar - res.
lG);
442 acc +=
static_cast<double>(n + 1) * delta * Pn;
445 for (std::size_t r : openCl)