Search in sources :

Example 6 with StopSequence

use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.

the class StopSequenceCollectionServiceImpl method exploreStopSequences.

private void exploreStopSequences(RecursiveStats rs, Map<StopSequence, PatternStats> patternStats, Iterable<StopSequence> patterns, String depth) {
    Segment prevSegment = rs.prevSegment;
    for (StopSequence pattern : patterns) {
        if (rs.visited.contains(pattern))
            continue;
        PatternStats stats = patternStats.get(pattern);
        double count = stats.tripCounts;
        double ratio = count / rs.maxTripCount;
        if (ratio < SERVICE_PATTERN_TRIP_COUNT_RATIO_MIN)
            continue;
        Segment segment = stats.segment;
        if (prevSegment != null)
            segment = new Segment(prevSegment, segment, prevSegment.distance + segment.distance);
        rs.longestSegment.add(segment.distance, segment);
        Set<StopSequence> nextPatterns = stats.continuations;
        if (!nextPatterns.isEmpty()) {
            rs.visited.add(pattern);
            rs.prevSegment = segment;
            exploreStopSequences(rs, patternStats, nextPatterns, depth + "  ");
            rs.visited.remove(pattern);
        }
    }
}
Also used : StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 7 with StopSequence

use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.

the class StopSequenceCollectionServiceImpl method getStatsForStopSequences.

/**
 * Computes some general statistics for each {@link StopSequence} in a
 * collection, including the number of trips taking that stop sequence, the
 * set of regions for the destination of the stop sequence
 *
 * @param sequences
 * @return the computed statistics
 */
private Map<StopSequence, PatternStats> getStatsForStopSequences(List<StopSequence> sequences) {
    Map<StopSequence, PatternStats> patternStats = new HashMap<StopSequence, PatternStats>();
    for (StopSequence sequence : sequences) {
        PatternStats stats = new PatternStats();
        stats.tripCounts = sequence.getTripCount();
        stats.segment = getSegmentForStopSequence(sequence);
        patternStats.put(sequence, stats);
    }
    return patternStats;
}
Also used : HashMap(java.util.HashMap) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 8 with StopSequence

use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.

the class StopSequenceCollectionServiceImpl method groupStopSequencesByNotDirectionIds.

private Map<String, List<StopSequence>> groupStopSequencesByNotDirectionIds(Iterable<StopSequence> sequences) {
    TreeUnionFind<StopSequence> unionFind = new TreeUnionFind<StopSequence>();
    for (StopSequence stopSequenceA : sequences) {
        unionFind.find(stopSequenceA);
        for (StopSequence stopSequenceB : sequences) {
            if (stopSequenceA == stopSequenceB)
                continue;
            double ratio = getMaxCommonStopSequenceRatio(stopSequenceA, stopSequenceB);
            if (ratio >= STOP_SEQUENCE_MIN_COMMON_RATIO)
                unionFind.union(stopSequenceA, stopSequenceB);
        }
    }
    Map<String, List<StopSequence>> results = new HashMap<String, List<StopSequence>>();
    int index = 0;
    for (Set<StopSequence> sequencesByDirection : unionFind.getSetMembers()) {
        String key = Integer.toString(index);
        List<StopSequence> asList = new ArrayList<StopSequence>(sequencesByDirection);
        results.put(key, asList);
        index++;
    }
    return results;
}
Also used : TreeUnionFind(org.onebusaway.utility.collections.TreeUnionFind) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 9 with StopSequence

use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.

the class StopSequencesServiceImpl method getStopSequencesForTrips.

@Override
public List<StopSequence> getStopSequencesForTrips(List<BlockTripEntry> trips) {
    Map<StopSequenceKey, List<BlockTripEntry>> tripsByStopSequenceKey = new FactoryMap<StopSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
    for (BlockTripEntry blockTrip : trips) {
        TripEntry trip = blockTrip.getTrip();
        String directionId = trip.getDirectionId();
        if (directionId == null)
            directionId = NO_DIRECTION_ID;
        AgencyAndId shapeId = trip.getShapeId();
        if (shapeId == null || !shapeId.hasValues())
            shapeId = NO_SHAPE_ID;
        List<StopEntry> stops = getStopTimesAsStops(trip.getStopTimes());
        StopSequenceKey key = new StopSequenceKey(stops, directionId, shapeId);
        tripsByStopSequenceKey.get(key).add(blockTrip);
    }
    List<StopSequence> sequences = new ArrayList<StopSequence>();
    for (Map.Entry<StopSequenceKey, List<BlockTripEntry>> entry : tripsByStopSequenceKey.entrySet()) {
        StopSequenceKey key = entry.getKey();
        StopSequence ss = new StopSequence();
        ss.setId(sequences.size());
        ss.setRoute(null);
        ss.setStops(key.getStops());
        if (!key.getDirectionId().equals(NO_DIRECTION_ID))
            ss.setDirectionId(key.getDirectionId());
        if (!key.getShapeId().equals(NO_SHAPE_ID))
            ss.setShapeId(key.getShapeId());
        ss.setTrips(entry.getValue());
        ss.setTripCount(entry.getValue().size());
        sequences.add(ss);
    }
    return sequences;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) List(java.util.List) ArrayList(java.util.ArrayList) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 10 with StopSequence

use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.

the class RouteBeanServiceImpl method getStopsForRouteCollectionAndNarrative.

private StopsForRouteBean getStopsForRouteCollectionAndNarrative(RouteCollectionEntry routeCollection, RouteCollectionNarrative narrative) {
    StopsForRouteBean result = new StopsForRouteBean();
    AgencyAndId routeCollectionId = routeCollection.getId();
    result.setRoute(getRouteBeanForRouteCollection(routeCollectionId, narrative));
    result.setStops(getStopBeansForRoute(routeCollectionId));
    result.setPolylines(getEncodedPolylinesForRoute(routeCollection));
    StopGroupingBean directionGrouping = new StopGroupingBean();
    directionGrouping.setType(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    List<StopGroupBean> directionGroups = new ArrayList<StopGroupBean>();
    directionGrouping.setStopGroups(directionGroups);
    directionGrouping.setOrdered(true);
    result.addGrouping(directionGrouping);
    List<BlockTripIndex> blockIndices = _blockIndexService.getBlockTripIndicesForRouteCollectionId(routeCollectionId);
    List<FrequencyBlockTripIndex> frequencyBlockIndices = _blockIndexService.getFrequencyBlockTripIndicesForRouteCollectionId(routeCollectionId);
    List<BlockTripEntry> blockTrips = new ArrayList<BlockTripEntry>();
    getBlockTripsForIndicesMatchingRouteCollection(blockIndices, routeCollectionId, blockTrips);
    getBlockTripsForIndicesMatchingRouteCollection(frequencyBlockIndices, routeCollectionId, blockTrips);
    List<StopSequence> sequences = _stopSequencesService.getStopSequencesForTrips(blockTrips);
    List<StopSequenceCollection> blocks = _stopSequenceBlocksService.getStopSequencesAsCollections(sequences);
    for (StopSequenceCollection block : blocks) {
        NameBean name = new NameBean(NameBeanTypes.DESTINATION, block.getDescription());
        List<StopEntry> stops = getStopsInOrder(block);
        List<String> groupStopIds = new ArrayList<String>();
        for (StopEntry stop : stops) groupStopIds.add(ApplicationBeanLibrary.getId(stop.getId()));
        Set<AgencyAndId> shapeIds = getShapeIdsForStopSequenceBlock(block);
        List<EncodedPolylineBean> polylines = _shapeBeanService.getMergedPolylinesForShapeIds(shapeIds);
        StopGroupBean group = new StopGroupBean();
        group.setId(block.getPublicId());
        group.setName(name);
        group.setStopIds(groupStopIds);
        group.setPolylines(polylines);
        directionGroups.add(group);
    }
    sortResult(result);
    return result;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) AbstractBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockTripIndex) StopSequenceCollection(org.onebusaway.transit_data_federation.model.StopSequenceCollection)

Aggregations

StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)10 ArrayList (java.util.ArrayList)6 List (java.util.List)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5 HashMap (java.util.HashMap)4 FactoryMap (org.onebusaway.collections.FactoryMap)4 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)4 Map (java.util.Map)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)3 HashSet (java.util.HashSet)2 StopSequenceCollection (org.onebusaway.transit_data_federation.model.StopSequenceCollection)2 Counter (org.onebusaway.collections.Counter)1 Max (org.onebusaway.collections.Max)1 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 DirectedGraph (org.onebusaway.transit_data_federation.impl.DirectedGraph)1