Search in sources :

Example 51 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TestFares method testPortland.

public void testPortland() throws Exception {
    Graph gg = ConstantsForTests.getInstance().getPortlandGraph();
    String feedId = gg.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    ShortestPathTree spt;
    GraphPath path = null;
    long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 0, 0);
    options.dateTime = startTime;
    options.setRoutingContext(gg, feedId + ":10579", feedId + ":8371");
    // from zone 3 to zone 2
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":8371"), true);
    assertNotNull(path);
    FareService fareService = gg.getService(FareService.class);
    Fare cost = fareService.getCost(path);
    assertEquals(new Money(new WrappedCurrency("USD"), 200), cost.getFare(FareType.regular));
    // long trip
    startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 14, 0, 0);
    options.dateTime = startTime;
    options.setRoutingContext(gg, feedId + ":8389", feedId + ":1252");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":1252"), true);
    assertNotNull(path);
    cost = fareService.getCost(path);
    // assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 460));
    // complex trip
    options.maxTransfers = 5;
    startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 14, 0, 0);
    options.dateTime = startTime;
    options.setRoutingContext(gg, feedId + ":10428", feedId + ":4231");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":4231"), true);
    assertNotNull(path);
    cost = fareService.getCost(path);
// 
// this is commented out because portland's fares are, I think, broken in the gtfs. see
// thread on gtfs-changes.
// assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 430));
}
Also used : Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare)

Example 52 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TestParkAndRide method testCar.

public void testCar() throws Exception {
    AStar aStar = new AStar();
    // It is impossible to get from A to C in WALK mode,
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK"));
    options.setRoutingContext(graph, A, C);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(C, false);
    assertNull(path);
    // or CAR+WALK (no P+R).
    options = new RoutingRequest("WALK,CAR");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // So we Add a P+R at B.
    ParkAndRideVertex PRB = new ParkAndRideVertex(graph, "P+R", "P+R.B", 0.001, 45.00001, new NonLocalizedString("P+R B"));
    new ParkAndRideEdge(PRB);
    new ParkAndRideLinkEdge(PRB, B);
    new ParkAndRideLinkEdge(B, PRB);
    // But it is still impossible to get from A to C by WALK only
    // (AB is CAR only).
    options = new RoutingRequest("WALK");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // Or CAR only (BC is WALK only).
    options = new RoutingRequest("CAR");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy false
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    // options.arriveBy
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy true
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    options.setArriveBy(true);
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(A, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy true interleavedBidiHeuristic
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    options.setArriveBy(true);
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(A, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy false interleavedBidiHeuristic
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    // options.arriveBy
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNotNull(path);
}
Also used : ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) InterleavedBidirectionalHeuristic(org.opentripplanner.routing.algorithm.strategies.InterleavedBidirectionalHeuristic) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 53 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 54 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 55 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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)

Aggregations

RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)124 GraphPath (org.opentripplanner.routing.spt.GraphPath)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)52 State (org.opentripplanner.routing.core.State)42 Test (org.junit.Test)35 Vertex (org.opentripplanner.routing.graph.Vertex)35 Graph (org.opentripplanner.routing.graph.Graph)24 GenericLocation (org.opentripplanner.common.model.GenericLocation)21 Edge (org.opentripplanner.routing.graph.Edge)18 StateEditor (org.opentripplanner.routing.core.StateEditor)17 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)17 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 AStar (org.opentripplanner.routing.algorithm.AStar)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11 Trip (org.onebusaway.gtfs.model.Trip)9