简体   繁体   English

使用Java Jung库将有向图转换为无向图

[英]converting directed graph to undirected one using java jung library

I am looking for a way to calculate degree of each node of a directedSparseGraph in a undirected way. 我正在寻找一种以无向方式计算directedSparseGraph的每个节点的程度的方法。 unfortunately the .degree method give me the sum of indegree and outdegree of each node. 不幸的是, .degree方法给了我每个节点的度数和度数之和。 Assume directed graph G={(A,B),(B,A),(C,D),(D,A)} . 假设有向图G={(A,B),(B,A),(C,D),(D,A)} I want to calculate undirected degree for this graph. 我想计算该图的无向度。 In this case it would be:A=2, B=1, C=1, D=2. 在这种情况下,它将是:A = 2,B = 1,C = 1,D = 2。

Regards. 问候。

I figure it out myself. 我自己弄清楚。 This can be done by using .getNeighborCount() method. 这可以通过使用.getNeighborCount()方法来完成。 This method can calculate degree of each node in undirected way. 该方法可以无方向地计算每个节点的度。

FYI, the degree of the node is the number of incident edges. 仅供参考,节点的度数是入射边的数量。 The number of neighbors is the number of nodes which are connected by a single edge. 邻居数是通过单个边缘连接的节点数。 In the case of your example these should be identical; 在您的示例中,这些应该相同; you only start getting discrepancies in the case of parallel or antiparallel edges, or self loops. 您只有在出现平行或反平行边缘或自环的情况下才开始出现差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM