Ejemplo n.º 1
0
        //eventHandler for DepartureEndStationEvent
        public override void handleEvent()
        {
            departureStation.numberOfTrams--;

            Queue <TimeSpan> pIn = Simulation.getPassengersIn(departureStation, tram.direction, departureStation.lastDeparture, eventTime);

            if (tram.direction == Direction.Uithof)
            {
                for (int i = pIn.Count(); i > 0; i--)
                {
                    departureStation.remainingPassengersA.Enqueue(pIn.Dequeue());
                }
                departureStation.remainingPassengersA = tram.passengersIn(departureStation.remainingPassengersA, eventTime);
            }
            else
            {
                for (int i = pIn.Count(); i > 0; i--)
                {
                    departureStation.remainingPassengersB.Enqueue(pIn.Dequeue());
                }
                departureStation.remainingPassengersB = tram.passengersIn(departureStation.remainingPassengersB, eventTime);
            }

            departureStation.lastDeparture = eventTime;
            departureStation.remainingDepartures.Remove(eventTime);

            if (departureStation.numberOfTrams > 0)
            {
                departureStation.remainingDepartures = departureStation.remainingDepartures.OrderBy(x => x.TotalSeconds).ToList();
                departureStation.nextDeparture       = departureStation.remainingDepartures[0];
            }
            else
            {
                departureStation.nextDeparture = TimeSpan.FromHours(0);
            }

            //Get traveltime
            int      estimatedTravelTime = Simulation.getTravelTime(departureStation, tram.direction);
            TimeSpan etaNextStation      = eventTime + TimeSpan.FromSeconds(estimatedTravelTime);

            //Check if not faster than last tram
            if (etaNextStation < departureStation.lastEta)
            {
                etaNextStation = TimeSpan.FromSeconds(departureStation.lastEta.TotalSeconds + 1);
            }
            departureStation.lastEta = etaNextStation;

            //gen. eta event & enqueue to eventQueue.
            expectedArrivalSubtStation etaEvent = new expectedArrivalSubtStation(etaNextStation, departureStation.nextStation, tram);

            Simulation.priorityQueue.Enqueue(etaEvent);

            //Console.WriteLine(String.Format("Event: dep.end | time: {0,-8} station: {1,-18} tramID: {2,-2} | pRemained: {3,-4} pIn: {4,-4}",eventTime, departureStation.stationName, tram.id, remainPassengers, inPassengers) + " | lastDeparture: "+ lastdep + " remTrams: " + departureStation.numberOfTrams + " nextDeparture: " + departureStation.nextDeparture );
        }
Ejemplo n.º 2
0
        //eventHandler for DepartureEndStationEvent
        public override void handleEvent()
        {
            int      estimatedTravelTime = Simulation.getTravelTime(departureStation, tram.direction);
            TimeSpan etaNextStation      = TimeSpan.FromSeconds(eventTime.TotalSeconds + estimatedTravelTime);

            //set track A last departure time
            if (tram.direction == Direction.Uithof)
            {
                departureStation.lastDepartureTrackA = eventTime;
                //Check if not faster than last tram
                if (etaNextStation < departureStation.lastEtaTrackA)
                {
                    etaNextStation = TimeSpan.FromSeconds(departureStation.lastEtaTrackA.TotalSeconds + 1);
                }
                departureStation.lastEtaTrackA = etaNextStation;
            }
            //set Track B last departure time
            if (tram.direction == Direction.UtrechtCentraal)
            {
                departureStation.lastDepartureTrackB = eventTime;
                //Check if not faster than last tram
                if (etaNextStation < departureStation.lastEtaTrackB)
                {
                    etaNextStation = TimeSpan.FromSeconds(departureStation.lastEtaTrackB.TotalSeconds + 1);
                }
                departureStation.lastEtaTrackB = etaNextStation;
            }

            // Push new event to queue. checks if end or sub Station
            if (departureStation.getNextStation(tram.direction) is SubStation)
            {
                // subStation event
                // gen. eta event & enqueue to eventQueue.
                expectedArrivalSubtStation etaEvent = new expectedArrivalSubtStation(etaNextStation, (SubStation)departureStation.getNextStation(tram.direction), tram);
                Simulation.priorityQueue.Enqueue(etaEvent);
            }
            else if (departureStation.getNextStation(tram.direction) is EndStation)
            {
                // endStation event
                // gen. eta event & enqueue to eventQueue.
                expectedArrivalEndStation etaEvent = new expectedArrivalEndStation(etaNextStation, (EndStation)departureStation.getNextStation(tram.direction), tram);
                Simulation.priorityQueue.Enqueue(etaEvent);
            }
        }