Search in sources :

Example 66 with GraphPath

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

the class TestTransfers method testStopToStopTransferWithFrequencyInReverse.

public void testStopToStopTransferWithFrequencyInReverse() throws Exception {
    // Replace the transfer table with an empty table
    TransferTable table = new TransferTable();
    when(graph.getTransferTable()).thenReturn(table);
    // Compute a normal path between two stops
    Vertex origin = graph.getVertex(feedId + ":U");
    Vertex destination = graph.getVertex(feedId + ":J");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.setArriveBy(true);
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options);
    trips = extractTrips(path);
    // Validate result
    assertEquals("15.1", trips.get(0).getId().getId());
    assertEquals("5.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long time = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && s.getBackState() != null) {
            time = s.getBackState().getTimeSeconds();
            break;
        }
    }
    assertTrue(time >= 0);
    // Add transfer to table such that the next trip will be chosen
    // (there are 3600 seconds between trips), transfer time was 75 seconds
    Stop stopV = new Stop();
    stopV.setId(new AgencyAndId(feedId, "V"));
    Stop stopI = new Stop();
    stopI.setId(new AgencyAndId(feedId, "I"));
    table.addTransferTime(stopV, stopI, null, null, null, null, 3675);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("15.1", trips.get(0).getId().getId());
    assertEquals("5.1", trips.get(1).getId().getId());
    // Find state with FrequencyBoard back edge and save time of that state
    long newTime = -1;
    for (State s : path.states) {
        if (s.getBackEdge() instanceof TransitBoardAlight && s.getBackState() != null) {
            newTime = s.getBackState().getTimeSeconds();
            break;
        }
    }
    assertTrue(newTime >= 0);
    assertTrue(newTime < time);
    assertEquals(3600, time - newTime);
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 67 with GraphPath

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

the class TestTransfers method testTimedStopToStopTransfer.

public void testTimedStopToStopTransfer() throws Exception {
    ServiceDate serviceDate = new ServiceDate(2009, 07, 11);
    // Replace the transfer table with an empty table
    TransferTable table = new TransferTable();
    when(graph.getTransferTable()).thenReturn(table);
    // Compute a normal path between two stops
    Vertex origin = graph.getVertex(feedId + ":N");
    Vertex destination = graph.getVertex(feedId + ":H");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options);
    trips = extractTrips(path);
    // Validate result
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Add timed transfer to table
    Stop stopK = new Stop();
    stopK.setId(new AgencyAndId(feedId, "K"));
    Stop stopF = new Stop();
    stopF.setId(new AgencyAndId(feedId, "F"));
    table.addTransferTime(stopK, stopF, null, null, null, null, StopTransfer.TIMED_TRANSFER);
    // Don't forget to also add a TimedTransferEdge
    Vertex fromVertex = graph.getVertex(feedId + ":K_arrive");
    Vertex toVertex = graph.getVertex(feedId + ":F_depart");
    TimedTransferEdge timedTransferEdge = new TimedTransferEdge(fromVertex, toVertex);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether the trips are still the same
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Now apply a real-time update: let the to-trip be early by 27600 seconds,
    // resulting in a transfer time of 0 seconds
    Trip trip = graph.index.tripForId.get(new AgencyAndId("agency", "4.2"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 55200, 55200, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether the trips are still the same
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Now apply a real-time update: let the to-trip be early by 27601 seconds,
    // resulting in a transfer time of -1 seconds
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 55199, 55199, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.3", trips.get(1).getId().getId());
    // "Revert" the real-time update
    applyUpdateToTripPattern(pattern, "4.2", "F", 1, 82800, 82800, ScheduleRelationship.SCHEDULED, 0, serviceDate);
    // Remove the timed transfer from the graph
    graph.removeEdge(timedTransferEdge);
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Trip(org.onebusaway.gtfs.model.Trip) TimedTransferEdge(org.opentripplanner.routing.edgetype.TimedTransferEdge) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath) TripPattern(org.opentripplanner.routing.edgetype.TripPattern)

Example 68 with GraphPath

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

the class TurnCostTest method testForwardDefaultConstTurnCosts.

@Test
public void testForwardDefaultConstTurnCosts() {
    RoutingRequest options = proto.clone();
    options.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
    options.setRoutingContext(_graph, topRight, bottomLeft);
    // Without turn costs, this path costs 2x100 + 2x50 = 300.
    // Since we traverse 3 intersections, the total cost should be 330.
    GraphPath path = checkForwardRouteDuration(options, 330);
    // The intersection traversal cost should be applied to the state *after*
    // the intersection itself.
    List<State> states = path.states;
    assertEquals(5, states.size());
    assertEquals("maple_1st", states.get(0).getVertex().getLabel());
    assertEquals("main_1st", states.get(1).getVertex().getLabel());
    assertEquals("main_2nd", states.get(2).getVertex().getLabel());
    assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
    assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
    assertEquals(0, states.get(0).getElapsedTimeSeconds());
    // maple_main1 = 50
    assertEquals(50, states.get(1).getElapsedTimeSeconds());
    // main1_2 = 100
    assertEquals(160, states.get(2).getElapsedTimeSeconds());
    // main_broad2 = 50
    assertEquals(220, states.get(3).getElapsedTimeSeconds());
    // broad2_3 = 100
    assertEquals(330, states.get(4).getElapsedTimeSeconds());
}
Also used : State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) ConstantIntersectionTraversalCostModel(org.opentripplanner.routing.core.ConstantIntersectionTraversalCostModel) Test(org.junit.Test)

Example 69 with GraphPath

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

the class TurnCostTest method testForwardCarNoTurnCosts.

@Test
public void testForwardCarNoTurnCosts() {
    RoutingRequest options = proto.clone();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, topRight, bottomLeft);
    // Without turn costs, this path costs 3x100 + 1x50 = 300.
    GraphPath path = checkForwardRouteDuration(options, 350);
    List<State> states = path.states;
    assertEquals(5, states.size());
    assertEquals("maple_1st", states.get(0).getVertex().getLabel());
    assertEquals("main_1st", states.get(1).getVertex().getLabel());
    assertEquals("broad_1st", states.get(2).getVertex().getLabel());
    assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
    assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
}
Also used : State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 70 with GraphPath

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

the class TestPatternHopFactory method testPickupDropoff.

public void testPickupDropoff() throws Exception {
    Vertex stop_o = graph.getVertex(feedId + ":O_depart");
    Vertex stop_p = graph.getVertex(feedId + ":P");
    assertEquals(2, stop_o.getOutgoing().size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 0, 0);
    RoutingRequest options = new RoutingRequest();
    options.dateTime = startTime;
    options.setRoutingContext(graph, stop_o, stop_p);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(stop_p, false);
    assertNotNull(path);
    long endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 10, 0);
    assertEquals(endTime, path.getEndTime());
    startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 12, 0, 1);
    options.dateTime = startTime;
    options.setRoutingContext(graph, stop_o, stop_p);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_p, false);
    assertNotNull(path);
    endTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 15, 10, 0);
    assertEquals(endTime, 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)

Aggregations

GraphPath (org.opentripplanner.routing.spt.GraphPath)76 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)47 Vertex (org.opentripplanner.routing.graph.Vertex)39 State (org.opentripplanner.routing.core.State)25 Test (org.junit.Test)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 Edge (org.opentripplanner.routing.graph.Edge)15 Graph (org.opentripplanner.routing.graph.Graph)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 Stop (org.onebusaway.gtfs.model.Stop)10 HashSet (java.util.HashSet)9 Trip (org.onebusaway.gtfs.model.Trip)9 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)9 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)8 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)6 File (java.io.File)5 TransitBoardAlight (org.opentripplanner.routing.edgetype.TransitBoardAlight)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5