Search in sources :

Example 1 with AccessEgress

use of org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress in project OpenTripPlanner by opentripplanner.

the class RaptorPathToItineraryMapper method mapEgressLeg.

private void mapEgressLeg(List<Leg> legs, EgressPathLeg<TripSchedule> egressPathLeg) {
    AccessEgress egressPath = (AccessEgress) egressPathLeg.egress();
    if (egressPath.durationInSeconds() == 0) {
        return;
    }
    GraphPath graphPath = new GraphPath(egressPath.getLastState(), false);
    Itinerary subItinerary = GraphPathToItineraryMapper.generateItinerary(graphPath, request.locale);
    if (subItinerary.legs.isEmpty()) {
        return;
    }
    subItinerary.timeShiftToStartAt(createCalendar(egressPathLeg.fromTime()));
    legs.addAll(subItinerary.legs);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) Itinerary(org.opentripplanner.model.plan.Itinerary) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress)

Example 2 with AccessEgress

use of org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress in project OpenTripPlanner by opentripplanner.

the class RaptorPathToItineraryMapper method mapAccessLeg.

private void mapAccessLeg(List<Leg> legs, AccessPathLeg<TripSchedule> accessPathLeg) {
    AccessEgress accessPath = (AccessEgress) accessPathLeg.access();
    if (accessPath.durationInSeconds() == 0) {
        return;
    }
    GraphPath graphPath = new GraphPath(accessPath.getLastState(), false);
    Itinerary subItinerary = GraphPathToItineraryMapper.generateItinerary(graphPath, request.locale);
    if (subItinerary.legs.isEmpty()) {
        return;
    }
    subItinerary.timeShiftToStartAt(createCalendar(accessPathLeg.fromTime()));
    legs.addAll(subItinerary.legs);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) Itinerary(org.opentripplanner.model.plan.Itinerary) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress)

Example 3 with AccessEgress

use of org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress in project OpenTripPlanner by opentripplanner.

the class AccessEgressRouter method streetSearch.

/**
 * @param rr the current routing request
 * @param fromTarget whether to route from or towards the point provided in the routing request
 *                   (access or egress)
 * @param distanceMeters the maximum street distance to search for access/egress stops
 * @return Transfer objects by access/egress stop
 */
public static Collection<AccessEgress> streetSearch(RoutingRequest rr, boolean fromTarget, int distanceMeters, StopIndexForRaptor stopIndex) {
    // TODO OTP2 This has to be done because we have not separated the main RoutingRequest from
    // the subrequest for street searches. From/to vertices are already set based on the main
    // request being arriveBy or not, but here we are actually setting arriveBy based on
    // whether we are doing an access or egress search, regardless of the direction of the
    // main request.
    Set<Vertex> vertices = fromTarget ^ rr.arriveBy ? rr.rctx.toVertices : rr.rctx.fromVertices;
    RoutingRequest nonTransitRoutingRequest = rr.getStreetSearchRequest(fromTarget ? rr.modes.egressMode : rr.modes.accessMode);
    NearbyStopFinder nearbyStopFinder = new NearbyStopFinder(rr.rctx.graph, distanceMeters, true);
    // We set removeTempEdges to false because this is a sub-request - the temporary edges for the origin and
    // target vertex will be cleaned up at the end of the super-request, and we don't want that to happen twice.
    List<StopAtDistance> stopAtDistanceList = nearbyStopFinder.findNearbyStopsViaStreets(vertices, fromTarget, false, nonTransitRoutingRequest);
    Collection<AccessEgress> result = new ArrayList<>();
    for (StopAtDistance stopAtDistance : stopAtDistanceList) {
        result.add(new AccessEgress(stopIndex.indexByStop.get(stopAtDistance.stop), (int) stopAtDistance.state.getElapsedTimeSeconds(), fromTarget ? stopAtDistance.state.reverse() : stopAtDistance.state));
    }
    LOG.debug("Found {} {} stops", result.size(), fromTarget ? "egress" : "access");
    return result;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ArrayList(java.util.ArrayList) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) NearbyStopFinder(org.opentripplanner.graph_builder.module.NearbyStopFinder) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress)

Example 4 with AccessEgress

use of org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress in project OpenTripPlanner by opentripplanner.

the class RoutingWorker method routeTransit.

private Collection<Itinerary> routeTransit(Router router) {
    request.setRoutingContext(router.graph);
    if (request.modes.transitModes.isEmpty()) {
        return Collections.emptyList();
    }
    if (!router.graph.transitFeedCovers(request.dateTime)) {
        throw new RoutingValidationException(List.of(new RoutingError(RoutingErrorCode.OUTSIDE_SERVICE_PERIOD, InputField.DATE_TIME)));
    }
    TransitLayer transitLayer = request.ignoreRealtimeUpdates ? router.graph.getTransitLayer() : router.graph.getRealtimeTransitLayer();
    RaptorRoutingRequestTransitData requestTransitDataProvider;
    requestTransitDataProvider = new RaptorRoutingRequestTransitData(transitLayer, request.getDateTime().toInstant(), ADDITIONAL_SEARCH_DAYS_BEFORE_TODAY, ADDITIONAL_SEARCH_DAYS_AFTER_TODAY, request.modes.transitModes, request.rctx.bannedRoutes, request.walkSpeed);
    this.debugAggregator.finishedPatternFiltering();
    // Prepare access/egress transfers
    Collection<AccessEgress> accessTransfers = AccessEgressRouter.streetSearch(request, false, 2000, transitLayer.getStopIndex());
    Collection<AccessEgress> egressTransfers = AccessEgressRouter.streetSearch(request, true, 2000, transitLayer.getStopIndex());
    verifyEgressAccess(accessTransfers, egressTransfers);
    this.debugAggregator.finishedAccessEgress();
    // Prepare transit search
    RaptorRequest<TripSchedule> raptorRequest = RaptorRequestMapper.mapRequest(request, requestTransitDataProvider.getStartOfTime(), accessTransfers, egressTransfers);
    // Route transit
    RaptorResponse<TripSchedule> transitResponse = raptorService.route(raptorRequest, requestTransitDataProvider);
    LOG.debug("Found {} transit itineraries", transitResponse.paths().size());
    LOG.debug("Transit search params used: {}", transitResponse.requestUsed().searchParams());
    this.debugAggregator.finishedRaptorSearch();
    // Create itineraries
    RaptorPathToItineraryMapper itineraryMapper = new RaptorPathToItineraryMapper(transitLayer, requestTransitDataProvider.getStartOfTime(), request);
    FareService fareService = request.getRoutingContext().graph.getService(FareService.class);
    List<Itinerary> itineraries = new ArrayList<>();
    for (Path<TripSchedule> path : transitResponse.paths()) {
        // Convert the Raptor/Astar paths to OTP API Itineraries
        Itinerary itinerary = itineraryMapper.createItinerary(path);
        // fare calculation. We derive the fares from the internal Path objects and add them to the itinerary.
        if (fareService != null) {
            itinerary.fare = fareService.getCost(path, transitLayer);
        }
        itineraries.add(itinerary);
    }
    checkIfTransitConnectionExists(transitResponse);
    // Filter itineraries away that depart after the latest-departure-time for depart after
    // search. These itineraries is a result of time-shifting the access leg and is needed for
    // the raptor to prune the results. These itineraries are often not ideal, but if they
    // pareto optimal for the "next" window, they will appear when a "next" search is performed.
    searchWindowUsedInSeconds = transitResponse.requestUsed().searchParams().searchWindowInSeconds();
    if (!request.arriveBy && searchWindowUsedInSeconds > 0) {
        filterOnLatestDepartureTime = Instant.ofEpochSecond(request.dateTime + searchWindowUsedInSeconds);
    }
    this.debugAggregator.finishedItineraryCreation();
    return itineraries;
}
Also used : RaptorPathToItineraryMapper(org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper) ArrayList(java.util.ArrayList) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) FareService(org.opentripplanner.routing.services.FareService) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) RoutingError(org.opentripplanner.routing.api.response.RoutingError) Itinerary(org.opentripplanner.model.plan.Itinerary) RaptorRoutingRequestTransitData(org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress) TransitLayer(org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer)

Aggregations

AccessEgress (org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress)4 Itinerary (org.opentripplanner.model.plan.Itinerary)3 ArrayList (java.util.ArrayList)2 GraphPath (org.opentripplanner.routing.spt.GraphPath)2 NearbyStopFinder (org.opentripplanner.graph_builder.module.NearbyStopFinder)1 RaptorPathToItineraryMapper (org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper)1 TransitLayer (org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer)1 TripSchedule (org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule)1 RaptorRoutingRequestTransitData (org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData)1 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)1 RoutingError (org.opentripplanner.routing.api.response.RoutingError)1 RoutingValidationException (org.opentripplanner.routing.error.RoutingValidationException)1 Vertex (org.opentripplanner.routing.graph.Vertex)1 StopAtDistance (org.opentripplanner.routing.graphfinder.StopAtDistance)1 FareService (org.opentripplanner.routing.services.FareService)1