Search in sources :

Example 31 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method getPath.

private GraphPath getPath(AStar aStar, RoutingRequest proto, Edge startBackEdge, Vertex u, Vertex v) {
    RoutingRequest options = proto.clone();
    options.setRoutingContext(graph, startBackEdge, u, v);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(v, false);
    options.cleanup();
    return path;
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest)

Example 32 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TestShapefileStreetGraphBuilderImpl method testBasic.

@Test
public void testBasic() throws Exception {
    Graph gg = new Graph();
    URL resource = getClass().getResource("nyc_streets/streets.shp");
    File file = null;
    if (resource != null) {
        file = new File(resource.getFile());
    }
    if (file == null || !file.exists()) {
        System.out.println("No New York City basemap; skipping; see comment here for details");
        /*
             * This test requires the New York City base map. Place it among the source 
             * resources and Eclipse should automatically copy it over to the target directory.
             * Once you have prepared these files, you may need to 'refresh' in Eclipse's package 
             * explorer to force Eclipse to notice the new resources.
             * 
             * Recent versions of this map are available only in Arcview Geodatabase format.
             * For conversion to a Shapefile, you will need the archived MapInfo version at:
             * http://www.nyc.gov/html/dcp/html/bytes/bytesarchive.shtml#lion
             * Download the MapInfo file of Lion version 10B. 
             * 
             * This must then be converted to a ShapeFile as follows:
             * cd opentripplanner-graph-builder/src/test/resources/org/opentripplanner/graph_builder/module/shapefile
             * mkdir nyc_streets       (this is where we will store the shapefile)
             * unzip nyc_lion10ami.zip (this should place zipfile contents in a ./lion directory)
             * ogr2ogr -f 'ESRI Shapefile' nyc_streets/streets.shp lion/MNLION1.tab 
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/SILION1.tab -nln streets 
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/QNLION1.tab -nln streets 
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BKLION1.tab -nln streets 
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BXLION1.tab -nln streets
             * 
             * Testing also requires NYC Subway data in GTFS in the same location: 
             * wget http://data.topplabs.org/data/mta_nyct_subway/subway.zip
             */
        return;
    }
    ShapefileFeatureSourceFactoryImpl factory = new ShapefileFeatureSourceFactoryImpl(file);
    ShapefileStreetSchema schema = new ShapefileStreetSchema();
    schema.setIdAttribute("SegmentID");
    schema.setNameAttribute("Street");
    /* only featuretyp=0 are streets */
    CaseBasedBooleanConverter selector = new CaseBasedBooleanConverter("FeatureTyp", false);
    HashMap<String, Boolean> streets = new HashMap<String, Boolean>();
    streets.put("0", true);
    selector.setValues(streets);
    schema.setFeatureSelector(selector);
    /* street directions */
    CaseBasedTraversalPermissionConverter perms = new CaseBasedTraversalPermissionConverter("TrafDir", StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
    perms.addPermission("W", StreetTraversalPermission.ALL, StreetTraversalPermission.PEDESTRIAN);
    perms.addPermission("A", StreetTraversalPermission.PEDESTRIAN, StreetTraversalPermission.ALL);
    perms.addPermission("T", StreetTraversalPermission.ALL, StreetTraversalPermission.ALL);
    schema.setPermissionConverter(perms);
    ShapefileStreetModule loader = new ShapefileStreetModule();
    loader.setFeatureSourceFactory(factory);
    loader.setSchema(schema);
    loader.buildGraph(gg, new HashMap<Class<?>, Object>());
    // find start and end vertices
    Vertex start = null;
    Vertex end = null;
    Vertex carlton = null;
    Coordinate vanderbiltAtPark = new Coordinate(-73.969178, 40.676785);
    Coordinate grandAtLafayette = new Coordinate(-73.999095, 40.720005);
    Coordinate carltonAtPark = new Coordinate(-73.972347, 40.677447);
    for (Vertex v : gg.getVertices()) {
        if (v.getCoordinate().distance(vanderbiltAtPark) < 0.00005) {
            /* we need the correct vanderbilt at park.  In this case,
                 * that's the one facing west on vanderbilt.
                 */
            int numParks = 0;
            int numCarltons = 0;
            for (Edge e : v.getOutgoing()) {
                if (e.getToVertex().getName().contains("PARK")) {
                    numParks++;
                }
                if (e.getToVertex().getName().contains("CARLTON")) {
                    numCarltons++;
                }
            }
            if (numCarltons != 2 || numParks != 1) {
                continue;
            }
            start = v;
        } else if (v.getCoordinate().distance(grandAtLafayette) < 0.0001) {
            end = v;
        } else if (v.getCoordinate().distance(carltonAtPark) < 0.00005) {
            /* we need the correct carlton at park.  In this case,
                 * that's the one facing west.
                 */
            int numFlatbushes = 0;
            int numParks = 0;
            for (Edge e : v.getOutgoing()) {
                if (e.getToVertex().getName().contains("FLATBUSH")) {
                    numFlatbushes++;
                }
                if (e.getToVertex().getName().contains("PARK")) {
                    numParks++;
                }
            }
            if (numFlatbushes != 2 || numParks != 1) {
                continue;
            }
            carlton = v;
        }
    }
    assertNotNull(start);
    assertNotNull(end);
    assertNotNull(carlton);
    assertEquals(3, start.getDegreeOut());
    assertEquals(3, start.getDegreeIn());
    AStar aStar = new AStar();
    RoutingRequest opt = new RoutingRequest();
    opt.setRoutingContext(gg, start, end);
    ShortestPathTree spt = aStar.getShortestPathTree(opt);
    assertNotNull(spt);
    // test that the option to walk bikes on the first or last segment works
    opt = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
    // Real live cyclists tell me that they would prefer to ride around the long way than to
    // walk their bikes the short way.  If we slow down the default biking speed, that will
    // force a change in preferences.
    opt.bikeSpeed = 2;
    opt.setRoutingContext(gg, start, carlton);
    spt = aStar.getShortestPathTree(opt);
    assertNotNull(spt);
/* commented out as bike walking is not supported */
/*
        GraphPath path = spt.getPath(carlton.vertex);
        assertNotNull(path);
        assertTrue(path.edges.size() <= 3);

        wo.setArriveBy(true);
        spt = AStar.getShortestPathTreeBack(gg, start.vertex, carlton.vertex, new State(0), wo);
        assertNotNull(spt);
        
        path = spt.getPath(carlton.vertex);
        assertTrue(path.edges.size() <= 3);
         */
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) HashMap(java.util.HashMap) AStar(org.opentripplanner.routing.algorithm.astar.AStar) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) URL(java.net.URL) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(org.locationtech.jts.geom.Coordinate) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) File(java.io.File) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 33 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testBuildingAreas.

/**
 * This reads test file with area
 * and tests if it can be routed if visibility is used and if it isn't
 *
 * Routing needs to be successful in both options since without visibility calculation
 * area rings are used.
 * @param skipVisibility if true visibility calculations are skipped
 * @throws UnsupportedEncodingException
 */
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
    Graph graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.skipVisibility = skipVisibility;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.pbf").getFile(), "UTF-8"));
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(file, false);
    loader.setProvider(provider);
    loader.buildGraph(graph, extra);
    new StreetVertexIndex(graph);
    Router router = new Router(graph, RouterConfig.DEFAULT);
    router.startup();
    RoutingRequest request = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    // This are vertices that can be connected only over edges on area (with correct permissions)
    // It tests if it is possible to route over area without visibility calculations
    Vertex bottomV = graph.getVertex("osm:node:580290955");
    Vertex topV = graph.getVertex("osm:node:559271124");
    request.setRoutingContext(router.graph, bottomV, topV);
    GraphPathFinder graphPathFinder = new GraphPathFinder(router);
    List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(pathList);
    assertFalse(pathList.isEmpty());
    for (GraphPath path : pathList) {
        assertFalse(path.states.isEmpty());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.server.Router) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) Graph(org.opentripplanner.routing.graph.Graph) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Example 34 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitterTest method testFindEndVertexForParkAndRide.

/**
 * Tests that traverse mode WALK is used when getting closest end vertex for park and ride.
 */
@Test
public void testFindEndVertexForParkAndRide() {
    GenericLocation genericLocation = new GenericLocation(10.0, 23.0);
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setMode(TraverseMode.CAR);
    routingRequest.parkAndRide = true;
    spySimpleStreetSplitter.getClosestVertex(genericLocation, routingRequest, true);
    verify(spySimpleStreetSplitter).link(any(Vertex.class), eq(TraverseMode.WALK), eq(routingRequest));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Test(org.junit.Test)

Example 35 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetLocationFinder.

@Test
public void testStreetLocationFinder() {
    StreetVertexIndex finder = new StreetVertexIndex(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);
    // 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();
    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();
    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);
    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) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex) Test(org.junit.Test)

Aggregations

RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)102 GraphPath (org.opentripplanner.routing.spt.GraphPath)50 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)42 Test (org.junit.Test)37 State (org.opentripplanner.routing.core.State)33 Vertex (org.opentripplanner.routing.graph.Vertex)31 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)18 Edge (org.opentripplanner.routing.graph.Edge)17 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)17 AStar (org.opentripplanner.routing.algorithm.astar.AStar)16 Graph (org.opentripplanner.routing.graph.Graph)15 StateEditor (org.opentripplanner.routing.core.StateEditor)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)10 HashSet (java.util.HashSet)9 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)9 TraverseMode (org.opentripplanner.routing.core.TraverseMode)7 ArrayList (java.util.ArrayList)6 Coordinate (org.locationtech.jts.geom.Coordinate)6