Search in sources :

Example 6 with GenericLocation

use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class LocationStringParserTest method testWithId.

@Test
public void testWithId() {
    GenericLocation loc = LocationStringParser.fromOldStyleString("name::aFeed:A1B2C3");
    assertEquals("name", loc.label);
    assertEquals(loc.stopId, new FeedScopedId("aFeed", "A1B2C3"));
    assertNull(loc.lat);
    assertNull(loc.lng);
    assertNull(loc.getCoordinate());
    loc = LocationStringParser.fromOldStyleString("feed:4321");
    assertNull(loc.label);
    assertEquals(loc.stopId, new FeedScopedId("feed", "4321"));
    assertNull(loc.lat);
    assertNull(loc.lng);
    assertNull(loc.getCoordinate());
}
Also used : GenericLocation(org.opentripplanner.model.GenericLocation) FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

Example 7 with GenericLocation

use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetLocationFinder.

@Test
public void testStreetLocationFinder() {
    RoutingRequest options = new RoutingRequest();
    StreetVertexIndex finder = graph.getStreetIndex();
    Set<DisposableEdgeCollection> tempEdges = new HashSet<>();
    // 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.getVertexForLocationForTest(new GenericLocation(40.00, -74.00), options, true, tempEdges);
    assertNotNull(some);
    // test that the closest vertex finder correctly splits streets
    TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocationForTest(new GenericLocation(40.004, -74.01), options, false, tempEdges);
    assertNotNull(start);
    assertTrue("wheelchair accessibility is correctly set (splitting)", start.isWheelchairAccessible());
    Collection<Edge> edges = start.getOutgoing();
    assertEquals(2, edges.size());
    RoutingRequest biking = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
    TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocationForTest(new GenericLocation(40.008, -74.0), biking, true, tempEdges);
    assertNotNull(end);
    edges = end.getIncoming();
    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.getVertexForLocationForTest(new GenericLocation(40.004, -74.0), walking, false, tempEdges);
    end = (TemporaryStreetLocation) finder.getVertexForLocationForTest(new GenericLocation(40.008, -74.0), walking, true, tempEdges);
    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();
    tempEdges.forEach(DisposableEdgeCollection::disposeEdges);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) DisposableEdgeCollection(org.opentripplanner.graph_builder.linking.DisposableEdgeCollection) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with GenericLocation

use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class SplitEdgeTurnRestrictionsTest method computeCarPolyline.

private static String computeCarPolyline(Graph graph, GenericLocation from, GenericLocation to) {
    RoutingRequest request = new RoutingRequest();
    request.setDateTime(dateTime);
    request.from = from;
    request.to = to;
    request.streetSubRequestModes = new TraverseModeSet(TraverseMode.CAR);
    request.setRoutingContext(graph);
    var gpf = new GraphPathFinder(new Router(graph, RouterConfig.DEFAULT));
    var paths = gpf.graphPathFinderEntryPoint(request);
    var itineraries = GraphPathToItineraryMapper.mapItineraries(paths);
    // make sure that we only get CAR legs
    itineraries.forEach(i -> i.legs.forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.CAR)));
    Geometry geometry = itineraries.get(0).legs.get(0).getLegGeometry();
    return PolylineEncoder.createEncodings(geometry).getPoints();
}
Also used : GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) GenericLocation(org.opentripplanner.model.GenericLocation) IOException(java.io.IOException) TestUtils(org.opentripplanner.util.TestUtils) Instant(java.time.Instant) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.jupiter.api.Test) PolylineEncoder(org.opentripplanner.util.PolylineEncoder) Graph(org.opentripplanner.routing.graph.Graph) Router(org.opentripplanner.standalone.server.Router) RouterConfig(org.opentripplanner.standalone.config.RouterConfig) Assertions(org.junit.jupiter.api.Assertions) ConstantsForTests(org.opentripplanner.ConstantsForTests) Geometry(org.locationtech.jts.geom.Geometry) TraverseMode(org.opentripplanner.routing.core.TraverseMode) PolylineAssert.assertThatPolylinesAreEqual(org.opentripplanner.PolylineAssert.assertThatPolylinesAreEqual) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) GraphPathToItineraryMapper(org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper) Geometry(org.locationtech.jts.geom.Geometry) Router(org.opentripplanner.standalone.server.Router) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder)

Example 9 with GenericLocation

use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class StreetGraphFinder method findClosestUsingStreets.

private void findClosestUsingStreets(double lat, double lon, double radius, TraverseVisitor visitor, SearchTerminationStrategy terminationStrategy) {
    // Make a normal OTP routing request so we can traverse edges and use GenericAStar
    // TODO make a function that builds normal routing requests from profile requests
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(null, null, lat, lon);
    rr.oneToMany = true;
    rr.setRoutingContext(graph);
    rr.walkSpeed = 1;
    rr.dominanceFunction = new DominanceFunction.LeastWalk();
    rr.rctx.remainingWeightHeuristic = new TrivialRemainingWeightHeuristic();
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    rr.worstTime = (rr.dateTime + (int) radius);
    AStar astar = new AStar();
    rr.setNumItineraries(1);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 1, terminationStrategy);
    // Destroy the routing context, to clean up the temporary edges & vertices
    rr.rctx.destroy();
}
Also used : AStar(org.opentripplanner.routing.algorithm.astar.AStar) GenericLocation(org.opentripplanner.model.GenericLocation) TrivialRemainingWeightHeuristic(org.opentripplanner.routing.algorithm.astar.strategies.TrivialRemainingWeightHeuristic) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 10 with GenericLocation

use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class BicycleRoutingTest method computePolyline.

private static String computePolyline(Graph graph, GenericLocation from, GenericLocation to) {
    RoutingRequest request = new RoutingRequest();
    request.setDateTime(dateTime);
    request.from = from;
    request.to = to;
    request.bicycleOptimizeType = BicycleOptimizeType.QUICK;
    request.streetSubRequestModes = new TraverseModeSet(TraverseMode.BICYCLE);
    request.setRoutingContext(graph);
    var gpf = new GraphPathFinder(new Router(graph, RouterConfig.DEFAULT));
    var paths = gpf.graphPathFinderEntryPoint(request);
    var itineraries = GraphPathToItineraryMapper.mapItineraries(paths);
    // make sure that we only get BICYLE legs
    itineraries.forEach(i -> i.legs.forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.BICYCLE)));
    Geometry legGeometry = itineraries.get(0).legs.get(0).getLegGeometry();
    return PolylineEncoder.createEncodings(legGeometry).getPoints();
}
Also used : GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) GenericLocation(org.opentripplanner.model.GenericLocation) Instant(java.time.Instant) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.jupiter.api.Test) PolylineEncoder(org.opentripplanner.util.PolylineEncoder) Graph(org.opentripplanner.routing.graph.Graph) Router(org.opentripplanner.standalone.server.Router) RouterConfig(org.opentripplanner.standalone.config.RouterConfig) Assertions(org.junit.jupiter.api.Assertions) ConstantsForTests(org.opentripplanner.ConstantsForTests) Geometry(org.locationtech.jts.geom.Geometry) TraverseMode(org.opentripplanner.routing.core.TraverseMode) BicycleOptimizeType(org.opentripplanner.routing.core.BicycleOptimizeType) PolylineAssert.assertThatPolylinesAreEqual(org.opentripplanner.PolylineAssert.assertThatPolylinesAreEqual) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) GraphPathToItineraryMapper(org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper) Geometry(org.locationtech.jts.geom.Geometry) Router(org.opentripplanner.standalone.server.Router) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder)

Aggregations

GenericLocation (org.opentripplanner.model.GenericLocation)25 Test (org.junit.Test)14 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)11 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)8 Test (org.junit.jupiter.api.Test)4 Instant (java.time.Instant)3 Assertions (org.junit.jupiter.api.Assertions)3 Geometry (org.locationtech.jts.geom.Geometry)3 ConstantsForTests (org.opentripplanner.ConstantsForTests)3 PolylineAssert.assertThatPolylinesAreEqual (org.opentripplanner.PolylineAssert.assertThatPolylinesAreEqual)3 FeedScopedId (org.opentripplanner.model.FeedScopedId)3 GraphPathToItineraryMapper (org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper)3 TraverseMode (org.opentripplanner.routing.core.TraverseMode)3 Graph (org.opentripplanner.routing.graph.Graph)3 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)3 RouterConfig (org.opentripplanner.standalone.config.RouterConfig)3 Router (org.opentripplanner.standalone.server.Router)3 PolylineEncoder (org.opentripplanner.util.PolylineEncoder)3 Ignore (org.junit.Ignore)2 Coordinate (org.locationtech.jts.geom.Coordinate)2