Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. #define C 300000;
  6.  
  7. double genExp(double lambda)
  8. {
  9. double u, x;
  10. u = (double)rand() / (RAND_MAX + 1);
  11. x = -1 / lambda*log(1 - u);
  12. return x;
  13. }
  14.  
  15.  
  16. double genGauss(double medie, double sigma)
  17. {
  18. double s = 0; int i;
  19. for (i = 1; i <= 12; i++)
  20. s += (double)rand() / RAND_MAX;
  21. return medie + sigma*(s - 6);
  22. }
  23.  
  24. int main()
  25. {
  26. //initializari
  27. int NS = 1000000;
  28. double pc = 0;
  29. double STa = 0;
  30. double lambda = (2 * 1.609) / C;
  31. //simulare cerere de acces
  32. for (int i = 0; i < NS; i++)
  33. {
  34. //generare cerere
  35. double m = 20;
  36. double sigma = (m - 1) / 3.5;
  37. double c = genExp(lambda);
  38. double b = genGauss(m, sigma);
  39.  
  40. //tratare cerere(calcul timp acces)
  41. double n = abs(pc - c);
  42.  
  43. if (n == 1)
  44. STa += 2;
  45. else
  46. STa += 1.2 + 0.0012 * (n - 1);
  47. double T = 7200.0 / 60000;
  48. STa += T / 2;
  49. STa += b*T / 255; //ns = 255
  50. pc = c;
  51. }
  52. //calcul timp mediu acces
  53. double Tma = STa / NS;
  54. cout << "Timpul mediu de acces este: " << Tma << "ms" << endl;
  55. int d;
  56. cin >> d;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement