From e5ae1c5beefe67ff2ccf7c281f1245bf646b0bfc Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Thu, 11 Jan 2024 20:40:44 +0800 Subject: [PATCH] tolerate and count patterns with no gtfs these should be the ones created by other modification in the scenario. also factor out long reference chain as final List variable. --- .../r5/analyst/scenario/SelectLink.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java b/src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java index c03ca1af3..42d31262a 100644 --- a/src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java +++ b/src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java @@ -50,6 +50,8 @@ 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. @@ -57,7 +59,8 @@ public boolean resolve(TransportNetwork network) { // 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)) { @@ -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 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; } @@ -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