Search in sources :

Example 1 with SimpleTransfer

use of org.opentripplanner.model.SimpleTransfer in project OpenTripPlanner by opentripplanner.

the class DirectTransferGenerator 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. */
    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)...");
    }
    Iterable<TransitStopVertex> stops = Iterables.filter(graph.getVertices(), TransitStopVertex.class);
    ProgressTracker progress = ProgressTracker.track("Create transfer edges", 1000, Iterables.size(stops));
    int nTransfersTotal = 0;
    int nLinkableStops = 0;
    // This could be multi-threaded, in which case we'd need to be careful about the lifecycle of NearbyStopFinder instances.
    for (TransitStopVertex ts0 : stops) {
        Stop stop = ts0.getStop();
        LOG.debug("Linking stop '{}' {}", stop, ts0);
        /* Make transfers to each nearby stop that is the closest stop on some trip pattern. */
        int n = 0;
        for (StopAtDistance sd : nearbyStopFinder.findNearbyStopsConsideringPatterns(ts0, false)) {
            // Skip the origin stop, loop transfers are not needed.
            if (sd.stop == stop) {
                continue;
            }
            graph.transfersByStop.put(stop, new SimpleTransfer(stop, sd.stop, sd.distance, sd.edges));
            n += 1;
        }
        if (OTPFeature.FlexRouting.isOn()) {
            // from Stops to FlexStopLocations and between Stops are already covered above.
            for (StopAtDistance sd : nearbyStopFinder.findNearbyStopsConsideringPatterns(ts0, true)) {
                // Skip the origin stop, loop transfers are not needed.
                if (sd.stop == ts0.getStop()) {
                    continue;
                }
                if (sd.stop instanceof Stop) {
                    continue;
                }
                graph.transfersByStop.put(sd.stop, new SimpleTransfer(sd.stop, ts0.getStop(), sd.distance, sd.edges));
                n += 1;
            }
        }
        LOG.debug("Linked stop {} to {} nearby stops on other patterns.", stop, n);
        if (n == 0) {
            issueStore.add(new StopNotLinkedForTransfers(ts0));
        }
        // Keep lambda! A method-ref would causes incorrect class and line number to be logged
        progress.step(m -> LOG.info(m));
        nTransfersTotal += n;
    }
    LOG.info(progress.completeMessage());
    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.issues.StopNotLinkedForTransfers) ProgressTracker(org.opentripplanner.util.ProgressTracker) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) SimpleTransfer(org.opentripplanner.model.SimpleTransfer)

Example 2 with SimpleTransfer

use of org.opentripplanner.model.SimpleTransfer in project OpenTripPlanner by opentripplanner.

the class TransfersMapper method mapTransfers.

/**
 * Copy pre-calculated transfers from the original graph
 */
static List<List<Transfer>> mapTransfers(StopIndexForRaptor stopIndex, Multimap<StopLocation, SimpleTransfer> transfersByStop) {
    List<List<Transfer>> transferByStopIndex = new ArrayList<>();
    for (int i = 0; i < stopIndex.stopsByIndex.size(); ++i) {
        Stop stop = stopIndex.stopsByIndex.get(i);
        ArrayList<Transfer> list = new ArrayList<>();
        transferByStopIndex.add(list);
        for (SimpleTransfer simpleTransfer : transfersByStop.get(stop)) {
            double effectiveDistance = simpleTransfer.getEffectiveWalkDistance();
            if (simpleTransfer.to instanceof Stop) {
                int toStopIndex = stopIndex.indexByStop.get(simpleTransfer.to);
                Transfer transfer = new Transfer(toStopIndex, (int) effectiveDistance, simpleTransfer.getEdges());
                list.add(transfer);
            }
        }
    }
    return transferByStopIndex;
}
Also used : Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) SimpleTransfer(org.opentripplanner.model.SimpleTransfer) Transfer(org.opentripplanner.routing.algorithm.raptor.transit.Transfer) List(java.util.List) ArrayList(java.util.ArrayList) SimpleTransfer(org.opentripplanner.model.SimpleTransfer)

Aggregations

SimpleTransfer (org.opentripplanner.model.SimpleTransfer)2 Stop (org.opentripplanner.model.Stop)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StopNotLinkedForTransfers (org.opentripplanner.graph_builder.issues.StopNotLinkedForTransfers)1 Transfer (org.opentripplanner.routing.algorithm.raptor.transit.Transfer)1 GraphIndex (org.opentripplanner.routing.graph.GraphIndex)1 StopAtDistance (org.opentripplanner.routing.graphfinder.StopAtDistance)1 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)1 ProgressTracker (org.opentripplanner.util.ProgressTracker)1