Search in sources :

Example 81 with RoutingRequest

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

the class NearbyStopFinder method findNearbyStopsViaStreets.

/**
 * Return all stops within a certain radius of the given vertex, using network distance along streets.
 * If the origin vertex is a TransitStop, the result will include it.
 */
public List<StopAtDistance> findNearbyStopsViaStreets(Vertex originVertex) {
    RoutingRequest routingRequest = new RoutingRequest(TraverseMode.WALK);
    routingRequest.clampInitialWait = (0L);
    routingRequest.setRoutingContext(graph, originVertex, null);
    ShortestPathTree spt = earliestArrivalSearch.getShortestPathTree(routingRequest);
    List<StopAtDistance> stopsFound = Lists.newArrayList();
    if (spt != null) {
        // TODO use GenericAStar and a traverseVisitor? Add an earliestArrival switch to genericAStar?
        for (State state : spt.getAllStates()) {
            Vertex targetVertex = state.getVertex();
            if (targetVertex == originVertex)
                continue;
            if (targetVertex instanceof TransitStop) {
                stopsFound.add(stopAtDistanceForState(state));
            }
        }
    }
    /* Add the origin vertex if needed. The SPT does not include the initial state. FIXME shouldn't it? */
    if (originVertex instanceof TransitStop) {
        stopsFound.add(new StopAtDistance((TransitStop) originVertex, 0));
    }
    routingRequest.cleanup();
    return stopsFound;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 82 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 83 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 84 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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)

Example 85 with RoutingRequest

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

the class EuclideanRemainingWeightHeuristic method determineRequiredWalkDistance.

/**
 * Figure out the minimum amount of walking to reach the destination from transit.
 * This is done by doing a Dijkstra search for the first reachable transit stop.
 */
private double determineRequiredWalkDistance(final RoutingRequest req) {
    // required walk distance will be unused.
    if (!transit)
        return 0;
    RoutingRequest options = req.clone();
    options.setArriveBy(!req.arriveBy);
    options.setRoutingContext(req.rctx.graph, req.rctx.fromVertex, req.rctx.toVertex);
    GenericDijkstra gd = new GenericDijkstra(options);
    State s = new State(options);
    gd.setHeuristic(new TrivialRemainingWeightHeuristic());
    final ClosestStopTraverseVisitor visitor = new ClosestStopTraverseVisitor();
    gd.traverseVisitor = visitor;
    gd.searchTerminationStrategy = new SearchTerminationStrategy() {

        @Override
        public boolean shouldSearchTerminate(Vertex origin, Vertex target, State current, ShortestPathTree spt, RoutingRequest traverseOptions) {
            return visitor.distanceToClosestStop != Double.POSITIVE_INFINITY;
        }
    };
    gd.getShortestPathTree(s);
    return visitor.distanceToClosestStop;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GenericDijkstra(org.opentripplanner.routing.algorithm.GenericDijkstra) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)124 GraphPath (org.opentripplanner.routing.spt.GraphPath)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)52 State (org.opentripplanner.routing.core.State)42 Test (org.junit.Test)35 Vertex (org.opentripplanner.routing.graph.Vertex)35 Graph (org.opentripplanner.routing.graph.Graph)24 GenericLocation (org.opentripplanner.common.model.GenericLocation)21 Edge (org.opentripplanner.routing.graph.Edge)18 StateEditor (org.opentripplanner.routing.core.StateEditor)17 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)17 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 AStar (org.opentripplanner.routing.algorithm.AStar)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11 Trip (org.onebusaway.gtfs.model.Trip)9