Search in sources :

Example 1 with Frequency

use of com.conveyal.gtfs.model.Frequency in project graphhopper by graphhopper.

the class GtfsReader method buildPtNetwork.

private void buildPtNetwork() {
    HashMultimap<String, Trip> blockTrips = HashMultimap.create();
    for (Trip trip : feed.trips.values()) {
        if (trip.block_id != null) {
            blockTrips.put(trip.block_id, trip);
        } else {
            blockTrips.put("non-block-trip" + trip.trip_id, trip);
        }
    }
    blockTrips.asMap().values().forEach(unsortedTrips -> {
        List<TripWithStopTimes> trips = unsortedTrips.stream().map(trip -> {
            Service service = feed.services.get(trip.service_id);
            BitSet validOnDay = new BitSet((int) DAYS.between(startDate, endDate));
            for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
                if (service.activeOn(date)) {
                    validOnDay.set((int) DAYS.between(startDate, date));
                }
            }
            ArrayList<StopTime> stopTimes = new ArrayList<>();
            getInterpolatedStopTimesForTrip(trip.trip_id).forEach(stopTimes::add);
            return new TripWithStopTimes(trip, stopTimes, validOnDay, Collections.emptySet(), Collections.emptySet());
        }).sorted(Comparator.comparingInt(trip -> trip.stopTimes.iterator().next().departure_time)).collect(Collectors.toList());
        if (trips.stream().map(trip -> feed.getFrequencies(trip.trip.trip_id)).distinct().count() != 1) {
            throw new RuntimeException("Found a block with frequency-based trips. Not supported.");
        }
        ZoneId zoneId = ZoneId.of(feed.agency.get(feed.routes.get(trips.iterator().next().trip.route_id).agency_id).agency_timezone);
        Collection<Frequency> frequencies = feed.getFrequencies(trips.iterator().next().trip.trip_id);
        if (frequencies.isEmpty()) {
            addTrips(zoneId, trips, 0, false);
        } else {
            for (Frequency frequency : frequencies) {
                for (int time = frequency.start_time; time < frequency.end_time; time += frequency.headway_secs) {
                    addTrips(zoneId, trips, time, true);
                }
            }
        }
    });
    wireUpStops();
}
Also used : Transfer(com.conveyal.gtfs.model.Transfer) SortedSet(java.util.SortedSet) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) ListIterator(java.util.ListIterator) Writer.convertToGtfsTime(com.conveyal.gtfs.model.Entity.Writer.convertToGtfsTime) Stop(com.conveyal.gtfs.model.Stop) LoggerFactory(org.slf4j.LoggerFactory) DistanceCalc(com.graphhopper.util.DistanceCalc) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashMultimap(com.google.common.collect.HashMultimap) IntArrayList(com.carrotsearch.hppc.IntArrayList) Map(java.util.Map) Frequency(com.conveyal.gtfs.model.Frequency) Graph(com.graphhopper.storage.Graph) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Service(com.conveyal.gtfs.model.Service) Logger(org.slf4j.Logger) LocationIndex(com.graphhopper.storage.index.LocationIndex) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Helper(com.graphhopper.util.Helper) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Collection(java.util.Collection) Set(java.util.Set) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) NavigableSet(java.util.NavigableSet) EdgeIterator(com.graphhopper.util.EdgeIterator) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) ZoneId(java.time.ZoneId) Fun(org.mapdb.Fun) DAYS(java.time.temporal.ChronoUnit.DAYS) List(java.util.List) NodeAccess(com.graphhopper.storage.NodeAccess) StopTime(com.conveyal.gtfs.model.StopTime) Trip(com.conveyal.gtfs.model.Trip) LocalDate(java.time.LocalDate) Optional(java.util.Optional) BitSet(java.util.BitSet) Comparator(java.util.Comparator) Route(com.conveyal.gtfs.model.Route) QueryResult(com.graphhopper.storage.index.QueryResult) Collections(java.util.Collections) Trip(com.conveyal.gtfs.model.Trip) ZoneId(java.time.ZoneId) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) Service(com.conveyal.gtfs.model.Service) LocalDate(java.time.LocalDate) Frequency(com.conveyal.gtfs.model.Frequency) StopTime(com.conveyal.gtfs.model.StopTime)

Aggregations

IntArrayList (com.carrotsearch.hppc.IntArrayList)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Writer.convertToGtfsTime (com.conveyal.gtfs.model.Entity.Writer.convertToGtfsTime)1 Frequency (com.conveyal.gtfs.model.Frequency)1 Route (com.conveyal.gtfs.model.Route)1 Service (com.conveyal.gtfs.model.Service)1 Stop (com.conveyal.gtfs.model.Stop)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Transfer (com.conveyal.gtfs.model.Transfer)1 Trip (com.conveyal.gtfs.model.Trip)1 HashMultimap (com.google.common.collect.HashMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1 Graph (com.graphhopper.storage.Graph)1 NodeAccess (com.graphhopper.storage.NodeAccess)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 QueryResult (com.graphhopper.storage.index.QueryResult)1 DistanceCalc (com.graphhopper.util.DistanceCalc)1 EdgeIterator (com.graphhopper.util.EdgeIterator)1