Exemplo n.º 1
0
        public override void Execute(State state, FastPriorityQueue <Event> eventQueue)
        {
            System.Diagnostics.Debug.WriteLine($"ExpectedDepartureStartstation: tram {tram.id}, station: {station.name}, {platform}, Timetable: {timeTableTime}, time: {state.time}");

            // Close doors if it is time to leave
            if (state.time >= timeTableTime)
            {
                // Mark tram as ready for departure
                tram.ReadyForDeparture();

                // Start leaving directly when possible
                SwitchLane lane    = Switch.ExitLaneFor(platform);
                bool       isFirst = station.first == platform;
                if (isFirst && station._switch.SwitchLaneFree(lane))
                {
                    station._switch.UseSwitchLane(lane);
                    eventQueue.Enqueue(new DepartureStartstation(tram, station, platform), state.time);
                }
            }
            // Otherwise let extra passengers enter
            else
            {
                (int pInExtra, List <int> e) = station.BoardPassengers(tram);
                entrances = e;
                int extraTime = Sampling.passengerExchangeTime(0, pInExtra);
                eventQueue.Enqueue(new ExpectedDepartureStartstation(tram, station, platform, timeTableTime), state.time + extraTime);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public override void Execute(State state, FastPriorityQueue <Event> eventQueue)
        {
            // Free the platform
            station.Free(platform);

            // Reset ready for departure
            tram.ResetReadyForDeparture();

            // Claim lane
            SwitchLane lane = Switch.ExitLaneFor(platform);

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

            // Clear the lane it's leaving over in 60s
            eventQueue.Enqueue(new ClearSwitchLane(station, lane), state.time + Config.c.switchClearanceTime);

            // Queue next arrival
            int stationIndex    = state.stations.IndexOf(station);
            int newStationIndex = stationIndex + 1;

            // Make sure trams do not take over each other
            int drivingTime = Sampling.drivingTime(Config.c.transferTimes[stationIndex].averageTime);
            int arrivalTime = station.SignalNextArrival(state.time + drivingTime);

            eventQueue.Enqueue(new ExpectedTramArrival(tram, newStationIndex), arrivalTime);
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
 public ClearSwitchLane(Endstation station, SwitchLane lane)
 {
     this.station = station;
     this.lane    = lane;
 }