Skip to contents

Partition a graph into maximal weakly or strongly connected components. This query supports every graph class, including cyclic graphs of class "UNKNOWN".

Usage

components(cg, mode = c("weak", "strong"))

Arguments

cg

A caugi object.

mode

Character; "weak" (default) or "strong". Weak connectivity ignores edge directions and includes all edge types. Strong connectivity uses only fully directed edges: every node in a component can reach every other node by following directed edges. Undirected, bidirected, and partial edges are ignored in strong mode.

Value

A list of character vectors, one per component. Nodes within each component follow the graph's node order, and components are ordered by their first node in that order. Isolated nodes form singleton components. An empty graph returns list().

Details

Every strong component of a DAG is a singleton. Strong components describe mutual directed reachability, whereas districts() describe connectivity through bidirected edges.

Examples

cg <- caugi(A %-->% B, C %-->% B, D, class = "DAG")
components(cg) # list(c("A", "B", "C"), "D")
#> [[1]]
#> [1] "A" "C" "B"
#> 
#> [[2]]
#> [1] "D"
#> 
components(cg, mode = "strong") # Four singleton components
#> [[1]]
#> [1] "A"
#> 
#> [[2]]
#> [1] "C"
#> 
#> [[3]]
#> [1] "B"
#> 
#> [[4]]
#> [1] "D"
#> 

cyclic <- caugi(
  A %-->% B, B %-->% C, C %-->% A, C %-->% D,
  class = "UNKNOWN"
)
components(cyclic, mode = "strong") # list(c("A", "B", "C"), "D")
#> [[1]]
#> [1] "A" "B" "C"
#> 
#> [[2]]
#> [1] "D"
#>