use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testFrequencies.
public void testFrequencies() {
Vertex stop_u = graph.getVertex(feedId + ":U_depart");
Vertex stop_v = graph.getVertex(feedId + ":V_arrive");
ShortestPathTree spt;
GraphPath path;
RoutingRequest options = new RoutingRequest();
options.setModes(new TraverseModeSet("TRANSIT"));
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_u, stop_v);
// U to V - original stop times - shouldn't be used
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_v, false);
assertNotNull(path);
assertEquals(4, path.states.size());
long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 6, 40, 0);
assertEquals(endTime, path.getEndTime());
// U to V - first frequency
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 7, 0, 0);
options.setRoutingContext(graph, stop_u, stop_v);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_v, false);
assertNotNull(path);
assertEquals(4, path.states.size());
endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 7, 40, 0);
assertEquals(endTime, path.getEndTime());
// U to V - second frequency
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 14, 0, 0);
options.setRoutingContext(graph, stop_u, stop_v);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_v, false);
assertNotNull(path);
assertEquals(4, path.states.size());
endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 14, 40, 0);
assertEquals(endTime, path.getEndTime());
// TODO more detailed testing of frequencies
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testWheelchairAccessible.
public void testWheelchairAccessible() throws Exception {
Vertex near_a = graph.getVertex("near_1_" + feedId + "_entrance_a");
Vertex near_b = graph.getVertex("near_1_" + feedId + "_entrance_b");
Vertex near_c = graph.getVertex("near_1_" + feedId + "_C");
Vertex near_e = graph.getVertex("near_1_" + feedId + "_E");
Vertex stop_d = graph.getVertex(feedId + ":D");
Vertex split_d = null;
for (StreetTransitLink e : Iterables.filter(stop_d.getOutgoing(), StreetTransitLink.class)) {
split_d = e.getToVertex();
}
RoutingRequest options = new RoutingRequest();
options.wheelchairAccessible = true;
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 0, 0);
ShortestPathTree spt;
GraphPath path;
// stop B is accessible, so there should be a path.
options.setRoutingContext(graph, near_a, near_b);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(near_b, false);
assertNotNull(path);
// stop C is not accessible, so there should be no path.
options.setRoutingContext(graph, near_a, near_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(near_c, false);
assertNull(path);
// stop E has no accessibility information, but we should still be able to route to it.
options.setRoutingContext(graph, near_a, near_e);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(near_e, false);
assertNotNull(path);
// from stop A to stop D would normally be trip 1.1 to trip 2.1, arriving at 00:30. But trip
// 2 is not accessible, so we'll do 1.1 to 3.1, arriving at 01:00
GregorianCalendar time = new GregorianCalendar(2009, 8, 18, 0, 0, 0);
time.setTimeZone(TimeZone.getTimeZone("America/New_York"));
options.dateTime = TestUtils.toSeconds(time);
options.setRoutingContext(graph, near_a, split_d);
spt = aStar.getShortestPathTree(options);
time.add(Calendar.HOUR, 1);
// for the StreetTransitLink
time.add(Calendar.SECOND, 1);
path = spt.getPath(split_d, false);
assertNotNull(path);
assertEquals(TestUtils.toSeconds(time), path.getEndTime());
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testFewestTransfers.
public void testFewestTransfers() {
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_d = graph.getVertex(feedId + ":D");
RoutingRequest options = new RoutingRequest();
options.optimize = OptimizeType.QUICK;
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 16, 0, 0);
options.setRoutingContext(graph, stop_c, stop_d);
ShortestPathTree spt = aStar.getShortestPathTree(options);
// when optimizing for speed, take the fast two-bus path
GraphPath path = spt.getPath(stop_d, false);
assertNotNull(path);
assertEquals(TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 16, 20, 0), path.getEndTime());
// when optimizing for fewest transfers, take the slow one-bus path
options.transferPenalty = 1800;
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_d, false);
assertNotNull(path);
assertEquals(TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 16, 50, 0), path.getEndTime());
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class GraphPathFinder method getGraphPathsConsideringIntermediates.
/**
* Break up a RoutingRequest with intermediate places into separate requests, in the given order.
*
* If there are no intermediate places, issue a single request. Otherwise process the places
* list [from, i1, i2, ..., to] either from left to right (if {@code request.arriveBy==false})
* or from right to left (if {@code request.arriveBy==true}). In the latter case the order of
* the requested subpaths is (i2, to), (i1, i2), and (from, i1) which has to be reversed at
* the end.
*/
private List<GraphPath> getGraphPathsConsideringIntermediates(RoutingRequest request) {
if (request.hasIntermediatePlaces()) {
List<GenericLocation> places = Lists.newArrayList(request.from);
places.addAll(request.intermediatePlaces);
places.add(request.to);
long time = request.dateTime;
List<GraphPath> paths = new ArrayList<>();
DebugOutput debugOutput = null;
int placeIndex = (request.arriveBy ? places.size() - 1 : 1);
while (0 < placeIndex && placeIndex < places.size()) {
RoutingRequest intermediateRequest = request.clone();
intermediateRequest.setNumItineraries(1);
intermediateRequest.dateTime = time;
intermediateRequest.from = places.get(placeIndex - 1);
intermediateRequest.to = places.get(placeIndex);
intermediateRequest.rctx = null;
intermediateRequest.setRoutingContext(router.graph);
if (debugOutput != null) {
// Restore the previous debug info accumulator
intermediateRequest.rctx.debugOutput = debugOutput;
} else {
// Store the debug info accumulator
debugOutput = intermediateRequest.rctx.debugOutput;
}
List<GraphPath> partialPaths = getPaths(intermediateRequest);
if (partialPaths.size() == 0) {
return partialPaths;
}
GraphPath path = partialPaths.get(0);
paths.add(path);
time = (request.arriveBy ? path.getStartTime() : path.getEndTime());
placeIndex += (request.arriveBy ? -1 : +1);
}
request.setRoutingContext(router.graph);
request.rctx.debugOutput = debugOutput;
if (request.arriveBy) {
Collections.reverse(paths);
}
return Collections.singletonList(joinPaths(paths));
} else {
return getPaths(request);
}
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class GraphPathFinder method compactLegsByReversedSearch.
/**
* Do a full reversed search to compact the legs of the path.
*
* By doing a reversed search we are looking for later departures that will still be in time for transfer
* to the next trip, shortening the transfer wait time. Also considering other routes than the ones found
* in the original search.
*
* For arrive-by searches, we are looking to shorten transfer wait time and rather arrive earlier.
*/
private List<GraphPath> compactLegsByReversedSearch(AStar aStar, RoutingRequest originalReq, RoutingRequest options, List<GraphPath> newPaths, double timeout, RemainingWeightHeuristic remainingWeightHeuristic) {
List<GraphPath> reversedPaths = new ArrayList<>();
for (GraphPath newPath : newPaths) {
State targetAcceptedState = options.arriveBy ? newPath.states.getLast().reverse() : newPath.states.getLast();
if (targetAcceptedState.stateData.getNumBooardings() < 2) {
reversedPaths.add(newPath);
continue;
}
final long arrDepTime = targetAcceptedState.getTimeSeconds();
LOG.debug("Dep time: " + new Date(newPath.getStartTime() * 1000));
LOG.debug("Arr time: " + new Date(newPath.getEndTime() * 1000));
// find first/last transit stop
Vertex transitStop = null;
long transitStopTime = arrDepTime;
while (transitStop == null) {
if (targetAcceptedState.backEdge instanceof TransitBoardAlight) {
if (options.arriveBy) {
transitStop = targetAcceptedState.backEdge.getFromVertex();
} else {
transitStop = targetAcceptedState.backEdge.getToVertex();
}
transitStopTime = targetAcceptedState.getTimeSeconds();
}
targetAcceptedState = targetAcceptedState.getBackState();
}
// find the path from transitStop to origin/destination
Vertex fromVertex = options.arriveBy ? options.rctx.fromVertex : transitStop;
Vertex toVertex = options.arriveBy ? transitStop : options.rctx.toVertex;
RoutingRequest reversedTransitRequest = createReversedTransitRequest(originalReq, options, fromVertex, toVertex, arrDepTime, new EuclideanRemainingWeightHeuristic());
aStar.getShortestPathTree(reversedTransitRequest, timeout);
List<GraphPath> pathsToTarget = aStar.getPathsToTarget();
if (pathsToTarget.isEmpty()) {
reversedPaths.add(newPath);
continue;
}
GraphPath walkPath = pathsToTarget.get(0);
// do the reversed search to/from transitStop
Vertex fromTransVertex = options.arriveBy ? transitStop : options.rctx.fromVertex;
Vertex toTransVertex = options.arriveBy ? options.rctx.toVertex : transitStop;
RoutingRequest reversedMainRequest = createReversedMainRequest(originalReq, options, fromTransVertex, toTransVertex, transitStopTime, remainingWeightHeuristic);
aStar.getShortestPathTree(reversedMainRequest, timeout);
List<GraphPath> newRevPaths = aStar.getPathsToTarget();
if (newRevPaths.isEmpty()) {
reversedPaths.add(newPath);
} else {
List<GraphPath> joinedPaths = new ArrayList<>();
for (GraphPath newRevPath : newRevPaths) {
LOG.debug("REV Dep time: " + new Date(newRevPath.getStartTime() * 1000));
LOG.debug("REV Arr time: " + new Date(newRevPath.getEndTime() * 1000));
List<GraphPath> concatenatedPaths = Arrays.asList(newRevPath, walkPath);
if (options.arriveBy) {
Collections.reverse(concatenatedPaths);
}
GraphPath joinedPath = joinPaths(concatenatedPaths);
if ((!options.arriveBy && joinedPath.states.getFirst().getTimeInMillis() > options.dateTime * 1000) || (options.arriveBy && joinedPath.states.getLast().getTimeInMillis() < options.dateTime * 1000)) {
joinedPaths.add(joinedPath);
if (newPaths.size() > 1) {
for (AgencyAndId tripId : joinedPath.getTrips()) {
options.banTrip(tripId);
}
}
}
}
reversedPaths.addAll(joinedPaths);
}
}
return reversedPaths.isEmpty() ? newPaths : reversedPaths;
}
Aggregations