use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testPathways.
public void testPathways() throws Exception {
Vertex entrance = graph.getVertex(feedId + ":entrance_a");
assertNotNull(entrance);
Vertex stop = graph.getVertex(feedId + ":A");
assertNotNull(stop);
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 16, 0, 0);
options.setRoutingContext(graph, entrance, stop);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(stop, false);
assertNotNull(path);
assertEquals(TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 16, 0, 34), path.getEndTime());
}
use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method testRunForTrain.
public void testRunForTrain() {
/**
* This is the notorious Byrd bug: we're going from Q to T at 8:30.
* There's a trip from S to T at 8:50 and a second one at 9:50.
* To get to S by 8:50, we need to take trip 12.1 from Q to R, and 13.1
* from R to S. If we take the direct-but-slower 11.1, we'll miss
* the 8:50 and have to catch the 9:50.
*/
Vertex destination = graph.getVertex(feedId + ":T");
RoutingRequest options = new RoutingRequest();
// test is designed such that transfers must be instantaneous
options.transferSlack = (0);
GregorianCalendar startTime = new GregorianCalendar(2009, 11, 2, 8, 30, 0);
startTime.setTimeZone(TimeZone.getTimeZone("America/New_York"));
options.dateTime = TestUtils.toSeconds(startTime);
options.setRoutingContext(graph, feedId + ":Q", destination.getLabel());
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(destination, false);
long endTime = path.getEndTime();
Calendar c = new GregorianCalendar();
c.setTimeInMillis(endTime * 1000L);
assertTrue(endTime - TestUtils.toSeconds(startTime) < 7200);
}
use of org.opentripplanner.routing.spt.ShortestPathTree 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.ShortestPathTree 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.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makePoints.
/**
* @return a map from each vertex to minimum travel time over the course of the day.
*/
private Map<Vertex, Double> makePoints() throws Exception {
rangeCheckParameters();
request = buildRequest();
Router router = otpServer.getRouter(routerId);
Graph graph = router.graph;
// double speed = request.getWalkSpeed();
Coordinate originCoord = request.from.getCoordinate();
if (originCoord == null)
return null;
List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
if (stops.isEmpty()) {
LOG.error("No stops found within {} meters.", radiusMeters);
return null;
}
if (shpName == null)
shpName = stops.get(0).getName().split(" ")[0];
StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
for (TransitStop stop : stops) {
new StreetTransitLink(origin, stop, false);
LOG.debug("linked to stop {}", stop.getName());
}
request.setRoutingContext(graph, origin, null);
/* Make one request every M minutes over H hours */
int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
request.clampInitialWait = (requestSpacingMinutes * 60);
Date date = request.getDateTime();
MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
for (int r = 0; r < nRequests; r++) {
request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
/* This could even be a good use for a generic SPT merging function */
for (State s : spt.getAllStates()) {
if (stopsOnly && !(s.getVertex() instanceof TransitStop))
continue;
points.putMin(s.getVertex(), (double) (s.getActiveTime()));
}
}
graph.removeVertexAndEdges(origin);
return points;
}
Aggregations