Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <time.h>
  4. #define NS 1000000
  5. #define S 3
  6. #define MAX 1000
  7. #define miu1 10
  8. #define miu2 10
  9.  
  10. using namespace std;
  11.  
  12. struct trei {
  13. double MS;
  14. double Tp1;
  15. double Tp2;
  16. };
  17.  
  18. double genGauss(double medie, double sigma)
  19. {
  20. double s = 0;
  21. int i;
  22. for (i = 1; i <= 12; i++)
  23. {
  24. s += (double)rand() / RAND_MAX;
  25. }
  26. return medie + sigma * (s - 6);
  27. }
  28. double genExp(double lambda)
  29. {
  30. double u;
  31. u = (double)rand() / (RAND_MAX + 1);
  32. double x;
  33. x = (-1) / lambda * log(1 - u);
  34. return x;
  35. }
  36.  
  37. int evUrmator(int n1, int n2, double Dis, trei Q1[300], trei Q2[300])
  38. {
  39. if (n1 == 0 && n2 == 0)
  40. return 1;
  41. if (n2 == 0)
  42. {
  43. if (Dis <= Q1[1].Tp1) return 1;
  44. if (Q1[1].Tp2 == 0) return 2;
  45. return 4;
  46. }
  47. if (n1 == 0)
  48. {
  49. if (Dis <= Q2[1].Tp2) return 1;
  50. if (Q1[1].Tp1 == 0) return 3;
  51. return 5;
  52. }
  53. if (Dis < Q1[1].Tp1 && Dis < Q2[1].Tp2)
  54. return 1;
  55. if (Q1[1].Tp1 < Q2[1].Tp2)
  56. {
  57. if (Q1[1].Tp2 == 0) return 2;
  58. return 4;
  59. }
  60. //if(Q2[1].Tp2<=Q1[1].Tp1)
  61. else
  62. {
  63. if (Q2[1].Tp1 == 0) return 3;
  64. return 5;
  65. }
  66. return 0;
  67. }
  68.  
  69. void Ms_lab12(double lambda)
  70. {
  71. double DS = NS / lambda;
  72. trei Q1[300], Q2[300];
  73. double Dis;
  74. double STR = 0;
  75. double CT = 0;
  76. double ceas = 0;
  77. int n1, n2;
  78. n1 = n2 = 0;
  79. double Tp1;
  80. double Tp2;
  81. Tp1 = genExp(miu1);
  82. Tp2 = genExp(miu2);
  83. Q1[1].MS = ceas;
  84. Q1[1].Tp1 = Tp1;
  85. Q1[1].Tp2 = Tp2;
  86. Dis = genExp(lambda);
  87. int ajutor;
  88. do {
  89. ajutor = evUrmator(n1, n2, Dis, Q1, Q2);
  90.  
  91. if (ajutor == 1)
  92. {
  93. ceas += Dis;
  94. for (int i = 1; i <= 2; ++i)
  95. {
  96. if (n1 > 0)
  97. {
  98. Q1[1].Tp1 -= Dis;
  99. }
  100. if (n2 > 0)
  101. {
  102. Q2[1].Tp2 -= Dis;
  103. }
  104. }
  105. Tp1 = genExp(miu1);
  106. Tp2 = genExp(miu2);
  107. if (n1 <= n2)
  108. {
  109. n1++;
  110. Q1[n1].MS = ceas;
  111. Q1[n1].Tp1 = Tp1;
  112. Q1[n1].Tp2 = Tp2;
  113. }
  114. else
  115. {
  116. n2++;
  117. Q2[n2].MS = ceas;
  118. Q2[n2].Tp1 = Tp1;
  119. Q2[n2].Tp2 = Tp2;
  120. }
  121.  
  122. Dis = genExp(lambda);
  123. }
  124. else if (ajutor == 2)
  125. {
  126. ceas += Q1[1].Tp1;
  127. Q2[1].Tp2 -= Q1[1].Tp1;
  128. Dis -= Q1[1].Tp1;
  129. STR += ceas - Q1[1].MS;
  130. CT++;
  131. --n1;
  132. for (int i = 1; i <= n1; ++i)
  133. {
  134. Q1[i] = Q1[i + 1];
  135. }
  136. }
  137. else if (ajutor == 3)
  138. {
  139. ceas += Q2[1].Tp2;
  140. Q1[1].Tp1 -= Q2[1].Tp2;
  141. Dis -= Q2[1].Tp2;
  142. STR += ceas - Q2[1].MS;
  143. CT++;
  144. --n2;
  145. for (int i = 1; i <= n2; ++i)
  146. {
  147. Q2[i] = Q2[i + 1];
  148. }
  149. }
  150. else if (ajutor == 4)
  151. {
  152. ceas += Q1[1].Tp1;
  153. Q2[1].Tp2 -= Q1[1].Tp1;
  154. Dis -= Q1[1].Tp1;
  155. Q1[1].Tp1 = 0;
  156. ++n2;
  157. Q2[n2] = Q1[1];
  158. --n1;
  159. for (int i = 1; i <= n1; ++i)
  160. {
  161. Q1[i] = Q1[i + 1];
  162. }
  163. }
  164. else if (ajutor == 5)
  165. {
  166. ceas += Q2[1].Tp2;
  167. Q1[1].Tp1 -= Q2[1].Tp2;
  168. Dis -= Q2[1].Tp2;
  169. Q2[1].Tp2 = 0;
  170. ++n1;
  171. Q1[n1] = Q2[1];
  172. --n2;
  173. for (int i = 1; i <= n2; ++i)
  174. {
  175. Q2[i] = Q2[i + 1];
  176. }
  177. }
  178. } while (ceas < DS);
  179.  
  180. double TRM;
  181. TRM = (STR / NS);
  182. cout << "TRM = " << TRM << endl << endl << endl;
  183. }
  184.  
  185. int main(void)
  186. {
  187. double i = 4;
  188. while (i <= 9)
  189. {
  190. cout << "------------------------------------------- LAMBDA = " << i << " -------------------------------------------" << endl << endl << endl;
  191. Ms_lab12(i);
  192. ++i;
  193. }
  194. system("pause");
  195. return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement