UndiGraph.chainComponents

UndiGraph.chainComponents()

Return the chain components (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]

Example

import pyagrum as gum

g = gum.fastUndiGraph("A-B-C;D-E")
cc = g.chainComponents()  # node id -> component
cc[0] == cc[1] == cc[2], cc[3] == cc[4], cc[0] == cc[3]
# (True, True, False)

Used by

UndiGraph, CliqueGraph

Inheritance diagram of pyagrum.UndiGraph, pyagrum.CliqueGraph

Overridden in

MixedGraph.chainComponents