Search in sources :

Example 21 with TransitStopVertex

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);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Stop(org.opentripplanner.model.Stop) HashMap(java.util.HashMap) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) TransitMode(org.opentripplanner.model.TransitMode) TripPattern(org.opentripplanner.model.TripPattern)

Example 22 with TransitStopVertex

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;
}
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 23 with TransitStopVertex

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);
    }
}
Also used : TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) FileNotFoundException(java.io.FileNotFoundException) IStopTester(org.opentripplanner.graph_builder.module.stopsAlerts.IStopTester) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 24 with TransitStopVertex

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;
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Envelope(org.locationtech.jts.geom.Envelope)

Example 25 with TransitStopVertex

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)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Aggregations

TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)28 Stop (org.opentripplanner.model.Stop)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)8 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)8 ArrayList (java.util.ArrayList)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 Envelope (org.locationtech.jts.geom.Envelope)7 Graph (org.opentripplanner.routing.graph.Graph)7 LineString (org.locationtech.jts.geom.LineString)6 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)5 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)5 Iterables (com.google.common.collect.Iterables)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)4 BikeRentalStationVertex (org.opentripplanner.routing.vertextype.BikeRentalStationVertex)4 SplitterVertex (org.opentripplanner.routing.vertextype.SplitterVertex)4 LinearLocation (org.locationtech.jts.linearref.LinearLocation)3 LocationIndexedLine (org.locationtech.jts.linearref.LocationIndexedLine)3