Search in sources :

Example 1 with GenericDijkstra

use of org.opentripplanner.routing.algorithm.GenericDijkstra in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method pruneAreaEdges.

/**
 * Do an all-pairs shortest path search from a list of vertices over a specified set of edges,
 * and retain only those edges which are actually used in some shortest path.
 *
 * @param startingVertices
 * @param edges
 */
private void pruneAreaEdges(Collection<Vertex> startingVertices, Set<Edge> edges) {
    if (edges.size() == 0)
        return;
    TraverseMode mode;
    StreetEdge firstEdge = (StreetEdge) edges.iterator().next();
    if (firstEdge.getPermission().allows(StreetTraversalPermission.PEDESTRIAN)) {
        mode = TraverseMode.WALK;
    } else if (firstEdge.getPermission().allows(StreetTraversalPermission.BICYCLE)) {
        mode = TraverseMode.BICYCLE;
    } else {
        mode = TraverseMode.CAR;
    }
    RoutingRequest options = new RoutingRequest(mode);
    options.setDummyRoutingContext(graph);
    options.dominanceFunction = new DominanceFunction.EarliestArrival();
    GenericDijkstra search = new GenericDijkstra(options);
    search.setSkipEdgeStrategy(new ListedEdgesOnly(edges));
    Set<Edge> usedEdges = new HashSet<Edge>();
    for (Vertex vertex : startingVertices) {
        State state = new State(vertex, options);
        ShortestPathTree spt = search.getShortestPathTree(state);
        for (Vertex endVertex : startingVertices) {
            GraphPath path = spt.getPath(endVertex, false);
            if (path != null) {
                for (Edge edge : path.edges) {
                    usedEdges.add(edge);
                }
            }
        }
    }
    for (Edge edge : edges) {
        if (!usedEdges.contains(edge)) {
            graph.removeEdge(edge);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GenericDijkstra(org.opentripplanner.routing.algorithm.GenericDijkstra) GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) TraverseMode(org.opentripplanner.routing.core.TraverseMode) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) EarliestArrival(org.opentripplanner.routing.spt.DominanceFunction.EarliestArrival) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 2 with GenericDijkstra

use of org.opentripplanner.routing.algorithm.GenericDijkstra in project OpenTripPlanner by opentripplanner.

the class EuclideanRemainingWeightHeuristic method determineRequiredWalkDistance.

/**
 * Figure out the minimum amount of walking to reach the destination from transit.
 * This is done by doing a Dijkstra search for the first reachable transit stop.
 */
private double determineRequiredWalkDistance(final RoutingRequest req) {
    // required walk distance will be unused.
    if (!transit)
        return 0;
    RoutingRequest options = req.clone();
    options.setArriveBy(!req.arriveBy);
    options.setRoutingContext(req.rctx.graph, req.rctx.fromVertex, req.rctx.toVertex);
    GenericDijkstra gd = new GenericDijkstra(options);
    State s = new State(options);
    gd.setHeuristic(new TrivialRemainingWeightHeuristic());
    final ClosestStopTraverseVisitor visitor = new ClosestStopTraverseVisitor();
    gd.traverseVisitor = visitor;
    gd.searchTerminationStrategy = new SearchTerminationStrategy() {

        @Override
        public boolean shouldSearchTerminate(Vertex origin, Vertex target, State current, ShortestPathTree spt, RoutingRequest traverseOptions) {
            return visitor.distanceToClosestStop != Double.POSITIVE_INFINITY;
        }
    };
    gd.getShortestPathTree(s);
    return visitor.distanceToClosestStop;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GenericDijkstra(org.opentripplanner.routing.algorithm.GenericDijkstra) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

GenericDijkstra (org.opentripplanner.routing.algorithm.GenericDijkstra)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 State (org.opentripplanner.routing.core.State)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)2 HashSet (java.util.HashSet)1 TraverseMode (org.opentripplanner.routing.core.TraverseMode)1 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)1 EarliestArrival (org.opentripplanner.routing.spt.DominanceFunction.EarliestArrival)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)1