use of org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong in project OpenTripPlanner by opentripplanner.
the class DirectTransferAnalyzer method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
/* Initialize graph index which is needed by the nearby stop finder. */
graph.index = new GraphIndex(graph);
LOG.info("Analyzing transfers (this can be time consuming)...");
List<TransferInfo> directTransfersTooLong = new ArrayList<>();
List<TransferInfo> directTransfersNotFound = new ArrayList<>();
DirectGraphFinder nearbyStopFinderEuclidian = new DirectGraphFinder(graph);
StreetGraphFinder nearbyStopFinderStreets = new StreetGraphFinder(graph);
int stopsAnalyzed = 0;
for (TransitStopVertex originStopVertex : Iterables.filter(graph.getVertices(), TransitStopVertex.class)) {
if (++stopsAnalyzed % 1000 == 0) {
LOG.info("{} stops analyzed", stopsAnalyzed);
}
/* Find nearby stops by euclidean distance */
Coordinate c0 = originStopVertex.getCoordinate();
Map<Stop, StopAtDistance> stopsEuclidean = nearbyStopFinderEuclidian.findClosestStops(c0.y, c0.x, radiusMeters).stream().filter(t -> t.stop instanceof Stop).collect(Collectors.toMap(t -> (Stop) t.stop, t -> t));
/* Find nearby stops by street distance */
Map<Stop, StopAtDistance> stopsStreets = nearbyStopFinderStreets.findClosestStops(c0.y, c0.x, radiusMeters * RADIUS_MULTIPLIER).stream().filter(t -> t.stop instanceof Stop).collect(Collectors.toMap(t -> (Stop) t.stop, t -> t));
Stop originStop = originStopVertex.getStop();
/* Get stops found by both street and euclidean search */
List<Stop> stopsConnected = stopsEuclidean.keySet().stream().filter(t -> stopsStreets.keySet().contains(t) && t != originStop).collect(Collectors.toList());
/* Get stops found by euclidean search but not street search */
List<Stop> stopsUnconnected = stopsEuclidean.keySet().stream().filter(t -> !stopsStreets.keySet().contains(t) && t != originStop).collect(Collectors.toList());
for (Stop destStop : stopsConnected) {
StopAtDistance euclideanStop = stopsEuclidean.get(destStop);
StopAtDistance streetStop = stopsStreets.get(destStop);
TransferInfo transferInfo = new TransferInfo(originStop, destStop, euclideanStop.distance, streetStop.distance);
/* Log transfer where the street distance is too long compared to the euclidean distance */
if (transferInfo.ratio > MIN_RATIO_TO_LOG && transferInfo.streetDistance > MIN_STREET_DISTANCE_TO_LOG) {
directTransfersTooLong.add(transferInfo);
}
}
for (Stop destStop : stopsUnconnected) {
StopAtDistance euclideanStop = stopsEuclidean.get(destStop);
/* Log transfers that are found by euclidean search but not by street search */
directTransfersNotFound.add(new TransferInfo(originStop, destStop, euclideanStop.distance, -1));
}
}
/* Sort by street distance to euclidean distance ratio before adding to issues */
directTransfersTooLong.sort(Comparator.comparingDouble(t -> t.ratio));
Collections.reverse(directTransfersTooLong);
for (TransferInfo transferInfo : directTransfersTooLong) {
issueStore.add(new TransferRoutingDistanceTooLong(transferInfo.origin, transferInfo.destination, transferInfo.directDistance, transferInfo.streetDistance, transferInfo.ratio));
}
/* Sort by direct distance before adding to issues */
directTransfersNotFound.sort(Comparator.comparingDouble(t -> t.directDistance));
for (TransferInfo transferInfo : directTransfersNotFound) {
issueStore.add(new TransferCouldNotBeRouted(transferInfo.origin, transferInfo.destination, transferInfo.directDistance));
}
LOG.info("Done analyzing transfers. {} transfers could not be routed and {} transfers had a too long routing" + " distance.", directTransfersNotFound.size(), directTransfersTooLong.size());
}
Aggregations