对象出现在多个图组中 [英] object appears in multiple graph cliques

查看:80
本文介绍了对象出现在多个图组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码本来可以找到节点组,而节点是Django模型对象的ID:

I have a piece of code that supposed to find cliques of nodes, while nodes are ids of django model objects:

    import networkx as nx
    final_groups = []
    graph = nx.Graph()
    for img_test in Same_Img_Test.objects.filter(id__in=test_ids, is_same=1):
        graph.add_edge(img_test.product_1.id, img_test.product_2.id)
    for x in nx.find_cliques(graph):
        final_groups.append(x)
        print x

我得到这个结果:

[1293856L, 909760L]
[1293856L, 909730L]
[1293856L, 909797L]
[1293856L, 909767L]
[1293856L, 909741L]

我的问题ID:同一ID(1293856L)如何在多个集团中出现? 结果不应该是这样的:

my question id: how same id (1293856L) can occur in multiple cliques? isn't the result supposed to be something like:

[1293856L, 909760L, 909730L, 909797L, 909767L, 909741L]

我在做什么错了?

我要找的是nx.connected_components(graph)而不是nx.find_cliques(graph)

what I was looking for was nx.connected_components(graph) instead of nx.find_cliques(graph)

推荐答案

是的,相同的ID可以出现在多个集团中(相同大小或不同大小).

Yes, same ID can be present in multiple cliques (of same size or different size).

我认为您只显示了大小为2的集团,可能是您期望的输出在下面.

I think that you are showing just the cliques of size 2, may be your expected output would be there in down below.

[1293856L, 909760L, 909730L, 909797L, 909767L, 909741L]才会作为集团之一出现.

[1293856L, 909760L, 909730L, 909797L, 909767L, 909741L] would come out as one of the clique only when each pair of these ID has an edge between them in the given graph.

这篇关于对象出现在多个图组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆