跳到内容

为图的每个连通分量创建一个单独的图。

用法

decompose(graph, mode = c("weak", "strong"), max.comps = NA, min.vertices = 0)

参数

graph

原始图。

mode

字符常量,用于指定组件的类型,weak 表示弱连通分量,strong 表示强连通分量。

max.comps

要返回的最大组件数。将返回前 max.comps 个组件(至少包含 min.vertices 个顶点,请参阅下一个参数),其他组件将被忽略。 如果您不想限制组件的数量,请在此处提供 NA

min.vertices

组件应包含的最小顶点数,以便将其放入结果列表中。 例如,在此处提供 2 以忽略孤立顶点。

图对象列表。

参见

is_connected() 用于确定图是否连通,components() 用于计算图的连通分量。

连通分量 articulation_points(), biconnected_components(), component_distribution(), is_biconnected()

作者

Gabor Csardi csardi.gabor@gmail.com

示例


# the diameter of each component in a random graph
g <- sample_gnp(1000, 1 / 1000)
components <- decompose(g, min.vertices = 2)
sapply(components, diameter)
#>   [1] 23  3  9  9  1  6 12  2  4  2  4  4  6  2  4  2  3  1  1  1  2  4  5  4  2
#>  [26]  3  3  7  3  2  9  5  1  2  6  1  3  2  2  1  4 12  3  4  6  1  1  4  2  2
#>  [51]  3  2  2  2  9  2  1  1  4  3  1  2  2  2  6  3  2  2  2  3  1  1  5  2  2
#>  [76]  2  2  1  2  1  2  3  1  1  1  4  1  3  1  1  3  1  5  1  1  2  2  1  2  1
#> [101]  1  1  2  1  4  1  1  2  1  1  1  1  1  1  4  1  1  2  2  2  1  2  1  1  1
#> [126]  1