GraphX 中有向图中连通分量的数量

Number of connected components in a directed graph in GraphX

我知道 graphx 的 connectedComponents() 方法会用其编号最小的顶点的 ID 标记图中的每个连通分量。 graphx中是否有计算连通分量数的方法调用?

您可以使用 connectedComponents() 来获取此计数。首先 运行 图表上的方法,然后计算结果中唯一 VertexId 的数量。在 Scala 中:

graph.connectedComponents().vertices.map{ case(_,cc) => cc}.distinct.count()