Search in sources :

Example 56 with GraphPath

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

the class TestHalfEdges method testRouteToSameEdge.

@Test
public void testRouteToSameEdge() {
    RoutingRequest options = new RoutingRequest();
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), true);
    assertEquals(start.getX(), end.getX(), 0.0001);
    assertTrue(start.getY() < end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(2, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, start, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    assertEquals(1, path.edges.size());
    options.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with GraphPath

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

the class TestHalfEdges method testRouteToSameEdgeBackwards.

@Test
public void testRouteToSameEdgeBackwards() {
    RoutingRequest options = new RoutingRequest();
    // Sits only on the leftmost edge, not on its reverse.
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), false);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), true);
    assertEquals(start.getX(), end.getX(), 0.001);
    assertTrue(start.getY() > end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(1, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, start, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    assertTrue(path.edges.size() > 1);
    options.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with GraphPath

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

the class AStarTest method testBack.

@Test
public void testBack() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setArriveBy(true);
    options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(_graph.getVertex("56th_24th"), false);
    List<State> states = path.states;
    assertTrue(states.size() == 6 || states.size() == 7);
    assertEquals("56th_24th", states.get(0).getVertex().getLabel());
    int n;
    // we could go either way around the block formed by 56th, 22nd, market, and 24th.
    if (states.size() == 7) {
        assertEquals("market_24th", states.get(1).getVertex().getLabel());
        assertEquals("market_ballard", states.get(2).getVertex().getLabel());
        n = 0;
    } else {
        assertEquals("56th_22nd", states.get(1).getVertex().getLabel());
        n = -1;
    }
    assertEquals("market_22nd", states.get(n + 3).getVertex().getLabel());
    assertEquals("market_leary", states.get(n + 4).getVertex().getLabel());
    assertEquals("leary_vernon", states.get(n + 5).getVertex().getLabel());
    assertEquals("leary_20th", states.get(n + 6).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 59 with GraphPath

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

the class AStarTest method testForwardExtraEdges.

@Test
public void testForwardExtraEdges() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    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(to, 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(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) TemporaryConcreteEdge(org.opentripplanner.routing.graph.TemporaryConcreteEdge) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 60 with GraphPath

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

the class AStarTest method testMultipleTargets.

@Test
public void testMultipleTargets() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.batch = true;
    options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
    Set<Vertex> targets = new HashSet<Vertex>();
    targets.add(_graph.getVertex("shilshole_22nd"));
    targets.add(_graph.getVertex("market_russell"));
    targets.add(_graph.getVertex("56th_20th"));
    targets.add(_graph.getVertex("leary_20th"));
    SearchTerminationStrategy strategy = new MultiTargetTerminationStrategy(targets);
    ShortestPathTree tree = new AStar().getShortestPathTree(options, -1, strategy);
    for (Vertex v : targets) {
        GraphPath path = tree.getPath(v, false);
        assertNotNull("No path found for target " + v.getLabel(), path);
    }
}
Also used : SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) MultiTargetTerminationStrategy(org.opentripplanner.routing.algorithm.strategies.MultiTargetTerminationStrategy) SearchTerminationStrategy(org.opentripplanner.routing.algorithm.strategies.SearchTerminationStrategy) HashSet(java.util.HashSet) 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