Advertisement
Leedwon

Untitled

May 1st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1.  
  2. // 12-6
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include "queue1.h"
  8.  
  9. const int MIN_PER_HR = 60;
  10. bool newcustomer(double x);
  11.  
  12. int main()
  13. {
  14.     using std::cin;
  15.     using std::cout;
  16.     using std::endl;
  17.     srand(time(NULL));
  18.  
  19.     cout << "Przypadek: 2 bankomaty" << endl;
  20.     cout << "Podaj maksymalna dlugosc kolejki oby 2 bankomatow: ";
  21.     int qs;
  22.     cin >> qs;
  23.     Queue atm1(qs);
  24.     Queue atm2(qs);
  25.  
  26.  
  27.     cout << "Podaj symulowany czas (w godzinach) ";
  28.     int hr;
  29.     cin >> hr;
  30.     long cycletime = hr * MIN_PER_HR;
  31.  
  32.  
  33.     cout << "Podaj srednia liczbe klientow na godzine: ";
  34.     double customers_per_hour;
  35.     cin >> customers_per_hour;
  36.     double min_per_customer = MIN_PER_HR / customers_per_hour;
  37.  
  38.     Item temp;
  39.     long turnaways = 0;
  40.     long served = 0;
  41.     long served1 = 0;
  42.     long served2 = 0;
  43.     long customers = 0;
  44.     long sum_line1 = 0;
  45.     long sum_line2 = 0;
  46.     long total_sum_line;
  47.     int wait_time1 = 0;
  48.     int wait_time2 = 0;
  49.     long line_wait1 = 0;
  50.     long line_wait2 = 0;
  51.     long total_line_wait;
  52.  
  53.     for (int cycle = 0; cycle < cycletime; cycle++)
  54.     {
  55.         if (newcustomer(min_per_customer))
  56.         {
  57.             if (atm1.isfull() && atm2.isfull())
  58.                 turnaways++;
  59.             else if (!atm1.isfull() && !atm2.isfull())
  60.             {
  61.                 customers++;
  62.                 temp.set(cycle);
  63.                 if (atm1 < atm2)
  64.                     atm1.enqueue(temp);
  65.                 else
  66.                     atm2.enqueue(temp);
  67.             }
  68.             else
  69.             {
  70.                 if (atm1.isfull() && !atm2.isfull())
  71.                 {
  72.                     customers++;
  73.                     temp.set(cycle);
  74.                     atm2.enqueue(temp);
  75.  
  76.                 }
  77.                 else if (!atm1.isfull() && atm2.isfull())
  78.                 {
  79.                     customers++;
  80.                     temp.set(cycle);
  81.                     atm1.enqueue(temp);
  82.                 }
  83.             }
  84.         }
  85.         if (wait_time1 <= 0 && !atm1.isempty())
  86.         {
  87.             atm1.dequeue(temp);
  88.             wait_time1 = temp.ptime();
  89.             line_wait1 += cycle - temp.when();
  90.             served1++;
  91.         }
  92.         if (wait_time1 > 0)
  93.             wait_time1--;
  94.         sum_line1 += atm1.queuecount();
  95.  
  96.         if (wait_time2 <= 0 && !atm2.isempty())
  97.         {
  98.             atm2.dequeue(temp);
  99.             wait_time2 = temp.ptime();
  100.             line_wait2 += cycle - temp.when();
  101.             served2++;
  102.         }
  103.         if (wait_time2 > 0)
  104.             wait_time2--;
  105.         sum_line2 += atm2.queuecount();
  106.     }
  107.     total_line_wait = line_wait1 + line_wait2;
  108.     total_sum_line = sum_line1 + sum_line2;
  109.     served = served1 + served2;
  110.  
  111.  
  112.     if (customers > 0)
  113.     {
  114.         cout << "Liczba przyjetych klientow w oby 2 bankomatach: " << customers << endl;
  115.         cout << "Liczba klientow odrzuconych: " << turnaways << endl;
  116.         cout << "Liczba klientow obsluzonych w oby 2 bankomatach: " << served << endl;
  117.         cout << "srednia dlugosc kolejki w bankomacie 1: ";
  118.         cout << double(sum_line1) / cycletime << endl;
  119.         cout << "srednia dlugosc kolejki w bankomacie 2: ";
  120.         cout << double(sum_line2) / cycletime << endl;
  121.         cout << "srednia dlugosc kolejki lacznie: ";
  122.         cout << (double(sum_line1) / cycletime + double(sum_line2) / cycletime) / 2 << endl;
  123.         cout << double(total_sum_line) / cycletime << endl;
  124.         cout << "sredni czas oczekiwania w bankomacie 1: ";
  125.         cout << double(line_wait1) / served1 << " minut" << endl;
  126.         cout << "sredni czas oczekiwania w bankomacie 2: ";
  127.         cout << double(line_wait2) / served2 << " minut" << endl;
  128.         cout << "sredni czas oczekiwania lacznie: ";
  129.         cout << (double(line_wait1) / served1 + double(line_wait2) / served2) / 2 << " minut" << endl;
  130.         cout << double(total_line_wait) / served << endl;
  131.     }
  132.     else
  133.     {
  134.         cout << "brak klientow!\n";
  135.     }
  136.     cout << "Gotowe.\n";
  137.     return 0;
  138. }
  139.  
  140. bool newcustomer(double x)
  141. {
  142.     return std::rand() * x / RAND_MAX < 1;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement