public override BusStopEvents CreateEvent(int busStopNumber)
        {
            BoardingEvent _evnt = null;

            try
            {
                if (busStopNumber.Equals(16))
                {
                    busStopNumber = 1;
                }
                _evnt = new BoardingEvent()
                {
                    BusStopNumber = busStopNumber,
                    TypeofEvent   = EventType.PersonBoarding,
                    BusNumber     = this.BusNumber,
                    BoardingTime  = this.BoardingTime
                };

                //Calcuate next execution time.
                _evnt.TimeofExecution = this.TimeofExecution; //ClockTime + _driveTime + NumberofPersonInQueueAtStop * BoardingTime
            }
            catch (Exception ex)
            {
                ApplicationLog.Instance.WriteException(ex);
            }
            return(_evnt);
        }
        public void Initialize()
        {
            int _totalBusStops = Configuration.TotalNumberofBusStops;
            int _busNumber     = 1;

            for (int _nIndex = 1; _nIndex <= _totalBusStops; _nIndex++)
            {
                int _currentPassangersAtStop = 0;
                if (_dicNumberOfPersonsByStopNumber.Keys.Contains(_nIndex))
                {
                    _dicNumberOfPersonsByStopNumber.TryGetValue(_nIndex, out _currentPassangersAtStop);
                }

                if ((_nIndex % 3).Equals(0))
                {
                    //Bus arrival event
                    BusArrivalEvent _busArrivalEvent = new BusArrivalEvent()
                    {
                        NumberofPersonInQueueAtStop = _currentPassangersAtStop,
                        BusNumber    = _busNumber,
                        ClockTime    = _nIndex,
                        DriveTime    = Configuration.BusDriveTime,
                        BoardingTime = Configuration.BoardingTime
                    };

                    _busArrivalEvent = _busArrivalEvent.CreateEvent(_nIndex) as BusArrivalEvent;

                    AddToQueue(_busArrivalEvent);

                    BoardingEvent _boardingEvent = new BoardingEvent()
                    {
                        NumberofPersonInQueueAtStop = _currentPassangersAtStop,
                        BusNumber       = _busNumber,
                        TimeofExecution = _busArrivalEvent.TimeofExecution,
                        BoardingTime    = Configuration.BoardingTime
                    };

                    _boardingEvent = _boardingEvent.CreateEvent(_nIndex) as BoardingEvent;

                    AddToQueue(_boardingEvent);
                    _busNumber += 1;
                }
                //Person Arrival event.
                PersonArrivalEvent _personArrival = new PersonArrivalEvent()
                {
                    NumberofPersonInQueueAtStop = _currentPassangersAtStop,
                    ClockTime          = _nIndex,
                    AverageArrivalTime = Configuration.MeanInterArrivalRate
                };
                _personArrival = _personArrival.CreateEvent(_nIndex) as PersonArrivalEvent;
                AddToQueue(_personArrival);
                _dicNumberOfPersonsByStopNumber.Add(_nIndex, _personArrival.NumberofPersonInQueueAtStop);
            }
        }
        public override BusStopEvents ExecuteEvent(BusStopEvents evnt)
        {
            BoardingEvent _event = null;

            try
            {
                _event = evnt as BoardingEvent;
                ApplicationLog.Instance.WriteInfo(string.Format("There are {0} passengers at stop# {1} and hence bus will be at stop for {2}.", _event.NumberofPersonInQueueAtStop, _event.BusStopNumber, BoardingTime * _event.NumberofPersonInQueueAtStop));
                do
                {
                    ApplicationLog.Instance.WriteInfo(string.Format("Boarding passenger in Bus# {0} at stop# {1}.", BusNumber, _event.BusStopNumber));
                    _event.NumberofPersonInQueueAtStop -= 1;
                }while (_event.NumberofPersonInQueueAtStop > 0);
                ApplicationLog.Instance.WriteInfo(string.Format("All passengers have boarded Bus# {0} at stop# {1}.", BusNumber, _event.BusStopNumber));
            }
            catch (Exception ex)
            {
                ApplicationLog.Instance.WriteException(ex);
            }
            return(_event);
        }