Infrastructure Topology Layer
API reference for the infrastructure topology layer (Feature 036). For conceptual background, see Material Geography: Infrastructure as Historical Force.
Module Overview
The babylon.infrastructure package contains six submodules:
Submodule |
Responsibility |
|---|---|
|
12 frozen Pydantic DTOs |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
Enumerations
All enumerations are StrEnum subclasses defined in
babylon.models.enums.
TerrainType
Member |
Value |
Description |
|---|---|---|
|
|
Default — no dominant water or resource coverage |
|
|
Majority water coverage (lakes, rivers) |
|
|
Majority resource region coverage (ranges, deltas, wetlands) |
BiocapacityType
Member |
Value |
Description |
|---|---|---|
|
|
Potable water extraction capacity |
|
|
Marine/lacustrine food production |
|
|
Navigable waterway throughput |
|
|
Extractable mineral resources |
|
|
Harvestable timber stock |
|
|
Hydroelectric generation capacity |
WATER hexes initialize FRESHWATER, FISHERY, SHIPPING_ACCESS.
RESOURCE hexes initialize MINERAL, TIMBER, HYDROELECTRIC.
InfrastructureType
Member |
Value |
Description |
|---|---|---|
|
|
Major highway / interstate (high FREIGHT + COMMUTER) |
|
|
Secondary highway (moderate FREIGHT + COMMUTER) |
|
|
Local / county road (low capacity, commuter-focused) |
|
|
Railroad line (high FREIGHT, low COMMUTER) |
|
|
Energy pipeline (ENERGY only) |
|
|
Power transmission line (ENERGY only) |
|
|
Navigable waterway or sea lane (FREIGHT only) |
|
|
Air route between airports (all categories, nonlocal) |
FlowCategory
Member |
Value |
Description |
|---|---|---|
|
|
Physical goods movement |
|
|
Human movement (labor, consumption) |
|
|
Financial/value flow |
|
|
Energy transmission |
|
|
Ideology/information diffusion |
JunctionType
Member |
Value |
Description |
|---|---|---|
|
|
Highway interchange (roads intersection) |
|
|
Power substation (energy distribution) |
|
|
Railroad junction (freight routing) |
|
|
Seaport or river port (shipping + freight) |
|
|
Airport terminal (air link generation) |
LocalityClass
Member |
Value |
Description |
|---|---|---|
|
|
Within 3 hex diameters (adjacent-equivalent) |
|
|
3–20 hex diameters (regional) |
|
|
20+ hex diameters (transcontinental) |
Ratio = distance_km / avg_hex_diameter_km.
InternetResponseMode
Member |
Value |
Description |
|---|---|---|
|
|
Full throughput, full surveillance |
|
|
Reduced throughput, maintained surveillance, covert |
|
|
Zero throughput, zero surveillance, overt with backfire |
Data Types
All data types are frozen Pydantic BaseModel subclasses defined in
babylon.infrastructure.types.
TerrainClassification
Terrain classification result for a single hex.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell identifier |
|
|
|
|
|
|
|
[0.0, 1.0] |
Fraction of hex area covered by water polygons |
|
|
[0.0, 1.0] |
Fraction of hex area covered by resource region polygons |
|
|
NE feature names contributing to classification |
BiocapacityStockState
Current state of a biocapacity stock on a non-LAND hex.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell identifier |
|
|
|
BiocapacityType value |
|
|
|
>= 0.0 |
Stock at initialization |
|
|
>= 0.0 |
Current stock level |
|
|
Extraction amounts per tick |
|
|
|
|
ExtractionResult
Result of biocapacity extraction through an edge.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
Resource hex (WATER/RESOURCE) |
|
|
|
Extracting LAND hex |
|
|
|
BiocapacityType value |
|
|
|
>= 0.0 |
Units extracted this tick |
|
|
>= 0.0 |
Stock after extraction |
|
|
>= 0.0 |
Max extraction allowed by edge infrastructure |
InfrastructureLinkState
State of a single infrastructure link on an edge or vertex.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
Unique identifier for this link |
|
|
|
InfrastructureType value |
|
|
|
Capacity per FlowCategory |
|
|
|
[0.0, 1.0] |
Health scalar (0.0 = destroyed, 1.0 = pristine) |
|
|
Owning organization node ID |
|
|
|
Natural Earth feature ID for provenance |
Method: effective_capacity(category: str) -> float returns
capacity.get(category, 0.0) * condition.
EdgeCapacityResult
Aggregate capacity computation result for an edge.
Field |
Type |
Description |
|---|---|---|
|
|
Source hex H3 index |
|
|
Target hex H3 index |
|
|
Sum of effective link capacities per FlowCategory |
|
|
Minimal natural capacity for LAND-LAND edges (COMMUTER, CONSCIOUSNESS) |
|
|
|
JunctionState
State of junction infrastructure at a vertex.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
JunctionType value |
|
|
|
>= 0.0 |
Capacity added to adjacent edges |
|
|
[0.0, 1.0] |
Health/degradation scalar |
|
|
Owning organization node ID |
|
|
|
Natural Earth feature ID for provenance |
VertexState
State of a vertex (triple junction) in the hex mesh.
Field |
Type |
Description |
|---|---|---|
|
|
Canonical ID (sorted triple hash) |
|
|
Three adjacent hex H3 indices (ordered) |
|
|
Latitude (centroid of 3 hex centroids) |
|
|
Longitude (centroid of 3 hex centroids) |
|
|
Junction infrastructure inventory |
NonlocalEdgeState
State of a nonlocal edge connecting non-adjacent vertices.
Field |
Type |
Description |
|---|---|---|
|
|
Origin vertex ID |
|
|
Destination vertex ID |
|
|
The infrastructure creating this edge |
|
|
Great-circle distance between vertices (> 0.0) |
|
|
|
|
|
NE feature that generated this edge |
InternetAccessState
Per-hex internet connectivity state.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell identifier |
|
|
|
Whether broadband is available at this hex |
|
|
|
[0.0, 1.0] |
Coverage quality scalar derived from FCC data |
|
|
[0.0, 1.0] |
Fraction of consciousness flow visible to the state |
|
|
|
SurveillanceResult
Result of surveillance intelligence generation for a tick.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell where surveillance occurred |
|
|
|
>= 0.0 |
Consciousness flow magnitude through this hex |
|
|
[0.0, 1.0] |
Current coupling value at this hex |
|
|
>= 0.0 |
Intelligence added to state observation graph |
|
|
Organization node IDs observed at this hex |
OpsecResult
Result of COUNTER_INTEL action on internet surveillance coupling.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell where OPSEC was applied |
|
|
|
Organization that invested in OPSEC |
|
|
|
[0.0, 1.0] |
Surveillance coupling before OPSEC |
|
|
[0.0, 1.0] |
Surveillance coupling after OPSEC |
|
|
[0.0, 1.0] |
Fraction of consciousness throughput lost |
InternetResponseResult
Result of state apparatus internet response mode change.
Field |
Type |
Constraints |
Description |
|---|---|---|---|
|
|
H3 cell targeted |
|
|
|
Previous response mode |
|
|
|
New response mode |
|
|
|
[0.0, 1.0] |
Remaining throughput fraction (1.0 = full, 0.0 = severed) |
|
|
[0.0, 1.0] |
Remaining surveillance fraction |
|
|
Whether the mode change is visible to target community |
|
|
|
>= 0.0 |
Consciousness backfire effect (signals state fear) |
Protocols
All protocols are @runtime_checkable and defined in
babylon.infrastructure.protocols.
TerrainClassifier
Classifies hex cells by terrain type from NE geographic data.
BiocapacityStore
Manages biocapacity stocks on WATER and RESOURCE hexes.
- initialize_stocks(classifications: dict[str, TerrainClassification]) dict[str, list[BiocapacityStockState]]
Initialize biocapacity stocks for all non-
LANDhexes.- Parameters:
classifications – Terrain classifications for the mesh.
- Returns:
Dict mapping h3_index to list of
BiocapacityStockState.
- get_stock(h3_index: str, stock_type: str) BiocapacityStockState | None
Get current stock state for a hex and type.
- Parameters:
h3_index – H3 cell identifier.
stock_type –
BiocapacityTypevalue.
- Returns:
Current stock state, or
Noneif not found.
- extract(source_h3: str, target_h3: str, stock_type: str, infrastructure_capacity: float, depletion_rate: float) ExtractionResult
Extract biocapacity from a resource hex through an edge.
- Parameters:
source_h3 – Resource hex (WATER/RESOURCE).
target_h3 – Extracting LAND hex.
stock_type –
BiocapacityTypevalue.infrastructure_capacity – Max extraction from edge infrastructure.
depletion_rate – Per-tick depletion rate from
GameDefines.
- Returns:
ExtractionResultwith amount extracted and remaining stock.
InfrastructureInventory
Manages infrastructure links on edges and junctions on vertices.
- get_edge_links(source_h3: str, target_h3: str) list[InfrastructureLinkState]
Get all infrastructure links on an edge.
- add_edge_link(source_h3: str, target_h3: str, link: InfrastructureLinkState) None
Add an infrastructure link to an edge.
- degrade_link(link_id: str, condition_delta: float) InfrastructureLinkState
Degrade an infrastructure link’s condition.
- Parameters:
link_id – Unique identifier of the link.
condition_delta – Amount to reduce condition by (positive).
- Returns:
Updated link state.
- Raises:
KeyError – If
link_idnot found.
- degrade_junction(vertex_id: str, junction_type: str, condition_delta: float) list[tuple[str, str]]
Degrade a junction’s condition, cascading to adjacent edges.
Cascade ratio: 50%. Each adjacent edge’s links are degraded by
condition_delta * 0.5.- Parameters:
vertex_id – Vertex containing the junction.
junction_type –
JunctionTypevalue.condition_delta – Amount to reduce condition by.
- Returns:
List of
(source_h3, target_h3)edge pairs affected.- Raises:
KeyError – If vertex or junction type not found.
EdgeCapacityCalculator
Computes aggregate edge capacity from infrastructure inventory.
- compute_edge_capacity(source_h3: str, target_h3: str, source_terrain: str, target_terrain: str, links: Sequence[InfrastructureLinkState], population_density: float) EdgeCapacityResult
Compute total capacity for an edge.
Algorithm:
Sum
effective_capacityacross all links per FlowCategoryFor LAND-LAND edges, add
natural_capacity_coefficientto COMMUTER and CONSCIOUSNESSFor WATER-WATER edges, force all capacities to zero
total = aggregate + natural
- Parameters:
source_h3 – Source hex H3 index.
target_h3 – Target hex H3 index.
source_terrain –
TerrainTypeof source hex.target_terrain –
TerrainTypeof target hex.links – Infrastructure links on this edge.
population_density – Average population density of adjacent hexes.
- Returns:
EdgeCapacityResultwith per-category capacity breakdown.
SpatialSnapper
Snaps Natural Earth features to H3 mesh edges and vertices.
- snap_linear_features(edges: Sequence[tuple[str, str]]) dict[tuple[str, str], list[InfrastructureLinkState]]
Snap NE linear features (roads, railroads) to H3 edges.
Algorithm:
Compute mesh bounding box from all edge cells
Load NE roads and railroads in the bounding box
For each edge, compute shared boundary polygon
Buffer boundary by
hex_diameter * snap_buffer_fractionTest each feature against the buffered boundary
Classify road type:
expressway=1orMajor Highway-> HIGHWAY,Secondary Highway-> ARTERIAL, else LOCAL_ROAD
- snap_point_features(vertices: Sequence[VertexState]) dict[str, list[JunctionState]]
Snap NE point features (airports, ports) to H3 vertices.
Finds the nearest vertex within tolerance (
_MAX_SNAP_DISTANCE_DEG = 0.2degrees, ~20 km at 42N) and creates aJunctionStatewithcapacity_contributionset to the NE feature’snatlscale.
InternetAccessManager
Manages per-hex internet access state and mutations.
- initialize_from_broadband(broadband: dict[str, float], hex_to_county: dict[str, str], quality_data: dict[str, float] | None, water_hexes: set[str] | None) None
Initialize internet access from FCC broadband data.
broadbandmaps county FIPS to penetration fraction (pct_25_3 / 100).quality_datamaps county FIPS to high-speed fraction (pct_100_20 / 100). WATER hexes forced tointernet_access=Falseregardless of county data.
- apply_opsec(h3_index: str, org_id: str, opsec_investment: float, infra_defines: InfrastructureDefines) OpsecResult
Apply OPSEC to reduce surveillance coupling at a hex.
Coupling reduction:
opsec_investment * opsec_tradeoff_ratio. Throughput reduction:(coupling_before - coupling_after) * opsec_tradeoff_ratio.- Raises:
KeyError – If hex not found.
- set_response_mode(h3_index: str, mode: str, infra_defines: InfrastructureDefines) InternetResponseResult
Set state apparatus internet response mode.
Effects by mode:
PERMIT: throughput 1.0, surveillance 1.0, not visible, no backfire
THROTTLE: throughput =
throttle_throughput_fraction, surveillance 1.0, not visible, no backfireSEVER: throughput 0.0, surveillance 0.0, visible, backfire =
surveillance_coupling + 0.1
- Raises:
KeyError – If hex not found.
InternetFieldOperator
Manages internet consciousness field diffusion operations.
- get_connected_component() set[str]
Get the set of internet-enabled hex indices forming the connected component. Includes hexes with
internet_access=Trueandresponse_mode != SEVER.
- propagate_consciousness(field_values: dict[str, float], diffusion_rate: float) dict[str, float]
Run consciousness field diffusion on the internet-connected component.
Mean-field approximation: each hex moves toward the component mean.
\[f_i' = f_i + \alpha \cdot q_i \cdot \tau_i \cdot (\bar{f} - f_i)\]where \(\alpha\) =
diffusion_rate, \(q_i\) =internet_quality, \(\tau_i\) = throughput factor (1.0 for PERMIT,throttle_throughput_fractionfor THROTTLE), and \(\bar{f}\) = mean field value across the connected component.Requires at least 2 active hexes; returns unchanged values otherwise.
- generate_surveillance(flow_magnitudes: dict[str, float], analytical_capacity: float) list[SurveillanceResult]
Generate surveillance intelligence from consciousness flow.
\[I_i = F_i \cdot \sigma_i \cdot A\]where \(F_i\) = flow magnitude, \(\sigma_i\) = surveillance coupling, \(A\) = analytical capacity.
Implementations
DefaultTerrainClassifier
babylon.infrastructure.terrain
Constructor:
DefaultTerrainClassifier(reader, defines)
- param reader:
NaturalEarthReader- param defines:
InfraTerrainDefines
Classifies H3 hexes by spatial intersection with NE lake and resource
region polygons. Converts H3 (lat, lon) boundaries to Shapely
(lon, lat) polygons. Coverage = intersection_area / hex_area.
Classification: WATER if water coverage >= threshold, else
RESOURCE if resource coverage >= threshold, else LAND.
DefaultBiocapacityStore
babylon.infrastructure.terrain
Constructor: DefaultBiocapacityStore(defines: InfraTerrainDefines)
Internally mutable store tracking biocapacity stocks per hex. Returns
frozen BiocapacityStockState DTOs via protocol methods.
Extraction formula:
where \(C_{\text{infra}}\) = infrastructure capacity, \(r\) = depletion rate, \(S\) = current stock.
Supports serialization via to_dict() / from_dict() for
tick-snapshot compatibility.
DefaultInfrastructureInventory
babylon.infrastructure.inventory
Constructor: DefaultInfrastructureInventory()
Stores infrastructure links indexed by canonical edge keys
(tuple(sorted([source, target]))), vertices indexed by vertex ID,
and nonlocal edges in a flat list. Canonical key ordering prevents
A->B vs B->A duplication.
Junction cascade ratio: condition_delta * 0.5 applied to all links
on the three edges adjacent to a degraded junction’s vertex.
Supports serialization via to_dict() / from_dict().
DefaultEdgeCapacityCalculator
babylon.infrastructure.capacity
Constructor: DefaultEdgeCapacityCalculator(defines: InfrastructureDefines)
Computes per-edge aggregate capacity. WATER-WATER edges forced to zero. LAND-LAND edges receive natural capacity for COMMUTER and CONSCIOUSNESS. Total = aggregate + natural.
DefaultSpatialSnapper
babylon.infrastructure.snapping
Constructor:
DefaultSpatialSnapper(reader, defines)
- param reader:
NaturalEarthReader- param defines:
InfrastructureDefines
Snaps NE linear features to H3 edges via buffered shared-boundary intersection. Road classification:
NE Feature Attribute |
InfrastructureType |
|---|---|
|
HIGHWAY |
|
ARTERIAL |
All other roads |
LOCAL_ROAD |
Railroads |
RAIL |
Link IDs are deterministic SHA-256 hashes of
source_table:ogc_fid:edge_key, truncated to 16 characters.
Point features snapped to nearest vertex within
_MAX_SNAP_DISTANCE_DEG = 0.2 degrees (~20 km at latitude 42N).
DefaultInternetAccessManager
babylon.infrastructure.internet
Constructor: DefaultInternetAccessManager(defines: InfraTerrainDefines)
Stores mutable internet state per hex. Initialization from FCC broadband
data maps county penetration to per-hex access. WATER hexes always
internet_access=False.
DefaultInternetFieldOperator
babylon.infrastructure.internet
Constructor:
DefaultInternetFieldOperator(manager, infra_defines=None)
- param manager:
DefaultInternetAccessManager- param infra_defines:
InfrastructureDefines | None
Operates on the connected component of internet-enabled, non-SEVER hexes. Consciousness diffuses via mean-field approximation. Surveillance intelligence generated proportional to flow, coupling, and analytical capacity.
Nonlocal Edge Generators
Two module-level functions in babylon.infrastructure.nonlocal_edges.
- generate_airport_edges(airport_vertices: Sequence[VertexState], all_airports: Sequence[VertexState], defines: InfrastructureDefines, avg_hex_diameter_km: float) list[NonlocalEdgeState]
Generate
AIR_LINKnonlocal edges between airport vertices. Creates edges from each airport inairport_verticesto every other airport inall_airports(excluding self-loops). Deduplicates via canonical sorted vertex ID pairs. Capacity scaled bymin(source_natlscale, dest_natlscale) / 100.0.
- generate_shipping_edges(port_vertices: Sequence[VertexState], defines: InfrastructureDefines, avg_hex_diameter_km: float) list[NonlocalEdgeState]
Generate
SHIPPING_LANEnonlocal edges between all pairs of port vertices. Capacity scaled bymin(source_natlscale, dest_natlscale) / 100.0.
Configuration
InfraTerrainDefines
babylon.config.defines.InfraTerrainDefines — terrain classification
and biocapacity coefficients.
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
0.5 |
Coverage fraction for WATER/RESOURCE classification |
|
|
100.0 |
Initial FRESHWATER stock for WATER hexes |
|
|
80.0 |
Initial FISHERY stock for WATER hexes |
|
|
50.0 |
Initial SHIPPING_ACCESS stock for WATER hexes |
|
|
120.0 |
Initial MINERAL stock for RESOURCE hexes |
|
|
90.0 |
Initial TIMBER stock for RESOURCE hexes |
|
|
60.0 |
Initial HYDROELECTRIC stock for RESOURCE hexes |
|
|
0.05 |
Per-tick depletion rate for FRESHWATER |
|
|
0.04 |
Per-tick depletion rate for FISHERY |
|
|
0.02 |
Per-tick depletion rate for SHIPPING_ACCESS |
|
|
0.03 |
Per-tick depletion rate for MINERAL |
|
|
0.04 |
Per-tick depletion rate for TIMBER |
|
|
0.01 |
Per-tick depletion rate for HYDROELECTRIC |
|
|
0.5 |
Min FCC broadband penetration for internet_access=True |
|
|
0.3 |
Default surveillance coupling at internet-connected hexes |
Methods:
get_initial_stock(stock_type: str) -> floatget_depletion_rate(stock_type: str) -> float
InfrastructureDefines
babylon.config.defines.InfrastructureDefines — infrastructure
capacity and internet operation coefficients.
Per-type base capacity coefficients ({infra_type}_{flow_category}):
Type |
FREIGHT |
COMMUTER |
VALUE |
ENERGY |
CONSCIOUSNESS |
|---|---|---|---|---|---|
HIGHWAY |
1.0 |
1.0 |
0.5 |
– |
0.3 |
ARTERIAL |
0.6 |
0.7 |
0.3 |
– |
0.2 |
LOCAL_ROAD |
0.2 |
0.4 |
0.1 |
– |
0.3 |
RAIL |
1.2 |
0.3 |
0.2 |
– |
0.1 |
PIPELINE |
– |
– |
– |
1.5 |
– |
TRANSMISSION |
– |
– |
– |
1.0 |
– |
SHIPPING_LANE |
1.5 |
– |
– |
– |
– |
AIR_LINK |
0.3 |
0.8 |
0.5 |
– |
0.5 |
-- indicates zero capacity (parameter not defined for that combination).
Other parameters:
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
0.1 |
Base natural capacity for LAND-LAND edges (COMMUTER, CONSCIOUSNESS) |
|
|
0.01 |
Edge capacity below which flow is zero |
|
|
0.5 |
Surveillance coupling reduction per unit of OPSEC investment |
|
|
0.3 |
Consciousness throughput under THROTTLE response mode |
|
|
0.3 |
Buffer around shared boundary as fraction of hex diameter |
|
|
3.0 |
Distance/hex ratio below which nonlocal edge is LOCAL |
|
|
20.0 |
Distance/hex ratio below which nonlocal edge is SEMI_LOCAL |
Method: get_capacity(infra_type: str, flow_category: str) -> float
returns the capacity value via attribute lookup on
{infra_type}_{flow_category}, or 0.0 if not defined.
Key Algorithms
Terrain Classification
Convert H3 cell boundary to Shapely polygon (
(lat, lon)->(lon, lat))Intersect with NE lakes -> compute
water_coverage = sum(intersection_area) / hex_areaIntersect with NE resource regions -> compute
resource_coverageClamp both to [0.0, 1.0]
If
water_coverage >= majority_coverage_threshold:WATERElse if
resource_coverage >= majority_coverage_threshold:RESOURCEElse:
LAND
Edge Capacity Aggregation
For each edge (source, target):
where \(k\) is the flow category, \(c_l^{(k)}\) is link \(l\)’s capacity for category \(k\), \(d_l\) is the link’s condition, and \(n^{(k)}\) is the natural capacity (nonzero only for LAND-LAND edges and only for COMMUTER and CONSCIOUSNESS categories).
WATER-WATER edges: all capacities forced to zero.
Mean-Field Consciousness Diffusion
\(\alpha\): base
diffusion_rate\(q_i\):
internet_qualityat hex \(i\)\(\tau_i\): 1.0 if PERMIT,
throttle_throughput_fractionif THROTTLE\(\bar{f}\): mean field value across connected component
Computed only when |active| >= 2.
Surveillance Intelligence
\(F_i\): consciousness flow magnitude at hex \(i\)
\(\sigma_i\): surveillance coupling
\(A\): state analytical capacity [0.0, 1.0]
OPSEC Coupling Reduction
where \(\omega\) is opsec_investment, \(\rho\) is
opsec_tradeoff_ratio, and \(\Delta\tau\) is the consciousness
throughput reduction incurred.
Haversine Distance
where \(R = 6371\) km (WGS-84 mean radius), \(\phi\) = latitude in radians, \(\lambda\) = longitude in radians.
Locality Classification
ratio < 3.0: LOCALratio < 20.0: SEMI_LOCALratio >= 20.0: NONLOCAL