use of org.opentripplanner.routing.algorithm.AStar in project OpenTripPlanner by opentripplanner.
the class AlertPatchTest method setUp.
public void setUp() throws Exception {
aStar = new AStar();
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
options = new RoutingRequest();
graph = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
graph.index(new DefaultStreetVertexIndexFactory());
feedId = context.getFeedId().getId();
}
use of org.opentripplanner.routing.algorithm.AStar in project OpenTripPlanner by opentripplanner.
the class ProfileRouter method findClosestStops.
/**
* Perform an on-street search around a point with a specific mode to find nearby stops.
* @param dest : whether to search at the destination instead of the origin.
*/
private Collection<StopAtDistance> findClosestStops(final QualifiedMode qmode, boolean dest) {
// Make a normal OTP routing request so we can traverse edges and use GenericAStar
// TODO make a function that builds normal routing requests from profile requests
RoutingRequest rr = new RoutingRequest(new TraverseModeSet());
qmode.applyToRoutingRequest(rr, request.transitModes.isTransit());
rr.from = (new GenericLocation(request.fromLat, request.fromLon));
// FIXME requires destination to be set, not necessary for analyst
rr.to = new GenericLocation(request.toLat, request.toLon);
rr.setArriveBy(dest);
rr.setRoutingContext(graph);
// Set batch after context, so both origin and dest vertices will be found.
rr.batch = (true);
rr.walkSpeed = request.walkSpeed;
rr.dominanceFunction = new DominanceFunction.EarliestArrival();
// RR dateTime defaults to currentTime.
// If elapsed time is not capped, searches are very slow.
int minAccessTime = 0;
int maxAccessTime = request.maxWalkTime;
if (qmode.mode == TraverseMode.BICYCLE) {
rr.bikeSpeed = request.bikeSpeed;
minAccessTime = request.minBikeTime;
maxAccessTime = request.maxBikeTime;
rr.optimize = OptimizeType.TRIANGLE;
rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
} else if (qmode.mode == TraverseMode.CAR) {
rr.carSpeed = request.carSpeed;
minAccessTime = request.minCarTime;
maxAccessTime = request.maxCarTime;
}
// convert from minutes to seconds
long worstElapsedTimeSeconds = maxAccessTime * 60;
if (dest)
worstElapsedTimeSeconds *= -1;
rr.worstTime = (rr.dateTime + worstElapsedTimeSeconds);
AStar astar = new AStar();
rr.setNumItineraries(1);
StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(qmode, minAccessTime * 60);
astar.setTraverseVisitor(visitor);
// timeout in seconds
astar.getShortestPathTree(rr, 5);
// Save the routing context for later cleanup. We need its temporary edges to render street segments at the end.
routingContexts.add(rr.rctx);
return visitor.stopClustersFound.values();
}
use of org.opentripplanner.routing.algorithm.AStar in project OpenTripPlanner by opentripplanner.
the class ProfileRouter method findDirectOption.
/**
* Look for an option connecting origin to destination without using transit.
*/
private void findDirectOption(QualifiedMode qmode) {
// Make a normal OTP routing request so we can traverse edges and use GenericAStar
RoutingRequest rr = new RoutingRequest(new TraverseModeSet());
// false because we never use transit in direct options
qmode.applyToRoutingRequest(rr, false);
if (qmode.mode == TraverseMode.BICYCLE) {
// TRIANGLE should only affect bicycle searches, but we wrap this in a conditional just to be clear.
rr.optimize = OptimizeType.TRIANGLE;
rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
}
rr.from = (new GenericLocation(request.fromLat, request.fromLon));
rr.to = new GenericLocation(request.toLat, request.toLon);
rr.setArriveBy(false);
rr.setRoutingContext(graph);
rr.dominanceFunction = new DominanceFunction.MinimumWeight();
// This is not a batch search, it is a point-to-point search with goal direction.
// Impose a max time to protect against very slow searches.
int worstElapsedTime = request.streetTime * 60;
rr.worstTime = (rr.dateTime + worstElapsedTime);
rr.walkSpeed = request.walkSpeed;
rr.bikeSpeed = request.bikeSpeed;
AStar astar = new AStar();
rr.setNumItineraries(1);
ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
State state = spt.getState(rr.rctx.target);
if (state != null) {
LOG.info("Found non-transit option for {}", qmode);
directPaths.add(new StopAtDistance(state, qmode));
}
// save context for later cleanup so temp edges remain available
routingContexts.add(rr.rctx);
}
use of org.opentripplanner.routing.algorithm.AStar in project OpenTripPlanner by opentripplanner.
the class RoundBasedProfileRouter method findInitialStops.
/**
* find the boarding stops
*/
private Collection<ProfileState> findInitialStops(boolean dest) {
double lat = dest ? request.toLat : request.fromLat;
double lon = dest ? request.toLon : request.fromLon;
QualifiedModeSet modes = dest ? request.accessModes : request.egressModes;
List<ProfileState> stops = Lists.newArrayList();
RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
rr.dominanceFunction = new DominanceFunction.EarliestArrival();
rr.batch = true;
rr.from = new GenericLocation(lat, lon);
rr.walkSpeed = request.walkSpeed;
rr.to = rr.from;
rr.setRoutingContext(graph);
// RoutingRequest dateTime defaults to currentTime.
// If elapsed time is not capped, searches are very slow.
rr.worstTime = (rr.dateTime + request.maxWalkTime * 60);
AStar astar = new AStar();
rr.longDistance = true;
rr.setNumItineraries(1);
// timeout in seconds
ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
for (TransitStop tstop : graph.index.stopVertexForStop.values()) {
State s = spt.getState(tstop);
if (s != null) {
ProfileState ps = new ProfileState();
ps.lowerBound = ps.upperBound = (int) s.getElapsedTimeSeconds();
ps.stop = tstop;
ps.accessType = Type.STREET;
stops.add(ps);
}
}
Map<TripPattern, ProfileState> optimalBoardingLocation = Maps.newHashMap();
TObjectIntMap<TripPattern> minBoardTime = new TObjectIntHashMap<TripPattern>(100, 0.75f, Integer.MAX_VALUE);
// Only board patterns at the closest possible stop
for (ProfileState ps : stops) {
for (TripPattern pattern : graph.index.patternsForStop.get(ps.stop.getStop())) {
if (ps.lowerBound < minBoardTime.get(pattern)) {
optimalBoardingLocation.put(pattern, ps);
minBoardTime.put(pattern, ps.lowerBound);
}
}
ps.targetPatterns = Sets.newHashSet();
}
LOG.info("Found {} reachable stops, filtering to only board at closest stops", stops.size());
for (Entry<TripPattern, ProfileState> e : optimalBoardingLocation.entrySet()) {
e.getValue().targetPatterns.add(e.getKey());
}
for (Iterator<ProfileState> it = stops.iterator(); it.hasNext(); ) {
if (it.next().targetPatterns.isEmpty())
it.remove();
}
rr.cleanup();
return stops;
}
use of org.opentripplanner.routing.algorithm.AStar in project OpenTripPlanner by opentripplanner.
the class AnalystProfileRouterPrototype method findClosestStops.
/**
* Perform an on-street search around a point with a specific mode to find nearby stops.
* TODO merge with NearbyStopFinder
*/
private TObjectIntMap<Stop> findClosestStops(final TraverseMode mode) {
RoutingRequest rr = new RoutingRequest(mode);
GenericLocation gl = new GenericLocation(request.fromLat, request.fromLon);
rr.from = gl;
// FIXME destination must be set, even though this is meaningless for one-to-many
rr.to = gl;
rr.setRoutingContext(graph);
// Set batch after context, so both origin and dest vertices will be found.
rr.batch = (true);
rr.walkSpeed = request.walkSpeed;
// RR dateTime defaults to currentTime.
// If elapsed time is not capped, searches are very slow.
int minAccessTime = 0;
int maxAccessTime = request.maxWalkTime;
rr.worstTime = (rr.dateTime + maxAccessTime * 60);
AStar astar = new AStar();
rr.dominanceFunction = new DominanceFunction.EarliestArrival();
rr.setNumItineraries(1);
StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(mode, minAccessTime * 60);
astar.setTraverseVisitor(visitor);
// timeout in seconds
astar.getShortestPathTree(rr, 5);
rr.cleanup();
return visitor.stopsFound;
}
Aggregations