예제 #1
0
        public override void Execute(State state, FastPriorityQueue <Event> eventQueue)
        {
            // Clear switch (no lane cleared if coming from depot)
            SwitchLane lane = fromDepot ? SwitchLane.None : Switch.ArrivalLaneFor(platform);

            eventQueue.Enqueue(new ClearSwitchLane(station, lane), state.time + Config.c.switchClearanceTime);

            // Log
            System.Diagnostics.Debug.WriteLine($"ArrivalEndstation: tram {tram.id}, station: {station.name}, {platform}, {lane}, time: {state.time}");

            // Check if tram can do another round trip if it is at endstation with depot
            if (!station.TramToDepot(state.time))
            {
                // Board and unboard
                (int pOut, int pIn, List <int> e) = station.UnboardAndBoard(tram, tram.passengerCount);
                entrances = e;

                // Calculate when to schedule departure
                // If boarding/unboarding takes shorter than the turnaround, take the turnaround time
                int passengerTransferTime = state.time + Math.Max(Sampling.passengerExchangeTime(pOut, pIn), Config.c.turnAroundTimeFor(station));
                int nextDepartureTime     = station.NextDeparture();
                int nextEventTime         = Math.Max(passengerTransferTime, nextDepartureTime);

                // Queue event
                eventQueue.Enqueue(new ExpectedDepartureStartstation(tram, station, platform, nextDepartureTime), nextEventTime);
            }
            // Transfer tram to depot
            else
            {
                station.Free(platform);
            }
        }
예제 #2
0
        public override void Execute(State state, FastPriorityQueue <Event> eventQueue)
        {
            System.Diagnostics.Debug.WriteLine($"ClearSwitchLane: {station.name}, {lane}, time: {state.time}");

            /* Kind of a critical point here:
             * - We have a possible departing tram
             * - We have a possible incoming tram
             * - The incoming tram can never go to the departing tram platform (not free yet)
             * This means that if the departing tram is on platform B, the arriving tram cannot enter because the cross will be used.
             * If the departing tram is on platform A, they can drive past each other, so it's okay to queue the arrival. */

            // Clear the switch
            station._switch.FreeSwitch(lane);

            // Check if tram is in queue at switch, give priority to departing trams
            var(departingTram, departingPlatform) = station.GetFirstDepartingTram();
            if (departingTram != null)
            {
                // Queue the departure
                SwitchLane departureLane = Switch.ExitLaneFor(departingPlatform);
                station._switch.UseSwitchLane(departureLane);

                Event e = new DepartureStartstation(departingTram, station, departingPlatform);
                eventQueue.Enqueue(e, state.time);
            }

            // Get the best free platform
            Platform arrivalPlatform = station.BestFreePlatform();

            if (arrivalPlatform != Platform.None)
            {
                // Check if there are trams arriving from the depot, if so prefer those.
                if (station.depotQueue.Count > 0)
                {
                    Tram  arrivingTram = station.OccupyFromDepotQueue(arrivalPlatform);
                    Event e            = new ArrivalEndstation(arrivingTram, station, arrivalPlatform, true);
                    eventQueue.Enqueue(e, state.time);
                }
                // Check if we can enqueue an arrival as well
                else if (station.HasQueue() && station._switch.SwitchLaneFree(Switch.ArrivalLaneFor(arrivalPlatform)))
                {
                    // Get best available platform && queue
                    Tram       arrivingTram = station.OccupyFromQueue(arrivalPlatform);
                    SwitchLane lane         = Switch.ArrivalLaneFor(arrivalPlatform);
                    station._switch.UseSwitchLane(lane);

                    // Queue the arrival
                    Event e = new ArrivalEndstation(arrivingTram, station, arrivalPlatform);
                    eventQueue.Enqueue(e, state.time);
                }
            }
        }
예제 #3
0
        public override void Execute(State state, FastPriorityQueue <Event> eventQueue)
        {
            System.Diagnostics.Debug.WriteLine($"ExpectedArrivalEndstation: tram {tram.id}, station: {station.name}, time: {state.time}");

            // Check if there is a free platform available and if switch lane is free
            Platform bestPlatform = station.BestFreePlatform();

            if (station.depotQueue.Count == 0 && bestPlatform != Platform.None)
            {
                station.Occupy(tram, bestPlatform);
                station._switch.UseSwitchLane(Switch.ArrivalLaneFor(bestPlatform));
                eventQueue.Enqueue(new ArrivalEndstation(tram, station, bestPlatform), state.time);
            }
            else
            {
                station.Enqueue(tram);
            }
        }