Search in sources :

Example 11 with QualifiedModeSet

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

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