Advertisement
Misipuk

Kurs_Test

Oct 28th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1.  class Dispatcher
  2.     {
  3.         public int clientsHour;
  4.         public int qCnt;
  5.         public int chCnt;
  6.  
  7.  
  8.         public int todayClients = 0;
  9.         public int queueClients;
  10.         public int refusedClients = 0;
  11.         public double[] timeClients;
  12.         public List<double> queuePlaces;
  13.         public List<double> channels;
  14.        
  15.  
  16.         public void genClients()
  17.         {
  18.             Random rand = new Random();
  19.             double time = 0;
  20.             double ctime = 0;
  21.             timeClients = new double[clientsHour];
  22.             timeClients[0] = 0;
  23.             queuePlaces = new List<double>();
  24.             channels = new List<double>();
  25.  
  26.             for (int i=0; i<qCnt; i++)
  27.             {
  28.                 queuePlaces.Add(0);
  29.             }
  30.             for (int i = 0; i < chCnt; i++)
  31.             {
  32.                 channels.Add(0);
  33.             }
  34.  
  35.             for (int i = 1; i < clientsHour; i++)
  36.             {
  37.                 ctime = -Math.Log((double)rand.Next(0, 1000) / 1000) / clientsHour;
  38.                 time = time + ctime * 60;
  39.                 time = Math.Round(time, 1);
  40.                 timeClients[i] = time;
  41.             }
  42.         }
  43.  
  44.         public void processClients()
  45.         {
  46.             Random rand = new Random();
  47.             int srTimeServHour = 12;
  48.             double time = 0;
  49.             double servTime = 0;
  50.             for (int i = 0; i < clientsHour; i++)
  51.             {
  52.                 Console.WriteLine(i + " прогон");
  53.                 channels.Sort();
  54.                 queuePlaces.Sort();
  55.                 for (int j = 0; j < qCnt; j++)
  56.                 {
  57.                     if ((double)queuePlaces[j] != 0)
  58.                     {
  59.                       //  queuePlaces[j] = timeClients[i];
  60.                         Console.WriteLine("В очереди");
  61.                     }
  62.                 }
  63.  
  64.  
  65.                 servTime = -Math.Log((double)rand.Next(0, 1000) / 1000) / srTimeServHour;
  66.  
  67.  
  68.                 if ((!checkQueue(i, servTime)) && (double)channels[0] < timeClients[i])
  69.                 {
  70.                     channels[0] = timeClients[i] + servTime;
  71.                     todayClients++;
  72.                     channels[0] = Math.Round((double)channels[0], 1);
  73.                     Console.WriteLine("Обслужен");
  74.                 }
  75.                 else
  76.                 {
  77.                     if ((double)queuePlaces[0] < timeClients[i])
  78.                     {
  79.                         queuePlaces[0] = timeClients[i];
  80.                     }
  81.                     else
  82.                     {
  83.                         refusedClients++;
  84.                         Console.WriteLine("Отказался");
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.  
  90.         bool checkQueue(int i, double servTime)
  91.         {
  92.             bool flag = false;
  93.             if ((double)queuePlaces[qCnt-1] == 0)
  94.             {
  95.                 return false;
  96.             }
  97.  
  98.             for (int j = 0; j < qCnt; j++)
  99.             {
  100.                 channels.Sort();
  101.                 if (((double)queuePlaces[j] != 0) && (double)channels[0] < (double)queuePlaces[j])
  102.                 {
  103.                     channels[0] = (double)queuePlaces[j] + servTime;
  104.                     queuePlaces[j] = 0;
  105.                     todayClients++;
  106.                     channels[0] = Math.Round((double)channels[0], 1);
  107.                 }
  108.             }
  109.  
  110.             if ((double)queuePlaces[qCnt-1] != 0)
  111.             {
  112.                 return true;
  113.             }
  114.  
  115.             return flag;
  116.         }
  117.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement