use of org.opentripplanner.routing.spt.ShortestPathTree 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.ShortestPathTree 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.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class IsoChroneSPTRendererRecursiveGrid method getIsochrones.
/**
* @param isoChroneRequest
* @param sptRequest
* @return
*/
@Override
public List<IsochroneData> getIsochrones(IsoChroneRequest isoChroneRequest, RoutingRequest sptRequest) {
if (sptRequest.routerId != null && !sptRequest.routerId.isEmpty())
throw new IllegalArgumentException("TODO: SampleSource is not multi-router compatible (yet).");
// 1. Compute the Shortest Path Tree.
long t0 = System.currentTimeMillis();
sptRequest.worstTime = (sptRequest.dateTime + (sptRequest.arriveBy ? -isoChroneRequest.maxCutoffSec : isoChroneRequest.maxCutoffSec));
sptRequest.batch = true;
sptRequest.setRoutingContext(graph);
// TODO handle different path dominance conditions
final ShortestPathTree spt = new AStar().getShortestPathTree(sptRequest);
sptRequest.cleanup();
// 2. Compute the set of initial points
long t1 = System.currentTimeMillis();
List<Coordinate> initialPoints = computeInitialPoints(spt);
// 3. Compute the isochrone based on the SPT.
ZFunc timeFunc = new ZFunc() {
@Override
public long z(Coordinate c) {
Sample sample = sampleSource.getSample(c.x, c.y);
if (sample == null) {
return Long.MAX_VALUE;
}
Long z = sample.eval(spt);
return z;
}
};
// TODO Snap the center as XYZ tile grid for better sample-reuse (if using sample cache).
Coordinate center = sptRequest.from.getCoordinate();
double gridSizeMeters = isoChroneRequest.precisionMeters;
double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
double dX = dY / Math.cos(Math.toRadians(center.x));
LOG.info("dX={}, dY={}", dX, dY);
RecursiveGridIsolineBuilder isolineBuilder = new RecursiveGridIsolineBuilder(dX, dY, center, timeFunc, initialPoints);
isolineBuilder.setDebugCrossingEdges(isoChroneRequest.includeDebugGeometry);
isolineBuilder.setDebugSeedGrid(isoChroneRequest.includeDebugGeometry);
List<IsochroneData> isochrones = new ArrayList<IsochroneData>();
for (Integer cutoffSec : isoChroneRequest.cutoffSecList) {
IsochroneData isochrone = new IsochroneData(cutoffSec, isolineBuilder.computeIsoline(cutoffSec));
if (isoChroneRequest.includeDebugGeometry)
isochrone.debugGeometry = isolineBuilder.getDebugGeometry();
isochrones.add(isochrone);
}
long t2 = System.currentTimeMillis();
LOG.info("Computed SPT in {}msec, {} isochrones in {}msec", (int) (t1 - t0), isochrones.size(), (int) (t2 - t1));
return isochrones;
}
use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class OtpsRouter method plan.
/**
* Plan a route on the router given the various options.
*
* @param req The routing request options (date/time, modes, etc...)
* @return A Shortest-path-tree (a time+various states for each vertices around the
* origin/destination).
*/
public OtpsSPT plan(OtpsRoutingRequest req) {
try {
// TODO Is this correct?
RoutingRequest req2 = req.req.clone();
req2.setRoutingContext(router.graph);
// TODO verify that this is indeed the intended behavior.
ShortestPathTree spt = new AStar().getShortestPathTree(req2);
return new OtpsSPT(spt, router.graph.getSampleFactory());
} catch (VertexNotFoundException e) {
// Can happen, not really an error
return null;
}
}
Aggregations