Search in sources :

Example 6 with ShortestPathTree

use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.

the class TestHopFactory method testRouting.

public void testRouting() 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");
    Vertex stop_e = graph.getVertex(feedId + ":E");
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
    ShortestPathTree spt;
    GraphPath path;
    // A to B
    options.setRoutingContext(graph, stop_a, stop_b);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_b, false);
    assertNotNull(path);
    assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_b));
    // A to C
    options.setRoutingContext(graph, stop_a, stop_c);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_c, false);
    assertNotNull(path);
    assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c));
    // A to D
    options.setRoutingContext(graph, stop_a, stop_d);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_d, false);
    assertNotNull(path);
    assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c, stop_d));
    long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0) + 40 * 60;
    assertEquals(endTime, path.getEndTime());
    // A to E
    options.setRoutingContext(graph, stop_a, stop_e);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_e, false);
    assertNotNull(path);
    assertEquals(extractStopVertices(path), Lists.newArrayList(stop_a, stop_c, stop_e));
    endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0) + 70 * 60;
    assertEquals(endTime, path.getEndTime());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 7 with ShortestPathTree

use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testTraverseMode.

public void testTraverseMode() throws Exception {
    Vertex stop_a = graph.getVertex(feedId + ":A_depart");
    Vertex stop_b = graph.getVertex(feedId + ":B_arrive");
    ShortestPathTree spt;
    RoutingRequest options = new RoutingRequest();
    options.setModes(new TraverseModeSet("TRAM,RAIL,SUBWAY,FUNICULAR,GONDOLA"));
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 0, 0, 0, 0);
    options.setRoutingContext(graph, stop_a, stop_b);
    spt = aStar.getShortestPathTree(options);
    // a to b is bus only
    assertNull(spt.getPath(stop_b, false));
    options.setModes(new TraverseModeSet("TRAM,RAIL,SUBWAY,FUNICULAR,GONDOLA,CABLE_CAR,BUS"));
    spt = aStar.getShortestPathTree(options);
    assertNotNull(spt.getPath(stop_b, false));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 8 with ShortestPathTree

use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testRouting.

public void testRouting() 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");
    Vertex stop_e = graph.getVertex(feedId + ":E");
    RoutingRequest options = new RoutingRequest();
    // test feed is designed for instantaneous transfers
    options.transferSlack = (0);
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
    options.dateTime = startTime;
    ShortestPathTree spt;
    GraphPath path;
    // A to B
    options.setRoutingContext(graph, stop_a, stop_b);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_b, false);
    assertNotNull(path);
    assertEquals(6, path.states.size());
    // A to C
    options.setRoutingContext(graph, stop_a, stop_c);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_c, false);
    assertNotNull(path);
    assertEquals(8, path.states.size());
    // A to D (change at C)
    options.setRoutingContext(graph, stop_a, stop_d);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_d, false);
    assertNotNull(path);
    // there are two paths of different lengths
    // both arrive at 40 minutes after midnight
    List<TransitStop> stops = extractStopVertices(path);
    assertEquals(stops.size(), 3);
    assertEquals(stops.get(1), stop_c);
    long endTime = startTime + 40 * 60;
    assertEquals(endTime, path.getEndTime());
    // A to E (change at C)
    options.setRoutingContext(graph, stop_a, stop_e);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_e, false);
    assertNotNull(path);
    stops = extractStopVertices(path);
    assertEquals(stops.size(), 3);
    assertEquals(stops.get(1), stop_c);
    endTime = startTime + 70 * 60;
    assertEquals(endTime, path.getEndTime());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 9 with ShortestPathTree

use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testTimelessStops.

public void testTimelessStops() throws Exception {
    Vertex stop_d = graph.getVertex(feedId + ":D");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 10, 0, 0);
    options.setRoutingContext(graph, stop_d, stop_c);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(stop_c, false);
    assertNotNull(path);
    assertEquals(TestUtils.dateInSeconds("America/New_York", 2009, 8, 1, 11, 0, 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 10 with ShortestPathTree

use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testTransfers.

public void testTransfers() throws Exception {
    TransferTable transferTable = graph.getTransferTable();
    // create dummy routes and trips
    // In tests we don't patch entities with the feed id, only default agency id is used.
    Route fromRoute = new Route();
    fromRoute.setId(new AgencyAndId("agency", "1"));
    Trip fromTrip = new Trip();
    fromTrip.setId(new AgencyAndId("agency", "1.1"));
    fromTrip.setRoute(fromRoute);
    Route toRoute = new Route();
    toRoute.setId(new AgencyAndId("agency", "2"));
    Trip toTrip = new Trip();
    toTrip.setId(new AgencyAndId("agency", "2.1"));
    toTrip.setRoute(toRoute);
    Trip toTrip2 = new Trip();
    toTrip2.setId(new AgencyAndId("agency", "2.2"));
    toTrip2.setRoute(toRoute);
    // find stops
    Stop stopK = ((TransitStopArrive) graph.getVertex(feedId + ":K_arrive")).getStop();
    Stop stopN = ((TransitStopDepart) graph.getVertex(feedId + ":N_depart")).getStop();
    Stop stopM = ((TransitStopDepart) graph.getVertex(feedId + ":M_depart")).getStop();
    assertTrue(transferTable.hasPreferredTransfers());
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, transferTable.getTransferTime(stopN, stopM, fromTrip, toTrip, true));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transferTable.getTransferTime(stopK, stopM, fromTrip, toTrip, true));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, transferTable.getTransferTime(stopN, stopK, toTrip, toTrip2, true));
    assertEquals(StopTransfer.TIMED_TRANSFER, transferTable.getTransferTime(stopN, stopK, fromTrip, toTrip, true));
    assertEquals(15, transferTable.getTransferTime(stopN, stopK, fromTrip, toTrip2, true));
    TransitStop e_arrive = (TransitStop) graph.getVertex(feedId + ":E");
    TransitStop f_depart = (TransitStop) graph.getVertex(feedId + ":F");
    Edge edge = new TransferEdge(e_arrive, f_depart, 10000, 10000);
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 50, 0);
    Vertex stop_b = graph.getVertex(feedId + ":B_depart");
    Vertex stop_g = graph.getVertex(feedId + ":G_arrive");
    RoutingRequest options = new RoutingRequest();
    options.dateTime = startTime;
    options.setRoutingContext(graph, stop_b, stop_g);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(stop_g, false);
    assertNotNull(path);
    assertTrue("expected to use much later trip due to min transfer time", path.getEndTime() - startTime > 4.5 * 60 * 60);
    /* cleanup */
    e_arrive.removeOutgoing(edge);
    f_depart.removeIncoming(edge);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath) TransferTable(org.opentripplanner.routing.core.TransferTable) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TransitStopArrive(org.opentripplanner.routing.vertextype.TransitStopArrive) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Route(org.onebusaway.gtfs.model.Route) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart)

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