Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dispatcher
- {
- public int clientsHour;
- public int qCnt;
- public int chCnt;
- public int todayClients = 0;
- public int queueClients;
- public int refusedClients = 0;
- public double[] timeClients;
- public List<double> queuePlaces;
- public List<double> channels;
- public void genClients()
- {
- Random rand = new Random();
- double time = 0;
- double ctime = 0;
- timeClients = new double[clientsHour];
- timeClients[0] = 0;
- queuePlaces = new List<double>();
- channels = new List<double>();
- for (int i=0; i<qCnt; i++)
- {
- queuePlaces.Add(0);
- }
- for (int i = 0; i < chCnt; i++)
- {
- channels.Add(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;
- double time = 0;
- double servTime = 0;
- for (int i = 0; i < clientsHour; i++)
- {
- Console.WriteLine(i + " прогон");
- channels.Sort();
- queuePlaces.Sort();
- for (int j = 0; j < qCnt; j++)
- {
- if ((double)queuePlaces[j] != 0)
- {
- // queuePlaces[j] = timeClients[i];
- Console.WriteLine("В очереди");
- }
- }
- servTime = -Math.Log((double)rand.Next(0, 1000) / 1000) / srTimeServHour;
- if ((!checkQueue(i, servTime)) && (double)channels[0] < timeClients[i])
- {
- channels[0] = timeClients[i] + servTime;
- todayClients++;
- channels[0] = Math.Round((double)channels[0], 1);
- Console.WriteLine("Обслужен");
- }
- else
- {
- if ((double)queuePlaces[0] < timeClients[i])
- {
- queuePlaces[0] = timeClients[i];
- }
- else
- {
- refusedClients++;
- Console.WriteLine("Отказался");
- }
- }
- }
- }
- bool checkQueue(int i, double servTime)
- {
- bool flag = false;
- if ((double)queuePlaces[qCnt-1] == 0)
- {
- return false;
- }
- for (int j = 0; j < qCnt; j++)
- {
- channels.Sort();
- if (((double)queuePlaces[j] != 0) && (double)channels[0] < (double)queuePlaces[j])
- {
- channels[0] = (double)queuePlaces[j] + servTime;
- queuePlaces[j] = 0;
- todayClients++;
- channels[0] = Math.Round((double)channels[0], 1);
- }
- }
- if ((double)queuePlaces[qCnt-1] != 0)
- {
- return true;
- }
- return flag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement