use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class AddTransitModelEntitiesToGraph method addStopsToGraphAndGenerateStopVertexes.
private void addStopsToGraphAndGenerateStopVertexes(Graph graph) {
// Compute the set of modes for each stop based on all the TripPatterns it is part of
Map<Stop, Set<TransitMode>> stopModeMap = new HashMap<>();
for (TripPattern pattern : transitService.getTripPatterns()) {
TransitMode mode = pattern.getMode();
graph.addTransitMode(mode);
for (Stop stop : pattern.getStops()) {
Set<TransitMode> set = stopModeMap.computeIfAbsent(stop, s -> new HashSet<>());
set.add(mode);
}
}
// It is now possible for these vertices to not be connected to any edges.
for (Stop stop : transitService.getAllStops()) {
Set<TransitMode> modes = stopModeMap.get(stop);
TransitStopVertex stopVertex = new TransitStopVertex(graph, stop, modes);
if (modes != null && modes.contains(TransitMode.SUBWAY)) {
stopVertex.setStreetToStopTime(subwayAccessTime);
}
// Add stops to internal index for Pathways to be created from this map
stationElementNodes.put(stop, stopVertex);
}
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex 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;
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class StopsAlerts method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
try {
PrintWriter pw = new PrintWriter(new File(logFile));
pw.printf("%s,%s,%s,%s\n", "stopId", "lon", "lat", "types");
for (TransitStopVertex ts : Iterables.filter(graph.getVertices(), TransitStopVertex.class)) {
StringBuilder types = new StringBuilder();
for (IStopTester stopTester : stopTesters) {
if (stopTester.fulfillDemands(ts, graph)) {
if (types.length() > 0)
types.append(";");
types.append(stopTester.getType());
}
}
if (types.length() > 0) {
pw.printf("%s,%f,%f,%s\n", ts.getStop().getId(), ts.getCoordinate().x, ts.getCoordinate().y, types.toString());
}
}
pw.close();
} catch (FileNotFoundException e) {
LOG.error("Failed to write StopsAlerts log file", e);
}
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method connectVertexToStop.
private boolean connectVertexToStop(TransitStopVertex ts, boolean wheelchairAccessible) {
String stopCode = ts.getStop().getCode();
if (stopCode == null) {
return false;
}
Envelope envelope = new Envelope(ts.getCoordinate());
double xscale = Math.cos(ts.getCoordinate().y * Math.PI / 180);
envelope.expandBy(searchRadiusLat / xscale, searchRadiusLat);
Collection<Vertex> vertices = index.getVerticesForEnvelope(envelope);
// in their ref= tag that matches the GTFS stop code of this StopVertex.
for (Vertex v : vertices) {
if (!(v instanceof TransitStopStreetVertex)) {
continue;
}
TransitStopStreetVertex tsv = (TransitStopStreetVertex) v;
// Only use stop codes for linking TODO: find better method to connect stops without stop code
if (tsv.stopCode != null && tsv.stopCode.equals(stopCode)) {
new StreetTransitLink(ts, tsv, wheelchairAccessible);
new StreetTransitLink(tsv, ts, wheelchairAccessible);
LOG.debug("Connected " + ts.toString() + " to " + tsv.getLabel());
return true;
}
}
return false;
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
LOG.info("Linking transit stops to tagged bus stops...");
index = new StreetVertexIndex(graph);
// iterate over a copy of vertex list because it will be modified
ArrayList<Vertex> vertices = new ArrayList<>();
vertices.addAll(graph.getVertices());
for (TransitStopVertex ts : Iterables.filter(vertices, TransitStopVertex.class)) {
// if the street is already linked there is no need to linked it again,
// could happened if using the prune isolated island
boolean alreadyLinked = false;
for (Edge e : ts.getOutgoing()) {
if (e instanceof StreetTransitLink) {
alreadyLinked = true;
break;
}
}
if (alreadyLinked)
continue;
// only connect transit stops that are not part of a pathway network
if (!ts.hasPathways()) {
boolean wheelchairAccessible = ts.hasWheelchairEntrance();
if (!connectVertexToStop(ts, wheelchairAccessible)) {
LOG.debug("Could not connect " + ts.getStop().getCode() + " at " + ts.getCoordinate().toString());
// TODO OTP2 - Why is this commented out? Is it not a problem or is it to nosey?
// LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
}
}
}
}
Aggregations