Search in sources :

Example 61 with ShortestPathTree

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());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) GregorianCalendar(java.util.GregorianCalendar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 62 with ShortestPathTree

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());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 63 with ShortestPathTree

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;
}
Also used : Sample(org.opentripplanner.analyst.core.Sample) AStar(org.opentripplanner.routing.algorithm.AStar) ArrayList(java.util.ArrayList) ZFunc(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder.ZFunc) IsochroneData(org.opentripplanner.analyst.core.IsochroneData) RecursiveGridIsolineBuilder(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 64 with ShortestPathTree

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;
    }
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Aggregations

ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)64 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)52 GraphPath (org.opentripplanner.routing.spt.GraphPath)47 Vertex (org.opentripplanner.routing.graph.Vertex)34 State (org.opentripplanner.routing.core.State)24 Edge (org.opentripplanner.routing.graph.Edge)17 Test (org.junit.Test)15 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)15 Graph (org.opentripplanner.routing.graph.Graph)13 AStar (org.opentripplanner.routing.algorithm.AStar)10 HashSet (java.util.HashSet)9 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)8 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)7 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 File (java.io.File)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5