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