Add R5 validation

This commit is contained in:
Andras Schmelczer 2026-05-12 06:44:15 +01:00
parent f2a2651b8a
commit b580c51b6d
4 changed files with 53 additions and 10 deletions

View file

@ -54,6 +54,7 @@ public class App {
LocalDate today = LocalDate.now();
TransportNetwork network = Router.loadNetwork(requiredEnv("DATA_DIR"), requiredEnv("NETWORK_CACHE_DIR"));
Router.validateTransitServices(network, today);
System.err.println("Loading postcodes (England only)...");
Parquet.Postcodes postcodes = Parquet.loadEnglandPostcodes(

View file

@ -22,6 +22,7 @@ import java.io.File;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.EnumSet;
import java.util.List;
@ -78,12 +79,42 @@ public class Router {
System.err.println(" Cached to " + cacheFile);
}
validateTransitNetwork(network, cacheFile, dataDir);
System.err.println(" Building distance tables...");
network.transitLayer.buildDistanceTables(null);
System.err.println(" Network ready");
return network;
}
private static void validateTransitNetwork(TransportNetwork network, File cacheFile, String dataDir) {
TransitLayer transitLayer = network.transitLayer;
int stops = transitLayer == null ? 0 : transitLayer.getStopCount();
int routes = transitLayer == null || transitLayer.routes == null ? 0 : transitLayer.routes.size();
int patterns = transitLayer == null || transitLayer.tripPatterns == null ? 0 : transitLayer.tripPatterns.size();
int services = transitLayer == null || transitLayer.services == null ? 0 : transitLayer.services.size();
if (stops == 0 || routes == 0 || patterns == 0) {
throw new IllegalStateException(String.format(
"R5 network has no usable transit data (stops=%d, routes=%d, patterns=%d). "
+ "The cache at %s was likely built without GTFS. Ensure %s contains GTFS .zip files, "
+ "then delete %s and rerun.",
stops, routes, patterns, cacheFile.getPath(), dataDir, cacheFile.getPath()));
}
System.err.printf(" Transit: %,d stops, %,d routes, %,d patterns, %,d services%n",
stops, routes, patterns, services);
}
static void validateTransitServices(TransportNetwork network, LocalDate date) {
BitSet activeServices = network.transitLayer.getActiveServicesForDate(date);
if (activeServices.cardinality() == 0) {
throw new IllegalStateException("R5 network has transit data, but no active services on "
+ date + ". Rebuild property-data/transit from current feeds or choose a date covered by GTFS.");
}
System.err.printf(" Active transit services on %s: %,d%n", date, activeServices.cardinality());
}
/**
* Filter destinations by distance, build chunks, compute travel times for one origin.
* Returns only the filtered subset indices and their travel times.