Search in sources :

Example 11 with ShortestPathTree

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());
}
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 12 with ShortestPathTree

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

Example 13 with ShortestPathTree

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);
}
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 14 with ShortestPathTree

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);
}
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 15 with ShortestPathTree

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;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Router(org.opentripplanner.standalone.Router) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

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