use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testRoutingOverMidnight.
public void testRoutingOverMidnight() throws Exception {
// this route only runs on weekdays
Vertex stop_g = graph.getVertex(feedId + ":G_depart");
Vertex stop_h = graph.getVertex(feedId + ":H_arrive");
ShortestPathTree spt;
GraphPath path;
RoutingRequest options = new RoutingRequest();
// Friday evening
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 23, 20, 0);
options.setRoutingContext(graph, stop_g, stop_h);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_h, false);
assertNotNull(path);
assertEquals(4, path.states.size());
// Saturday morning
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 0, 5, 0);
options.dateTime = startTime;
options.setRoutingContext(graph, stop_g.getLabel(), stop_h.getLabel());
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_h, false);
assertNotNull(path);
assertEquals(4, path.states.size());
long endTime = path.getEndTime();
assertTrue(endTime < startTime + 60 * 60);
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testTripBikesAllowed.
public void testTripBikesAllowed() throws Exception {
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_b = graph.getVertex(feedId + ":B");
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_d = graph.getVertex(feedId + ":D");
RoutingRequest options = new RoutingRequest();
options.modes.setWalk(false);
options.modes.setBicycle(true);
options.modes.setTransit(true);
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 0, 0);
options.setRoutingContext(graph, stop_a, stop_b);
ShortestPathTree spt;
GraphPath path;
// route: bikes allowed, trip: no value
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_b, false);
assertNotNull(path);
// route: bikes allowed, trip: bikes not allowed
options.setRoutingContext(graph, stop_d, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNull(path);
// route: bikes not allowed, trip: bikes allowed
options.setRoutingContext(graph, stop_c, stop_d);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_d, false);
assertNotNull(path);
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverter method generatePlan.
/**
* Generates a TripPlan from a set of paths
*/
public static TripPlan generatePlan(List<GraphPath> paths, RoutingRequest request) {
Locale requestedLocale = request.locale;
GraphPath exemplar = paths.get(0);
Vertex tripStartVertex = exemplar.getStartVertex();
Vertex tripEndVertex = exemplar.getEndVertex();
String startName = tripStartVertex.getName(requestedLocale);
String endName = tripEndVertex.getName(requestedLocale);
// Use vertex labels if they don't have names
if (startName == null) {
startName = tripStartVertex.getLabel();
}
if (endName == null) {
endName = tripEndVertex.getLabel();
}
Place from = new Place(tripStartVertex.getX(), tripStartVertex.getY(), startName);
Place to = new Place(tripEndVertex.getX(), tripEndVertex.getY(), endName);
from.orig = request.from.name;
to.orig = request.to.name;
TripPlan plan = new TripPlan(from, to, request.getDateTime());
// Convert GraphPaths to Itineraries, keeping track of the best non-transit (e.g. walk/bike-only) option time
long bestNonTransitTime = Long.MAX_VALUE;
List<Itinerary> itineraries = new LinkedList<>();
for (GraphPath path : paths) {
Itinerary itinerary = generateItinerary(path, request.showIntermediateStops, request.disableAlertFiltering, requestedLocale);
itinerary = adjustItinerary(request, itinerary);
if (itinerary.transitTime == 0 && itinerary.walkTime < bestNonTransitTime) {
bestNonTransitTime = itinerary.walkTime;
}
itineraries.add(itinerary);
}
// Filter and add itineraries to plan
for (Itinerary itinerary : itineraries) {
// do not include in plan
if (itinerary.transitTime > 0 && itinerary.walkTime > bestNonTransitTime)
continue;
plan.addItinerary(itinerary);
}
if (plan != null) {
for (Itinerary i : plan.itinerary) {
/* Communicate the fact that the only way we were able to get a response was by removing a slope limit. */
i.tooSloped = request.rctx.slopeRestrictionRemoved;
/* fix up from/to on first/last legs */
if (i.legs.size() == 0) {
LOG.warn("itinerary has no legs");
continue;
}
Leg firstLeg = i.legs.get(0);
firstLeg.from.orig = plan.from.orig;
Leg lastLeg = i.legs.get(i.legs.size() - 1);
lastLeg.to.orig = plan.to.orig;
}
}
request.rctx.debugOutput.finishedRendering();
return plan;
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestIntermediatePlaces method handleRequest.
private void handleRequest(GenericLocation from, GenericLocation to, GenericLocation[] via, String modes, boolean arriveBy) {
RoutingRequest request = new RoutingRequest(modes);
request.setDateTime("2016-04-20", "13:00", timeZone);
request.setArriveBy(arriveBy);
request.from = from;
request.to = to;
for (GenericLocation intermediateLocation : via) {
request.addIntermediatePlace(intermediateLocation);
}
List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
assertNotNull(pathList);
assertFalse(pathList.isEmpty());
TripPlan plan = GraphPathToTripPlanConverter.generatePlan(pathList, request);
assertLocationIsVeryCloseToPlace(from, plan.from);
assertLocationIsVeryCloseToPlace(to, plan.to);
assertTrue(1 <= plan.itinerary.size());
for (Itinerary itinerary : plan.itinerary) {
validateIntermediatePlacesVisited(itinerary, via);
assertTrue(via.length < itinerary.legs.size());
validateLegsTemporally(request, itinerary);
validateLegsSpatially(plan, itinerary);
if (modes.contains("TRANSIT")) {
assert itinerary.transitTime > 0;
}
}
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestUnroutable method testOnBoardRouting.
/**
* Search for a path across the Willamette river. This OSM data includes a bridge that is not yet built and is
* therefore tagged highway=construction.
* TODO also test unbuilt, proposed, raceways etc.
*/
public void testOnBoardRouting() throws Exception {
RoutingRequest options = new RoutingRequest();
Vertex from = graph.getVertex("osm:node:2003617278");
Vertex to = graph.getVertex("osm:node:40446276");
options.setRoutingContext(graph, from, to);
options.setMode(TraverseMode.BICYCLE);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(to, false);
// is filtered out, thus the null check.
if (path != null) {
for (Edge edge : path.edges) {
assertFalse("Path should not use the as-yet unbuilt Tilikum Crossing bridge.", "Tilikum Crossing".equals(edge.getName()));
}
}
}
Aggregations