Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node_t *queue1 = create('a');
- Node_t *queue2;
- float time1;
- float time2;
- for (int i = 0; i < QUEUE_MAX_SIZE - 1; i++)
- Node_push('a', queue1);
- srand(time(NULL));
- double t1 = (rand() % 7) * UNIT_OF_TIME;
- double t2 = (1+ rand() % 8) * UNIT_OF_TIME;
- int out_count = 0;
- int total = 100;
- double oa1_sum_time = 0;
- double oa2_sum_time = 0;
- double oa1_100_time = 0;
- double oa2_100_time = 0;
- int oa1_count = 0;
- int oa2_count = 0;
- char elem;
- while (out_count < 1000)
- {
- elem = pop_front(&queue1);
- double t1 = (rand() % 7) * UNIT_OF_TIME;
- oa1_sum_time += t1;
- oa1_100_time += t1;
- oa1_count++;
- if (get_rand() >= P)
- {
- if (Node_getSize(queue2))
- Node_push(elem, queue2);
- else
- queue2 = create(elem);
- }
- else
- {
- Node_push(elem, queue1);
- }
- if (Node_getSize(queue2))
- {
- elem = pop_front(&queue2);
- double t2 = (10 + rand() % 8) * UNIT_OF_TIME;
- oa2_sum_time += t2;
- oa2_100_time += t2;
- oa2_count++;
- out_count++;
- Node_push(elem, queue1);
- }
- if (out_count == total)
- {
- int in_queue1 = Node_getSize(queue1);
- int in_queue2 = Node_getSize(queue2);
- if (oa2_100_time > oa1_100_time)
- {
- double time_for_one_oa2 = (10 + 8) / 2;
- double time_for_one_oa1 = (0 + 6) / 2;
- while (oa2_100_time > oa1_100_time)
- {
- oa2_100_time -= time_for_one_oa2;
- in_queue2 += 1;
- in_queue1 -= 1;
- }
- }
- in_queue1 = 100 - in_queue2;
- printf("\noa1_100_time = %lf", oa1_100_time);
- printf("\noa2_100_time = %lf", oa2_100_time);
- printf("\nin queue1: %ld", in_queue1);
- printf("\nin queue2: %ld", in_queue2);
- printf("\noa1_count = %d", oa1_count);
- printf("\noa2_count = %d\n", oa2_count);
- total += 100;
- }
- }
- printf("\nТеоритическое время = %lf", theoretical_time());
- printf("\nВремя моделирования = %lf\n", oa1_sum_time + oa2_sum_time);
- printf("Время простоя ОА2: %lf\n", oa1_sum_time - oa2_sum_time);
- printf("Погрешность = %lf%%", fabs(fabs(theoretical_time() - (oa1_sum_time + oa2_sum_time)) / theoretical_time())*100);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement