Finding cycle of 3 nodes ( or triangles) in a graph

后端 未结 11 2146
南旧
南旧 2020-12-31 15:42

I am working with complex networks. I want to find group of nodes which forms a cycle of 3 nodes (or triangles) in a given graph. As my graph contains about million edges, u

11条回答
  •  Happy的楠姐
    2020-12-31 16:21

    i just found that nx.edge_disjoint_paths works to count the triangle contains certain edges. faster than nx.enumerate_all_cliques and nx.cycle_basis. It returns the edges disjoint paths between source and target.Edge disjoint paths are paths that do not share any edge.
    And result-1 is the number of triangles that contain certain edges or between source node and target node.

    edge_triangle_dict = {}
    for i in g.edges:
        edge_triangle_dict[i] = len(list(nx.edge_disjoint_paths(g, i[0], i[1]))-1)
    

提交回复
热议问题