107 const std::size_t M =
Lin.size();
109 const std::size_t NN =
static_cast<std::size_t
>(N);
112 if (muIn.
rows() != M)
113 throw InputError(
ErrorKind{
"Invalid"},
"pfqn_ldsy_bounds: mu must have one row per station.");
114 for (std::size_t i = 0; i < M; ++i)
115 for (std::size_t n = 0; n < NN; ++n)
116 mu0(i, n) = muIn(i, n < muIn.
cols() ? n : muIn.
cols() - 1);
118 for (std::size_t i = 0; i < M; ++i)
119 for (std::size_t n = 0; n < NN; ++n)
122 "pfqn_ldsy_bounds: rate scalings must be finite and positive.");
124 const auto tabs = [](
const T& x) -> T {
return x < T(0) ? T(-x) : x; };
127 std::vector<std::vector<T> > mu;
128 for (std::size_t i = 0; i < M; ++i) {
129 if (!(
Lin[i] > zero))
continue;
132 for (std::size_t n = 0; n < NN && isinfst; ++n) {
134 if (tabs(T(mu0(i, n) - lin)) > T(tol * lin)) isinfst =
false;
137 Z += T(
Lin[i] / mu0(i, 0));
141 std::vector<T> row(NN);
142 for (std::size_t n = 0; n < NN; ++n) row[n] = mu0(i, n);
151 "pfqn_ldsy_bounds needs a station with positive demand or a positive think time.");
152 const T X = T(NT / Z);
159 const std::size_t Ms = L.size();
160 std::vector<T> muL(Ms), muU(Ms);
161 std::vector<bool> isld(Ms);
162 for (std::size_t i = 0; i < Ms; ++i) {
165 for (std::size_t n = 1; n < NN; ++n) {
166 if (mu[i][n] < muL[i]) muL[i] = mu[i][n];
167 if (mu[i][n] > muU[i]) muU[i] = mu[i][n];
169 isld[i] = T(muU[i] - muL[i]) > T(tol * muU[i]);
171 std::vector<T> lows, highs;
175 std::vector<T> Dlo(Ms), Dhi(Ms);
176 for (std::size_t i = 0; i < Ms; ++i) {
177 Dlo[i] = T(L[i] / muL[i]);
178 Dhi[i] = T(L[i] / muU[i]);
180 info.
thm31_lo = detail::ldsy_mva_x(Dlo, N, Z);
181 info.
thm31_hi = detail::ldsy_mva_x(Dhi, N, Z);
190 for (std::size_t i = 0; i < Ms && nondecr; ++i)
191 for (std::size_t n = 1; n < NN; ++n)
192 if (T(mu[i][n] - mu[i][n - 1]) < T(-(tol * mu[i][n]))) {
198 for (std::size_t i = 0; i < Ms; ++i) {
199 const T thr = T(muU[i] * T(one - tol));
201 while (a < NN && mu[i][a] < thr) ++a;
202 A +=
static_cast<long>(a);
205 std::vector<T> D(Ms);
206 for (std::size_t i = 0; i < Ms; ++i) D[i] = T(L[i] / muU[i]);
207 info.
thm32_lo = detail::ldsy_mva_x(D,
static_cast<int>(N - A), Z);
215 T shi = T(Z / NT), slo = T(Z / NT);
216 for (std::size_t i = 0; i < Ms; ++i) {
217 T rmax = T(NT * mu[i][0]), rmin = rmax;
218 for (std::size_t n = 1; n < NN; ++n) {
220 if (rr > rmax) rmax = rr;
221 if (rr < rmin) rmin = rr;
223 shi += T(L[i] / rmax);
224 slo += T(L[i] / rmin);
235 std::vector<bool> isms(Ms,
false);
236 std::vector<long> cvec(Ms, 0);
238 for (std::size_t i = 0; i < Ms; ++i) {
240 if (!(c > 1 && c < N))
continue;
242 for (std::size_t n = 0; n < NN && ok; ++n) {
244 const T shape = T(mu[i][n] / mu[i][0]);
245 if (tabs(T(shape - cap)) > T(tol * cap)) ok =
false;
254 std::vector<T> Dq(Ms);
255 for (std::size_t i = 0; i < Ms; ++i) Dq[i] = T(L[i] / muL[i]);
257 for (std::size_t i = 0; i < Ms; ++i) {
258 if (!isms[i])
continue;
259 const T m1 = mu[i][0];
261 Dq[i] = T(L[i] / T(cT * m1));
262 Zq += T(L[i] * T(cT - one) / T(cT * m1));
264 info.
thm42_lo = detail::ldsy_mva_x(Dq, N, Zq);
274 for (std::size_t i = 0; i < Ms; ++i) anyld = anyld || isld[i];
276 bool havePrev =
false, haveBest =
false;
277 T prevUb = zero, best = zero;
279 for (
int K = 1; K <= N; ++K) {
281 T Dtot = zero, Dmax = zero;
284 for (std::size_t i = 0; i < Ms; ++i) {
292 for (std::size_t n = 0; n < NN; ++n) {
294 const T v = T(T(nT + KT - one) * mu[i][n] / nT);
295 if (n == 0 || v > muStar) muStar = v;
297 Di = T(L[i] / muStar);
301 if (firstD || Di > Dmax) Dmax = Di;
305 const T capK = T(one / Dmax);
306 const T m = ubK < capK ? ubK : capK;
307 if (!haveBest || m < best) best = m;
309 if (havePrev && !(ubK < prevUb))
break;
318 highs.push_back(best);
322 for (
const T& v : lows)
323 if (v > out.
Xlo) out.
Xlo = v;
325 for (
const T& v : highs)
326 if (v < out.
Xhi) out.
Xhi = v;