Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <random>
- #include <string>
- using namespace std;
- void connectFilesToStandardInputOutputStreams()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- }
- random_device rnd;
- mt19937 mersenne(rnd());
- int randomSign()
- {
- return (mersenne() % 2 == 0 ? 1 : -1);
- }
- double generateSmallNumber(int N = 100)
- //функция возвращает случайное значение от [-9;9]/N
- //можно использовать для изменения начальных условий
- //и наблюдением за системой
- {
- double res = (mersenne() % 10) / (N);
- return res * randomSign();
- }
- struct params
- {
- int K;
- int N;
- params(int k, int n)
- {
- K = max(k, 3);
- N = max(n, 3);
- }
- };
- vector< vector< long double > > calcPij
- (double lambda, params par, vector<double> mu)
- {
- int N = par.N;
- int K = par.K;
- double p0 = 1;
- vector< vector< long double > > P
- (K + 1, vector<long double>(N + 1));
- for (int i = 1; i <= K; ++i)
- for (int j = 1; j <= N; ++j)
- P[i][j] = 0;
- P[1][N] = lambda / mu[N];
- P[1][N - 1] = ((lambda + mu[N]) / mu[N - 1])*P[1][N];
- for (int i = N - 1; i > 1; --i)
- P[1][i - 1] = (lambda + mu[i]) / mu[i - 1] * P[1][i];
- P[2][N] = (lambda + mu[1]) / mu[N] * P[1][1] - lambda / mu[N];
- for (int i = 2; i <= K - 1; ++i)
- {
- P[i][N - 1] = (lambda + mu[N]) / mu[N - 1] * P[i][N]
- - (lambda / mu[N - 1]) * P[i - 1][N];
- for (int j = N - 1; j >= 2; --j)
- P[i][j - 1] = (lambda + mu[j]) / mu[j - 1] * P[i][j]
- - (lambda / mu[j - 1]) * P[i - 1][j];
- P[i + 1][N] = (lambda + mu[1]) / mu[N] * P[i][1]
- - (lambda / mu[N]) * P[i - 1][1];
- }
- P[K][N - 1] = mu[N] / mu[N - 1] * P[K][N]
- - (lambda / mu[N - 1]) * P[K - 1][N];
- for (int i = N - 1; i >= 2; --i)
- {
- P[K][i - 1] = mu[i] / mu[i - 1] * P[K][i]
- - (lambda / mu[i - 1]) * P[K - 1][i];
- }
- long double sumP = 0;
- for (int i = 1; i <= K; ++i)
- for (int j = 1; j <= N; ++j)
- sumP += P[i][j];
- p0 = 1 / (p0 + sumP);
- for (int i = 1; i <= K; ++i)
- for (int j = 1; j <= N; ++j)
- P[i][j] *= p0;
- P[0][0] = p0;
- return P;
- }
- struct features
- {
- int cntLambda;
- double lambda;
- vector<double> mu;
- double p0;
- double X;
- double gamma;
- double p;
- double Ploss;
- double Ek;
- double Ekq;
- double W;
- double Wq;
- double U;
- features() {}
- features(int cntLambda, double lambda, vector<double> mu, double p0, double X,
- double gamma, double p, double Ploss, double Ek, double Ekq, double W,
- double Wq, double U) : cntLambda(cntLambda), lambda(lambda), mu(mu), p0(p0), X(X),
- gamma(gamma), p(p), Ploss(Ploss), Ek(Ek), Ekq(Ekq), W(W), Wq(Wq), U(U)
- {}
- void Show()
- {
- string line = string(30, '-');
- line += "\n";
- cout << line;
- cout << "Test #" << cntLambda << endl;
- cout << line;
- cout << "lambda = " << lambda <<endl;
- cout << "mu [] = ";
- for (auto v : mu)
- cout << v << "\t";
- cout << line;
- cout << "U = " << U << endl;
- cout << "gamma = " << gamma << endl;
- cout << "p0 = " << p0 << endl;
- cout << "p = " << p << endl;
- cout << "E[K] = " << Ek << endl;
- cout << "E[Kq] = " << Ekq << endl;
- cout << "W = " << W << endl;
- cout << "Wq = " << Wq << endl;
- cout << "X = " << X << endl;
- cout << "\n====================================\n";
- }
- static void ShowInfoAboutSystem()
- {
- cout << "K - размер системы,\n";
- cout << "N - количество этапов в системе,\n";
- cout << "cntLambda - количество различных лямбда"
- << "(корень квадратный из количества экспериментов) ,\n";
- cout << "lambda[i] - интенсивность потока на iм эксперементе,\n";
- cout << "mu[i] - вектор интенсивности обслуживания на iм эксперементе,\n";
- cout << "lambdaMin - минимальное значение lambda,\n";
- cout << "deltaLambda - разница lambda между двумя последующими экспериментами,\n";
- cout << "coefficientMu - коэффициент роста интенсивности Mu,\n";
- cout << "gamma - пропускная способность,\n";
- cout << "Ploss - вероятность потери,\n";
- cout << "p - коэффициент использования,\n";
- cout << "X - м.о. длительности обслуживания,\n";
- cout << "Ek - м.о. числа требований в системе,\n";
- cout << "Ekq - м.о. числа требований в очереди,\n";
- cout << "W - м.о. длительности пребывания требований в системе,\n";
- cout << "Wq - м.о. длительности пребывания требований в очереди,\n";
- cout << "U - rоэффициент использования системы.";
- }
- };
- int main() {
- connectFilesToStandardInputOutputStreams();
- params par(8, 5);
- int cntLambda = 15;
- vector<double> lambda(cntLambda);
- vector<vector<double> > mu(cntLambda, vector<double>(par.N + 1));
- double lambdaMin = 0.0002;
- double deltaLambda = 0.019990;
- double coefficientMu = 1.1;
- for (int i = 0; i < cntLambda; ++i)
- {
- lambda[i] = (i == 0 ? lambdaMin : lambda[i - 1] + deltaLambda);
- for (int j = 0; j < par.N; ++j)
- mu[i][j + 1] = coefficientMu*(i + 1);
- }
- cout << setprecision(3);
- vector<features> result(cntLambda * cntLambda);
- int cnt = 0;
- for (int f = 0; f < cntLambda; f++)
- {
- for (int i = 0; i < cntLambda; ++i)
- {
- vector<double> Mu = mu[f];
- vector<vector<long double> > P
- = calcPij(lambda[i], par, mu[f]);
- double p0 = P[0][0];
- double SumPkN = 0;
- for (int k = 1; k <= par.K; ++k)
- SumPkN += P[k][par.N];
- double X = 0;
- for (int n = 1; n <= par.N; ++n)
- X += 1 / Mu[n];
- double gamma = (1. - p0) / X;
- double p = lambda[i] * X;
- double Ploss = (p0 + p - 1) / p;
- double SumPKn = 0;
- double Ek = 0;
- for (int k = 1; k <= par.K; ++k)
- for (int n = 1; n <= par.N; ++n)
- Ek += P[k][n] * k;
- double Ekq = Ek - (1 - p0);
- double W = Ek / gamma;
- double Wq = Ekq / gamma;
- double U = gamma * X;
- result[cnt++] = features(cnt, lambda[i], Mu, p0, X, gamma, p, Ploss,
- Ek, Ekq, W, Wq, U);
- }
- for (auto v : result)
- v.Show();
- features::ShowInfoAboutSystem();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement