Skip to content

Commit f4c2a67

Browse files
committed
default to OSM_ONLY, fix GTFS_ONLY implementation
clarified some docs, set network version to nv4 as a precaution, restore original StreetLayer field initialization order
1 parent 658f628 commit f4c2a67

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

src/main/java/com/conveyal/r5/analyst/scenario/Scenario.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public TransportNetwork applyToTransportNetwork (TransportNetwork originalNetwor
159159

160160
// Find the transfers originating at or terminating at new stops.
161161
// TODO also rebuild transfers which are near street network changes but which do not connect to new stops.
162-
// The original GtfsTransferLoader is not retained after network build time. Here, for making transfers
162+
// The GtfsTransferLoader instance is not retained after network build time. Here, for making transfers
163163
// necessitated by scenario changes, we use a no-op instance that completely ignores anything from GTFS.
164164
var osmOnlyLoader = new GtfsTransferLoader(copiedNetwork.transitLayer, OSM_ONLY);
165165
var transferFinder = new TransferFinder(copiedNetwork, osmOnlyLoader);

src/main/java/com/conveyal/r5/kryo/KryoNetworkSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public abstract class KryoNetworkSerializer {
5454
* When prototyping new features, use a unique identifier such as the branch or a commit ID, not sequential nvX ones.
5555
* This avoids conflicts when multiple changes are combined in a single production release, or some are abandoned.
5656
*/
57-
public static final String NETWORK_FORMAT_VERSION = "nv4-testing"; // TODO change to nv4 for release
57+
public static final String NETWORK_FORMAT_VERSION = "nv4"; // TODO change to nv4 for release
5858

5959
public static final byte[] HEADER = "R5NETWORK".getBytes();
6060

src/main/java/com/conveyal/r5/transit/GtfsTransferLoader.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,28 @@
2121
import static com.conveyal.r5.analyst.cluster.TransportNetworkConfig.TransferConfig.STOP_TO_PATTERN;
2222
import static com.google.common.base.Strings.isNullOrEmpty;
2323

24-
/**
25-
* Transfers between transit stops can come from two sources: transfers.txt in GTFS inputs and
26-
* routing through the OSM-derived street network. This class handles loading from transfers.txt and
27-
* retains enough information so the subsequent street routing approach can adopt the behavior
28-
* specified with TransportNetworkConfig.TransferConfig. The way in which GTFS transfers take
29-
* priority over transfers found through the street network can be configured.
30-
* <p>
31-
* There can be multiple GTFS feeds and they are loaded in a streaming fashion, with only one open
32-
* and consuming memory at a time. Therefore we lose a lot of context by the time the street routing
33-
* happens.
34-
* <p>
35-
* Use a single instance across all GTFS feeds. Call the load method once on each feed in turn. This
36-
* accumulates information from all feeds that will later be important for finding transfers through
37-
* the OSM street network.
38-
* <p>
39-
* The GTFS transfers we load are specified in terms of minimum time, while the street transfers are
40-
* stored as distances and resolved to time during searches based on the specified walk speed. On
41-
* the downside this requires two separate data structures, but on the upside it simplifies loading
42-
* because GTFS must be loaded one feed at a time, while on-street transfers must be found later
43-
* after all GTFS feeds are loaded and all stops linked (because street transfers are expected to
44-
* connect stops from different feeds).
45-
* <p>
46-
* TODO Further increase transfer time accuracy using GTFS pathways.txt
47-
*/
24+
/// Transfers between transit stops can come from two sources: transfers.txt in GTFS inputs and
25+
/// routing through the OSM-derived street network. This class handles loading from transfers.txt
26+
/// and retains enough information so the subsequent street routing approach can adopt the behavior
27+
/// specified with TransportNetworkConfig.TransferConfig. The way in which GTFS transfers take
28+
/// priority over transfers found through the street network can be configured.
29+
///
30+
/// There can be multiple GTFS feeds and they are loaded in a streaming fashion, with only one open
31+
/// and consuming memory at a time. Therefore we lose a lot of context by the time the street routing
32+
/// happens.
33+
///
34+
/// Use a single instance across all GTFS feeds. Call the load method once on each feed in turn. This
35+
/// accumulates information from all feeds that will later be important for finding transfers through
36+
/// the OSM street network.
37+
///
38+
/// The GTFS transfers we load are specified in terms of minimum time, while the street transfers are
39+
/// stored as distances and resolved to time during searches based on the specified walk speed. On
40+
/// the downside this requires two separate data structures, but on the upside it simplifies loading
41+
/// because GTFS must be loaded one feed at a time, while on-street transfers must be found later
42+
/// after all GTFS feeds are loaded and all stops linked (because street transfers are expected to
43+
/// connect stops from different feeds).
44+
///
45+
/// TODO Further increase transfer time accuracy using GTFS pathways.txt
4846
public class GtfsTransferLoader {
4947

5048
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -78,7 +76,7 @@ public record StopPair(int fromStop, int toStop) { }
7876

7977
public GtfsTransferLoader (TransitLayer transit, TransferConfig transferConfig) {
8078
this.transit = transit;
81-
this.transferConfig = transferConfig != null ? transferConfig : STOP_TO_PATTERN;
79+
this.transferConfig = transferConfig != null ? transferConfig : OSM_ONLY;
8280
}
8381

8482
/// @param indexForUnscopedStopId Map of stop IDs not yet scoped by feed ID, which exists only during GTFS loading

src/main/java/com/conveyal/r5/transit/TransferFinder.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
import gnu.trove.map.TIntObjectMap;
1212
import gnu.trove.map.hash.TIntIntHashMap;
1313
import gnu.trove.map.hash.TIntObjectHashMap;
14-
import gnu.trove.set.TIntSet;
1514
import org.slf4j.Logger;
1615
import org.slf4j.LoggerFactory;
1716

18-
import java.util.stream.Collectors;
1917
import java.util.stream.IntStream;
2018

21-
import static com.conveyal.r5.analyst.cluster.TransportNetworkConfig.*;
19+
import static com.conveyal.r5.analyst.cluster.TransportNetworkConfig.TransferConfig.GTFS_ONLY;
2220
import static com.conveyal.r5.streets.StreetRouter.State.RoutingVariable;
2321
import static com.conveyal.r5.transit.TransitLayer.PARKRIDE_DISTANCE_LIMIT_METERS;
2422
import static com.conveyal.r5.transit.TransitLayer.TRANSFER_DISTANCE_LIMIT_METERS;
@@ -106,15 +104,19 @@ public void findParkRideTransfer() {
106104
* However, existing transfer lists will be extended if new stops are reachable from existing stops.
107105
*/
108106
public void findTransfers () {
109-
if (gtfsTransferLoader.transferConfig == TransferConfig.GTFS_ONLY) {
110-
LOG.info("Not finding transfers through street network due to GTFS_ONLY in TransportNetworkConfig.");
111-
return;
112-
}
113107
// Look at the existing list of transfers (if any) and do enough iterations to make that transfer list as long
114108
// as the list of stops.
115109
int firstStopToProcess = transitLayer.streetTransfers.size();
116110
int nStopsTotal = transitLayer.getStopCount();
117111
int nStopsToProcess = nStopsTotal - firstStopToProcess;
112+
if (gtfsTransferLoader.transferConfig == GTFS_ONLY) {
113+
LOG.info("Not finding transfers through street network due to GTFS_ONLY in TransportNetworkConfig.");
114+
// Unlike the GTFS transfers which are in a map (because they may be very sparse),
115+
// street transfers are in a list because they are expected to exist at most stops.
116+
// We must extend that list to avoid out of bounds index exceptions.
117+
for (int i = 0; i < nStopsToProcess; i++) transitLayer.streetTransfers.add(null);
118+
return; // Do not add any street transfers, leave them null for all new stops.
119+
}
118120
LOG.info("Finding transfers through the street network from {} new transit stops...", nStopsToProcess);
119121
LambdaCounter stopCounter = new LambdaCounter(LOG, nStopsToProcess, 10_000,
120122
"Processed OSM street transfers from {} of {} new transit stops.");
@@ -229,10 +231,10 @@ public void findTransfers () {
229231
* street network. TODO we could check stop positions in the target pattern to help handle a case like this -- for
230232
* any continuous sequence of stops, retain only the closest.
231233
*
232-
* @param timesToReachedStops map from target stop index to distance (along the street network) to it. The method
233-
* mutates this parameter.
234-
* @param ignorePatterns used to filter out stop-pattern pairs that already have a transfer from GTFS. May be null
235-
* or empty in other situations.
234+
* @param timesToReachedStops map from target stop index to distance (along the street network) to it.
235+
* The method mutates this parameter.
236+
* @param ignorePatterns used to filter out stop-pattern pairs that already have a transfer from GTFS.
237+
* May be null or empty in other situations.
236238
*/
237239
private void retainClosestStopsOnPatterns(TIntIntMap timesToReachedStops, TIntCollection ignorePatterns) {
238240
TIntIntMap bestStopOnPattern = new TIntIntHashMap(50, 0.5f, -1, -1);

src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ private TransportNetwork buildNetworkFromConfig (TransportNetworkConfig config)
247247
// gtfs1, gtfs2...) (see various methods in TransportNetwork).
248248
TransportNetwork network = new TransportNetwork();
249249
network.streetLayer = new StreetLayer(config);
250-
network.streetLayer.parentNetwork = network;
251250
network.streetLayer.loadFromOsm(osmCache.get(config.osmId));
251+
network.streetLayer.parentNetwork = network;
252252
network.streetLayer.indexStreets();
253253

254254
// The GTFS transfer loader persists across all loaded feeds so we can feed information about all the transfers

0 commit comments

Comments
 (0)