Search in sources :

Example 31 with GraphPath

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

the class TestParkAndRide method testBike.

public void testBike() throws Exception {
    AStar aStar = new AStar();
    // Impossible to get from B to D in BIKE+WALK (no bike P+R).
    RoutingRequest options = new RoutingRequest("BICYCLE_PARK,TRANSIT");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, B, D);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(D, false);
    assertNull(path);
    // So we add a bike P+R at C.
    BikePark bpc = new BikePark();
    bpc.id = "bpc";
    bpc.name = "Bike Park C";
    bpc.x = 0.002;
    bpc.y = 45.00001;
    bpc.spacesAvailable = 1;
    BikeParkVertex BPRC = new BikeParkVertex(graph, bpc);
    new BikeParkEdge(BPRC);
    new StreetBikeParkLink(BPRC, C);
    new StreetBikeParkLink(C, BPRC);
    // Still impossible from B to D by bike only (CD is WALK only).
    options = new RoutingRequest("BICYCLE");
    options.setRoutingContext(graph, B, D);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(D, false);
    assertNotNull(path);
    State s = tree.getState(D);
    assertFalse(s.isBikeParked());
    // TODO backWalkingBike flag is broken
    // assertTrue(s.isBackWalkingBike());
    assertTrue(s.getBackMode() == TraverseMode.WALK);
    // But we can go from B to D using bike P+R.
    options = new RoutingRequest("BICYCLE_PARK,WALK,TRANSIT");
    options.setRoutingContext(graph, B, D);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(D, false);
    assertNotNull(path);
    s = tree.getState(D);
    assertTrue(s.isBikeParked());
    assertFalse(s.isBackWalkingBike());
}
Also used : BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) BikePark(org.opentripplanner.routing.bike_park.BikePark)

Example 32 with GraphPath

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

the class TurnRestrictionTest method testForwardAsPedestrian.

@Test
public void testForwardAsPedestrian() {
    RoutingRequest options = new RoutingRequest(TraverseMode.WALK);
    options.walkSpeed = 1.0;
    options.setRoutingContext(_graph, topRight, bottomLeft);
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(bottomLeft, false);
    assertNotNull(path);
    // Since there are no turn restrictions applied to the default modes (walking + transit)
    // the shortest path is 1st to Main, Main to 2nd, 2nd to Broad and Broad until the
    // corner of Broad and 3rd.
    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());
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 33 with GraphPath

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

the class TurnRestrictionTest method testForwardDefault.

@Test
public void testForwardDefault() {
    RoutingRequest options = new RoutingRequest();
    options.carSpeed = 1.0;
    options.walkSpeed = 1.0;
    options.setRoutingContext(_graph, topRight, bottomLeft);
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(bottomLeft, false);
    assertNotNull(path);
    // Since there are no turn restrictions applied to the default modes (walking + transit)
    // the shortest path is 1st to Main, Main to 2nd, 2nd to Broad and Broad until the
    // corner of Broad and 3rd.
    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());
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 34 with GraphPath

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

the class TestGraphPath method testGraphPathOptimize.

public void testGraphPathOptimize() throws Exception {
    String feedId = graph.getFeedIds().iterator().next();
    Vertex stop_a = graph.getVertex(feedId + ":A");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    Vertex stop_e = graph.getVertex(feedId + ":E");
    ShortestPathTree spt;
    GraphPath path;
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
    options.setRoutingContext(graph, stop_a.getLabel(), stop_e.getLabel());
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_e, false);
    /* do not optimize yet, since we are testing optimization */
    assertNotNull(path);
    // Check that the resulting path visits the stops in the right order.
    List<Vertex> stopvs = Lists.newArrayList();
    for (State state : path.states) {
        if (state.getVertex() instanceof TransitStop) {
            stopvs.add(state.getVertex());
        }
    }
    assertTrue(stopvs.get(0) == stop_a);
    assertTrue(stopvs.get(1) == stop_c);
    assertTrue(stopvs.get(2) == stop_e);
    long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
    assertNotSame(bestStart, path.getStartTime());
    path = spt.getPath(stop_e, true);
    /* optimize */
    assertEquals(bestStart, path.getStartTime());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 35 with GraphPath

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

the class TurnCostTest method testForwardCarConstTurnCosts.

@Test
public void testForwardCarConstTurnCosts() {
    RoutingRequest options = proto.clone();
    options.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, topRight, bottomLeft);
    // Without turn costs, this path costs 3x100 + 1x50 = 350.
    // Since there are 3 turns, the total cost should be 380.
    GraphPath path = checkForwardRouteDuration(options, 380);
    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());
    assertEquals(0, states.get(0).getElapsedTimeSeconds());
    // maple_main1 = 50
    assertEquals(50, states.get(1).getElapsedTimeSeconds());
    // main1_2 = 100
    assertEquals(160, states.get(2).getElapsedTimeSeconds());
    // broad1_2 = 100
    assertEquals(270, states.get(3).getElapsedTimeSeconds());
    // broad2_3 = 100
    assertEquals(380, 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)

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