Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.64 KB | None | 0 0
  1. Node_t *queue1 = create('a');
  2.     Node_t *queue2;
  3.  
  4.     float time1;
  5.     float time2;
  6.  
  7.     for (int i = 0; i < QUEUE_MAX_SIZE - 1; i++)
  8.         Node_push('a', queue1);
  9.  
  10.     srand(time(NULL));
  11.     double t1 = (rand() % 7) * UNIT_OF_TIME;
  12.     double t2 = (1+ rand() % 8) * UNIT_OF_TIME;
  13.  
  14.     int out_count = 0;
  15.     int total = 100;
  16.  
  17.     double oa1_sum_time = 0;
  18.     double oa2_sum_time = 0;
  19.  
  20.     double oa1_100_time = 0;
  21.     double oa2_100_time = 0;
  22.  
  23.     int oa1_count = 0;
  24.     int oa2_count = 0;
  25.  
  26.     char elem;
  27.     while (out_count < 1000)
  28.     {
  29.         elem = pop_front(&queue1);
  30.         double t1 = (rand() % 7) * UNIT_OF_TIME;
  31.         oa1_sum_time += t1;
  32.         oa1_100_time += t1;
  33.         oa1_count++;
  34.         if (get_rand() >= P)
  35.         {
  36.             if (Node_getSize(queue2))
  37.                 Node_push(elem, queue2);
  38.             else
  39.                 queue2 = create(elem);
  40.         }
  41.         else
  42.         {
  43.             Node_push(elem, queue1);
  44.         }
  45.  
  46.         if (Node_getSize(queue2))
  47.         {
  48.             elem = pop_front(&queue2);
  49.             double t2 = (10 + rand() % 8) * UNIT_OF_TIME;
  50.             oa2_sum_time += t2;
  51.             oa2_100_time += t2;
  52.             oa2_count++;
  53.             out_count++;
  54.             Node_push(elem, queue1);
  55.         }
  56.  
  57.         if (out_count == total)
  58.         {
  59.             int in_queue1 = Node_getSize(queue1);
  60.             int in_queue2 = Node_getSize(queue2);
  61.  
  62.             if (oa2_100_time > oa1_100_time)
  63.             {
  64.                 double time_for_one_oa2 = (10 + 8) / 2;
  65.                 double time_for_one_oa1 = (0 + 6) / 2;
  66.  
  67.                 while (oa2_100_time > oa1_100_time)
  68.                 {
  69.                     oa2_100_time -= time_for_one_oa2;
  70.                     in_queue2 += 1;
  71.                     in_queue1 -= 1;
  72.                 }
  73.             }
  74.             in_queue1 = 100 - in_queue2;
  75.             printf("\noa1_100_time = %lf", oa1_100_time);
  76.             printf("\noa2_100_time = %lf", oa2_100_time);
  77.             printf("\nin queue1: %ld", in_queue1);
  78.             printf("\nin queue2: %ld", in_queue2);
  79.             printf("\noa1_count = %d", oa1_count);
  80.             printf("\noa2_count = %d\n", oa2_count);
  81.             total += 100;
  82.         }
  83.  
  84.     }
  85.     printf("\nТеоритическое время = %lf", theoretical_time());
  86.     printf("\nВремя моделирования = %lf\n", oa1_sum_time + oa2_sum_time);
  87.     printf("Время простоя ОА2: %lf\n", oa1_sum_time - oa2_sum_time);
  88.     printf("Погрешность = %lf%%", fabs(fabs(theoretical_time() - (oa1_sum_time + oa2_sum_time)) / theoretical_time())*100);
  89.  
  90.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement