networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturns
voronoi_cells(G, center_nodes, weight='weight')

If C is a set of nodes in the graph and c is an element of C, the Voronoi cell centered at a node c is the set of all nodes v that are closer to c than to any other center node in C with respect to the shortest-path distance metric.

For directed graphs, this will compute the "outward" Voronoi cells, as defined in , in which distance is measured from the center nodes to the target node. For the "inward" Voronoi cells, use the DiGraph.reverse method to reverse the orientation of the edges before invoking this function on the directed graph.

Parameters

G : NetworkX graph
center_nodes : set

A nonempty set of nodes in the graph G that represent the center of the Voronoi cells.

weight : string or function

The edge attribute (or an arbitrary function) representing the weight of an edge. This keyword argument is as described in the documentation for ~networkx.multi_source_dijkstra_path , for example.

Raises

ValueError

If :None:None:`center_nodes` is empty.

Returns

dictionary

A mapping from center node to set of all nodes in the graph closer to that center node than to any other center node. The keys of the dictionary are the element of :None:None:`center_nodes`, and the values of the dictionary form a partition of the nodes of G.

Returns the Voronoi cells centered at :None:None:`center_nodes` with respect to the shortest-path distance metric.

Examples

>>> G = nx.path_graph(6)
>>> center_nodes = {0, 3}
>>> cells = nx.voronoi_cells(G, center_nodes)
>>> partition = set(map(frozenset, cells.values()))
>>> sorted(map(sorted, partition))
[[0, 1], [2, 3, 4, 5]]
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/voronoi.py#8
type: <class 'function'>
Commit: