Search in sources :

Example 6 with AStar

use of org.opentripplanner.routing.algorithm.astar.AStar 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(TraverseMode.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(new TraverseModeSet(TraverseMode.WALK, TraverseMode.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(new TraverseModeSet(TraverseMode.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(new TraverseModeSet(TraverseMode.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(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
    options.parkAndRide = true;
    // 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(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
    options.parkAndRide = true;
    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(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
    options.parkAndRide = true;
    options.setArriveBy(true);
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
    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(new TraverseModeSet(TraverseMode.WALK, TraverseMode.CAR, TraverseMode.TRANSIT));
    options.parkAndRide = true;
    // options.arriveBy
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new EuclideanRemainingWeightHeuristic();
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNotNull(path);
}
Also used : ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) EuclideanRemainingWeightHeuristic(org.opentripplanner.routing.algorithm.astar.strategies.EuclideanRemainingWeightHeuristic)

Example 7 with AStar

use of org.opentripplanner.routing.algorithm.astar.AStar 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(new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.TRANSIT));
    options.bikeParkAndRide = true;
    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(new TraverseModeSet(TraverseMode.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(new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.WALK, TraverseMode.TRANSIT));
    options.bikeParkAndRide = true;
    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) AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetBikeParkLink(org.opentripplanner.routing.edgetype.StreetBikeParkLink) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) BikeParkEdge(org.opentripplanner.routing.edgetype.BikeParkEdge) BikePark(org.opentripplanner.routing.bike_park.BikePark)

Example 8 with AStar

use of org.opentripplanner.routing.algorithm.astar.AStar in project OpenTripPlanner by opentripplanner.

the class AStarTest method testForward.

@Test
public void testForward() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setRoutingContext(graph, graph.getVertex("56th_24th"), graph.getVertex("leary_20th"));
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(graph.getVertex("leary_20th"), false);
    List<State> states = path.states;
    assertEquals(7, states.size());
    assertEquals("56th_24th", states.get(0).getVertex().getLabel());
    assertEquals("market_24th", states.get(1).getVertex().getLabel());
    assertEquals("market_ballard", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("leary_vernon", states.get(5).getVertex().getLabel());
    assertEquals("leary_20th", states.get(6).getVertex().getLabel());
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Test(org.junit.Test)

Example 9 with AStar

use of org.opentripplanner.routing.algorithm.astar.AStar in project OpenTripPlanner by opentripplanner.

the class AStarTest method testBackExtraEdges.

@Test
public void testBackExtraEdges() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setArriveBy(true);
    TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
    new TemporaryConcreteEdge(from, graph.getVertex("shilshole_22nd"));
    TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
    new TemporaryConcreteEdge(graph.getVertex("56th_20th"), to);
    options.setRoutingContext(graph, from, to);
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    options.cleanup();
    GraphPath path = tree.getPath(from, false);
    List<State> states = path.states;
    assertEquals(9, states.size());
    assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
    assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
    assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("market_russell", states.get(5).getVertex().getLabel());
    assertEquals("market_20th", states.get(6).getVertex().getLabel());
    assertEquals("56th_20th", states.get(7).getVertex().getLabel());
    assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(org.locationtech.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) TemporaryConcreteEdge(org.opentripplanner.routing.graph.TemporaryConcreteEdge) AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Test(org.junit.Test)

Example 10 with AStar

use of org.opentripplanner.routing.algorithm.astar.AStar 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) AStar(org.opentripplanner.routing.algorithm.astar.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Test(org.junit.Test)

Aggregations

AStar (org.opentripplanner.routing.algorithm.astar.AStar)17 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)16 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)15 Test (org.junit.Test)9 State (org.opentripplanner.routing.core.State)9 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)4 Edge (org.opentripplanner.routing.graph.Edge)4 Vertex (org.opentripplanner.routing.graph.Vertex)4 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)4 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)4 HashSet (java.util.HashSet)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 TrivialRemainingWeightHeuristic (org.opentripplanner.routing.algorithm.astar.strategies.TrivialRemainingWeightHeuristic)3 EuclideanRemainingWeightHeuristic (org.opentripplanner.routing.algorithm.astar.strategies.EuclideanRemainingWeightHeuristic)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 Graph (org.opentripplanner.routing.graph.Graph)2 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)2 File (java.io.File)1 URL (java.net.URL)1