Search in sources :

Example 1 with EgressPathLeg

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

the class ForwardPathMapper method createEgressPathLeg.

private EgressPathLeg<T> createEgressPathLeg(DestinationArrival<T> destinationArrival) {
    RaptorTransfer egress = destinationArrival.egressLeg().egress();
    int departureTime = destinationArrival.arrivalTime() - egress.durationInSeconds();
    return new EgressPathLeg<>(egress, destinationArrival.previous().stop(), departureTime, destinationArrival.arrivalTime());
}
Also used : EgressPathLeg(org.opentripplanner.transit.raptor.api.path.EgressPathLeg) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer)

Example 2 with EgressPathLeg

use of org.opentripplanner.transit.raptor.api.path.EgressPathLeg 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 3 with EgressPathLeg

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

the class ReversePathMapper method mapToEgressLeg.

private EgressPathLeg<T> mapToEgressLeg(ArrivalView<T> accessArrival) {
    RaptorTransfer egress = accessArrival.accessLeg().access();
    int targetDepartureTime = accessArrival.arrivalTime();
    int targetArrivalTime = accessArrival.arrivalTime() + egress.durationInSeconds();
    // No need to time-shift the egress leg, this is done when stopArrival is created
    return new EgressPathLeg<>(egress, accessArrival.stop(), targetDepartureTime, targetArrivalTime);
}
Also used : EgressPathLeg(org.opentripplanner.transit.raptor.api.path.EgressPathLeg) RaptorTransfer(org.opentripplanner.transit.raptor.api.transit.RaptorTransfer)

Example 4 with EgressPathLeg

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

the class RaptorPathToItineraryMapper method createItinerary.

public Itinerary createItinerary(Path<TripSchedule> path) {
    List<Leg> legs = new ArrayList<>();
    // Map access leg
    mapAccessLeg(legs, path.accessLeg());
    // TODO: Add back this code when PathLeg interface contains object references
    PathLeg<TripSchedule> pathLeg = path.accessLeg().nextLeg();
    boolean firstLeg = true;
    while (!pathLeg.isEgressLeg()) {
        // Map transit leg
        if (pathLeg.isTransitLeg()) {
            Leg transitLeg = mapTransitLeg(request, pathLeg.asTransitLeg(), firstLeg);
            firstLeg = false;
            legs.add(transitLeg);
        }
        // Map transfer leg
        if (pathLeg.isTransferLeg()) {
            mapTransferLeg(legs, pathLeg.asTransferLeg());
        }
        pathLeg = pathLeg.nextLeg();
    }
    // Map egress leg
    EgressPathLeg<TripSchedule> egressPathLeg = pathLeg.asEgressLeg();
    mapEgressLeg(legs, egressPathLeg);
    propagateStopPlaceNamesToWalkingLegs(legs);
    Itinerary itinerary = new Itinerary(legs);
    // Map general itinerary fields
    itinerary.generalizedCost = path.cost();
    itinerary.nonTransitLimitExceeded = itinerary.nonTransitDistanceMeters > request.maxWalkDistance;
    return itinerary;
}
Also used : ArrayList(java.util.ArrayList) Itinerary(org.opentripplanner.model.plan.Itinerary) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) Leg(org.opentripplanner.model.plan.Leg) TransitPathLeg(org.opentripplanner.transit.raptor.api.path.TransitPathLeg) 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

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