2012-06-13 61 views

回答

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:這是一個有向圖

NOTE2:如果你想從Graph2找到邊緣的子集,不存在在Graph1然後假設它最好在Graph2的邊緣上操作

+0

你能幫我解決我正在處理的圖嗎不是直接的...我想要得到具有邊緣的圖的補充...直觀地我會在所有沒有優勢的節點中獲得優勢......但似乎無法獲得正確的代碼...可以幫助我解決這個問題... – irfanbukhari

+0

發佈您的一些代碼,並且有人可能會告訴您爲什麼它不起作用。 –