Search in sources :

Example 1 with AccessPathLeg

use of org.opentripplanner.transit.raptor.api.path.AccessPathLeg 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)

Example 2 with AccessPathLeg

use of org.opentripplanner.transit.raptor.api.path.AccessPathLeg in project OpenTripPlanner by opentripplanner.

the class ReversePathMapper method mapAccessLeg.

AccessPathLeg<T> mapAccessLeg(DestinationArrival<T> destArrival) {
    ArrivalView<T> prevArrival = destArrival.previous();
    RaptorTransfer access = destArrival.egressLeg().egress();
    int targetDepartureTime = destArrival.arrivalTime();
    int targetArrivalTime = destArrival.arrivalTime() + access.durationInSeconds();
    return new AccessPathLeg<>(access, prevArrival.stop(), targetDepartureTime, targetArrivalTime, // Recursive
    mapToTransit(prevArrival));
}
Also used : AccessPathLeg(org.opentripplanner.transit.raptor.api.path.AccessPathLeg) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer)

Example 3 with AccessPathLeg

use of org.opentripplanner.transit.raptor.api.path.AccessPathLeg in project OpenTripPlanner by opentripplanner.

the class ForwardPathMapper method createAccessPathLeg.

private AccessPathLeg<T> createAccessPathLeg(ArrivalView<T> from, PathLeg<T> nextLeg) {
    RaptorTransfer access = from.accessLeg().access();
    int departureTime = from.arrivalTime() - access.durationInSeconds();
    return new AccessPathLeg<>(access, from.stop(), departureTime, from.arrivalTime(), nextLeg);
}
Also used : AccessPathLeg(org.opentripplanner.transit.raptor.api.path.AccessPathLeg) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer)

Aggregations

AccessPathLeg (org.opentripplanner.transit.raptor.api.path.AccessPathLeg)3 RaptorTransfer (org.opentripplanner.transit.raptor.api.transit.RaptorTransfer)2 Route (org.opentripplanner.model.Route)1 TripPattern (org.opentripplanner.model.TripPattern)1 TripSchedule (org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule)1 EgressPathLeg (org.opentripplanner.transit.raptor.api.path.EgressPathLeg)1 PathLeg (org.opentripplanner.transit.raptor.api.path.PathLeg)1 TransferPathLeg (org.opentripplanner.transit.raptor.api.path.TransferPathLeg)1 TransitPathLeg (org.opentripplanner.transit.raptor.api.path.TransitPathLeg)1 Itinerary (org.opentripplanner.transit.raptor.speed_test.model.Itinerary)1 Leg (org.opentripplanner.transit.raptor.speed_test.model.Leg)1