Package org.onebusaway.transit_data_federation.services.transit_graph

Examples of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry


    /**
     * TODO: Eventually, use startDate and startTime to distinguish between
     * different instances
     */
    BlockInstance instance = instances.get(0);
    BlockConfigurationEntry blockConfiguration = instance.getBlock();
    List<BlockTripEntry> blockTrips = blockConfiguration.getTrips();

    Map<String, List<TripUpdate>> tripUpdatesByTripId = MappingLibrary.mapToValueList(
        tripUpdates, "trip.tripId");

    int currentTime = (int) ((t - instance.getServiceDate()) / 1000);
View Full Code Here


  public ScheduledBlockLocation getBestScheduledBlockLocationForLocation(
      BlockInstance blockInstance, CoordinatePoint location, long timestamp,
      double blockDistanceFrom, double blockDistanceTo) {

    BlockConfigurationEntry block = blockInstance.getBlock();

    ProjectedPoint targetPoint = ProjectedPointFactory.forward(location);

    List<AgencyAndId> shapePointIds = MappingLibrary.map(block.getTrips(),
        "trip.shapeId");

    T2<List<XYPoint>, double[]> tuple = _projectedShapePointService.getProjectedShapePoints(
        shapePointIds, targetPoint.getSrid());

    if (tuple == null) {
      throw new IllegalStateException("block had no shape points: "
          + block.getBlock().getId());
    }

    List<XYPoint> projectedShapePoints = tuple.getFirst();
    double[] distances = tuple.getSecond();

    int fromIndex = 0;
    int toIndex = distances.length;

    if (blockDistanceFrom > 0) {
      fromIndex = Arrays.binarySearch(distances, blockDistanceFrom);
      if (fromIndex < 0) {
        fromIndex = -(fromIndex + 1);
        // Include the previous point if we didn't get an exact match
        if (fromIndex > 0)
          fromIndex--;
      }
    }

    if (blockDistanceTo < distances[distances.length - 1]) {
      toIndex = Arrays.binarySearch(distances, blockDistanceTo);
      if (toIndex < 0) {
        toIndex = -(toIndex + 1);
        // Include the previous point if we didn't get an exact match
        if (toIndex < distances.length)
          toIndex++;
      }
    }

    XYPoint xyPoint = new XYPoint(targetPoint.getX(), targetPoint.getY());

    List<PointAndIndex> assignments = _shapePointsLibrary.computePotentialAssignments(
        projectedShapePoints, distances, xyPoint, fromIndex, toIndex);

    Min<ScheduledBlockLocation> best = new Min<ScheduledBlockLocation>();

    for (PointAndIndex index : assignments) {

      double distanceAlongBlock = index.distanceAlongShape;

      if (distanceAlongBlock > block.getTotalBlockDistance())
        distanceAlongBlock = block.getTotalBlockDistance();

      ScheduledBlockLocation blockLocation = _scheduledBlockLocationService.getScheduledBlockLocationFromDistanceAlongBlock(
          block, distanceAlongBlock);

      if (blockLocation != null) {
View Full Code Here

    _service = new StopTimeServiceImpl();
    _service.setTransitGraphDao(graph);
    _service.setCalendarService(_calendarService);
    _service.setBlockIndexService(_blockIndexService);

    BlockConfigurationEntry bcA = blockConfiguration(block("bA"),
        serviceIds(lsids("sA"), lsids()));
    BlockConfigurationEntry bcB = blockConfiguration(block("bB"),
        serviceIds(lsids("sB"), lsids()));

    _transitGraphDao = Mockito.mock(TransitGraphDao.class);
    Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(
        Arrays.asList(bcA.getBlock(), bcB.getBlock()));
    _calendarService.setTransitGraphDao(_transitGraphDao);

    _calendarService.start();
  }
View Full Code Here

    StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(9, 50), 0);
    StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(10, 10), 0);
    StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sA"), time(10, 20), 0);
    StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sA"), time(10, 40), 0);

    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
    BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
    BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());

    addFirstStopToBlockIndex(bA, bB, bC, bD);

    List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(
        _stopId, from, to);
View Full Code Here

    // 01:00am, 01:30am (both on next day)
    StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 00),
        time(25, 30), 0);

    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());

    addFirstStopToBlockIndex(bA, bB);

    /****
     *
 
View Full Code Here

    StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sB"), time(10, 00),
        time(10, 30), 0);
    StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sB"), time(25, 0),
        time(25, 30), 0);

    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
    BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
    BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());

    addFirstStopToBlockIndex(bA, bB);
    addFirstStopToBlockIndex(bC, bD);

    /****
 
View Full Code Here

    stopTime(4, toStop, trip1A, time(10, 10), time(10, 15), 0.0);
    stopTime(5, toStop, trip1B, time(10, 20), time(10, 25), 0.0);
    stopTime(6, toStop, trip1C, time(10, 30), time(10, 35), 0.0);
    stopTime(7, toStop, trip1D, time(10, 40), time(10, 45), 0.0);

    BlockConfigurationEntry b1A = linkBlockTrips("b1A", trip1A);
    BlockConfigurationEntry b1B = linkBlockTrips("b1B", trip1B);
    BlockConfigurationEntry b1C = linkBlockTrips("b1C", trip1C);
    BlockConfigurationEntry b1D = linkBlockTrips("b1D", trip1D);

    BlockSequenceIndex index1 = createBlockSequenceIndex(b1A, b1B, b1C, b1D);
    BlockStopSequenceIndex fromIndex1 = new BlockStopSequenceIndex(index1, 0);
    BlockStopSequenceIndex toIndex1 = new BlockStopSequenceIndex(index1, 1);

    Pair<BlockStopSequenceIndex> indexPair1 = Tuples.pair(fromIndex1, toIndex1);

    TripEntryImpl trip2A = trip("2A", "sA");
    TripEntryImpl trip2B = trip("2B", "sA");
    TripEntryImpl trip2C = trip("2C", "sA");
    TripEntryImpl trip2D = trip("2D", "sA");

    stopTime(0, fromStop, trip2A, time(10, 07), time(10, 07), 0.0);
    stopTime(1, fromStop, trip2B, time(10, 17), time(10, 17), 0.0);
    stopTime(2, fromStop, trip2C, time(10, 27), time(10, 27), 0.0);
    stopTime(3, fromStop, trip2D, time(10, 37), time(10, 37), 0.0);

    stopTime(4, toStop, trip2A, time(10, 17), time(10, 17), 0.0);
    stopTime(5, toStop, trip2B, time(10, 27), time(10, 27), 0.0);
    stopTime(6, toStop, trip2C, time(10, 37), time(10, 37), 0.0);
    stopTime(7, toStop, trip2D, time(10, 47), time(10, 47), 0.0);

    BlockConfigurationEntry b2A = linkBlockTrips("bA", trip2A);
    BlockConfigurationEntry b2B = linkBlockTrips("bB", trip2B);
    BlockConfigurationEntry b2C = linkBlockTrips("bC", trip2C);
    BlockConfigurationEntry b2D = linkBlockTrips("bD", trip2D);

    BlockSequenceIndex index2 = createBlockSequenceIndex(b2A, b2B, b2C, b2D);
    BlockStopSequenceIndex fromIndex2 = new BlockStopSequenceIndex(index2, 0);
    BlockStopSequenceIndex toIndex2 = new BlockStopSequenceIndex(index2, 1);

    Pair<BlockStopSequenceIndex> indexPair2 = Tuples.pair(fromIndex2, toIndex2);

    List<Pair<BlockStopSequenceIndex>> indices = new ArrayList<Pair<BlockStopSequenceIndex>>();
    indices.add(indexPair1);
    indices.add(indexPair2);

    Mockito.when(
        _blockIndexService.getBlockSequenceIndicesBetweenStops(fromStop, toStop)).thenReturn(
        indices);

    TripEntryImpl tripF = trip("freq", "sA");

    stopTime(0, fromStop, tripF, time(10, 00), time(10, 00), 0.0);
    stopTime(4, toStop, tripF, time(10, 05), time(10, 05), 0.0);

    FrequencyEntry frequency = new FrequencyEntryImpl(time(10, 30),
        time(11, 30), 10 * 60);
    List<FrequencyEntry> frequencies = Arrays.asList(frequency);

    BlockConfigurationEntry bcFreq = linkBlockTrips(block("bFreq"),
        frequencies, tripF);

    FrequencyBlockTripIndex freqIndex = _factory.createFrequencyIndexForTrips(
        bcFreq.getTrips(), frequencies);
    FrequencyStopTripIndex freqFromIndex = new FrequencyStopTripIndex(
        freqIndex, 0);
    FrequencyStopTripIndex freqToIndex = new FrequencyStopTripIndex(freqIndex,
        1);
    Pair<FrequencyStopTripIndex> freqIndexPair = Tuples.pair(freqFromIndex,
        freqToIndex);

    List<Pair<FrequencyStopTripIndex>> frequencyIndices = new ArrayList<Pair<FrequencyStopTripIndex>>();
    frequencyIndices.add(freqIndexPair);

    Mockito.when(
        _blockIndexService.getFrequencyIndicesBetweenStops(fromStop, toStop)).thenReturn(
        frequencyIndices);

    /****
     *
     ****/

    Date time = date("2009-09-01 08:00");

    List<Pair<StopTimeInstance>> instances = _service.getNextDeparturesBetweenStopPair(
        fromStop, toStop, time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    Pair<StopTimeInstance> pair = instances.get(0);
    assertSame(fromStop, pair.getFirst().getStop());
    assertSame(toStop, pair.getSecond().getStop());
    assertEquals(dateAsLong("2009-09-01 00:00"),
        pair.getFirst().getServiceDate());
    assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-01 08:00");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 10 * 60, 0, 3, includePrivateService);

    assertEquals(5, instances.size());

    pair = instances.get(0);
    assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(3);
    assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(4);
    assertEquals(b1C.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1C.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-01 10:06");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-01 10:06");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 10 * 60, 5 * 60, 3, includePrivateService);

    assertEquals(8, instances.size());

    pair = instances.get(0);
    assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(3);
    assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(4);
    assertEquals(b1C.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1C.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(5);
    assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(6);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-01 10:30"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-01 10:35"),
        pair.getSecond().getDepartureTime());

    pair = instances.get(7);
    assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-02 10:06");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(dateAsLong("2009-09-02 00:00"),
        pair.getFirst().getServiceDate());

    assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-02 10:29");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-02 10:30"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-02 10:35"),
        pair.getSecond().getDepartureTime());

    pair = instances.get(1);
    assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b2D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2D.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-02 10:40");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(1, instances.size());

    pair = instances.get(0);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-02 10:40"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-02 10:45"),
        pair.getSecond().getDepartureTime());

    /****
     *
     ****/

    time = date("2009-09-02 11:40");

    instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(0, instances.size());

    /****
     *
     ****/

    time = date("2009-09-02 10:50");

    instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(b2D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2D.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-02 10:40"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-02 10:45"),
        pair.getSecond().getDepartureTime());

    pair = instances.get(2);
    assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-02 10:46");

    instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-02 10:40"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-02 10:45"),
        pair.getSecond().getDepartureTime());

    pair = instances.get(1);
    assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(2);
    assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());

    /****
     *
     ****/

    time = date("2009-09-02 10:40");

    instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
        time, 0, 0, 3, includePrivateService);

    assertEquals(3, instances.size());

    pair = instances.get(0);
    assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());

    pair = instances.get(1);
    assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
    assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
    assertEquals(dateAsLong("2009-09-02 10:30"),
        pair.getFirst().getDepartureTime());
    assertEquals(dateAsLong("2009-09-02 10:35"),
        pair.getSecond().getDepartureTime());

View Full Code Here

    long serviceDate = System.currentTimeMillis();

    BlockEntryImpl block = block("blockA");
    TripEntryImpl trip = trip("tripA", "serviceId");
    stopTime(0, null, trip, time(9, 00), 0);
    BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
    BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);

    VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(20);
View Full Code Here

    long serviceDate = System.currentTimeMillis();

    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "serviceId");
    stopTime(0, null, tripA, time(9, 00), 0);
    BlockConfigurationEntry blockConfigA = linkBlockTrips(blockA, tripA);
    BlockInstance instanceA = new BlockInstance(blockConfigA, serviceDate);

    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "serviceId");
    stopTime(0, null, tripB, time(9, 00), 0);
    BlockConfigurationEntry blockConfigB = linkBlockTrips(blockB, tripB);
    BlockInstance instanceB = new BlockInstance(blockConfigB, serviceDate);

    VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(20);
View Full Code Here

    for (int i = 0; i < 20; i++) {

      BlockEntryImpl block = block(Integer.toString(i));
      TripEntryImpl trip = trip(Integer.toString(i), "serviceId");
      stopTime(0, null, trip, time(9, 00), 0);
      BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
      BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);

      for (int j = 0; j < 5; j++) {

        AgencyAndId vehicleId = new AgencyAndId("1", Integer.toString(vid++));
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.