Advertisement
Misipuk

Course_BUp

Oct 28th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. namespace Test
  2. {
  3.     class Dispatcher
  4.     {
  5.         public int clientsHour;
  6.         public int qCnt;
  7.         public int stCnt;
  8.  
  9.  
  10.         public int todayClients = 0;
  11.         public int refusedClients = 0;
  12.         public double[] timeClients;
  13.         public GasStation[] stations;
  14.        
  15.         public Dispatcher()
  16.         {
  17.             clientsHour = 5;
  18.             qCnt = 3;
  19.             stCnt = 2;
  20.         }
  21.  
  22.         public Dispatcher(int clH, int stCount, int qCount)
  23.         {
  24.             clientsHour = clH;
  25.             qCnt = qCount;
  26.             stCnt = stCount;
  27.         }
  28.  
  29.         public void genClients()
  30.         {
  31.             Random rand = new Random();
  32.             double time = 0;
  33.             double ctime = 0;
  34.             timeClients = new double[clientsHour];
  35.             timeClients[0] = 0;
  36.             stations = new GasStation[stCnt];
  37.             for (int i = 0; i<stCnt; i++)
  38.             {
  39.                 stations[i] = new GasStation(qCnt);
  40.             }
  41.             timeClients[0] = 0;
  42.             for (int i = 1; i < clientsHour; i++)
  43.             {
  44.                 ctime = -Math.Log((double)rand.Next(0, 1000) / 1000) / clientsHour;
  45.                 time = time + ctime * 60;
  46.                 time = Math.Round(time, 1);
  47.                 timeClients[i] = time;
  48.             }
  49.         }
  50.  
  51.         public void processClients()
  52.         {
  53.             Random rand = new Random();
  54.             int srTimeServHour = 12;
  55.             int ind = 0;
  56.             for (int i = 0; i < clientsHour; i++)
  57.             {
  58.                 for(int k=0; k<stCnt; k++)
  59.                 {                  
  60.                     while (stations[k].getCnt() != 0)
  61.                     {
  62.                         if (stations[k].queue.Peek() <= timeClients[i])
  63.                         {
  64.                             stations[k].queue.Dequeue();
  65.                             Console.WriteLine("Goes Out");
  66.                         }
  67.                         else
  68.                         {
  69.                             break;
  70.                         }
  71.                     }
  72.                 }
  73.                 ind = getMinIndex();
  74.                 if (stations[ind].getCnt() < qCnt)
  75.                 {
  76.                     stations[ind].Add(timeClients[i], srTimeServHour);
  77.                     todayClients++;
  78.                     Console.WriteLine("Comes");
  79.                 }
  80.                 else
  81.                 {
  82.                     refusedClients++;
  83.                     Console.WriteLine("Refused");
  84.                 }
  85.                
  86.             }
  87.         }
  88.  
  89.         int getMinIndex()
  90.         {
  91.             int minInd = 0;
  92.             int minC = stations[0].getCnt();
  93.             for (int i=0; i<stCnt; i++)
  94.             {
  95.                 if (minC > stations[i].getCnt())
  96.                 {
  97.                     minC = stations[i].getCnt();
  98.                     minInd = i;
  99.                 }
  100.             }
  101.             return minInd;
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  class GasStation
  116.     {
  117.         public Queue<double> queue;
  118.         public int pCnt;
  119.         public double fTime =0;
  120.         Random rand;
  121.  
  122.         public GasStation()
  123.         {
  124.             pCnt = 0;
  125.             queue = new Queue<double>();
  126.             rand = new Random();
  127.         }
  128.  
  129.         public GasStation(int cnt)
  130.         {
  131.             pCnt = cnt;
  132.             queue = new Queue<double>();
  133.             rand = new Random();
  134.         }
  135.  
  136.         public int getCnt()
  137.         {
  138.             return queue.Count;
  139.         }
  140.  
  141.         public void Add(double tClient, int tServ)
  142.         {
  143.             double ctime = 3;
  144.            
  145.             if (queue.Count == 0)
  146.             {
  147.                 fTime = Math.Round(tClient + ctime, 1);
  148.             }
  149.             else
  150.             {
  151.                 fTime = Math.Round(fTime + ctime, 1);
  152.             }
  153.             queue.Enqueue(fTime);
  154.         }
  155.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement