use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImplTest method testGetActiveBlocksInTimeRange.
@Test
public void testGetActiveBlocksInTimeRange() {
Date serviceDateA = UnitTestingSupport.date("2010-09-07 00:00");
Date serviceDateB = UnitTestingSupport.date("2010-09-08 00:00");
Date serviceDateC = UnitTestingSupport.date("2010-09-09 00:00");
UnitTestingSupport.addDates(_calendarData, "sidA", serviceDateA, serviceDateB);
UnitTestingSupport.addDates(_calendarData, "sidB", serviceDateB, serviceDateC);
ServiceIdActivation ids_A_not_B = serviceIds(lsids("sidA"), lsids("sidB"));
ServiceIdActivation ids_B_not_A = serviceIds(lsids("sidB"), lsids("sidA"));
ServiceIdActivation ids_A_and_B = serviceIds(lsids("sidA", "sidB"), lsids());
StopEntryImpl stopA = stop("stopA", 0.0, 0.0);
StopEntryImpl stopB = stop("stopB", 0.0, 0.0);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidB");
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopB, tripB, time(10, 00), time(10, 00), 200);
stopTime(3, stopA, tripB, time(10, 30), time(10, 30), 300);
linkBlockTrips(ids_A_not_B, blockA, tripA);
linkBlockTrips(ids_A_and_B, blockA, tripA, tripB);
linkBlockTrips(ids_B_not_A, blockA, tripB);
BlockConfigurationEntry bcA_A_B = findBlockConfig(blockA, ids_A_not_B);
BlockConfigurationEntry bcA_B_A = findBlockConfig(blockA, ids_B_not_A);
BlockConfigurationEntry bcA_AB = findBlockConfig(blockA, ids_A_and_B);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripC = trip("tripC", "sidA");
TripEntryImpl tripD = trip("tripD", "sidB");
TripEntryImpl tripE = trip("tripE", "sidA");
stopTime(4, stopA, tripC, time(10, 00), time(10, 00), 0);
stopTime(5, stopB, tripC, time(10, 30), time(10, 30), 0);
stopTime(6, stopB, tripD, time(11, 00), time(11, 00), 0);
stopTime(7, stopA, tripD, time(11, 30), time(11, 30), 0);
stopTime(8, stopA, tripE, time(12, 00), time(12, 00), 0);
stopTime(9, stopB, tripE, time(12, 30), time(12, 30), 0);
linkBlockTrips(ids_A_not_B, blockB, tripC, tripE);
linkBlockTrips(ids_A_and_B, blockB, tripC, tripD, tripE);
linkBlockTrips(ids_B_not_A, blockB, tripD);
BlockConfigurationEntry bcB_A_B = findBlockConfig(blockB, ids_A_not_B);
BlockConfigurationEntry bcB_B_A = findBlockConfig(blockB, ids_B_not_A);
BlockConfigurationEntry bcB_AB = findBlockConfig(blockB, ids_A_and_B);
List<BlockTripIndex> blocks = blockTripIndices(blockA, blockB);
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
/**
**
*
***
*/
long time = timeFromString("2010-09-07 09:15");
List<BlockInstance> instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
BlockInstance instance = instances.get(0);
assertEquals(bcA_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-07 010:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
/*
* time = timeFromString("2010-09-07 011:15");
*
* instances = _service.getActiveBlocksInTimeRange(blocks, frequencyIndices,
* time, time);
*
* assertEquals(1, instances.size());
*
* instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock());
* assertEquals(serviceDateA.getTime(), instance.getServiceDate());
*/
/**
**
*
***
*/
time = timeFromString("2010-09-07 012:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
Collections.sort(instances, new BlockInstanceComparator());
assertEquals(2, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
instance = instances.get(1);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 12:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(0, instances.size());
/**
**
*
***
*/
time = timeFromString("2010-09-09 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactoryTest method test.
@Test
public void test() {
StopEntryImpl stopA = stop("a", 47.0, -122.0);
StopEntryImpl stopB = stop("b", 47.1, -122.1);
StopEntryImpl stopC = stop("c", 47.2, -122.2);
/**
**
* Block A
***
*/
BlockEntryImpl blockA = block("a");
// 1
TripEntryImpl tripA1 = trip("a1", "s1");
TripEntryImpl tripA2 = trip("a2", "s1");
TripEntryImpl tripA3 = trip("a3", "s1");
stopTime(0, stopA, tripA1, 0, 10, 0);
stopTime(0, stopB, tripA1, 20, 20, 0);
stopTime(0, stopC, tripA2, 30, 30, 0);
stopTime(0, stopA, tripA2, 40, 40, 0);
stopTime(0, stopA, tripA3, 50, 50, 0);
stopTime(0, stopB, tripA3, 60, 70, 0);
BlockConfigurationEntry bcA = linkBlockTrips(blockA, tripA1, tripA2, tripA3);
/**
**
* Block B - Same trip/stop sequence as A
***
*/
BlockEntryImpl blockB = block("b");
TripEntryImpl tripB1 = trip("b1", "s1");
TripEntryImpl tripB2 = trip("b2", "s1");
TripEntryImpl tripB3 = trip("b3", "s1");
stopTime(0, stopA, tripB1, 20, 30, 0);
stopTime(0, stopB, tripB1, 50, 50, 0);
stopTime(0, stopC, tripB2, 60, 60, 0);
stopTime(0, stopA, tripB2, 70, 70, 0);
stopTime(0, stopA, tripB3, 80, 80, 0);
stopTime(0, stopB, tripB3, 90, 100, 0);
BlockConfigurationEntry bcB = linkBlockTrips(blockB, tripB1, tripB2, tripB3);
/**
**
* Block C - Same stop sequence, but runs a little bit faster
***
*/
BlockEntryImpl blockC = block("c");
TripEntryImpl tripC1 = trip("c1", "s1");
TripEntryImpl tripC2 = trip("c2", "s1");
TripEntryImpl tripC3 = trip("c3", "s1");
stopTime(0, stopA, tripC1, 40, 50, 0);
stopTime(0, stopB, tripC1, 60, 60, 0);
stopTime(0, stopC, tripC2, 70, 70, 0);
stopTime(0, stopA, tripC2, 80, 80, 0);
stopTime(0, stopA, tripC3, 85, 85, 0);
stopTime(0, stopB, tripC3, 90, 95, 0);
BlockConfigurationEntry bcC = linkBlockTrips(blockC, tripC1, tripC2, tripC3);
/**
**
* Block D - Same stop sequence, but with different service id
***
*/
BlockEntryImpl blockD = block("d");
TripEntryImpl tripD1 = trip("d1", "s1");
TripEntryImpl tripD2 = trip("d2", "s1");
TripEntryImpl tripD3 = trip("d3", "s2");
stopTime(0, stopA, tripD1, 40, 50, 0);
stopTime(0, stopB, tripD1, 70, 70, 0);
stopTime(0, stopC, tripD2, 80, 80, 0);
stopTime(0, stopA, tripD2, 90, 90, 0);
stopTime(0, stopA, tripD3, 100, 100, 0);
stopTime(0, stopB, tripD3, 110, 120, 0);
BlockConfigurationEntry bcD = linkBlockTrips(blockD, tripD1, tripD2, tripD3);
/**
**
* Block E - One less stop
***
*/
BlockEntryImpl blockE = block("e");
TripEntryImpl tripE1 = trip("e1", "s1");
TripEntryImpl tripE2 = trip("e2", "s1");
TripEntryImpl tripE3 = trip("e3", "s1");
stopTime(0, stopA, tripE1, 50, 60, 0);
stopTime(0, stopB, tripE1, 80, 80, 0);
stopTime(0, stopC, tripE2, 90, 90, 0);
stopTime(0, stopA, tripE2, 100, 100, 0);
stopTime(0, stopA, tripE3, 110, 110, 0);
BlockConfigurationEntry bcE = linkBlockTrips(blockE, tripE1, tripE2, tripE3);
/**
**
* Block F - Another to group with E, but earlier
***
*/
BlockEntryImpl blockF = block("f");
TripEntryImpl tripF1 = trip("f1", "s1");
TripEntryImpl tripF2 = trip("f2", "s1");
TripEntryImpl tripF3 = trip("f3", "s1");
stopTime(0, stopA, tripF1, 40, 50, 0);
stopTime(0, stopB, tripF1, 70, 70, 0);
stopTime(0, stopC, tripF2, 80, 80, 0);
stopTime(0, stopA, tripF2, 90, 90, 0);
stopTime(0, stopA, tripF3, 100, 100, 0);
BlockConfigurationEntry bcF = linkBlockTrips(blockF, tripF1, tripF2, tripF3);
BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
List<BlockStopTimeIndex> allIndices = factory.createIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
assertEquals(6, allIndices.size());
List<BlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
assertEquals(1, indices.size());
BlockStopTimeIndex index = indices.get(0);
assertEquals(15, index.getStopTimes().size());
assertEquals(bcA.getStopTimes().get(0), index.getStopTimes().get(0));
assertEquals(bcB.getStopTimes().get(0), index.getStopTimes().get(1));
assertEquals(bcA.getStopTimes().get(3), index.getStopTimes().get(2));
assertEquals(bcF.getStopTimes().get(0), index.getStopTimes().get(3));
assertEquals(bcC.getStopTimes().get(0), index.getStopTimes().get(4));
assertEquals(bcA.getStopTimes().get(4), index.getStopTimes().get(5));
assertEquals(bcE.getStopTimes().get(0), index.getStopTimes().get(6));
assertEquals(bcB.getStopTimes().get(3), index.getStopTimes().get(7));
assertEquals(bcC.getStopTimes().get(3), index.getStopTimes().get(8));
assertEquals(bcB.getStopTimes().get(4), index.getStopTimes().get(9));
assertEquals(bcC.getStopTimes().get(4), index.getStopTimes().get(10));
assertEquals(bcF.getStopTimes().get(3), index.getStopTimes().get(11));
assertEquals(bcF.getStopTimes().get(4), index.getStopTimes().get(12));
assertEquals(bcE.getStopTimes().get(3), index.getStopTimes().get(13));
assertEquals(bcE.getStopTimes().get(4), index.getStopTimes().get(14));
indices = grep(allIndices, aid("a"), serviceIds(lsids("s1", "s2"), lsids()));
assertEquals(1, indices.size());
index = indices.get(0);
assertEquals(3, index.getStopTimes().size());
assertEquals(bcD.getStopTimes().get(0), index.getStopTimes().get(0));
assertEquals(bcD.getStopTimes().get(3), index.getStopTimes().get(1));
assertEquals(bcD.getStopTimes().get(4), index.getStopTimes().get(2));
indices = grep(allIndices, aid("b"), serviceIds(lsids("s1"), lsids()));
assertEquals(1, indices.size());
index = indices.get(0);
assertEquals(8, index.getStopTimes().size());
assertEquals(bcA.getStopTimes().get(1), index.getStopTimes().get(0));
assertEquals(bcB.getStopTimes().get(1), index.getStopTimes().get(1));
assertEquals(bcC.getStopTimes().get(1), index.getStopTimes().get(2));
assertEquals(bcA.getStopTimes().get(5), index.getStopTimes().get(3));
assertEquals(bcF.getStopTimes().get(1), index.getStopTimes().get(4));
assertEquals(bcE.getStopTimes().get(1), index.getStopTimes().get(5));
assertEquals(bcC.getStopTimes().get(5), index.getStopTimes().get(6));
assertEquals(bcB.getStopTimes().get(5), index.getStopTimes().get(7));
indices = grep(allIndices, aid("b"), serviceIds(lsids("s1", "s2"), lsids()));
assertEquals(1, indices.size());
index = indices.get(0);
assertEquals(2, index.getStopTimes().size());
assertEquals(bcD.getStopTimes().get(1), index.getStopTimes().get(0));
assertEquals(bcD.getStopTimes().get(5), index.getStopTimes().get(1));
indices = grep(allIndices, aid("c"), serviceIds(lsids("s1"), lsids()));
assertEquals(1, indices.size());
index = indices.get(0);
assertEquals(5, index.getStopTimes().size());
assertEquals(bcA.getStopTimes().get(2), index.getStopTimes().get(0));
assertEquals(bcB.getStopTimes().get(2), index.getStopTimes().get(1));
assertEquals(bcC.getStopTimes().get(2), index.getStopTimes().get(2));
assertEquals(bcF.getStopTimes().get(2), index.getStopTimes().get(3));
assertEquals(bcE.getStopTimes().get(2), index.getStopTimes().get(4));
indices = grep(allIndices, aid("c"), serviceIds(lsids("s1", "s2"), lsids()));
assertEquals(1, indices.size());
index = indices.get(0);
assertEquals(1, index.getStopTimes().size());
assertEquals(bcD.getStopTimes().get(2), index.getStopTimes().get(0));
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImplTest method testWithShapeInfo.
@Test
public void testWithShapeInfo() {
StopEntryImpl stopA = stop("a", 47.5, -122.5);
StopEntryImpl stopB = stop("b", 47.6, -122.4);
StopEntryImpl stopC = stop("c", 47.5, -122.3);
BlockEntryImpl block = block("block");
TripEntryImpl tripA = trip("tripA", "serviceId");
TripEntryImpl tripB = trip("tripB", "serviceId");
stopTime(0, stopA, tripA, 30, 90, 0);
stopTime(1, stopB, tripA, 120, 120, 100);
stopTime(2, stopC, tripA, 180, 210, 200);
stopTime(3, stopC, tripB, 240, 240, 300);
stopTime(4, stopB, tripB, 270, 270, 400);
stopTime(5, stopA, tripB, 300, 300, 500);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, tripA, tripB);
long serviceDate = 1000 * 1000;
double epsilon = 0.001;
TargetTime target = new TargetTime(t(serviceDate, 0, 0), System.currentTimeMillis());
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
BlockLocation location = _service.getLocationForBlockInstance(blockInstance, target);
assertNull(location);
ScheduledBlockLocation p = new ScheduledBlockLocation();
p.setActiveTrip(blockConfig.getTrips().get(0));
p.setClosestStop(blockConfig.getStopTimes().get(0));
p.setClosestStopTimeOffset(0);
p.setDistanceAlongBlock(0);
p.setLocation(new CoordinatePoint(stopA.getStopLat(), stopA.getStopLon()));
p.setInService(true);
Mockito.when(_blockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, 1800)).thenReturn(p);
target = new TargetTime(t(serviceDate, 0, 30), System.currentTimeMillis());
location = _service.getLocationForBlockInstance(blockInstance, target);
assertTrue(location.isInService());
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
assertEquals(stopA.getStopLocation(), location.getLocation());
assertFalse(location.isScheduleDeviationSet());
assertTrue(Double.isNaN(location.getScheduleDeviation()));
assertFalse(location.isDistanceAlongBlockSet());
assertTrue(Double.isNaN(location.getDistanceAlongBlock()));
assertEquals(blockInstance, location.getBlockInstance());
assertEquals(0, location.getLastUpdateTime());
assertEquals(blockConfig.getTrips().get(0), location.getActiveTrip());
assertNull(location.getVehicleId());
assertEquals(47.5, location.getLocation().getLat(), epsilon);
assertEquals(-122.5, location.getLocation().getLon(), epsilon);
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method constructError.
private void constructError(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, UTMProjection projection) throws InvalidStopToShapeMappingException {
StopTimeEntryImpl first = stopTimes.get(0);
StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
_log.error("We were attempting to compute the distance along a particular trip for each stop time of that trip by " + "snapping them to the shape for that trip. However, we could not find an assignment for each stop time " + "where the distance traveled along the shape for each stop time was strictly increasing (aka a stop time " + "seemed to travel backwards). For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
TripEntryImpl trip = first.getTrip();
_log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
StringBuilder b = new StringBuilder();
int index = 0;
b.append("# potential assignments:\n");
b.append("# stopLat stopLon stopId\n");
b.append("# locationOnShapeLat locationOnShapeLon distanceAlongShape distanceFromShape shapePointIndex\n");
b.append("# ...\n");
double prevMaxDistanceAlongShape = Double.NEGATIVE_INFINITY;
for (List<PointAndIndex> possible : possibleAssignments) {
StopTimeEntryImpl stopTime = stopTimes.get(index);
StopEntryImpl stop = stopTime.getStop();
b.append(stop.getStopLat());
b.append(' ');
b.append(stop.getStopLon());
b.append(' ');
b.append(index);
b.append(' ');
b.append(stop.getId());
b.append('\n');
double maxDistanceAlongShape = Double.NEGATIVE_INFINITY;
double minDistanceAlongShape = Double.POSITIVE_INFINITY;
for (PointAndIndex pindex : possible) {
b.append(" ");
b.append(projection.reverse(pindex.point));
b.append(' ');
b.append(_errorFormatter.format(pindex.distanceAlongShape));
b.append(' ');
b.append(_errorFormatter.format(pindex.distanceFromTarget));
b.append(' ');
b.append(pindex.index);
b.append("\n");
maxDistanceAlongShape = Math.max(maxDistanceAlongShape, pindex.distanceAlongShape);
minDistanceAlongShape = Math.min(minDistanceAlongShape, pindex.distanceAlongShape);
}
if (minDistanceAlongShape < prevMaxDistanceAlongShape) {
b.append(" ^ potential problem here ^\n");
}
prevMaxDistanceAlongShape = maxDistanceAlongShape;
index++;
}
_log.error(b.toString());
if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
b = new StringBuilder();
index = 0;
for (int i = 0; i < shapePoints.getSize(); i++) {
b.append(shapePoints.getLatForIndex(i));
b.append(' ');
b.append(shapePoints.getLonForIndex(i));
b.append(' ');
b.append(shapePoints.getDistTraveledForIndex(i));
b.append('\n');
}
_log.error("shape points:\n" + b.toString());
}
throw new InvalidStopToShapeMappingException(first.getTrip());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method getDistancesAlongShape.
public PointAndIndex[] getDistancesAlongShape(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes) throws DistanceAlongShapeException {
PointAndIndex[] stopTimePoints = new PointAndIndex[stopTimes.size()];
UTMProjection projection = UTMLibrary.getProjectionForPoint(shapePoints.getLats()[0], shapePoints.getLons()[0]);
List<XYPoint> projectedShapePoints = _shapePointsLibrary.getProjectedShapePoints(shapePoints, projection);
double[] shapePointsDistTraveled = shapePoints.getDistTraveled();
List<List<PointAndIndex>> possibleAssignments = computePotentialAssignments(projection, projectedShapePoints, shapePointsDistTraveled, stopTimes);
pruneUnnecessaryAssignments(possibleAssignments);
assignmentSanityCheck(shapePoints, stopTimes, possibleAssignments);
double maxDistanceTraveled = shapePointsDistTraveled[shapePointsDistTraveled.length - 1];
List<PointAndIndex> bestAssignment = computeBestAssignment(shapePoints, stopTimes, possibleAssignments, projection, projectedShapePoints);
double last = Double.NEGATIVE_INFINITY;
for (int i = 0; i < stopTimePoints.length; i++) {
PointAndIndex pindex = bestAssignment.get(i);
if (pindex.distanceAlongShape > maxDistanceTraveled) {
int index = projectedShapePoints.size() - 1;
XYPoint point = projectedShapePoints.get(index);
StopEntryImpl stop = stopTimes.get(i).getStop();
XYPoint stopPoint = projection.forward(stop.getStopLocation());
double d = stopPoint.getDistance(point);
pindex = new PointAndIndex(point, index, d, maxDistanceTraveled);
}
if (last > pindex.distanceAlongShape) {
constructError(shapePoints, stopTimes, possibleAssignments, projection);
}
last = pindex.distanceAlongShape;
stopTimePoints[i] = pindex;
}
return stopTimePoints;
}
Aggregations