Examples of TripTimes


Examples of org.opentripplanner.routing.trippattern.TripTimes

        return GtfsLibrary.getRouteName(getPattern().route);
    }

    public State traverse(State state0) {
        //int trip = state0.getTrip();
        TripTimes tripTimes = state0.getTripTimes();
        int dwellTime = tripTimes.getDwellTime(stopIndex);
        StateEditor s1 = state0.edit(this);
        s1.setBackMode(getMode());
        s1.incrementTimeInSeconds(dwellTime);
        s1.incrementWeight(dwellTime);
        return s1.makeState();
View Full Code Here

Examples of org.opentripplanner.routing.trippattern.TripTimes

     */
    public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boolean boarding) {
        /* Search at the state's time, but relative to midnight on the given service day. */
        int time = serviceDay.secondsSinceMidnight(s0.getTimeSeconds());
        // NOTE the time is sometimes negative here. That is fine, we search for the first trip of the day.
        TripTimes bestTrip = null;
        Stop currentStop = pattern.getStop(stopIndex);
        // Linear search through the timetable looking for the best departure.
        // We no longer use a binary search on Timetables because:
        // 1. we allow combining trips from different service IDs on the same tripPattern.
        // 2. We mix frequency-based and one-off TripTimes together on tripPatterns.
        // 3. Stoptimes may change with realtime updates, and we cannot count on them being sorted.
        //    The complexity of keeping sorted indexes up to date does not appear to be worth the
        //    apparently minor speed improvement.
        int bestTime = boarding ? Integer.MAX_VALUE : Integer.MIN_VALUE;
        // Hoping JVM JIT will distribute the loop over the if clauses as needed.
        // We could invert this and skip some service days based on schedule overlap as in RRRR.
        for (TripTimes tt : tripTimes) {
            if ( ! serviceDay.serviceRunning(tt.serviceCode)) continue; // TODO merge into call on next line
            if ( ! tt.tripAcceptable(s0, stopIndex)) continue;
            int adjustedTime = adjustTimeForTransfer(s0, currentStop, tt.trip, boarding, serviceDay, time);
            if (adjustedTime == -1) continue;
            if (boarding) {
                int depTime = tt.getDepartureTime(stopIndex);
                if (depTime < 0) continue;
                if (depTime >= adjustedTime && depTime < bestTime) {
                    bestTrip = tt;
                    bestTime = depTime;
                }
            } else {
                int arvTime = tt.getArrivalTime(stopIndex);
                if (arvTime < 0) continue;
                if (arvTime <= adjustedTime && arvTime > bestTime) {
                    bestTrip = tt;
                    bestTime = arvTime;
                }
            }
        }
        // ACK all logic is identical to above.
        // A sign that FrequencyEntries and TripTimes need a common interface.
        FrequencyEntry bestFreq = null;
        for (FrequencyEntry freq : frequencyEntries) {
            TripTimes tt = freq.tripTimes;
            if ( ! serviceDay.serviceRunning(tt.serviceCode)) continue; // TODO merge into call on next line
            if ( ! tt.tripAcceptable(s0, stopIndex)) continue;
            int adjustedTime = adjustTimeForTransfer(s0, currentStop, tt.trip, boarding, serviceDay, time);
            if (adjustedTime == -1) continue;
            LOG.debug("  running freq {}", freq);
            if (boarding) {
                int depTime = freq.nextDepartureTime(stopIndex, adjustedTime); // min transfer time included in search
View Full Code Here

Examples of org.opentripplanner.routing.trippattern.TripTimes

                return false;
            } else {
                LOG.trace("tripId {} found at index {} in scheduled timetable.", tripId, tripIndex);
            }

            TripTimes newTimes = new TripTimes(getTripTimes(tripIndex));

            if (tripDescriptor.hasScheduleRelationship() && tripDescriptor.getScheduleRelationship()
                    == TripDescriptor.ScheduleRelationship.CANCELED) {
                newTimes.cancel();
            } else {
                // The GTFS-RT reference specifies that StopTimeUpdates are sorted by stop_sequence.
                Iterator<StopTimeUpdate> updates = tripUpdate.getStopTimeUpdateList().iterator();
                if (!updates.hasNext()) {
                    LOG.warn("Won't apply zero-length trip update to trip {}.", tripId);
                    return false;
                }
                StopTimeUpdate update = updates.next();

                int numStops = newTimes.getNumStops();
                Integer delay = null;

                for (int i = 0; i < numStops; i++) {
                    boolean match = false;
                    if (update != null) {
                        if (update.hasStopSequence()) {
                            match = update.getStopSequence() == newTimes.getStopSequence(i);
                        } else if (update.hasStopId()) {
                            match = pattern.getStop(i).getId().getId().equals(update.getStopId());
                        }
                    }

                    if (match) {
                        StopTimeUpdate.ScheduleRelationship scheduleRelationship =
                                update.hasScheduleRelationship() ? update.getScheduleRelationship()
                                : StopTimeUpdate.ScheduleRelationship.SCHEDULED;
                        if (scheduleRelationship == StopTimeUpdate.ScheduleRelationship.SKIPPED) {
                            // TODO: Handle partial trip cancellations
                            LOG.warn("Partially canceled trips are currently unsupported." +
                                    " Skipping TripUpdate.");
                            return false;
                        } else if (scheduleRelationship ==
                                StopTimeUpdate.ScheduleRelationship.NO_DATA) {
                            newTimes.updateArrivalDelay(i, 0);
                            newTimes.updateDepartureDelay(i, 0);
                            delay = 0;
                        } else {
                            long today = updateServiceDate.getAsDate(timeZone).getTime() / 1000;

                            if (update.hasArrival()) {
                                StopTimeEvent arrival = update.getArrival();
                                if (arrival.hasDelay()) {
                                    delay = arrival.getDelay();
                                    if (arrival.hasTime()) {
                                        newTimes.updateArrivalTime(i,
                                                (int) (arrival.getTime() - today));
                                    } else {
                                        newTimes.updateArrivalDelay(i, delay);
                                    }
                                } else if (arrival.hasTime()) {
                                    newTimes.updateArrivalTime(i,
                                            (int) (arrival.getTime() - today));
                                    delay = newTimes.getArrivalDelay(i);
                                } else {
                                    LOG.error("Arrival time at index {} is erroneous.", i);
                                    return false;
                                }
                            } else {
                                if (delay == null) {
                                    newTimes.updateArrivalTime(i, TripTimes.UNAVAILABLE);
                                } else {
                                    newTimes.updateArrivalDelay(i, delay);
                                }
                            }

                            if (update.hasDeparture()) {
                                StopTimeEvent departure = update.getDeparture();
                                if (departure.hasDelay()) {
                                    delay = departure.getDelay();
                                    if (departure.hasTime()) {
                                        newTimes.updateDepartureTime(i,
                                                (int) (departure.getTime() - today));
                                    } else {
                                        newTimes.updateDepartureDelay(i, delay);
                                    }
                                } else if (departure.hasTime()) {
                                    newTimes.updateDepartureTime(i,
                                            (int) (departure.getTime() - today));
                                    delay = newTimes.getDepartureDelay(i);
                                } else {
                                    LOG.error("Departure time at index {} is erroneous.", i);
                                    return false;
                                }
                            } else {
                                if (delay == null) {
                                    newTimes.updateDepartureTime(i, TripTimes.UNAVAILABLE);
                                } else {
                                    newTimes.updateDepartureDelay(i, delay);
                                }
                            }
                        }

                        if (updates.hasNext()) {
                            update = updates.next();
                        } else {
                            update = null;
                        }
                    } else {
                        if (delay == null) {
                            newTimes.updateArrivalTime(i, TripTimes.UNAVAILABLE);
                            newTimes.updateDepartureTime(i, TripTimes.UNAVAILABLE);
                        } else {
                            newTimes.updateArrivalDelay(i, delay);
                            newTimes.updateDepartureDelay(i, delay);
                        }
                    }
                }
                if (update != null) {
                    LOG.error("Part of a TripUpdate object could not be applied successfully.");
                    return false;
                }
            }
            if (!newTimes.timesIncreasing()) {
                LOG.error("TripTimes are non-increasing after applying GTFS-RT delay propagation.");
                return false;
            }

            // Update succeeded, save the new TripTimes back into this Timetable.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.