Search in sources :

Example 96 with RoutingRequest

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

the class TestHalfEdges method testStreetSplittingAlerts.

/**
 * Test that alerts on split streets are preserved, i.e. if there are alerts on the street that is split the same alerts should be present on the
 * new street.
 */
@Test
public void testStreetSplittingAlerts() {
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    Alert alert = Alert.createSimpleAlerts("This is the alert");
    Set<Alert> alerts = new HashSet<>();
    alerts.add(alert);
    graph.streetNotesService.addStaticNote(left, alert, StreetNotesService.ALWAYS_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, alert, StreetNotesService.ALWAYS_MATCHER);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    // The alert should be preserved
    // traverse the FreeEdge from the StreetLocation to the new IntersectionVertex
    RoutingRequest req = new RoutingRequest();
    req.setMaxWalkDistance(Double.MAX_VALUE);
    State traversedOne = new State(start, req);
    State currentState;
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(alerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    // now, make sure wheelchair alerts are preserved
    Alert wheelchairAlert = Alert.createSimpleAlerts("This is the wheelchair alert");
    Set<Alert> wheelchairAlerts = new HashSet<>();
    wheelchairAlerts.add(wheelchairAlert);
    graph.streetNotesService.removeStaticNotes(left);
    graph.streetNotesService.removeStaticNotes(leftBack);
    graph.streetNotesService.addStaticNote(left, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    req.setWheelchairAccessible(true);
    start.dispose();
    start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    traversedOne = new State(start, req);
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(wheelchairAlerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    start.dispose();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Alert(org.opentripplanner.routing.alertpatch.Alert) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) 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 97 with RoutingRequest

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

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

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

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

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