Search in sources :

Example 1 with TransferRoutingDistanceTooLong

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());
}
Also used : StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) StreetGraphFinder(org.opentripplanner.routing.graphfinder.StreetGraphFinder) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) LoggerFactory(org.slf4j.LoggerFactory) Coordinate(org.locationtech.jts.geom.Coordinate) DirectGraphFinder(org.opentripplanner.routing.graphfinder.DirectGraphFinder) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) TransferCouldNotBeRouted(org.opentripplanner.ext.transferanalyzer.annotations.TransferCouldNotBeRouted) List(java.util.List) GraphBuilderModule(org.opentripplanner.graph_builder.services.GraphBuilderModule) TransferRoutingDistanceTooLong(org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong) Graph(org.opentripplanner.routing.graph.Graph) Map(java.util.Map) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Comparator(java.util.Comparator) Collections(java.util.Collections) TransferRoutingDistanceTooLong(org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) StreetGraphFinder(org.opentripplanner.routing.graphfinder.StreetGraphFinder) Coordinate(org.locationtech.jts.geom.Coordinate) DirectGraphFinder(org.opentripplanner.routing.graphfinder.DirectGraphFinder) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) TransferCouldNotBeRouted(org.opentripplanner.ext.transferanalyzer.annotations.TransferCouldNotBeRouted) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance)

Aggregations

Iterables (com.google.common.collect.Iterables)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 TransferCouldNotBeRouted (org.opentripplanner.ext.transferanalyzer.annotations.TransferCouldNotBeRouted)1 TransferRoutingDistanceTooLong (org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 GraphBuilderModule (org.opentripplanner.graph_builder.services.GraphBuilderModule)1 Stop (org.opentripplanner.model.Stop)1 Graph (org.opentripplanner.routing.graph.Graph)1 GraphIndex (org.opentripplanner.routing.graph.GraphIndex)1 DirectGraphFinder (org.opentripplanner.routing.graphfinder.DirectGraphFinder)1 StopAtDistance (org.opentripplanner.routing.graphfinder.StopAtDistance)1 StreetGraphFinder (org.opentripplanner.routing.graphfinder.StreetGraphFinder)1 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)1