5#ifndef LINE_API_ME_ME_TYPES_H
6#define LINE_API_ME_ME_TYPES_H
67inline T num_exp(
const T& v) {
74inline T num_log(
const T& v) {
81inline T num_sqrt(
const T& v) {
88inline T log_factorial(
long k) {
89 T s = num_traits<T>::from_int(0);
90 for (
long j = 2; j <= k; ++j) s += num_log(num_traits<T>::from_int(j));
95inline bool is_is(
const std::vector<long>& c, std::size_t i) {
return c[i] <= 0; }
99std::vector<T> linear_solve(Matrix<T> A, std::vector<T> b) {
100 const std::size_t n = A.rows();
101 if (A.cols() != n || b.size() != n)
102 throw InputError(
"me: linear solve with inconsistent dimensions");
103 const T zero = num_traits<T>::from_int(0);
104 for (std::size_t k = 0; k < n; ++k) {
107 for (std::size_t i = k + 1; i < n; ++i) {
114 if (amax == zero)
throw NumericError(
"me: singular flow balance equations");
116 for (std::size_t j = 0; j < n; ++j) std::swap(A(k, j), A(p, j));
117 std::swap(b[k], b[p]);
119 for (std::size_t i = k + 1; i < n; ++i) {
120 const T f = A(i, k) / A(k, k);
121 if (f == zero)
continue;
122 for (std::size_t j = k; j < n; ++j) A(i, j) -= f * A(k, j);
126 std::vector<T> x(n, zero);
127 for (std::size_t ii = n; ii-- > 0;) {
129 for (std::size_t j = ii + 1; j < n; ++j) s -= A(ii, j) * x[j];
130 x[ii] = s / A(ii, ii);
137inline void check_dims(std::size_t M, std::size_t R,
const Matrix<T>& mu,
const Matrix<T>& Cs,
138 const std::vector<Matrix<T>>& P,
const std::vector<long>& c,
139 const std::vector<char>& insens,
const char* who) {
140 if (M == 0 || R == 0)
throw InputError(std::string(who) +
": M and R must be positive");
141 if (mu.rows() != M || mu.cols() != R || Cs.rows() != M || Cs.cols() != R)
142 throw InputError(std::string(who) +
": mu and Cs must be M x R");
143 if (P.size() != R)
throw InputError(std::string(who) +
": one routing matrix per class");
144 for (std::size_t r = 0; r < R; ++r)
145 if (P[r].rows() != M || P[r].cols() != M)
146 throw InputError(std::string(who) +
": each routing matrix must be M x M");
147 if (c.size() != M)
throw InputError(std::string(who) +
": one server count per station");
148 if (insens.size() != M)
throw InputError(std::string(who) +
": one insens flag per station");
NumericError(const std::string &what)
The exception types the port throws.
Dense matrix and non-owning view.
Number-type abstraction for the templated API port.
Iteration control, mirroring the MATLAB options struct.
Mean-value results shared by the open, closed and mixed algorithms.
Matrix< T > rho
utilizations (M x R)
Matrix< T > L
mean queue lengths (M x R)
Matrix< T > W
mean response times (M x R)
Matrix< T > Ca
arrival scvs (M x R)
Matrix< T > Cd
departure scvs (M x R)
std::vector< T > X
class throughputs (R)
long iter
fixed-point iterations performed
Matrix< T > lambda
per-station throughputs (M x R)