Search in sources :

Example 16 with TraverseModeSet

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

the class TestParkAndRide method testCar.

public void testCar() throws Exception {
    AStar aStar = new AStar();
    // It is impossible to get from A to C in WALK mode,
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK"));
    options.setRoutingContext(graph, A, C);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(C, false);
    assertNull(path);
    // or CAR+WALK (no P+R).
    options = new RoutingRequest("WALK,CAR");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // So we Add a P+R at B.
    ParkAndRideVertex PRB = new ParkAndRideVertex(graph, "P+R", "P+R.B", 0.001, 45.00001, new NonLocalizedString("P+R B"));
    new ParkAndRideEdge(PRB);
    new ParkAndRideLinkEdge(PRB, B);
    new ParkAndRideLinkEdge(B, PRB);
    // But it is still impossible to get from A to C by WALK only
    // (AB is CAR only).
    options = new RoutingRequest("WALK");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // Or CAR only (BC is WALK only).
    options = new RoutingRequest("CAR");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy false
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    // options.arriveBy
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy true
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    options.setArriveBy(true);
    options.setRoutingContext(graph, A, C);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(A, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy true interleavedBidiHeuristic
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    options.setArriveBy(true);
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(A, false);
    assertNotNull(path);
    // But we can go from A to C with CAR+WALK mode using P+R. arriveBy false interleavedBidiHeuristic
    options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
    // options.arriveBy
    options.setRoutingContext(graph, A, C);
    options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(C, false);
    assertNotNull(path);
}
Also used : ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) InterleavedBidirectionalHeuristic(org.opentripplanner.routing.algorithm.strategies.InterleavedBidirectionalHeuristic) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 17 with TraverseModeSet

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

the class TurnRestrictionTest method DisallowTurn.

private void DisallowTurn(StreetEdge from, StreetEdge to) {
    TurnRestrictionType rType = TurnRestrictionType.NO_TURN;
    TraverseModeSet restrictedModes = new TraverseModeSet(TraverseMode.CAR);
    TurnRestriction restrict = new TurnRestriction(from, to, rType, restrictedModes);
    _graph.addTurnRestriction(from, restrict);
}
Also used : TurnRestrictionType(org.opentripplanner.common.TurnRestrictionType) TurnRestriction(org.opentripplanner.common.TurnRestriction) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 18 with TraverseModeSet

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

the class TurnCostTest method DisallowTurn.

private void DisallowTurn(StreetEdge from, StreetEdge to) {
    TurnRestrictionType rType = TurnRestrictionType.NO_TURN;
    TraverseModeSet restrictedModes = new TraverseModeSet(TraverseMode.CAR);
    TurnRestriction restrict = new TurnRestriction(from, to, rType, restrictedModes);
    _graph.addTurnRestriction(from, restrict);
}
Also used : TurnRestrictionType(org.opentripplanner.common.TurnRestrictionType) TurnRestriction(org.opentripplanner.common.TurnRestriction) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet)

Example 19 with TraverseModeSet

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

the class ConvertToFrequencyTest method testBidirectional.

/**
 * Test bidirectional conversion
 */
@Test
public void testBidirectional() throws Exception {
    Graph gg = buildGraphNoTransit();
    addTransitBidirectional(gg);
    link(gg);
    gg.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest pr2 = new ProfileRequest();
    pr2.date = new LocalDate(2015, 6, 10);
    pr2.fromTime = 7 * 3600;
    pr2.toTime = 9 * 3600;
    pr2.fromLat = pr2.toLat = 39.9621;
    pr2.fromLon = pr2.toLon = -83.0007;
    pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
    pr2.transitModes = new TraverseModeSet("TRANSIT");
    ConvertToFrequency ctf = new ConvertToFrequency();
    ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
    ctf.routeId = new String[] { "route" };
    ctf.windowStart = 5 * 3600;
    ctf.windowEnd = 10 * 3600;
    pr2.scenario = new Scenario(0);
    pr2.scenario.modifications = Arrays.asList(ctf);
    RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
    rrpr2.route();
    assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
    assertEquals(2, rrpr2.raptorWorkerData.timetablesForPattern.size());
    // make sure we got trips in both directions
    RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
    RaptorWorkerTimetable tt2 = rrpr2.raptorWorkerData.timetablesForPattern.get(1);
    assertEquals(2, tt2.stopIndices.length);
    assertEquals(2, tt.stopIndices.length);
    assertEquals(tt.stopIndices[0], tt2.stopIndices[1]);
    assertEquals(tt.stopIndices[1], tt2.stopIndices[0]);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ConvertToFrequency(org.opentripplanner.analyst.scenario.ConvertToFrequency) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) RaptorWorkerTimetable(org.opentripplanner.profile.RaptorWorkerTimetable) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) Scenario(org.opentripplanner.analyst.scenario.Scenario) Test(org.junit.Test)

Example 20 with TraverseModeSet

use of org.opentripplanner.routing.core.TraverseModeSet 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) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) URL(java.net.URL) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)44 Test (org.junit.Test)25 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)17 Graph (org.opentripplanner.routing.graph.Graph)14 Edge (org.opentripplanner.routing.graph.Edge)10 Vertex (org.opentripplanner.routing.graph.Vertex)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)8 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)8 GenericLocation (org.opentripplanner.common.model.GenericLocation)8 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)8 LocalDate (org.joda.time.LocalDate)7 ProfileRequest (org.opentripplanner.profile.ProfileRequest)7 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)7 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 GraphPath (org.opentripplanner.routing.spt.GraphPath)6 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)5 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)5 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)5 LineString (com.vividsolutions.jts.geom.LineString)4 ArrayList (java.util.ArrayList)4