我想找到不的边缘连接它们的所有可能的节点对,然后检查这些节点对是否在另一个图中有边缘。有什么建议吗?
答案 0 :(得分:2)
如果您不关心表现,那么您可以尝试:
g1Edges = Graph1.edges()
notG1Edges = set()
for a in Graph1.nodes():
for b in Graph1.nodes():
if a != b and (a,b) not in g1Edges:
notG1Edges.add( (a, b) )
# print edges missed in Graph1 and Graph2
print notG1Edges.difference( Graph2.edges_iter() )
注1:这是针对有向图
注2:如果你想从Graph2中找不到Graph1中边缘的子集,那么假设最好在Graph2的边缘上操作