Skip to content

Commit

Permalink
tolerate and count patterns with no gtfs
Browse files Browse the repository at this point in the history
these should be the ones created by other modification in the scenario.
also factor out long reference chain as final List variable.
  • Loading branch information
abyrd committed Jan 11, 2024
1 parent e294e80 commit e5ae1c5
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ public class SelectLink extends Modification {

private int nPatternsWithoutShapes = 0;

private int nPatternsWithoutGtfs = 0;

@Override
public boolean resolve(TransportNetwork network) {
// Convert the incoming description of the selected link area to a Geometry for computing intersections.
boxPolygon = polygonForEnvelope(envelopeForCircle(lon, lat, radiusMeters));
// Iterate over all TripPatterns in the TransitLayer and ensure that we can associate a feed with each one.
// These feeds must have been previously supplied with the injectGtfs() method. The feed IDs recorded in the
// TripPatterns are not bundle-scoped. Check that a feed with a correctly de-scoped ID was supplied for every
// TripPattern in this TransitLayer.
// TripPattern in this TransitLayer. Note that this only applies to patterns in the base network - other
// modifications in the scenario such as add-trips can create new patterns that don't reference any GTFS.
for (TripPattern tripPattern : network.transitLayer.tripPatterns) {
String feedId = feedIdForTripPattern(tripPattern);
if (isNullOrEmpty(feedId)) {
Expand All @@ -80,15 +83,23 @@ public boolean apply(TransportNetwork network) {

// During raptor search, paths are recorded in terms of pattern and stop index numbers rather than
// TripPattern and Stop instance references, so iterate over the numbers.
for (int patternIndex = 0; patternIndex < network.transitLayer.tripPatterns.size(); patternIndex++) {
TripPattern tripPattern = network.transitLayer.tripPatterns.get(patternIndex);
final List<TripPattern> patterns = network.transitLayer.tripPatterns;
for (int patternIndex = 0; patternIndex < patterns.size(); patternIndex++) {
TripPattern tripPattern = patterns.get(patternIndex);
// Make a sacrificial protective copy to avoid interfering with other requests using this network.
// We're going to add shape data to this TripPattern then throw it away immediately afterward.
// Be careful not to use a reference to this clone as a key in any Maps, it will not match TransitLayer.
tripPattern = tripPattern.clone();
String feedId = feedIdForTripPattern(tripPattern);
GTFSFeed feed = feedForUnscopedId.get(feedId);
TransitLayer.addShapeToTripPattern(feed, tripPattern);
if (feed == null) {
// We could not find any feed ID on this pattern, or the apparent feed ID does not match any known feed.
// Since feeds for all patterns were all verified in apply(), this means the pattern must have been
// added by another modification in the scenario.
nPatternsWithoutGtfs += 1;
} else {
TransitLayer.addShapeToTripPattern(feed, tripPattern);
}
if (tripPattern.shape == null) {
nPatternsWithoutShapes += 1;
}
Expand All @@ -105,9 +116,14 @@ public boolean apply(TransportNetwork network) {
hopsInTripPattern.put(patternIndex, intersectedHops.toArray());
}
}
if (nPatternsWithoutGtfs > 0) {
addInfo("Of %d patterns, %d did not reference any GTFS (apparently generated by scenario).".formatted(
patterns.size(), nPatternsWithoutGtfs
));
}
if (nPatternsWithoutShapes > 0) {
addInfo( "Out of %d patterns, %d had no shapes and used straight lines.".formatted(
network.transitLayer.tripPatterns.size(), nPatternsWithoutShapes
addInfo("Of %d patterns, %d had no shapes and used straight lines.".formatted(
patterns.size(), nPatternsWithoutShapes
));
}
// After finding all links (TripPattern hops) in the SelectedLink area, release the GTFSFeeds which don't really
Expand Down

0 comments on commit e5ae1c5

Please sign in to comment.