DiGraph.connectedComponents

DiGraph.connectedComponents()

Returns the weakly connected components of the graph.

Each node is mapped to the index of its component: 0, 1, …, (number of components - 1), numbered in the order in which the components are found.

Returns:

mapping node id → index of its component

Return type:

dict[int, int]

See also

connectedComponentsList

returns a dict[int, set[int]] grouping nodes by component

connectedComponentsCount

returns the number of components

Example

import pyagrum as gum

g = gum.fastDiGraph("A->B<-C;D->E")
cc = g.connectedComponents()  # node id -> index of its component
cc[0] == cc[1] == cc[2], cc[3] == cc[4], cc[0] == cc[3]
# (True, True, False)

Used by

DiGraph, DAG

Inheritance diagram of pyagrum.DiGraph, pyagrum.DAG

Overridden in

MixedGraph.connectedComponents