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;
}
Aggregations