Search in sources :

Example 1 with QualifiedModeSet

use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.

the class RepeatedRaptorProfileRouter method findInitialStops.

/**
 * Find all transit stops accessible by streets around the origin, leaving behind a shortest path tree of the
 * reachable area in the field preTransitSpt.
 *
 * @param data the raptor data table to use. If this is null (i.e. there is no transit) range is extended,
 *             and we don't care if we actually find any stops, we just want the tree of on-street distances.
 */
@VisibleForTesting
public TIntIntMap findInitialStops(boolean dest, RaptorWorkerData data) {
    LOG.info("Finding initial stops");
    double lat = dest ? request.toLat : request.fromLat;
    double lon = dest ? request.toLon : request.fromLon;
    QualifiedModeSet modes = dest ? request.egressModes : request.accessModes;
    RoutingRequest rr = new RoutingRequest(modes);
    rr.batch = true;
    rr.from = new GenericLocation(lat, lon);
    // rr.walkSpeed = request.walkSpeed;
    rr.to = rr.from;
    rr.setRoutingContext(graph);
    rr.dateTime = request.date.toDateMidnight(DateTimeZone.forTimeZone(graph.getTimeZone())).getMillis() / 1000 + request.fromTime;
    rr.walkSpeed = request.walkSpeed;
    rr.bikeSpeed = request.bikeSpeed;
    if (data == null) {
        // Non-transit mode. Search out to the full 120 minutes.
        // Should really use directModes.
        rr.worstTime = rr.dateTime + RaptorWorker.MAX_DURATION;
        rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    } else {
        // Transit mode, limit pre-transit travel.
        if (rr.modes.contains(TraverseMode.BICYCLE)) {
            rr.dominanceFunction = new DominanceFunction.EarliestArrival();
            rr.worstTime = rr.dateTime + request.maxBikeTime * 60;
        } else {
            // We use walk-distance limiting and a least-walk dominance function in order to be consistent with egress walking
            // which is implemented this way because walk times can change when walk speed changes. Also, walk times are floating
            // point and can change slightly when streets are split. Street lengths are internally fixed-point ints, which do not
            // suffer from roundoff. Great care is taken when splitting to preserve sums.
            // When cycling, this is not an issue; we already have an explicitly asymmetrical search (cycling at the origin, walking at the destination),
            // so we need not preserve symmetry.
            // We use the max walk time for the search at the origin, but we clamp it to MAX_WALK_METERS so that we don;t
            // have every transit stop in the state as an initial transit stop if someone sets max walk time to four days,
            // and so that symmetry is preserved.
            // FIXME kind of arbitrary
            rr.maxWalkDistance = Math.min(request.maxWalkTime * 60 * request.walkSpeed, GraphIndex.MAX_WALK_METERS);
            rr.softWalkLimiting = false;
            rr.dominanceFunction = new DominanceFunction.LeastWalk();
        }
    }
    rr.numItineraries = 1;
    rr.longDistance = true;
    AStar aStar = new AStar();
    preTransitSpt = aStar.getShortestPathTree(rr, 5);
    // otherwise return null and leave preTransitSpt around for later use.
    if (data != null) {
        TIntIntMap accessTimes = data.findStopsNear(preTransitSpt, graph, rr.modes.contains(TraverseMode.BICYCLE), request.walkSpeed);
        LOG.info("Found {} transit stops", accessTimes.size());
        return accessTimes;
    } else {
        return null;
    }
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) TIntIntMap(gnu.trove.map.TIntIntMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with QualifiedModeSet

use of org.opentripplanner.api.parameter.QualifiedModeSet 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 3 with QualifiedModeSet

use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.

the class TestBikeRental method testBasic.

public void testBasic() throws Exception {
    // generate a very simple graph
    Graph graph = new Graph();
    StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
    StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
    StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
    @SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
    AStar aStar = new AStar();
    // it is impossible to get from v1 to v3 by walking
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
    options.setRoutingContext(graph, v1, v3);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(v3, false);
    assertNull(path);
    // or biking + walking (assuming walking bikes is disallowed)
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNull(path);
    // so we add a bike share
    BikeRentalStation station = new BikeRentalStation();
    station.id = "id";
    station.name = new NonLocalizedString("station");
    station.x = -77.049;
    station.y = 36.856;
    station.bikesAvailable = 5;
    station.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
    new StreetBikeRentalLink(stationVertex, v2);
    new StreetBikeRentalLink(v2, stationVertex);
    Set<String> networks = new HashSet<String>(Arrays.asList("default"));
    new RentABikeOnEdge(stationVertex, stationVertex, networks);
    new RentABikeOffEdge(stationVertex, stationVertex, networks);
    // but we can't get off the bike at v3, so we still fail
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    // null is returned because the only state at the target is not final
    assertNull(path);
    BikeRentalStation station2 = new BikeRentalStation();
    station2.id = "id2";
    station2.name = new NonLocalizedString("station2");
    station2.x = -77.049;
    station2.y = 36.857;
    station2.bikesAvailable = 5;
    station2.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
    new StreetBikeRentalLink(stationVertex2, v3);
    new StreetBikeRentalLink(v3, stationVertex2);
    new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
    new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
    // now we succeed!
    options = new RoutingRequest();
    new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNotNull(path);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 4 with QualifiedModeSet

use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.

the class InitialStopsTest method testInitialStopWalkSpeedIncrease.

/**
 * Test that increasing the walk speed on a walk-to-transit search
 * a) decreases or leaves unchanged all access times.
 * b) allows access to a superset of the originally accessible stops.
 * c) decreases at least some access times.
 *
 * There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
 */
@Test
public void testInitialStopWalkSpeedIncrease() throws Exception {
    Graph g = buildGraphNoTransit();
    addRegularStopGrid(g);
    addTransitMultipleLines(g);
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest req = new ProfileRequest();
    req.fromLon = req.toLon = -83.0118;
    req.fromLat = req.toLat = 39.9908;
    req.date = new LocalDate(2015, 9, 17);
    req.bikeSpeed = 4.1f;
    req.walkSpeed = 1.3f;
    req.fromTime = 7 * 3600;
    req.toTime = 9 * 3600;
    req.maxBikeTime = 20;
    req.maxWalkTime = 20;
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("WALK");
    RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
    assertFalse(initialStops1.isEmpty());
    // let's get crazy, set walk speed really high.
    req.walkSpeed = 25f;
    data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
    // we should find decreases to at least some stops
    boolean foundDecreases = false;
    for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
        it.advance();
        // the reached stops from the faster search should be a superset of the reached stops from the slower search
        assertTrue(initialStops2.containsKey(it.key()));
        assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
        foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
    }
    assertTrue("No decreases were found due to increased walk speed", foundDecreases);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) TaskStatistics(org.opentripplanner.analyst.cluster.TaskStatistics) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RaptorWorkerData(org.opentripplanner.profile.RaptorWorkerData) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) TIntIntMap(gnu.trove.map.TIntIntMap) Test(org.junit.Test)

Example 5 with QualifiedModeSet

use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.

the class InitialStopsTest method testInitialStopBikeSpeedIncrease.

/**
 * Test that increasing the bike speed on a bike-to-transit search
 * a) decreases or leaves unchanged all access times.
 * b) allows access to a superset of the originally accessible stops.
 *
 * There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
 */
@Test
public void testInitialStopBikeSpeedIncrease() throws Exception {
    Graph g = buildGraphNoTransit();
    addRegularStopGrid(g);
    addTransitMultipleLines(g);
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest req = new ProfileRequest();
    req.fromLon = req.toLon = -83.0118;
    req.fromLat = req.toLat = 39.9908;
    req.date = new LocalDate(2015, 9, 17);
    req.bikeSpeed = 4.1f;
    req.walkSpeed = 1.3f;
    req.fromTime = 7 * 3600;
    req.toTime = 9 * 3600;
    req.maxBikeTime = 20;
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("BICYCLE");
    RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
    assertFalse(initialStops1.isEmpty());
    // let's get crazy, set bike speed really high.
    req.bikeSpeed = 25f;
    data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
    // we should find decreases to at least some stops
    boolean foundDecreases = false;
    for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
        it.advance();
        // the reached stops from the faster search should be a superset of the reached stops from the slower search
        assertTrue(initialStops2.containsKey(it.key()));
        assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
        foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
    }
    assertTrue(foundDecreases);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) TaskStatistics(org.opentripplanner.analyst.cluster.TaskStatistics) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RaptorWorkerData(org.opentripplanner.profile.RaptorWorkerData) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) TIntIntMap(gnu.trove.map.TIntIntMap) Test(org.junit.Test)

Aggregations

QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)11 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)8 LocalDate (org.joda.time.LocalDate)7 ProfileRequest (org.opentripplanner.profile.ProfileRequest)7 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)7 Graph (org.opentripplanner.routing.graph.Graph)7 Test (org.junit.Test)5 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)5 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)5 TIntIntMap (gnu.trove.map.TIntIntMap)3 TaskStatistics (org.opentripplanner.analyst.cluster.TaskStatistics)3 ConvertToFrequency (org.opentripplanner.analyst.scenario.ConvertToFrequency)3 Scenario (org.opentripplanner.analyst.scenario.Scenario)3 RaptorWorkerData (org.opentripplanner.profile.RaptorWorkerData)3 RaptorWorkerTimetable (org.opentripplanner.profile.RaptorWorkerTimetable)3 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)2 GenericLocation (org.opentripplanner.common.model.GenericLocation)2 AStar (org.opentripplanner.routing.algorithm.AStar)2 Vertex (org.opentripplanner.routing.graph.Vertex)2