n 個のノードで構成されるグラフ G を通過したいと考えていました。そして、n 番目のノードごとに、その隣接ノードの dict を開きます。最大の数値属性を持つ近傍を見つけます。少なくとも 100 のネイバーが存在する可能性があります。そして、各ノードとその最大の隣接ノードのリストを返します。
[node,biggestneighbor]
[node,biggestneighbor]
[node,biggestneighbor]
ノードの属性データは次のようになります。
G.node[0]
{'type': 'a', 'pos': [0.76, 0.11]}
そして私が興味を持っている属性は
G.node[0]['pos'][0]
0.76
これが存在するかどうか誰かが知っていますか?または、そうでない場合、開始ロジックは適切な開始点のように見えますか? それとも頭の良い人ほど優れたアイデアを持っているのでしょうか?
def thebiggestneighbor(G,attribute,nodes=None):
if nodes is None:
node_set = G
else:
node_set = G.subgraph(nodes)
node=G.node
for u,nbrsdict in G.adjacency_iter():
if u not in node_set:
continue
for v,eattr in nbrsdict.items():
vattr=node[v].get(attribute,None)
# then something like this but for many nodes. probably better subtraction
# of all nodes from each other and which one yeilds the biggest numner
#
# if x.[vattra] > x.[vattrb] then
# a
# elif x.[vattra] < x.[vattrb] then
# b
yield (u,b)