aequilibrae.transit.TransitGraphBuilder#
- class aequilibrae.transit.TransitGraphBuilder(public_transport_conn, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = 124, geometry_noise: bool = True, noise_coef: float = 1e-05, with_inner_stop_transfers: bool = False, with_outer_stop_transfers: bool = False, with_walking_edges: bool = True, distance_upper_bound: float = inf, blocking_centroid_flows: bool = True, connector_method: str = 'nearest_neighbour', max_connectors_per_zone: int = -1)[source]#
Graph builder for the transit assignment Spiess & Florian algorithm.
- Arguments:
public_transport_conn (
sqlite3.Connection
): Connection to thepublic_transport.sqlite
database.period_id (
int
): Period id for the period to be used. Preferred over start and end.time_margin (
int
): Time margin, extends thestart
andend
times bytime_margin
([start
,end
] becomes [start
-time_margin
,end
+time_margin
]), in order to include more trips when computing mean values. Defaults to0
.projected_crs (
str
): Projected CRS of the network, intended for more accurate distance calculations. Defaults to"EPSG:3857"
, Spherical Mercator.num_threads (
int
): Number of threads to be used where possible. Defaults to-1
, using all available threads.seed (
int
): Seed forself.rng
. Defaults to124
.geometry_noise (
bool
): Whether to use noise in geometry creation, in order to avoid colocated nodes. Defaults toTrue
.noise_coef (
float
): Scaling factor of the noise. Defaults to1.0e-5
.with_inner_stop_transfers (
bool
): Whether to create transfer edges within parent stations. Defaults toFalse
.with_outer_stop_transfers (
bool
): Whether to create transfer edges between parent stations. Defaults toFalse
.with_walking_edges (
bool
): Whether to create walking edges between distinct stops of each station. Defaults toTrue
.distance_upper_bound (
float
): Upper bound on connector distance. Defaults tonp.inf
.blocking_centroid_flows (
bool
): Whether to block flow through centroids. Defaults toTrue
.max_connectors_per_zone (
int
): Maximum connectors per zone. Defaults to-1
for unlimited.
- __init__(public_transport_conn, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = 124, geometry_noise: bool = True, noise_coef: float = 1e-05, with_inner_stop_transfers: bool = False, with_outer_stop_transfers: bool = False, with_walking_edges: bool = True, distance_upper_bound: float = inf, blocking_centroid_flows: bool = True, connector_method: str = 'nearest_neighbour', max_connectors_per_zone: int = -1)[source]#
Methods
__init__
(public_transport_conn[, period_id, ...])add_zones
(zones[, from_crs])Add zones as ODs.
Convert a sparse demand matrix from
zone_id
's to the correspondingnode_id
's.Create the additional required entries in the tables.
Create the SF transit graph (vertices and edges).
create_line_geometry
([method, graph])Create the LineString for each edge.
Build a dataframe mapping the centroid node ids with to transport assignment zone ids.
from_db
(public_transport_conn, period_id, ...)Create a SF graph instance from an existing database save.
save
([robust])Save the current graph to the public transport database.
save_edges
([recreate_line_geometry])Save the contents of self.edges to the public transport database.
save_vertices
([robust])Write the vertices DataFrame to the public transport database.
Create an AequilibraE
TransitGraph
object from an SF graph builder.Attributes
- add_zones(zones, from_crs: str | None = None)[source]#
Add zones as ODs.
- Arguments:
zones (
pd.DataFrame
): DataFrame containing the zoning information. Columns must includezone_id
andgeometry
.from_crs (
str
): The CRS of thegeometry
column ofzones
. If not provided it’s assumed that the geometry is already inself.projected_crs
. If provided, the geometry will be projected toself.projected_crs
. Defaults toNone
.
- convert_demand_matrix_from_zone_to_node_ids(demand_matrix, o_zone_col='origin_zone_id', d_zone_col='destination_zone', demand_col='demand')[source]#
Convert a sparse demand matrix from
zone_id
’s to the correspondingnode_id
’s.
- create_line_geometry(method='direct', graph='w')[source]#
Create the LineString for each edge.
The direct method creates a straight line between all points.
The connect project match method uses the existing line geometry within the project to create more accurate line strings. It creates a line string that matches the path between the shortest path between the project nodes closest to either end of the access and egress connectors.
Project graphs must be built for the “connector project match” method.
- Arguments:
method (
str
): Must be either"direct"
or"connector project match"
. If method is"direct"
,graph
argument is ignored.graph (
str
): Must be a key withinproject.network.graphs
.
- create_od_node_mapping()[source]#
Build a dataframe mapping the centroid node ids with to transport assignment zone ids.
- classmethod from_db(public_transport_conn, period_id: int, **kwargs)[source]#
Create a SF graph instance from an existing database save.
Assumes the database was constructed with the provided save methods. No checks are performed to see if the provided arguments are compatible with the saved graph.
All arguments are forwarded to the constructor.
- Arguments:
public_transport_conn (
sqlite3.Connection
): Connection to the ‘public_transport.sqlite’ database.
- save(robust=True)[source]#
Save the current graph to the public transport database.
- Arguments:
recreate_line_geometry (
bool
): Whether to recreate the line strings for the edges as direct lines. Defaults toFalse
.
- save_edges(recreate_line_geometry=False)[source]#
Save the contents of self.edges to the public transport database.
If no geometry for the edges is present or
recreate_line_geometry
isTrue
, direct lines will be created.- Arguments:
recreate_line_geometry (
bool
): Whether to recreate the line strings for the edges as direct lines. Defaults toFalse
.
- save_vertices(robust=True)[source]#
Write the vertices DataFrame to the public transport database.
Within the database nodes may not exist at the exact same point in space, provide
robust=True
to move the nodes slightly.- Arguments:
robust (
bool
): Whether to move stack nodes slightly before saving. Defaults toTrue
.
- to_transit_graph() TransitGraph [source]#
Create an AequilibraE
TransitGraph
object from an SF graph builder.
- property config#