use of org.opentripplanner.routing.algorithm.astar.strategies.RemainingWeightHeuristic in project OpenTripPlanner by opentripplanner.
the class GraphPathFinder method getPaths.
/**
* This no longer does "trip banning" to find multiple itineraries.
* It just searches once trying to find a non-transit path.
*/
public List<GraphPath> getPaths(RoutingRequest options) {
if (options == null) {
LOG.error("PathService was passed a null routing request.");
return null;
}
if (options.streetSubRequestModes.isTransit()) {
throw new UnsupportedOperationException("Transit search not supported");
}
// Reuse one instance of AStar for all N requests, which are carried out sequentially
AStar aStar = new AStar();
if (options.rctx == null) {
options.setRoutingContext(router.graph);
// The special long-distance heuristic should be sufficient to constrain the search to the right area.
}
// If this Router has a GraphVisualizer attached to it, set it as a callback for the AStar search
if (router.graphVisualizer != null) {
aStar.setTraverseVisitor(router.graphVisualizer.traverseVisitor);
// options.disableRemainingWeightHeuristic = true; // DEBUG
}
// FORCING the dominance function to weight only
options.dominanceFunction = new DominanceFunction.MinimumWeight();
LOG.debug("rreq={}", options);
// Choose an appropriate heuristic for goal direction.
RemainingWeightHeuristic heuristic;
if (options.disableRemainingWeightHeuristic || options.oneToMany) {
heuristic = new TrivialRemainingWeightHeuristic();
} else {
heuristic = new EuclideanRemainingWeightHeuristic();
}
options.rctx.remainingWeightHeuristic = heuristic;
/* maxWalk has a different meaning than it used to. It's the radius around the origin or destination within
* which you can walk on the streets. An unlimited value would cause the bidi heuristic to do unbounded street
* searches and consider the whole graph walkable.
*
* After the limited areas of the street network around the origin and destination are explored, the
* options.maxWalkDistance will be set to unlimited for similar reasons to maxTransfers above. That happens
* in method org.opentripplanner.routing.algorithm.astar.strategies.InterleavedBidirectionalHeuristic.initialize
*/
if (options.maxWalkDistance == Double.MAX_VALUE)
options.maxWalkDistance = DEFAULT_MAX_WALK;
if (options.maxWalkDistance > CLAMP_MAX_WALK)
options.maxWalkDistance = CLAMP_MAX_WALK;
long searchBeginTime = System.currentTimeMillis();
LOG.debug("BEGIN SEARCH");
double timeout = searchBeginTime + router.streetRoutingTimeoutSeconds() * 1000;
// Convert from absolute to relative time
timeout -= System.currentTimeMillis();
// Convert milliseconds to seconds
timeout /= 1000;
if (timeout <= 0) {
// Catch the case where advancing to the next (lower) timeout value means the search is timed out
// before it even begins. Passing a negative relative timeout in the SPT call would mean "no timeout".
options.rctx.aborted = true;
return null;
}
// Don't dig through the SPT object, just ask the A star algorithm for the states that reached the target.
aStar.getShortestPathTree(options, timeout);
List<GraphPath> paths = aStar.getPathsToTarget().stream().filter(path -> {
double duration = options.useRequestedDateTimeInMaxHours ? options.arriveBy ? options.dateTime - path.getStartTime() : path.getEndTime() - options.dateTime : path.getDuration();
return duration < options.maxHours * 60 * 60;
}).collect(Collectors.toList());
LOG.debug("we have {} paths", paths.size());
LOG.debug("END SEARCH ({} msec)", System.currentTimeMillis() - searchBeginTime);
Collections.sort(paths, options.getPathComparator(options.arriveBy));
return paths;
}
Aggregations