Search in sources :

Example 1 with TripSchedule

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

the class SpeedTestRequest method createRangeRaptorRequest.

RaptorRequest<TripSchedule> createRangeRaptorRequest(SpeedTestProfile profile, int numOfExtraTransfers, boolean oneIterationOnly, EgressAccessRouter streetRouter) {
    // Add half of the extra time to departure and half to the arrival
    int expandSearchSec = EXPAND_SEARCH_WINDOW_HOURS * 3600 / 2;
    RaptorRequestBuilder<TripSchedule> builder = new RaptorRequestBuilder<>();
    builder.searchParams().boardSlackInSeconds(120).timetableEnabled(true).numberOfAdditionalTransfers(numOfExtraTransfers);
    if (testCase.departureTime != TestCase.NOT_SET) {
        builder.searchParams().earliestDepartureTime(testCase.departureTime - expandSearchSec);
    }
    if (testCase.arrivalTime != TestCase.NOT_SET) {
        builder.searchParams().latestArrivalTime(testCase.arrivalTime + expandSearchSec);
    }
    if (testCase.window != TestCase.NOT_SET) {
        builder.searchParams().searchWindowInSeconds(testCase.window + 2 * expandSearchSec);
    }
    if (oneIterationOnly) {
        builder.searchParams().searchOneIterationOnly();
    }
    builder.enableOptimization(Optimization.PARALLEL);
    builder.profile(profile.raptorProfile);
    for (Optimization it : profile.optimizations) {
        builder.enableOptimization(it);
    }
    if (profile.raptorProfile.isOneOf(RaptorProfile.NO_WAIT_STD, RaptorProfile.NO_WAIT_BEST_TIME)) {
        builder.searchParams().searchOneIterationOnly();
    }
    builder.slackProvider(new SlackProvider(config.request.transferSlack, config.request.boardSlack, config.request.boardSlackForMode, config.request.alightSlack, config.request.alightSlackForMode));
    builder.searchDirection(profile.direction);
    addAccessEgressStopArrivals(streetRouter.getAccessTimesInSecondsByStopIndex(), builder.searchParams()::addAccessStop);
    addAccessEgressStopArrivals(streetRouter.getEgressTimesInSecondsByStopIndex(), builder.searchParams()::addEgressStop);
    addDebugOptions(builder, opts);
    RaptorRequest<TripSchedule> req = builder.build();
    if (opts.debugRequest()) {
        System.err.println("-> Request: " + req);
    }
    return req;
}
Also used : SlackProvider(org.opentripplanner.routing.algorithm.raptor.transit.SlackProvider) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) Optimization(org.opentripplanner.transit.raptor.api.request.Optimization) RaptorRequestBuilder(org.opentripplanner.transit.raptor.api.request.RaptorRequestBuilder)

Example 2 with TripSchedule

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

the class RaptorPathToItineraryMapper method extractTransitLegCoordinates.

private List<Coordinate> extractTransitLegCoordinates(TransitPathLeg<TripSchedule> pathLeg) {
    List<Coordinate> transitLegCoordinates = new ArrayList<>();
    TripPattern tripPattern = pathLeg.trip().getOriginalTripPattern();
    TripSchedule tripSchedule = pathLeg.trip();
    boolean boarded = false;
    for (int j = 0; j < tripPattern.stopPattern.stops.length; j++) {
        int currentStopIndex = transitLayer.getStopIndex().indexByStop.get(tripPattern.getStop(j));
        if (boarded) {
            transitLegCoordinates.addAll(Arrays.asList(tripPattern.getHopGeometry(j - 1).getCoordinates()));
        }
        if (!boarded && tripSchedule.departure(j) == pathLeg.fromTime() && currentStopIndex == pathLeg.fromStop()) {
            boarded = true;
        }
        if (boarded && tripSchedule.arrival(j) == pathLeg.toTime() && currentStopIndex == pathLeg.toStop()) {
            break;
        }
    }
    return transitLegCoordinates;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) TripPattern(org.opentripplanner.model.TripPattern) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule)

Example 3 with TripSchedule

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

the class RideMapper method rideForTransitPathLeg.

public static Ride rideForTransitPathLeg(TransitPathLeg leg, TransitLayer transitLayer) {
    TransitPathLeg<TripSchedule> transitPathLeg = leg.asTransitLeg();
    TripSchedule tripSchedule = transitPathLeg.trip();
    Ride ride = new Ride();
    TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
    ride.firstStop = transitLayer.getStopByIndex(transitPathLeg.fromStop());
    ride.lastStop = transitLayer.getStopByIndex(transitPathLeg.toStop());
    ride.startZone = ride.firstStop.getFirstZoneAsString();
    ride.endZone = ride.lastStop.getFirstZoneAsString();
    // In almost all cases (except some loop routes) this should get the right set of zones passed through.
    // We don't have the position of the stops within the pattern so can't readily get more accurate than this.
    boolean onBoard = false;
    for (Stop stop : tripPattern.getStops()) {
        if (stop == ride.firstStop) {
            onBoard = true;
        }
        if (onBoard) {
            ride.zones.add(stop.getFirstZoneAsString());
            if (stop == ride.lastStop)
                break;
        }
    }
    ride.agency = tripPattern.route.getAgency().getId();
    ride.route = tripPattern.route.getId();
    ride.trip = tripSchedule.getOriginalTripTimes().trip.getId();
    // TODO verify that times are in seconds after midnight
    ride.startTime = transitPathLeg.fromTime();
    ride.endTime = transitPathLeg.toTime();
    // In the default fare service, we classify rides by mode.
    ride.classifier = tripPattern.getMode();
    return ride;
}
Also used : Stop(org.opentripplanner.model.Stop) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) TripPattern(org.opentripplanner.model.TripPattern)

Example 4 with TripSchedule

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

the class RaptorRequestMapper method mapRequest.

public static RaptorRequest<TripSchedule> mapRequest(RoutingRequest request, ZonedDateTime startOfTime, Collection<? extends RaptorTransfer> accessTimes, Collection<? extends RaptorTransfer> egressTimes) {
    RaptorRequestBuilder<TripSchedule> builder = new RaptorRequestBuilder<>();
    int time = DateMapper.secondsSinceStartOfTime(startOfTime, request.getDateTime().toInstant());
    if (request.arriveBy) {
        builder.searchParams().latestArrivalTime(time);
    } else {
        builder.searchParams().earliestDepartureTime(time);
    }
    if (request.maxTransfers != null) {
        builder.searchParams().maxNumberOfTransfers(request.maxTransfers);
    }
    builder.profile(RaptorProfile.MULTI_CRITERIA).enableOptimization(Optimization.PARETO_CHECK_AGAINST_DESTINATION).slackProvider(new SlackProvider(request.transferSlack, request.boardSlack, request.boardSlackForMode, request.alightSlack, request.alightSlackForMode));
    builder.searchParams().searchWindow(request.searchWindow).addAccessStops(accessTimes.stream().map(t -> (RaptorTransfer) t).collect(Collectors.toList())).addEgressStops(egressTimes.stream().map(t -> (RaptorTransfer) t).collect(Collectors.toList())).boardSlackInSeconds(request.boardSlack).timetableEnabled(true);
    builder.mcCostFactors().waitReluctanceFactor(request.waitReluctance).walkReluctanceFactor(request.walkReluctance);
    return builder.build();
}
Also used : RaptorRequest(org.opentripplanner.transit.raptor.api.request.RaptorRequest) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer) RaptorProfile(org.opentripplanner.transit.raptor.api.request.RaptorProfile) RaptorRequestBuilder(org.opentripplanner.transit.raptor.api.request.RaptorRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Collection(java.util.Collection) SlackProvider(org.opentripplanner.routing.algorithm.raptor.transit.SlackProvider) Optimization(org.opentripplanner.transit.raptor.api.request.Optimization) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Collectors(java.util.stream.Collectors) SlackProvider(org.opentripplanner.routing.algorithm.raptor.transit.SlackProvider) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) RaptorRequestBuilder(org.opentripplanner.transit.raptor.api.request.RaptorRequestBuilder)

Example 5 with TripSchedule

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

the class ItineraryMapper method createItinerary.

private Itinerary createItinerary(Path<TripSchedule> path, StopAtDistance accessPath, StopAtDistance egressPath) {
    if (path == null) {
        return null;
    }
    Itinerary itinerary = new Itinerary();
    itinerary.walkDistance = 0.0;
    itinerary.transitTime = 0;
    itinerary.waitingTime = 0;
    itinerary.weight = path.cost();
    int numberOfTransits = 0;
    // Access leg
    Leg leg = new Leg();
    AccessPathLeg<TripSchedule> accessLeg = path.accessLeg();
    leg.startTime = accessLeg.fromTime();
    leg.endTime = accessLeg.toTime();
    leg.from = request.tc().fromPlace;
    leg.to = request.tc().toPlace;
    leg.mode = WALK;
    leg.distance = accessPath.distance;
    itinerary.addLeg(leg);
    PathLeg<TripSchedule> pathLeg = accessLeg.nextLeg();
    int previousArrivalTime = -1;
    while (pathLeg.isTransitLeg() || pathLeg.isTransferLeg()) {
        leg = new Leg();
        // Transfer leg if present
        if (pathLeg.isTransferLeg()) {
            TransferPathLeg<?> it = pathLeg.asTransferLeg();
            previousArrivalTime = it.toTime();
            leg.startTime = it.fromTime();
            leg.endTime = previousArrivalTime;
            leg.mode = WALK;
            leg.from = mapToPlace(it.fromStop());
            leg.to = mapToPlace(it.toStop());
            // distanceMMToMeters (transferPath.getDistance());
            leg.distance = -1.0;
        } else {
            // Transit leg
            TransitPathLeg<TripSchedule> it = pathLeg.asTransitLeg();
            itinerary.transitTime += it.toTime() - it.fromTime();
            itinerary.waitingTime += it.fromTime() - previousArrivalTime;
            previousArrivalTime = it.toTime();
            ++numberOfTransits;
            leg.distance = 0.0;
            TripSchedule tripSchedule = it.trip();
            TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
            Route routeInfo = tripPattern.route;
            leg.from = mapToPlace(it.fromStop());
            leg.to = mapToPlace(it.toStop());
            leg.route = routeInfo.getShortName();
            leg.agencyName = routeInfo.getAgency().getName();
            leg.tripShortName = tripSchedule.getOriginalTripPattern().name;
            leg.agencyId = routeInfo.getAgency().getId();
            leg.routeShortName = routeInfo.getShortName();
            leg.routeLongName = routeInfo.getLongName();
            leg.mode = TraverseMode.fromTransitMode(tripSchedule.getOriginalTripPattern().getMode());
            leg.startTime = it.fromTime();
            leg.endTime = it.toTime();
        }
        itinerary.addLeg(leg);
        pathLeg = pathLeg.nextLeg();
    }
    // Egress leg
    leg = new Leg();
    EgressPathLeg<TripSchedule> egressLeg = pathLeg.asEgressLeg();
    leg.startTime = egressLeg.fromTime();
    leg.endTime = egressLeg.toTime();
    leg.from = mapToPlace(egressLeg.fromStop());
    leg.to = request.tc().toPlace;
    leg.mode = WALK;
    leg.distance = egressPath.distance;
    itinerary.addLeg(leg);
    itinerary.startTime = itinerary.legs.get(0).startTime;
    itinerary.endTime = leg.endTime;
    itinerary.duration = itinerary.endTime - itinerary.startTime;
    // The number of transfers is the number of transits minus one, we can NOT count the number of Transfers
    // in the path or itinerary, because transfers at the same stop does not produce a transfer object, just two
    // transits following each other.
    itinerary.transfers = numberOfTransits - 1;
    return itinerary;
}
Also used : Itinerary(org.opentripplanner.transit.raptor.speed_test.model.Itinerary) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) TripPattern(org.opentripplanner.model.TripPattern) Route(org.opentripplanner.model.Route) TransitPathLeg(org.opentripplanner.transit.raptor.api.path.TransitPathLeg) Leg(org.opentripplanner.transit.raptor.speed_test.model.Leg) TransferPathLeg(org.opentripplanner.transit.raptor.api.path.TransferPathLeg) AccessPathLeg(org.opentripplanner.transit.raptor.api.path.AccessPathLeg) PathLeg(org.opentripplanner.transit.raptor.api.path.PathLeg) EgressPathLeg(org.opentripplanner.transit.raptor.api.path.EgressPathLeg)

Aggregations

TripSchedule (org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule)11 ArrayList (java.util.ArrayList)5 TripPattern (org.opentripplanner.model.TripPattern)4 Stop (org.opentripplanner.model.Stop)3 AccessPathLeg (org.opentripplanner.transit.raptor.api.path.AccessPathLeg)3 EgressPathLeg (org.opentripplanner.transit.raptor.api.path.EgressPathLeg)3 PathLeg (org.opentripplanner.transit.raptor.api.path.PathLeg)3 TransferPathLeg (org.opentripplanner.transit.raptor.api.path.TransferPathLeg)3 TransitPathLeg (org.opentripplanner.transit.raptor.api.path.TransitPathLeg)3 Coordinate (org.locationtech.jts.geom.Coordinate)2 Itinerary (org.opentripplanner.model.plan.Itinerary)2 Leg (org.opentripplanner.model.plan.Leg)2 SlackProvider (org.opentripplanner.routing.algorithm.raptor.transit.SlackProvider)2 Optimization (org.opentripplanner.transit.raptor.api.request.Optimization)2 RaptorRequestBuilder (org.opentripplanner.transit.raptor.api.request.RaptorRequestBuilder)2 Itinerary (org.opentripplanner.transit.raptor.speed_test.model.Itinerary)2 ZonedDateTime (java.time.ZonedDateTime)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Route (org.opentripplanner.model.Route)1