iduedu.assign_flows

iduedu.assign_flows(urban_graph, *, source_nodes, source_flows, node_weights, cluster_offsets=None, decay='gaussian', mean=None, std=None, beta=None, cutoff=None, min_flow=0.0, weight='time_min', per='edges', max_workers=None)[source]

Assign flows from sources to attractive nodes along shortest paths and sum them on the edges.

Sources are grouped into clusters by cluster_offsets (cluster c holds the sources cluster_offsets[c]:cluster_offsets[c + 1]; by default every source is a cluster of its own). Each cluster runs one search from all of its sources at once, every node joining its nearest source (equal costs go to the source that comes first in nodes_gdf). Every reached node other than a source is a destination with the weight node_weights[node] * decay(cost):

  • "gaussian": exp(-0.5 * ((cost - mean) / std) ** 2), trips of a typical length mean;

  • "exp": exp(-beta * cost);

  • "flat": 1.

The summed flow of the cluster’s sources is split between its destinations in proportion to these weights and carried back along the search tree. An arc keeps the flow of one cluster only when it exceeds min_flow or when the arc leaves a source and the flow is positive; the kept flows of all clusters are summed.

Parameters:
  • urban_graph (UrbanGraph) – Graph to load.

  • source_nodes (Iterable) – Graph node ids of the sources, grouped by cluster.

  • source_flows (Iterable[float]) – Flow sent from every source (trips, vehicles), finite and non-negative.

  • node_weights (str | Series | ndarray) – Attraction of every node: a nodes_gdf column name, a Series indexed by node id or an array in nodes_gdf order. Missing values count as 0.

  • cluster_offsets (Optional[Iterable[int]]) – n_clusters + 1 ascending positions into source_nodes starting at 0 and ending at len(source_nodes); None makes every source a cluster.

  • decay (Literal['gaussian', 'exp', 'flat']) – Decay of the destination weight with the travel cost.

  • mean (float | None) – Typical trip cost for "gaussian", in the units of weight.

  • std (float | None) – Spread of trip costs for "gaussian", positive.

  • beta (float | None) – Rate of "exp", per unit of weight.

  • cutoff (float | None) – Largest travel cost of a trip, inclusive; None for no limit.

  • min_flow (float) – Flow of one cluster below which an arc that does not leave a source is ignored.

  • weight (Literal['length_meter', 'time_min']) – Edge cost column: time_min (minutes, the default) or length_meter (metres).

  • per (Literal['edges', 'arcs']) – "edges" (default) for a table of the edges; "arcs" for one value per arc of urban_graph.adjacency_matrix (aligned with its data, after the call), where parallel edges are one arc.

  • max_workers (int | None) – Number of threads; None uses all cores.

Return type:

DataFrame | ndarray

Returns:

With per="arcs", a float64 array of the arc flows. Otherwise a DataFrame indexed like edges_gdf with flow_uv (along the edge from u to v), flow_vu (against it, for edges travelled both ways) and their sum flow. Among parallel edges only the cheapest one carries flow; equally cheap ones share it.