Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- #define C 300000;
- double genExp(double lambda)
- {
- double u, x;
- u = (double)rand() / (RAND_MAX + 1);
- x = -1 / lambda*log(1 - u);
- return x;
- }
- double genGauss(double medie, double sigma)
- {
- double s = 0; int i;
- for (i = 1; i <= 12; i++)
- s += (double)rand() / RAND_MAX;
- return medie + sigma*(s - 6);
- }
- int main()
- {
- //initializari
- int NS = 1000000;
- double pc = 0;
- double STa = 0;
- double lambda = (2 * 1.609) / C;
- //simulare cerere de acces
- for (int i = 0; i < NS; i++)
- {
- //generare cerere
- double m = 20;
- double sigma = (m - 1) / 3.5;
- double c = genExp(lambda);
- double b = genGauss(m, sigma);
- //tratare cerere(calcul timp acces)
- double n = abs(pc - c);
- if (n == 1)
- STa += 2;
- else
- STa += 1.2 + 0.0012 * (n - 1);
- double T = 7200.0 / 60000;
- STa += T / 2;
- STa += b*T / 255; //ns = 255
- pc = c;
- }
- //calcul timp mediu acces
- double Tma = STa / NS;
- cout << "Timpul mediu de acces este: " << Tma << "ms" << endl;
- int d;
- cin >> d;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement