Ağ geçidini Python 3.4 ile kullanıyorum ve erişilebilen düğümleri bulmaya çalıştığımda tuhaf bir hata alıyorum. Sanırım daha önce belirlediğim düğümlerin isteğe bağlı bir özelliği ile ilgili bir şey var.Düğümlerin etiketleri varken networx.descendants() hatası
: Ben etiketi 'olaylar' set zaman çizgileri yorum yaparsanız ben beklenen sonucu elde,Now computing nodes reachable from "A"...
Traceback (most recent call last):
File "exampleStackOverflow.py", line 17, in <module>
reachableNodes = nx.descendants(G, "A")
File "/usr/local/lib/python3.4/dist-packages/networkx/algorithms/dag.py", line 42, in descendants
des = set(nx.shortest_path_length(G, source=source).keys()) - set([source])
File "/usr/local/lib/python3.4/dist-packages/networkx/algorithms/shortest_paths/generic.py", line 239, in shortest_path_length
paths=nx.single_source_shortest_path_length(G,source)
File "/usr/local/lib/python3.4/dist-packages/networkx/algorithms/shortest_paths/unweighted.py", line 63, in single_source_shortest_path_length
nextlevel.update(G[v]) # add neighbors of v
File "/usr/local/lib/python3.4/dist-packages/networkx/classes/graph.py", line 407, in __getitem__
return self.adj[n]
KeyError: 'occurrences'
Şimdi:
import networkx as nx
G = nx.Graph()
nodes = ["A", "B", "C", "D", "E"]
G.add_nodes_from(nodes)
G.add_edge("A", "B")
G.add_edge("A", "C")
G.add_edge("A", "D")
G.add_edge("B", "E")
for node in nodes :
G[node]['occurrences'] = 1
print("Now computing nodes reachable from \"A\"...")
reachableNodes = nx.descendants(G, "A")
print("List of reachable nodes:", reachableNodes)
çıktısı: Bu minimal kod hatası çoğaltır
Now computing nodes reachable from "A"...
List of reachable nodes: {'B', 'D', 'C', 'E'}
Yanlış bir şey yapıyorum?
Çok kullanışlıdır. İlgili dokümanlar için herhangi bir bağlantı var mı? – Gerrat
İlgili ağ geçidi eğitim bölümüne bir bağlantı ekledim. – Aric