Search in sources :

Example 1 with StopNotLinkedForTransfers

use of org.opentripplanner.graph_builder.annotation.StopNotLinkedForTransfers in project OpenTripPlanner by opentripplanner.

the class DirectTransferGenerator method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    /* Initialize graph index which is needed by the nearby stop finder. */
    if (graph.index == null) {
        graph.index = new GraphIndex(graph);
    }
    /* The linker will use streets if they are available, or straight-line distance otherwise. */
    NearbyStopFinder nearbyStopFinder = new NearbyStopFinder(graph, radiusMeters);
    if (nearbyStopFinder.useStreets) {
        LOG.info("Creating direct transfer edges between stops using the street network from OSM...");
    } else {
        LOG.info("Creating direct transfer edges between stops using straight line distance (not streets)...");
    }
    int nTransfersTotal = 0;
    int nLinkableStops = 0;
    for (TransitStop ts0 : Iterables.filter(graph.getVertices(), TransitStop.class)) {
        /* Skip stops that are entrances to stations or whose entrances are coded separately */
        if (!ts0.isStreetLinkable())
            continue;
        if (++nLinkableStops % 1000 == 0) {
            LOG.info("Linked {} stops", nLinkableStops);
        }
        LOG.debug("Linking stop '{}' {}", ts0.getStop(), ts0);
        /* Determine the set of stops that are already reachable via other pathways or transfers */
        Set<TransitStop> pathwayDestinations = new HashSet<TransitStop>();
        for (Edge e : ts0.getOutgoing()) {
            if (e instanceof PathwayEdge || e instanceof SimpleTransfer) {
                if (e.getToVertex() instanceof TransitStop) {
                    TransitStop to = (TransitStop) e.getToVertex();
                    pathwayDestinations.add(to);
                }
            }
        }
        /* Make transfers to each nearby stop that is the closest stop on some trip pattern. */
        int n = 0;
        for (NearbyStopFinder.StopAtDistance sd : nearbyStopFinder.findNearbyStopsConsideringPatterns(ts0)) {
            /* Skip the origin stop, loop transfers are not needed. */
            if (sd.tstop == ts0 || pathwayDestinations.contains(sd.tstop))
                continue;
            new SimpleTransfer(ts0, sd.tstop, sd.dist, sd.geom, sd.edges);
            n += 1;
        }
        LOG.debug("Linked stop {} to {} nearby stops on other patterns.", ts0.getStop(), n);
        if (n == 0) {
            LOG.debug(graph.addBuilderAnnotation(new StopNotLinkedForTransfers(ts0)));
        }
        nTransfersTotal += n;
    }
    LOG.info("Done connecting stops to one another. Created a total of {} transfers from {} stops.", nTransfersTotal, nLinkableStops);
    graph.hasDirectTransfers = true;
}
Also used : StopNotLinkedForTransfers(org.opentripplanner.graph_builder.annotation.StopNotLinkedForTransfers) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 StopNotLinkedForTransfers (org.opentripplanner.graph_builder.annotation.StopNotLinkedForTransfers)1 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)1 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)1 Edge (org.opentripplanner.routing.graph.Edge)1 GraphIndex (org.opentripplanner.routing.graph.GraphIndex)1 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)1