Search in sources :

Example 1 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.

/**
 * Compute a set of initial coordinates for the given SPT
 *
 * @param spt
 * @return
 */
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
    List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
    for (State s : spt.getAllStates()) {
        Vertex v = s.getVertex();
        // Take only street
        if (v instanceof StreetVertex) {
            retval.add(v.getCoordinate());
        }
    }
    LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
    return retval;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) ArrayList(java.util.ArrayList) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 2 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class GraphPathFinder method joinPaths.

private static GraphPath joinPaths(List<GraphPath> paths) {
    State lastState = paths.get(0).states.getLast();
    GraphPath newPath = new GraphPath(lastState, false);
    Vertex lastVertex = lastState.getVertex();
    // With more paths we should allow more transfers
    lastState.getOptions().maxTransfers *= paths.size();
    for (GraphPath path : paths.subList(1, paths.size())) {
        lastState = newPath.states.getLast();
        // add a leg-switching state
        LegSwitchingEdge legSwitchingEdge = new LegSwitchingEdge(lastVertex, lastVertex);
        lastState = legSwitchingEdge.traverse(lastState);
        newPath.edges.add(legSwitchingEdge);
        newPath.states.add(lastState);
        // add the next subpath
        for (Edge e : path.edges) {
            lastState = e.traverse(lastState);
            newPath.edges.add(e);
            newPath.states.add(lastState);
        }
        lastVertex = path.getEndVertex();
    }
    return newPath;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) LegSwitchingEdge(org.opentripplanner.routing.edgetype.LegSwitchingEdge) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) LegSwitchingEdge(org.opentripplanner.routing.edgetype.LegSwitchingEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 3 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TripPattern method dumpVertices.

public void dumpVertices() {
    for (int i = 0; i < this.stopPattern.size; ++i) {
        Vertex arrive = arriveVertices[i];
        Vertex depart = departVertices[i];
        System.out.format("%s %02d %s %s\n", this.code, i, arrive == null ? "NULL" : arrive.getLabel(), depart == null ? "NULL" : depart.getLabel());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex)

Example 4 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class StreetVertexIndexServiceImpl method createTemporaryStreetLocation.

/**
 * Creates a TemporaryStreetLocation on the given street (set of PlainStreetEdges). How far
 * along is controlled by the location parameter, which represents a distance along the edge
 * between 0 (the from vertex) and 1 (the to vertex).
 *
 * @param graph
 *
 * @param label
 * @param name
 * @param edges A collection of nearby edges, which represent one street.
 * @param nearestPoint
 *
 * @return the new TemporaryStreetLocation
 */
public static TemporaryStreetLocation createTemporaryStreetLocation(Graph graph, String label, I18NString name, Iterable<StreetEdge> edges, Coordinate nearestPoint, boolean endVertex) {
    boolean wheelchairAccessible = false;
    TemporaryStreetLocation location = new TemporaryStreetLocation(label, nearestPoint, name, endVertex);
    for (StreetEdge street : edges) {
        Vertex fromv = street.getFromVertex();
        Vertex tov = street.getToVertex();
        wheelchairAccessible |= ((StreetEdge) street).isWheelchairAccessible();
        /* forward edges and vertices */
        Vertex edgeLocation;
        if (SphericalDistanceLibrary.distance(nearestPoint, fromv.getCoordinate()) < 1) {
            // no need to link to area edges caught on-end
            edgeLocation = fromv;
            if (endVertex) {
                new TemporaryFreeEdge(edgeLocation, location);
            } else {
                new TemporaryFreeEdge(location, edgeLocation);
            }
        } else if (SphericalDistanceLibrary.distance(nearestPoint, tov.getCoordinate()) < 1) {
            // no need to link to area edges caught on-end
            edgeLocation = tov;
            if (endVertex) {
                new TemporaryFreeEdge(edgeLocation, location);
            } else {
                new TemporaryFreeEdge(location, edgeLocation);
            }
        } else {
            // location is somewhere in the middle of the edge.
            edgeLocation = location;
            // creates links from street head -> location -> street tail.
            createHalfLocation(location, name, nearestPoint, street, endVertex);
        }
    }
    location.setWheelchairAccessible(wheelchairAccessible);
    return location;
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Vertex(org.opentripplanner.routing.graph.Vertex) SampleVertex(org.opentripplanner.routing.vertextype.SampleVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 5 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitter method link.

/**
 * Link this vertex into the graph
 */
public boolean link(Vertex vertex, TraverseMode traverseMode, RoutingRequest options) {
    // find nearby street edges
    // TODO: we used to use an expanding-envelope search, which is more efficient in
    // dense areas. but first let's see how inefficient this is. I suspect it's not too
    // bad and the gains in simplicity are considerable.
    final double radiusDeg = SphericalDistanceLibrary.metersToDegrees(MAX_SEARCH_RADIUS_METERS);
    Envelope env = new Envelope(vertex.getCoordinate());
    // Perform a simple local equirectangular projection, so distances are expressed in degrees latitude.
    final double xscale = Math.cos(vertex.getLat() * Math.PI / 180);
    // Expand more in the longitude direction than the latitude direction to account for converging meridians.
    env.expandBy(radiusDeg / xscale, radiusDeg);
    final double DUPLICATE_WAY_EPSILON_DEGREES = SphericalDistanceLibrary.metersToDegrees(DUPLICATE_WAY_EPSILON_METERS);
    final TraverseModeSet traverseModeSet;
    if (traverseMode == TraverseMode.BICYCLE) {
        traverseModeSet = new TraverseModeSet(traverseMode, TraverseMode.WALK);
    } else {
        traverseModeSet = new TraverseModeSet(traverseMode);
    }
    // We sort the list of candidate edges by distance to the stop
    // This should remove any issues with things coming out of the spatial index in different orders
    // Then we link to everything that is within DUPLICATE_WAY_EPSILON_METERS of of the best distance
    // so that we capture back edges and duplicate ways.
    List<StreetEdge> candidateEdges = idx.query(env).stream().filter(streetEdge -> streetEdge instanceof StreetEdge).map(edge -> (StreetEdge) edge).filter(edge -> edge.canTraverse(traverseModeSet) && // only link to edges still in the graph.
    edge.getToVertex().getIncoming().contains(edge)).collect(Collectors.toList());
    // Make a map of distances to all edges.
    final TIntDoubleMap distances = new TIntDoubleHashMap();
    for (StreetEdge e : candidateEdges) {
        distances.put(e.getId(), distance(vertex, e, xscale));
    }
    // Sort the list.
    Collections.sort(candidateEdges, (o1, o2) -> {
        double diff = distances.get(o1.getId()) - distances.get(o2.getId());
        // A Comparator must return an integer but our distances are doubles.
        if (diff < 0)
            return -1;
        if (diff > 0)
            return 1;
        return 0;
    });
    // find the closest candidate edges
    if (candidateEdges.isEmpty() || distances.get(candidateEdges.get(0).getId()) > radiusDeg) {
        // We only link to stops if we are searching for origin/destination and for that we need transitStopIndex.
        if (destructiveSplitting || transitStopIndex == null) {
            return false;
        }
        LOG.debug("No street edge was found for {}", vertex);
        // We search for closest stops (since this is only used in origin/destination linking if no edges were found)
        // in the same way the closest edges are found.
        List<TransitStop> candidateStops = new ArrayList<>();
        transitStopIndex.query(env).forEach(candidateStop -> candidateStops.add((TransitStop) candidateStop));
        final TIntDoubleMap stopDistances = new TIntDoubleHashMap();
        for (TransitStop t : candidateStops) {
            stopDistances.put(t.getIndex(), distance(vertex, t, xscale));
        }
        Collections.sort(candidateStops, (o1, o2) -> {
            double diff = stopDistances.get(o1.getIndex()) - stopDistances.get(o2.getIndex());
            if (diff < 0) {
                return -1;
            }
            if (diff > 0) {
                return 1;
            }
            return 0;
        });
        if (candidateStops.isEmpty() || stopDistances.get(candidateStops.get(0).getIndex()) > radiusDeg) {
            LOG.debug("Stops aren't close either!");
            return false;
        } else {
            List<TransitStop> bestStops = Lists.newArrayList();
            // Add stops until there is a break of epsilon meters.
            // we do this to enforce determinism. if there are a lot of stops that are all extremely close to each other,
            // we want to be sure that we deterministically link to the same ones every time. Any hard cutoff means things can
            // fall just inside or beyond the cutoff depending on floating-point operations.
            int i = 0;
            do {
                bestStops.add(candidateStops.get(i++));
            } while (i < candidateStops.size() && stopDistances.get(candidateStops.get(i).getIndex()) - stopDistances.get(candidateStops.get(i - 1).getIndex()) < DUPLICATE_WAY_EPSILON_DEGREES);
            for (TransitStop stop : bestStops) {
                LOG.debug("Linking vertex to stop: {}", stop.getName());
                makeTemporaryEdges((TemporaryStreetLocation) vertex, stop);
            }
            return true;
        }
    } else {
        // find the best edges
        List<StreetEdge> bestEdges = Lists.newArrayList();
        // add edges until there is a break of epsilon meters.
        // we do this to enforce determinism. if there are a lot of edges that are all extremely close to each other,
        // we want to be sure that we deterministically link to the same ones every time. Any hard cutoff means things can
        // fall just inside or beyond the cutoff depending on floating-point operations.
        int i = 0;
        do {
            bestEdges.add(candidateEdges.get(i++));
        } while (i < candidateEdges.size() && distances.get(candidateEdges.get(i).getId()) - distances.get(candidateEdges.get(i - 1).getId()) < DUPLICATE_WAY_EPSILON_DEGREES);
        for (StreetEdge edge : bestEdges) {
            link(vertex, edge, xscale, options);
        }
        // Warn if a linkage was made, but the linkage was suspiciously long.
        if (vertex instanceof TransitStop) {
            double distanceDegreesLatitude = distances.get(candidateEdges.get(0).getId());
            int distanceMeters = (int) SphericalDistanceLibrary.degreesLatitudeToMeters(distanceDegreesLatitude);
            if (distanceMeters > WARNING_DISTANCE_METERS) {
                // Registering an annotation but not logging because tests produce thousands of these warnings.
                graph.addBuilderAnnotation(new StopLinkedTooFar((TransitStop) vertex, distanceMeters));
            }
        }
        return true;
    }
}
Also used : P2(org.opentripplanner.common.model.P2) Iterables(com.google.common.collect.Iterables) TemporarySplitterVertex(org.opentripplanner.routing.vertextype.TemporarySplitterVertex) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex) LocationIndexedLine(com.vividsolutions.jts.linearref.LocationIndexedLine) LoggerFactory(org.slf4j.LoggerFactory) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) SphericalDistanceLibrary(org.opentripplanner.common.geometry.SphericalDistanceLibrary) TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LineString(com.vividsolutions.jts.geom.LineString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StopLinkedTooFar(org.opentripplanner.graph_builder.annotation.StopLinkedTooFar) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) ArrayList(java.util.ArrayList) StopUnlinked(org.opentripplanner.graph_builder.annotation.StopUnlinked) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Graph(org.opentripplanner.routing.graph.Graph) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) GenericLocation(org.opentripplanner.common.model.GenericLocation) SpatialIndex(com.vividsolutions.jts.index.SpatialIndex) TraverseMode(org.opentripplanner.routing.core.TraverseMode) Lists(jersey.repackaged.com.google.common.collect.Lists) HashGridSpatialIndex(org.opentripplanner.common.geometry.HashGridSpatialIndex) Coordinate(com.vividsolutions.jts.geom.Coordinate) Logger(org.slf4j.Logger) Envelope(com.vividsolutions.jts.geom.Envelope) Vertex(org.opentripplanner.routing.graph.Vertex) StreetBikeRentalLink(org.opentripplanner.routing.edgetype.StreetBikeRentalLink) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) BikeParkUnlinked(org.opentripplanner.graph_builder.annotation.BikeParkUnlinked) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetBikeParkLink(org.opentripplanner.routing.edgetype.StreetBikeParkLink) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) GeometryUtils(org.opentripplanner.common.geometry.GeometryUtils) List(java.util.List) TIntDoubleMap(gnu.trove.map.TIntDoubleMap) BikeRentalStationUnlinked(org.opentripplanner.graph_builder.annotation.BikeRentalStationUnlinked) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Collections(java.util.Collections) Edge(org.opentripplanner.routing.graph.Edge) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TIntDoubleMap(gnu.trove.map.TIntDoubleMap) ArrayList(java.util.ArrayList) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StopLinkedTooFar(org.opentripplanner.graph_builder.annotation.StopLinkedTooFar) Envelope(com.vividsolutions.jts.geom.Envelope) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11