Search in sources :

Example 6 with TemporaryStreetLocation

use of org.opentripplanner.routing.location.TemporaryStreetLocation in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetLocationFinder.

@Test
public void testStreetLocationFinder() {
    StreetVertexIndexServiceImpl finder = new StreetVertexIndexServiceImpl(graph);
    // test that the local stop finder finds stops
    GenericLocation loc = new GenericLocation(40.01, -74.005000001);
    assertTrue(finder.getNearbyTransitStops(loc.getCoordinate(), 100).size() > 0);
    // test that the closest vertex finder returns the closest vertex
    TemporaryStreetLocation some = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.00, -74.00), null, true);
    assertNotNull(some);
    some.dispose();
    // test that the closest vertex finder correctly splits streets
    TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.01), null, false);
    assertNotNull(start);
    assertTrue("wheelchair accessibility is correctly set (splitting)", start.isWheelchairAccessible());
    Collection<Edge> edges = start.getOutgoing();
    start.dispose();
    assertEquals(2, edges.size());
    RoutingRequest biking = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
    TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), biking, true);
    assertNotNull(end);
    edges = end.getIncoming();
    end.dispose();
    assertEquals(2, edges.size());
    // test that it is possible to travel between two splits on the same street
    RoutingRequest walking = new RoutingRequest(TraverseMode.WALK);
    start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.0), walking, false);
    exception.expect(TrivialPathException.class);
    end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), walking, true);
/*assertNotNull(end);
        // The visibility for temp edges for start and end is set in the setRoutingContext call
        walking.setRoutingContext(graph, start, end);
        ShortestPathTree spt = aStar.getShortestPathTree(walking);
        GraphPath path = spt.getPath(end, false);
        for (State s : path.states) {
            assertFalse(s.getBackEdge() == top);
        }
        walking.cleanup();*/
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl) Test(org.junit.Test)

Example 7 with TemporaryStreetLocation

use of org.opentripplanner.routing.location.TemporaryStreetLocation 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(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 8 with TemporaryStreetLocation

use of org.opentripplanner.routing.location.TemporaryStreetLocation in project OpenTripPlanner by opentripplanner.

the class GraphPathToTripPlanConverter method makePlace.

/**
 * Make a {@link Place} to add to a {@link Leg}.
 *
 * @param state The {@link State} that the {@link Place} pertains to.
 * @param vertex The {@link Vertex} at the {@link State}.
 * @param edge The {@link Edge} leading out of the {@link Vertex}.
 * @param stop The {@link Stop} associated with the {@link Vertex}.
 * @param tripTimes The {@link TripTimes} associated with the {@link Leg}.
 * @return The resulting {@link Place} object.
 */
private static Place makePlace(State state, Vertex vertex, Edge edge, Stop stop, TripTimes tripTimes, Locale requestedLocale) {
    // If no edge was given, it means we're at the end of this leg and need to work around that.
    boolean endOfLeg = (edge == null);
    String name = vertex.getName(requestedLocale);
    // We use name in TemporaryStreetLocation since this name generation already happened when temporary location was generated
    if (vertex instanceof StreetVertex && !(vertex instanceof TemporaryStreetLocation)) {
        name = ((StreetVertex) vertex).getIntersectionName(requestedLocale).toString(requestedLocale);
    }
    Place place = new Place(vertex.getX(), vertex.getY(), name, makeCalendar(state), makeCalendar(state));
    if (endOfLeg)
        edge = state.getBackEdge();
    if (vertex instanceof TransitVertex && edge instanceof OnboardEdge) {
        place.stopId = stop.getId();
        place.stopCode = stop.getCode();
        place.platformCode = stop.getPlatformCode();
        place.zoneId = stop.getZoneId();
        place.stopIndex = ((OnboardEdge) edge).getStopIndex();
        if (endOfLeg)
            place.stopIndex++;
        if (tripTimes != null) {
            place.stopSequence = tripTimes.getStopSequence(place.stopIndex);
        }
        place.vertexType = VertexType.TRANSIT;
    } else if (vertex instanceof BikeRentalStationVertex) {
        place.bikeShareId = ((BikeRentalStationVertex) vertex).getId();
        LOG.trace("Added bike share Id {} to place", place.bikeShareId);
        place.vertexType = VertexType.BIKESHARE;
    } else if (vertex instanceof BikeParkVertex) {
        place.vertexType = VertexType.BIKEPARK;
    } else {
        place.vertexType = VertexType.NORMAL;
    }
    return place;
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LineString(com.vividsolutions.jts.geom.LineString)

Example 9 with TemporaryStreetLocation

use of org.opentripplanner.routing.location.TemporaryStreetLocation 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 10 with TemporaryStreetLocation

use of org.opentripplanner.routing.location.TemporaryStreetLocation 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)

Aggregations

TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)12 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)9 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)9 Test (org.junit.Test)8 Edge (org.opentripplanner.routing.graph.Edge)7 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 TemporaryFreeEdge (org.opentripplanner.routing.edgetype.TemporaryFreeEdge)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)5 State (org.opentripplanner.routing.core.State)5 GraphPath (org.opentripplanner.routing.spt.GraphPath)5 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)5 HashSet (java.util.HashSet)4 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)4 LineString (com.vividsolutions.jts.geom.LineString)3 ArrayList (java.util.ArrayList)2 GenericLocation (org.opentripplanner.common.model.GenericLocation)2 TraverseMode (org.opentripplanner.routing.core.TraverseMode)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)2