Search in sources :

Example 66 with BlockTripEntry

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

the class BlockIndexFactoryServiceImpl method ensureLayoverGroups.

private List<List<BlockTripEntry>> ensureLayoverGroups(List<BlockTripEntry> blockTrips) {
    Collections.sort(blockTrips, _blockLayoverComparator);
    List<List<BlockTripEntry>> lists = new ArrayList<List<BlockTripEntry>>();
    for (BlockTripEntry block : blockTrips) {
        List<BlockTripEntry> list = getBestLayoverList(lists, block);
        if (list == null) {
            list = new ArrayList<BlockTripEntry>();
            lists.add(list);
        }
        list.add(block);
    }
    return lists;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with BlockTripEntry

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

the class BlockIndexServiceImpl method loadStopTripIndices.

private void loadStopTripIndices() {
    // Clear any existing indices
    for (StopEntry stop : _graphDao.getAllStops()) {
        StopEntryImpl stopImpl = (StopEntryImpl) stop;
        stopImpl.getStopTripIndices().clear();
        stopImpl.getFrequencyStopTripIndices().clear();
    }
    for (BlockSequenceIndex index : _blockSequenceIndices) {
        BlockSequence sequence = index.getSequences().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            BlockStopSequenceIndex blockStopTripIndex = new BlockStopSequenceIndex(index, offset);
            stop.addBlockStopTripIndex(blockStopTripIndex);
            offset++;
        }
    }
    for (FrequencyBlockTripIndex index : _frequencyBlockTripIndices) {
        BlockTripEntry trip = index.getTrips().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : trip.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            FrequencyStopTripIndex stopTripIndex = new FrequencyStopTripIndex(index, offset);
            stop.addFrequencyStopTripIndex(stopTripIndex);
            offset++;
        }
    }
}
Also used : BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) FrequencyStopTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyStopTripIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 68 with BlockTripEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationBetweenStopTimes.

private ScheduledBlockLocation getScheduledBlockLocationBetweenStopTimes(List<BlockStopTimeEntry> stopTimes, int scheduleTime, int stopTimeIndex) {
    BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
    BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
    StopTimeEntry before = blockBefore.getStopTime();
    StopTimeEntry after = blockAfter.getStopTime();
    ScheduledBlockLocation result = new ScheduledBlockLocation();
    result.setScheduledTime(scheduleTime);
    result.setInService(true);
    result.setStopTimeIndex(stopTimeIndex);
    int fromTime = before.getDepartureTime();
    int toTime = after.getArrivalTime();
    int fromTimeOffset = fromTime - scheduleTime;
    int toTimeOffset = toTime - scheduleTime;
    if (Math.abs(fromTimeOffset) < Math.abs(toTimeOffset)) {
        result.setClosestStop(blockBefore);
        result.setClosestStopTimeOffset(fromTimeOffset);
    } else {
        result.setClosestStop(blockAfter);
        result.setClosestStopTimeOffset(toTimeOffset);
    }
    result.setPreviousStop(blockBefore);
    result.setNextStop(blockAfter);
    result.setNextStopTimeOffset(toTimeOffset);
    double ratio = (scheduleTime - fromTime) / ((double) (toTime - fromTime));
    double fromDistance = blockBefore.getDistanceAlongBlock();
    double toDistance = blockAfter.getDistanceAlongBlock();
    double distanceAlongBlock = ratio * (toDistance - fromDistance) + fromDistance;
    result.setDistanceAlongBlock(distanceAlongBlock);
    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;
    /**
     * Are we between trips? Where is the transition point?
     */
    if (!before.getTrip().equals(after.getTrip())) {
        if (distanceAlongBlock >= blockAfter.getTrip().getDistanceAlongBlock()) {
            result.setActiveTrip(blockAfter.getTrip());
            shapePointIndexFrom = 0;
            shapePointIndexTo = nextShapePointIndex(after);
        } else {
            result.setActiveTrip(blockBefore.getTrip());
            shapePointIndexFrom = before.getShapePointIndex();
            shapePointIndexTo = Integer.MAX_VALUE;
        }
    } else {
        result.setActiveTrip(blockBefore.getTrip());
        shapePointIndexFrom = before.getShapePointIndex();
        shapePointIndexTo = nextShapePointIndex(after);
    }
    BlockTripEntry activeTrip = result.getActiveTrip();
    PointAndOrientation po = getLocationAlongShape(activeTrip, distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);
    if (po != null) {
        result.setLocation(po.getPoint());
        result.setOrientation(po.getOrientation());
        return result;
    }
    StopEntry beforeStop = before.getStop();
    StopEntry afterStop = after.getStop();
    double latFrom = beforeStop.getStopLat();
    double lonFrom = beforeStop.getStopLon();
    double latTo = afterStop.getStopLat();
    double lonTo = afterStop.getStopLon();
    double lat = (latTo - latFrom) * ratio + latFrom;
    double lon = (lonTo - lonFrom) * ratio + lonFrom;
    CoordinatePoint location = new CoordinatePoint(lat, lon);
    result.setLocation(location);
    double orientation = SphericalGeometryLibrary.getOrientation(latFrom, lonFrom, latTo, lonTo);
    result.setOrientation(orientation);
    return result;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 69 with BlockTripEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromDistanceAlongBlock.

@Override
public ScheduledBlockLocation getScheduledBlockLocationFromDistanceAlongBlock(ScheduledBlockLocation previousLocation, double distanceAlongBlock) {
    if (previousLocation.getDistanceAlongBlock() > distanceAlongBlock)
        throw new IllegalStateException("previousLocation's distanceAlongBlock must be before the requested distanceAlongBlock");
    BlockTripEntry trip = previousLocation.getActiveTrip();
    BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
    List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
    int indexFrom = previousLocation.getStopTimeIndex();
    int indexTo = indexFrom + 1;
    while (indexTo < stopTimes.size()) {
        double d = blockConfig.getDistanceAlongBlockForIndex(indexTo);
        if (distanceAlongBlock <= d)
            break;
        indexTo++;
    }
    int stopTimeIndex = GenericBinarySearch.searchRange(blockConfig, indexFrom, indexTo, distanceAlongBlock, IndexAdapters.BLOCK_CONFIG_DISTANCE_INSTANCE);
    return getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex(stopTimes, distanceAlongBlock, stopTimeIndex);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 70 with BlockTripEntry

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

the class ScheduledBlockLocationServiceImpl method interpolateLocation.

private ScheduledBlockLocation interpolateLocation(BlockStopTimeEntry blockPrevious, BlockStopTimeEntry blockFrom, BlockStopTimeEntry blockTo, double distanceAlongBlock, int stopTimeIndex) {
    if (distanceAlongBlock < 0.0)
        return null;
    StopTimeEntry from = blockFrom.getStopTime();
    StopTimeEntry to = blockTo.getStopTime();
    double r = (distanceAlongBlock - blockFrom.getDistanceAlongBlock()) / (blockTo.getDistanceAlongBlock() - blockFrom.getDistanceAlongBlock());
    int scheduledTime = (int) (r * (to.getArrivalTime() - from.getDepartureTime()) + from.getDepartureTime());
    if (r > 1)
        scheduledTime += to.getSlackTime();
    BlockTripEntry activeTrip = distanceAlongBlock < blockTo.getDistanceAlongBlock() ? blockFrom.getTrip() : blockTo.getTrip();
    BlockStopTimeEntry closestStop = r < 0.5 ? blockFrom : blockTo;
    BlockStopTimeEntry previousStop = null;
    BlockStopTimeEntry nextStop = null;
    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;
    if (r <= 0) {
        /**
         * Location along the block is before the two stop times
         */
        previousStop = blockPrevious;
        nextStop = blockFrom;
        shapePointIndexFrom = 0;
        shapePointIndexTo = nextShapePointIndex(from);
    } else if (r <= 1.0) {
        /**
         * Location along the block is between the two stop times
         */
        previousStop = blockFrom;
        nextStop = blockTo;
        shapePointIndexFrom = from.getShapePointIndex();
        shapePointIndexTo = nextShapePointIndex(to);
    } else {
        /**
         * Location along the block is after the two stop times
         */
        shapePointIndexFrom = to.getShapePointIndex();
        shapePointIndexTo = Integer.MAX_VALUE;
    }
    ScheduledBlockLocation location = new ScheduledBlockLocation();
    location.setActiveTrip(activeTrip);
    location.setClosestStop(closestStop);
    location.setClosestStopTimeOffset(closestStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setPreviousStop(previousStop);
    location.setNextStop(nextStop);
    if (nextStop != null)
        location.setNextStopTimeOffset(nextStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setInService(nextStop != null);
    location.setStopTimeIndex(stopTimeIndex);
    location.setDistanceAlongBlock(distanceAlongBlock);
    location.setScheduledTime(scheduledTime);
    /**
     * In this case, distance along block and distance along trip are the same
     * because we are still in the first trip of the block
     */
    PointAndOrientation po = getLocationAlongShape(activeTrip, distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);
    if (po != null) {
        location.setLocation(po.getPoint());
        location.setOrientation(po.getOrientation());
    }
    return location;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5