Search in sources :

Example 1 with MinMap

use of org.opentripplanner.common.MinMap in project OpenTripPlanner by opentripplanner.

the class NearbyStopFinder method findNearbyStopsConsideringPatterns.

/**
 * Find all unique nearby stops that are the closest stop on some trip pattern or flex trip.
 * Note that the result will include the origin vertex if it is an instance of StopVertex.
 * This is intentional: we don't want to return the next stop down the line for trip patterns that pass through the
 * origin vertex.
 */
public Set<StopAtDistance> findNearbyStopsConsideringPatterns(Vertex vertex, boolean reverseDirection) {
    /* Track the closest stop on each pattern passing nearby. */
    MinMap<TripPattern, StopAtDistance> closestStopForPattern = new MinMap<TripPattern, StopAtDistance>();
    /* Track the closest stop on each flex trip nearby. */
    MinMap<FlexTrip, StopAtDistance> closestStopForFlexTrip = new MinMap<>();
    /* Iterate over nearby stops via the street network or using straight-line distance, depending on the graph. */
    for (StopAtDistance stopAtDistance : findNearbyStops(vertex, reverseDirection)) {
        StopLocation ts1 = stopAtDistance.stop;
        if (ts1 instanceof Stop) {
            /* Consider this destination stop as a candidate for every trip pattern passing through it. */
            for (TripPattern pattern : graph.index.getPatternsForStop(ts1)) {
                closestStopForPattern.putMin(pattern, stopAtDistance);
            }
        }
        if (OTPFeature.FlexRouting.isOn()) {
            for (FlexTrip trip : graph.index.getFlexIndex().flexTripsByStop.get(ts1)) {
                closestStopForFlexTrip.putMin(trip, stopAtDistance);
            }
        }
    }
    /* Make a transfer from the origin stop to each destination stop that was the closest stop on any pattern. */
    Set<StopAtDistance> uniqueStops = Sets.newHashSet();
    uniqueStops.addAll(closestStopForFlexTrip.values());
    uniqueStops.addAll(closestStopForPattern.values());
    return uniqueStops;
}
Also used : FlexTrip(org.opentripplanner.ext.flex.trip.FlexTrip) MinMap(org.opentripplanner.common.MinMap) Stop(org.opentripplanner.model.Stop) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) StopLocation(org.opentripplanner.model.StopLocation) FlexStopLocation(org.opentripplanner.model.FlexStopLocation) TripPattern(org.opentripplanner.model.TripPattern)

Aggregations

MinMap (org.opentripplanner.common.MinMap)1 FlexTrip (org.opentripplanner.ext.flex.trip.FlexTrip)1 FlexStopLocation (org.opentripplanner.model.FlexStopLocation)1 Stop (org.opentripplanner.model.Stop)1 StopLocation (org.opentripplanner.model.StopLocation)1 TripPattern (org.opentripplanner.model.TripPattern)1 StopAtDistance (org.opentripplanner.routing.graphfinder.StopAtDistance)1