Search in sources :

Example 21 with GenericLocation

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

the class AddTripPatternTest method testStopLinking.

/**
 * Make sure that stops are properly linked into the graph
 */
@Test
public void testStopLinking() throws Exception {
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(true));
    // get a graph
    Graph g = buildGraphNoTransit();
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    // materialize the trip pattern
    atp.materialize(g);
    // there should be five stops because one point is not a stop
    assertEquals(5, atp.temporaryStops.length);
    // they should all be linked into the graph
    for (int i = 0; i < atp.temporaryStops.length; i++) {
        assertNotNull(atp.temporaryStops[i].sample);
        assertNotNull(atp.temporaryStops[i].sample.v0);
        assertNotNull(atp.temporaryStops[i].sample.v1);
    }
    // no services running: not needed for trips added on the fly.
    TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
    Scenario scenario = new Scenario(0);
    scenario.modifications = Lists.newArrayList(atp);
    ProfileRequest req = new ProfileRequest();
    req.scenario = scenario;
    req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
    RaptorWorkerData data = new RaptorWorkerData(g, window, req);
    assertEquals(5, data.nStops);
    // make sure we can find the stops
    AStar aStar = new AStar();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(39.963417, -82.980799);
    rr.batch = true;
    rr.setRoutingContext(g);
    rr.batch = true;
    ShortestPathTree spt = aStar.getShortestPathTree(rr);
    TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
    // we should have found stops
    assertFalse(stops.isEmpty());
    // ensure that the times made it into the data
    // This assumes worst-case departure, and the first worst departure is 10:30 after the service
    // starts running (dwell + headway)
    assertEquals(4 * 3600 + 600 + 30, data.timetablesForPattern.get(0).getFrequencyDeparture(0, 0, 39 * 360, -1, null));
}
Also used : BitSet(java.util.BitSet) AStar(org.opentripplanner.routing.algorithm.AStar) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TIntIntMap(gnu.trove.map.TIntIntMap) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 22 with GenericLocation

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

the class AddTripPatternTest method testTimetableTrips.

/**
 * Test adding trips with a timetable rather than frequencies
 */
@Test
public void testTimetableTrips() throws Exception {
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(false));
    // get a graph
    Graph g = buildGraphNoTransit();
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    // materialize the trip pattern
    atp.materialize(g);
    // there should be five stops because one point is not a stop
    assertEquals(5, atp.temporaryStops.length);
    // they should all be linked into the graph
    for (int i = 0; i < atp.temporaryStops.length; i++) {
        assertNotNull(atp.temporaryStops[i].sample);
        assertNotNull(atp.temporaryStops[i].sample.v0);
        assertNotNull(atp.temporaryStops[i].sample.v1);
    }
    // no services running: not needed for trips added on the fly.
    TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
    Scenario scenario = new Scenario(0);
    scenario.modifications = Lists.newArrayList(atp);
    ProfileRequest req = new ProfileRequest();
    req.scenario = scenario;
    req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
    RaptorWorkerData data = new RaptorWorkerData(g, window, req);
    assertEquals(5, data.nStops);
    // make sure we can find the stops
    AStar aStar = new AStar();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(39.963417, -82.980799);
    rr.batch = true;
    rr.setRoutingContext(g);
    rr.batch = true;
    ShortestPathTree spt = aStar.getShortestPathTree(rr);
    TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
    // we should have found stops
    assertFalse(stops.isEmpty());
    // ensure that the times made it into the data
    // This is after the first dwell time has been applied
    assertEquals(7 * 3600 + 30, data.timetablesForPattern.get(0).getDeparture(0, 0));
}
Also used : BitSet(java.util.BitSet) AStar(org.opentripplanner.routing.algorithm.AStar) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TIntIntMap(gnu.trove.map.TIntIntMap) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 23 with GenericLocation

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

the class ProfileRouter method findClosestStops.

/**
 * Perform an on-street search around a point with a specific mode to find nearby stops.
 * @param dest : whether to search at the destination instead of the origin.
 */
private Collection<StopAtDistance> findClosestStops(final QualifiedMode qmode, boolean dest) {
    // 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(new TraverseModeSet());
    qmode.applyToRoutingRequest(rr, request.transitModes.isTransit());
    rr.from = (new GenericLocation(request.fromLat, request.fromLon));
    // FIXME requires destination to be set, not necessary for analyst
    rr.to = new GenericLocation(request.toLat, request.toLon);
    rr.setArriveBy(dest);
    rr.setRoutingContext(graph);
    // Set batch after context, so both origin and dest vertices will be found.
    rr.batch = (true);
    rr.walkSpeed = request.walkSpeed;
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    int minAccessTime = 0;
    int maxAccessTime = request.maxWalkTime;
    if (qmode.mode == TraverseMode.BICYCLE) {
        rr.bikeSpeed = request.bikeSpeed;
        minAccessTime = request.minBikeTime;
        maxAccessTime = request.maxBikeTime;
        rr.optimize = OptimizeType.TRIANGLE;
        rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
    } else if (qmode.mode == TraverseMode.CAR) {
        rr.carSpeed = request.carSpeed;
        minAccessTime = request.minCarTime;
        maxAccessTime = request.maxCarTime;
    }
    // convert from minutes to seconds
    long worstElapsedTimeSeconds = maxAccessTime * 60;
    if (dest)
        worstElapsedTimeSeconds *= -1;
    rr.worstTime = (rr.dateTime + worstElapsedTimeSeconds);
    AStar astar = new AStar();
    rr.setNumItineraries(1);
    StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(qmode, minAccessTime * 60);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 5);
    // Save the routing context for later cleanup. We need its temporary edges to render street segments at the end.
    routingContexts.add(rr.rctx);
    return visitor.stopClustersFound.values();
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 24 with GenericLocation

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

the class ProfileRouter method findDirectOption.

/**
 * Look for an option connecting origin to destination without using transit.
 */
private void findDirectOption(QualifiedMode qmode) {
    // Make a normal OTP routing request so we can traverse edges and use GenericAStar
    RoutingRequest rr = new RoutingRequest(new TraverseModeSet());
    // false because we never use transit in direct options
    qmode.applyToRoutingRequest(rr, false);
    if (qmode.mode == TraverseMode.BICYCLE) {
        // TRIANGLE should only affect bicycle searches, but we wrap this in a conditional just to be clear.
        rr.optimize = OptimizeType.TRIANGLE;
        rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
    }
    rr.from = (new GenericLocation(request.fromLat, request.fromLon));
    rr.to = new GenericLocation(request.toLat, request.toLon);
    rr.setArriveBy(false);
    rr.setRoutingContext(graph);
    rr.dominanceFunction = new DominanceFunction.MinimumWeight();
    // This is not a batch search, it is a point-to-point search with goal direction.
    // Impose a max time to protect against very slow searches.
    int worstElapsedTime = request.streetTime * 60;
    rr.worstTime = (rr.dateTime + worstElapsedTime);
    rr.walkSpeed = request.walkSpeed;
    rr.bikeSpeed = request.bikeSpeed;
    AStar astar = new AStar();
    rr.setNumItineraries(1);
    ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
    State state = spt.getState(rr.rctx.target);
    if (state != null) {
        LOG.info("Found non-transit option for {}", qmode);
        directPaths.add(new StopAtDistance(state, qmode));
    }
    // save context for later cleanup so temp edges remain available
    routingContexts.add(rr.rctx);
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 25 with GenericLocation

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

the class RoundBasedProfileRouter method findInitialStops.

/**
 * find the boarding stops
 */
private Collection<ProfileState> findInitialStops(boolean dest) {
    double lat = dest ? request.toLat : request.fromLat;
    double lon = dest ? request.toLon : request.fromLon;
    QualifiedModeSet modes = dest ? request.accessModes : request.egressModes;
    List<ProfileState> stops = Lists.newArrayList();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.batch = true;
    rr.from = new GenericLocation(lat, lon);
    rr.walkSpeed = request.walkSpeed;
    rr.to = rr.from;
    rr.setRoutingContext(graph);
    // RoutingRequest dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    rr.worstTime = (rr.dateTime + request.maxWalkTime * 60);
    AStar astar = new AStar();
    rr.longDistance = true;
    rr.setNumItineraries(1);
    // timeout in seconds
    ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
    for (TransitStop tstop : graph.index.stopVertexForStop.values()) {
        State s = spt.getState(tstop);
        if (s != null) {
            ProfileState ps = new ProfileState();
            ps.lowerBound = ps.upperBound = (int) s.getElapsedTimeSeconds();
            ps.stop = tstop;
            ps.accessType = Type.STREET;
            stops.add(ps);
        }
    }
    Map<TripPattern, ProfileState> optimalBoardingLocation = Maps.newHashMap();
    TObjectIntMap<TripPattern> minBoardTime = new TObjectIntHashMap<TripPattern>(100, 0.75f, Integer.MAX_VALUE);
    // Only board patterns at the closest possible stop
    for (ProfileState ps : stops) {
        for (TripPattern pattern : graph.index.patternsForStop.get(ps.stop.getStop())) {
            if (ps.lowerBound < minBoardTime.get(pattern)) {
                optimalBoardingLocation.put(pattern, ps);
                minBoardTime.put(pattern, ps.lowerBound);
            }
        }
        ps.targetPatterns = Sets.newHashSet();
    }
    LOG.info("Found {} reachable stops, filtering to only board at closest stops", stops.size());
    for (Entry<TripPattern, ProfileState> e : optimalBoardingLocation.entrySet()) {
        e.getValue().targetPatterns.add(e.getKey());
    }
    for (Iterator<ProfileState> it = stops.iterator(); it.hasNext(); ) {
        if (it.next().targetPatterns.isEmpty())
            it.remove();
    }
    rr.cleanup();
    return stops;
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) AStar(org.opentripplanner.routing.algorithm.AStar) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) State(org.opentripplanner.routing.core.State) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Aggregations

GenericLocation (org.opentripplanner.common.model.GenericLocation)28 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)20 Test (org.junit.Test)14 AStar (org.opentripplanner.routing.algorithm.AStar)9 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 Graph (org.opentripplanner.routing.graph.Graph)5 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)4 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 TIntIntMap (gnu.trove.map.TIntIntMap)3 ArrayList (java.util.ArrayList)3 Agency (org.onebusaway.gtfs.model.Agency)3 Route (org.onebusaway.gtfs.model.Route)3 Stop (org.onebusaway.gtfs.model.Stop)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 Trip (org.onebusaway.gtfs.model.Trip)3 StopPattern (org.opentripplanner.model.StopPattern)3