Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Test
- {
- class Dispatcher
- {
- public int clientsHour;
- public int qCnt;
- public int stCnt;
- public int todayClients = 0;
- public int refusedClients = 0;
- public double[] timeClients;
- public GasStation[] stations;
- public Dispatcher()
- {
- clientsHour = 5;
- qCnt = 3;
- stCnt = 2;
- }
- public Dispatcher(int clH, int stCount, int qCount)
- {
- clientsHour = clH;
- qCnt = qCount;
- stCnt = stCount;
- }
- public void genClients()
- {
- Random rand = new Random();
- double time = 0;
- double ctime = 0;
- timeClients = new double[clientsHour];
- timeClients[0] = 0;
- stations = new GasStation[stCnt];
- for (int i = 0; i<stCnt; i++)
- {
- stations[i] = new GasStation(qCnt);
- }
- timeClients[0] = 0;
- for (int i = 1; i < clientsHour; i++)
- {
- ctime = -Math.Log((double)rand.Next(0, 1000) / 1000) / clientsHour;
- time = time + ctime * 60;
- time = Math.Round(time, 1);
- timeClients[i] = time;
- }
- }
- public void processClients()
- {
- Random rand = new Random();
- int srTimeServHour = 12;
- int ind = 0;
- for (int i = 0; i < clientsHour; i++)
- {
- for(int k=0; k<stCnt; k++)
- {
- while (stations[k].getCnt() != 0)
- {
- if (stations[k].queue.Peek() <= timeClients[i])
- {
- stations[k].queue.Dequeue();
- Console.WriteLine("Goes Out");
- }
- else
- {
- break;
- }
- }
- }
- ind = getMinIndex();
- if (stations[ind].getCnt() < qCnt)
- {
- stations[ind].Add(timeClients[i], srTimeServHour);
- todayClients++;
- Console.WriteLine("Comes");
- }
- else
- {
- refusedClients++;
- Console.WriteLine("Refused");
- }
- }
- }
- int getMinIndex()
- {
- int minInd = 0;
- int minC = stations[0].getCnt();
- for (int i=0; i<stCnt; i++)
- {
- if (minC > stations[i].getCnt())
- {
- minC = stations[i].getCnt();
- minInd = i;
- }
- }
- return minInd;
- }
- }
- }
- class GasStation
- {
- public Queue<double> queue;
- public int pCnt;
- public double fTime =0;
- Random rand;
- public GasStation()
- {
- pCnt = 0;
- queue = new Queue<double>();
- rand = new Random();
- }
- public GasStation(int cnt)
- {
- pCnt = cnt;
- queue = new Queue<double>();
- rand = new Random();
- }
- public int getCnt()
- {
- return queue.Count;
- }
- public void Add(double tClient, int tServ)
- {
- double ctime = 3;
- if (queue.Count == 0)
- {
- fTime = Math.Round(tClient + ctime, 1);
- }
- else
- {
- fTime = Math.Round(fTime + ctime, 1);
- }
- queue.Enqueue(fTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement