Search in sources :

Example 16 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSource method getPatternForTripId.

/**
 * Retrieve a trip pattern given a feed id and trip id.
 *
 * @param feedId feed id for the trip id
 * @param tripId trip id without agency
 * @return trip pattern or null if no trip pattern was found
 */
private TripPattern getPatternForTripId(String feedId, String tripId) {
    Trip trip = routingService.getTripForId().get(new FeedScopedId(feedId, tripId));
    TripPattern pattern = routingService.getPatternForTrip().get(trip);
    return pattern;
}
Also used : Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern)

Example 17 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class TripPatternCache method getOrCreateTripPattern.

/**
 * Get cached trip pattern or create one if it doesn't exist yet. If a trip pattern is created, vertices
 * and edges for this trip pattern are also created in the graph.
 *
 * @param stopPattern stop pattern to retrieve/create trip pattern
 * @param trip the trip the new trip pattern will be created for
 * @param graph graph to add vertices and edges in case a new trip pattern will be created
 * @return cached or newly created trip pattern
 */
public synchronized TripPattern getOrCreateTripPattern(@NotNull final StopPattern stopPattern, @NotNull final Trip trip, @NotNull final Graph graph) {
    Route route = trip.getRoute();
    // Check cache for trip pattern
    TripPattern tripPattern = cache.get(stopPattern);
    // Create TripPattern if it doesn't exist yet
    if (tripPattern == null) {
        tripPattern = new TripPattern(route, stopPattern);
        // Generate unique code for trip pattern
        tripPattern.setId(new FeedScopedId(tripPattern.getFeedId(), generateUniqueTripPatternCode(tripPattern)));
        // Create an empty bitset for service codes (because the new pattern does not contain any trips)
        tripPattern.setServiceCodes(graph.getServiceCodes());
        // Finish scheduled time table
        tripPattern.scheduledTimetable.finish();
        TripPattern originalTripPattern = graph.index.getPatternForTrip().get(trip);
        // Copy information from the TripPattern this is replacing
        if (originalTripPattern != null) {
            tripPattern.setHopGeometriesFromPattern(originalTripPattern);
        }
        // Add pattern to cache
        cache.put(stopPattern, tripPattern);
    }
    return tripPattern;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern)

Example 18 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class PlaceFinderTraverseVisitor method handlePatternsAtStop.

private void handlePatternsAtStop(Stop stop, double distance) {
    if (includePatternAtStops) {
        List<TripPattern> patterns = routingService.getPatternsForStop(stop).stream().filter(pattern -> filterByModes == null || filterByModes.contains(pattern.getMode())).filter(pattern -> filterByRoutes == null || filterByRoutes.contains(pattern.route.getId())).filter(pattern -> pattern.canBoard(pattern.getStopIndex(stop))).collect(toList());
        for (TripPattern pattern : patterns) {
            String seenKey = pattern.route.getId().toString() + ":" + pattern.getId().toString();
            if (!seenPatternAtStops.contains(seenKey)) {
                PatternAtStop row = new PatternAtStop(stop, pattern);
                PlaceAtDistance place = new PlaceAtDistance(row, distance);
                placesFound.add(place);
                seenPatternAtStops.add(seenKey);
            }
        }
    }
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) SearchTerminationStrategy(org.opentripplanner.routing.algorithm.astar.strategies.SearchTerminationStrategy) RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) Vertex(org.opentripplanner.routing.graph.Vertex) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) Set(java.util.Set) TraverseVisitor(org.opentripplanner.routing.algorithm.astar.TraverseVisitor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) State(org.opentripplanner.routing.core.State) TransitMode(org.opentripplanner.model.TransitMode) Edge(org.opentripplanner.routing.graph.Edge) TripPattern(org.opentripplanner.model.TripPattern)

Example 19 with TripPattern

use of org.opentripplanner.model.TripPattern 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 20 with TripPattern

use of org.opentripplanner.model.TripPattern 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)

Aggregations

TripPattern (org.opentripplanner.model.TripPattern)61 Trip (org.opentripplanner.model.Trip)26 FeedScopedId (org.opentripplanner.model.FeedScopedId)23 Stop (org.opentripplanner.model.Stop)23 ArrayList (java.util.ArrayList)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Timetable (org.opentripplanner.model.Timetable)13 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 Route (org.opentripplanner.model.Route)12 Test (org.junit.Test)11 HashSet (java.util.HashSet)8 RoutingService (org.opentripplanner.routing.RoutingService)8 List (java.util.List)7 StopPattern (org.opentripplanner.model.StopPattern)7 TimetableSnapshot (org.opentripplanner.model.TimetableSnapshot)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 StopTime (org.opentripplanner.model.StopTime)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)4