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
I get this result:
[1293856L, 909760L]
[1293856L, 909730L]
[1293856L, 909797L]
[1293856L, 909767L]
[1293856L, 909741L]
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]
what am I doing wrong?
EDIT:
what I was looking for was nx.connected_components(graph)
instead of nx.find_cliques(graph)