Esempio n. 1
0
 //Поиск курьера
 public void FindCourier(List <Courier> couriers)
 {
     if (status == StatusLetter.Application)
     {
         bool freeCourier = false;
         //Есть ли свободные курьеры
         foreach (Courier c in couriers)
         {
             if (c.status == StatusCourier.Free)
             {
                 freeCourier = true;
                 break;
             }
         }
         if (freeCourier)
         {
             ownCourier = couriers.First(x => x.status == StatusCourier.Free);
             foreach (Courier c in couriers)
             {
                 if (c.status == StatusCourier.Free && branches.timeBetween(c.currentPlace, sender).inMinutes < branches.timeBetween(ownCourier.currentPlace, sender).inMinutes)
                 {
                     ownCourier = c;
                 }
             }
             ownCourier.status      = StatusCourier.HasApplication;
             ownCourier.application = this;
             ownCourier.nextPlace   = sender;
             this.status            = StatusLetter.Engaged;
             //Время между текущим и следующим положениями курьера
             Random rand = new Random();
             ownCourier.timeCurrNext = branches.timeBetween(ownCourier.currentPlace, sender) + new Time(0, rand.Next(5, 35));
             if (ownCourier.timeCurrNext.inMinutes != 0)
             {
                 ownCourier.timeSingleTranfers = ownCourier.timeSingleTranfers + ownCourier.timeCurrNext;
                 ownCourier.amountSingleTransfers++;
             }
         }
     }
 }
Esempio n. 2
0
 //Приезд в филиал
 void arrivalToBranch(Time currentTime, List <Letter> letters)
 {
     //Если курьер приехал на место
     if (timeCurrNext.inMinutes == 0)
     {
         lettersToBranch(currentTime);
         lettersFromBranch(currentTime, letters);
         if (amountReceived == 0 && status == StatusCourier.GetLetter)
         {
             status = StatusCourier.Free;
         }
         getApplication(currentTime);
         //Если у курьера есть письма, выбираем письмо, которое нужно доставить раньше всех
         if (status == StatusCourier.GetLetter)
         {
             recieveLetters.OrderBy(x => (x.Deadline - branches.timeBetween(currentPlace, x.Destination)));
             nextPlace = recieveLetters.First(x => x.status == StatusLetter.Taking).Destination;
             Random rand = new Random();
             timeCurrNext = branches.timeBetween(currentPlace, nextPlace) + new Time(0, rand.Next(5, 35));
         }
     }
 }