Search in sources :

Example 16 with FrequencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method testFrequencies.

@Test
public void testFrequencies() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    linkBlockTrips(blockB, freqsB, tripB);
    List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(1, allIndices.size());
    List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
    assertEquals(1, indices.size());
    FrequencyBlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(4, trips.size());
    assertEquals(tripA, trips.get(0));
    assertEquals(tripB, trips.get(1));
    assertEquals(tripA, trips.get(2));
    assertEquals(tripB, trips.get(3));
    List<FrequencyEntry> freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqA1, freqB1, freqA2, freqB2), freqs);
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(6, 0), time(9, 0), time(15, 0), time(18, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(9, 0), time(15, 0), time(18, 0), time(21, 0) }, intervalBlock.getEndTimes()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 17 with FrequencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method testOverlappingFrequencies.

@Test
public void testOverlappingFrequencies() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(8, 00), time(14, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(17, 00), time(20, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    linkBlockTrips(blockB, freqsB, tripB);
    List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(2, allIndices.size());
    List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
    assertEquals(1, indices.size());
    FrequencyBlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripA, trips.get(0));
    assertEquals(tripA, trips.get(1));
    List<FrequencyEntry> freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqA1, freqA2), freqs);
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(6, 0), time(15, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(9, 0), time(18, 0) }, intervalBlock.getEndTimes()));
    /**
     **
     *
     ***
     */
    indices = grep(allIndices, aid("b"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripB, trips.get(0));
    assertEquals(tripB, trips.get(1));
    freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqB1, freqB2), freqs);
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(8, 0), time(17, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(14, 0), time(20, 0) }, intervalBlock.getEndTimes()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 18 with FrequencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactoryTest method testFrequencies.

@Test
public void testFrequencies() {
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    BlockConfigurationEntry bcA = linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    BlockConfigurationEntry bcB = linkBlockTrips(blockB, freqsB, tripB);
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    List<FrequencyBlockStopTimeIndex> allIndices = factory.createFrequencyIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(2, allIndices.size());
    List<FrequencyBlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    FrequencyBlockStopTimeIndex index = indices.get(0);
    assertEquals(freqA1, index.getFrequencies().get(0));
    assertEquals(freqB1, index.getFrequencies().get(1));
    assertEquals(freqA2, index.getFrequencies().get(2));
    assertEquals(freqB2, index.getFrequencies().get(3));
    assertEquals(bcA, index.getBlockConfigs().get(0));
    assertEquals(bcB, index.getBlockConfigs().get(1));
    assertEquals(bcA, index.getBlockConfigs().get(2));
    assertEquals(bcB, index.getBlockConfigs().get(3));
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 19 with FrequencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.

the class FrequencyEntriesFactory method processFrequencies.

public void processFrequencies(TransitGraphImpl graph) {
    Map<AgencyAndId, List<FrequencyEntry>> frequenciesByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
    Collection<Frequency> allFrequencies = _gtfsDao.getAllFrequencies();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allFrequencies.size());
    int frequencyIndex = 0;
    Map<AgencyAndId, Integer> exactTimesValueByTrip = new HashMap<AgencyAndId, Integer>();
    for (Frequency frequency : allFrequencies) {
        if (frequencyIndex % logInterval == 0)
            _log.info("frequencies: " + (frequencyIndex++) + "/" + allFrequencies.size());
        frequencyIndex++;
        processRawFrequency(graph, frequency, frequenciesByTripId, exactTimesValueByTrip);
    }
    FrequencyComparator comparator = new FrequencyComparator();
    for (List<FrequencyEntry> list : frequenciesByTripId.values()) {
        Collections.sort(list, comparator);
    }
    int blockIndex = 0;
    Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = MappingLibrary.mapToValueList(graph.getTrips(), "block.id");
    for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
        if (blockIndex % 10 == 0)
            _log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
        blockIndex++;
        AgencyAndId blockId = entry.getKey();
        List<TripEntryImpl> tripsInBlock = entry.getValue();
        Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
        for (TripEntryImpl trip : tripsInBlock) {
            List<FrequencyEntry> frequencies = frequenciesByTripId.get(trip.getId());
            if (frequencies != null) {
                frequenciesAlongBlockByTripId.put(trip.getId(), frequencies);
            }
        }
        checkForInvalidFrequencyConfigurations(blockId, tripsInBlock, frequenciesAlongBlockByTripId);
        applyFrequenciesToBlockTrips(tripsInBlock, frequenciesAlongBlockByTripId);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Frequency(org.onebusaway.gtfs.model.Frequency) ArrayList(java.util.ArrayList) List(java.util.List) FrequencyComparator(org.onebusaway.transit_data_federation.impl.blocks.FrequencyComparator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with FrequencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getFrequenciesForStopAndServiceIdsAndTimeRange.

private List<Integer> getFrequenciesForStopAndServiceIdsAndTimeRange(FrequencyStopTripIndex index, Date serviceDate, Date from, Date to, List<StopTimeInstance> stopTimeInstances, EFrequencyStopTimeBehavior frequencyBehavior) {
    int relativeFrom = effectiveTime(serviceDate, from);
    int relativeTo = effectiveTime(serviceDate, to);
    int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
    int toIndex = GenericBinarySearch.search(index, index.size(), relativeTo, IndexAdapters.FREQUENCY_START_TIME_INSTANCE);
    List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
    List<Integer> offsetsIntoIndex = new ArrayList<Integer>();
    for (int in = fromIndex; in < toIndex; in++) {
        FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(in);
        BlockStopTimeEntry bst = entry.getStopTime();
        FrequencyEntry frequency = entry.getFrequency();
        InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
        switch(frequencyBehavior) {
            case INCLUDE_UNSPECIFIED:
                {
                    stopTimeInstances.add(new StopTimeInstance(bst, state));
                    offsetsIntoIndex.add(in);
                    break;
                }
            case INCLUDE_INTERPOLATED:
                {
                    int stopTimeOffset = entry.getStopTimeOffset();
                    int tFrom = Math.max(relativeFrom, frequency.getStartTime());
                    int tTo = Math.min(relativeTo, frequency.getEndTime());
                    tFrom = snapToFrequencyStopTime(frequency, tFrom, stopTimeOffset, true);
                    tTo = snapToFrequencyStopTime(frequency, tTo, stopTimeOffset, false);
                    for (int t = tFrom; t <= tTo; t += frequency.getHeadwaySecs()) {
                        int frequencyOffset = t - bst.getStopTime().getDepartureTime();
                        stopTimeInstances.add(new StopTimeInstance(bst, state, frequencyOffset));
                        offsetsIntoIndex.add(in);
                    }
                    break;
                }
        }
    }
    return offsetsIntoIndex;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Aggregations

FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)28 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 ArrayList (java.util.ArrayList)10 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)7 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)5 Date (java.util.Date)4 Test (org.junit.Test)4 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)4 TripBean (org.onebusaway.transit_data.model.trips.TripBean)4 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)4 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)4 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)4 FrequencyServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock)4 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)4 HashMap (java.util.HashMap)3