如何通过两步连接在GraphX中计算度数

问题描述 投票:1回答:1

我有一个有向图说,例如fromNode-> toNode。我想计算“ toNode”上的总传入连接,包括1跳或2跳连接。

例如:如果存在节点Z使得X连接Z且Z连接Y的情况,则从节点X到节点Y有两跳连接。

scala spark-graphx
1个回答
0
投票

我认为您可以两次使用aggregateMessages()。第一步,收集每个节点的inDegrees并将其存储。在第二步中,将节点中的inDegrees信息收集到最终节点。或者,您可以先使用externalJoinVertices(),例如:

yourGraph = followerGraph.outerJoinVertices(
        yourGraph.ops().inDegrees(),
        new setDegreesMsg()//use the function to combine inDegrees info with yourGraph
);

然后,使用aggregateMessages()收集邻居中的inDegrees信息,例如:

        degrees:RDD[(VertexId, Int)] = yourGraph.aggregateMessages(
                new getInfoSendMsg(),
                new getInfoMergeMsg()
);
© www.soinside.com 2019 - 2024. All rights reserved.