networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
collapse(G, grouped_nodes)

This is similar to condensation, but works on undirected graphs.

Parameters

G : NetworkX Graph
grouped_nodes: list or generator :

Grouping of nodes to collapse. The grouping must be disjoint. If grouped_nodes are strongly_connected_components then this is equivalent to condensation .

Returns

C : NetworkX Graph

The collapsed graph C of G with respect to the node grouping. The node labels are integers corresponding to the index of the component in the list of grouped_nodes. C has a graph attribute named 'mapping' with a dictionary mapping the original nodes to the nodes in C to which they belong. Each node in C also has a node attribute 'members' with the set of original nodes in G that form the group that the node in C represents.

Collapses each group of nodes into a single node.

Examples

>>> # Collapses a graph using disjoint groups, but not necesarilly connected
... G = nx.Graph([(1, 0), (2, 3), (3, 1), (3, 4), (4, 5), (5, 6), (5, 7)])
... G.add_node("A")
... grouped_nodes = [{0, 1, 2, 3}, {5, 6, 7}]
... C = collapse(G, grouped_nodes)
... members = nx.get_node_attributes(C, "members")
... sorted(members.keys()) [0, 1, 2, 3]
>>> member_values = set(map(frozenset, members.values()))
... assert {0, 1, 2, 3} in member_values
... assert {4} in member_values
... assert {5, 6, 7} in member_values
... assert {"A"} in member_values
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.connectivity.edge_augmentation.collapse

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/connectivity/edge_augmentation.py#1032
type: <class 'function'>
Commit: