Пример #1
0
        private void lookForNew()
        {
            int i = 0;

            //Looking through ships on service
            while (i < shipService.Count)
            {
                //If current ship finished service, than remove it from service
                if (currentTime == shipService[i].timeOut)
                {
                    currentCapacity        += shipService[i].defineShipType();
                    Ship.statTimeInService += shipService[i].timeInService;
                    shipService.RemoveAt(i);
                    NotifyAll?.Invoke("Корабль обслужен");
                    shipCounter++;
                }
                else
                {
                    i++;
                }
            }
            //Checking if we can add on service ship from queue
            if (shipQueue.Count > 0)
            {
                for (int j = 0; j < shipQueue.Count; j++)
                {
                    addShip(shipQueue.Peek());
                }
            }
        }
Пример #2
0
        private void addShip(Ship newShip)
        {
            int n;

            n = newShip.defineShipType();
            //If current ship amount of docks is higher, than current harbor capacity
            if (n > currentCapacity)
            {
                //Add to queue, if it isn't already ship from the queue
                if ((shipQueue.Count == 0) || (newShip != shipQueue.Peek()))
                {
                    NotifyOrder?.Invoke("Корабль добавлен в очередь");
                    shipQueue.Enqueue(newShip);
                }
            }
            else
            {
                //If it is ship from the queue, than remove it from the queue
                if ((shipQueue.Count > 0) && (newShip == shipQueue.Peek()))
                {
                    shipQueue.Dequeue();
                    if (newShip is SmallShip)
                    {
                        NotifyOrder?.Invoke("Малый корабль вышел из очереди и поступил на обслуживание");
                    }
                    else if (newShip is MiddleShip)
                    {
                        NotifyOrder?.Invoke("Средний корабль вышел из очереди и поступил на обслуживание");
                    }
                    else
                    {
                        NotifyOrder?.Invoke("Большой корабль вышел из очереди и поступил на обслуживание");
                    }
                }
                //Reducing current harbor capacity
                currentCapacity -= n;
                if (newShip is SmallShip)
                {
                    NotifyAll?.Invoke("Малый корабль поступил на обслуживание");
                }
                else if (newShip is MiddleShip)
                {
                    NotifyAll?.Invoke("Средний корабль поступил на обслуживание");
                }
                else
                {
                    NotifyAll?.Invoke("Большой корабль поступил на обслуживание");
                }
                NotifyAll?.Invoke($"Время обслуживания {newShip.timeInService} часов");
                //Defining time out of current ship
                newShip.timeOut = currentTime + newShip.timeInService;
                //Adding current ship to service list
                shipService.Add(newShip);
            }
        }
Пример #3
0
        public void addShip(Ship newShip)
        {
            int n;

            n = newShip.defineShipType();
            if (n > currentCapacity)
            {
                if ((shipQueue.Count == 0) || (newShip != shipQueue.Peek()))
                {
                    NotifyOrder?.Invoke("Корабль добавлен в очередь");
                    shipQueue.Enqueue(newShip);
                }
            }
            else
            {
                if ((shipQueue.Count > 0) && (newShip == shipQueue.Peek()))
                {
                    shipQueue.Dequeue();
                    if (newShip is SmallShip)
                    {
                        NotifyOrder?.Invoke("Малый корабль вышел из очереди и поступил на обслуживание");
                    }
                    else if (newShip is MiddleShip)
                    {
                        NotifyOrder?.Invoke("Средний корабль вышел из очереди и поступил на обслуживание");
                    }
                    else
                    {
                        NotifyOrder?.Invoke("Большой корабль вышел из очереди и поступил на обслуживание");
                    }
                }

                currentCapacity -= n;
                if (newShip is SmallShip)
                {
                    NotifyAll?.Invoke("Малый корабль поступил на обслуживание");
                }
                else if (newShip is MiddleShip)
                {
                    NotifyAll?.Invoke("Средний корабль поступил на обслуживание");
                }
                else
                {
                    NotifyAll?.Invoke("Большой корабль поступил на обслуживание");
                }
                NotifyAll?.Invoke($"Время обслуживания {newShip.timeInService} часов");
                newShip.timeOut = currentTime + newShip.timeInService;
                shipService.Add(newShip);
            }
        }
Пример #4
0
 public void NotifyAllTest()
 {
     NotifyAll request = new NotifyAll();
     var       result  = JsonConvert.DeserializeObject <KodiJSON.JSONRPC.Response.NotifyAllResponse>(ExecuteTest.GetResponse(request));
 }
Пример #5
0
        public void Simulate()
        {
            NotifyAll   += DisplayMessage;
            NotifyOrder += DisplayMessage;
            currentTime  = 0;
            Random random = new Random();

            Queue <SmallShip>  smallShipList  = new Queue <SmallShip>();
            Queue <MiddleShip> middleShipList = new Queue <MiddleShip>();
            Queue <BigShip>    bigShipList    = new Queue <BigShip>();


            SmallShip.minTimeInPort = 1;
            SmallShip.maxTimeInPort = 3;
            SmallShip.amountOfDock  = 1;


            MiddleShip.minTimeInPort = 4;
            MiddleShip.maxTimeInPort = 6;
            MiddleShip.amountOfDock  = 2;

            BigShip.minTimeInPort = 6;
            BigShip.maxTimeInPort = 10;
            BigShip.amountOfDock  = 3;

            for (int i = 0; i < 6; i++)
            {
                SmallShip newShip = new SmallShip();
                smallShipList.Enqueue(newShip);
            }

            for (int i = 0; i < 4; i++)
            {
                MiddleShip newShip = new MiddleShip();
                middleShipList.Enqueue(newShip);
            }

            for (int i = 0; i < 1; i++)
            {
                BigShip newShip = new BigShip();
                bigShipList.Enqueue(newShip);
            }

            int randMin = 1;
            int randMax = 2;

            do
            {
                if (currentTime % 2 == 0)
                {
                    //System.Threading.Thread.Sleep();
                    switch (random.Next(1, 4))
                    {
                    case 1:
                        if (smallShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый малый корабль в {currentTime} часов");
                            this.addShip(smallShipList.Dequeue());
                        }
                        break;

                    case 2:
                        if (middleShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый средний корабль в {currentTime} часов");
                            this.addShip(middleShipList.Dequeue());
                        }
                        break;

                    case 3:
                        if (bigShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый большой корабль в {currentTime} часов");
                            this.addShip(bigShipList.Dequeue());
                        }
                        break;

                    default:
                        break;
                    }
                    randMin += currentTime;
                    randMax += currentTime;
                }
                this.lookForNew();
                currentTime++;
            } while (this.counter < 10);
            NotifyAll   -= DisplayMessage;
            NotifyOrder -= DisplayMessage;
            Thread.Sleep(50);
        }
Пример #6
0
        public void Simulate(int A, int B, int C, int D, int E, int F, int G, int H)
        {
            //Defing event hadelers
            NotifyAll         += DisplayAllMessage;
            NotifyOrder       += DisplayQueueMessage;
            NotifyCurrentStat += DisplayCurrentStatMessage;
            NotifyStat        += DisplayStatMessage;
            currentTime        = 0;
            Random random = new Random();
            //Creating queue for all types of ships
            Queue <SmallShip>  smallShipList  = new Queue <SmallShip>();
            Queue <MiddleShip> middleShipList = new Queue <MiddleShip>();
            Queue <BigShip>    bigShipList    = new Queue <BigShip>();

            //Filling queue for all types of ships
            for (int i = 0; i < 30; i++)
            {
                SmallShip newShip = new SmallShip();
                smallShipList.Enqueue(newShip);
            }

            for (int i = 0; i < 15; i++)
            {
                MiddleShip newShip = new MiddleShip();
                middleShipList.Enqueue(newShip);
            }

            for (int i = 0; i < 5; i++)
            {
                BigShip newShip = new BigShip();
                bigShipList.Enqueue(newShip);
            }
            //Defing time intervals for all types of ships
            SmallShip.minTimeInPort  = C;
            SmallShip.maxTimeInPort  = D;
            MiddleShip.minTimeInPort = E;
            MiddleShip.maxTimeInPort = F;
            BigShip.minTimeInPort    = G;
            BigShip.maxTimeInPort    = H;
            //Defing time intervals for ship arrival
            int randMin = A;
            int randMax = B;
            //Finding time of arrival of first ship
            int timeOfNextShip = random.Next(randMin, randMax);

            do
            {
                //Checking if current time is time of arrival of new ship
                if (currentTime == timeOfNextShip)
                {
                    //Defining which type of ship has arrived
                    switch (random.Next(1, 4))
                    {
                    case 1:
                        if (smallShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый малый корабль в {currentTime} часов");
                            this.addShip(smallShipList.Dequeue());
                        }
                        break;

                    case 2:
                        if (middleShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый средний корабль в {currentTime} часов");
                            this.addShip(middleShipList.Dequeue());
                        }
                        break;

                    case 3:
                        if (bigShipList.Count > 0)
                        {
                            NotifyAll?.Invoke($"Поступил новый большой корабль в {currentTime} часов");
                            this.addShip(bigShipList.Dequeue());
                        }
                        break;

                    default:
                        break;
                    }
                    //Changing arrive intervals
                    randMin = currentTime + 1;
                    randMax = currentTime + 2;
                    //Finding time of arrival of next ship
                    timeOfNextShip = random.Next(randMin, randMax);
                }
                this.lookForNew();
                //Increasing current time
                currentTime++;
                //Displaing current statistics
                DisplayCurrentStatus();
                //Thread.Sleep(10);
            } while (this.shipCounter < 50);
            //Displaying all of statistics
            DisplayStatistics();
            NotifyAll         -= DisplayAllMessage;
            NotifyOrder       -= DisplayQueueMessage;
            NotifyCurrentStat -= DisplayCurrentStatMessage;
            NotifyStat        -= DisplayStatMessage;
        }