use of org.opentripplanner.ext.flex.trip.FlexTrip 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;
}
Aggregations