use of org.opentripplanner.routing.algorithm.astar.strategies.EuclideanRemainingWeightHeuristic 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;
}
use of org.opentripplanner.routing.algorithm.astar.strategies.EuclideanRemainingWeightHeuristic in project OpenTripPlanner by opentripplanner.
the class TestParkAndRide method testCar.
public void testCar() throws Exception {
AStar aStar = new AStar();
// It is impossible to get from A to C in WALK mode,
RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
options.setRoutingContext(graph, A, C);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(C, false);
assertNull(path);
// or CAR+WALK (no P+R).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// So we Add a P+R at B.
ParkAndRideVertex PRB = new ParkAndRideVertex(graph, "P+R", "P+R.B", 0.001, 45.00001, new NonLocalizedString("P+R B"));
new ParkAndRideEdge(PRB);
new ParkAndRideLinkEdge(PRB, B);
new ParkAndRideLinkEdge(B, PRB);
// But it is still impossible to get from A to C by WALK only
// (AB is CAR only).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// Or CAR only (BC is WALK only).
options = new RoutingRequest(new TraverseModeSet(TraverseMode.CAR));
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
// options.arriveBy
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true interleavedBidiHeuristic
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false interleavedBidiHeuristic
options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
options.parkAndRide = true;
// options.arriveBy
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
}
Aggregations