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(clustercholds the sourcescluster_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 innodes_gdf). Every reached node other than a source is a destination with the weightnode_weights[node] * decay(cost):"gaussian":exp(-0.5 * ((cost - mean) / std) ** 2), trips of a typical lengthmean;"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_flowor 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: anodes_gdfcolumn name, a Series indexed by node id or an array innodes_gdforder. Missing values count as 0.cluster_offsets (
Optional[Iterable[int]]) –n_clusters + 1ascending positions intosource_nodesstarting at 0 and ending atlen(source_nodes);Nonemakes 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 ofweight.std (
float|None) – Spread of trip costs for"gaussian", positive.cutoff (
float|None) – Largest travel cost of a trip, inclusive;Nonefor 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) orlength_meter(metres).per (
Literal['edges','arcs']) –"edges"(default) for a table of the edges;"arcs"for one value per arc ofurban_graph.adjacency_matrix(aligned with itsdata, after the call), where parallel edges are one arc.max_workers (
int|None) – Number of threads;Noneuses all cores.
- Return type:
- Returns:
With
per="arcs", a float64 array of the arc flows. Otherwise a DataFrame indexed likeedges_gdfwithflow_uv(along the edge fromutov),flow_vu(against it, for edges travelled both ways) and their sumflow. Among parallel edges only the cheapest one carries flow; equally cheap ones share it.