I want to select and print a walk of three nodes in a highly interconnected network. Starting with a given node, the function should select as a second node for the walk that adjacent node with the highest degree centrality.
In the case of a tie, I want to have the programme randomly select between these nodes.
Here's what I have so far:
import networkx as nx
from random import choice
g =nx.Graph()
g.add_nodes_from(range(1,5))
g.add_edges_from([(1,5),(2,5),(3,5),(4,5), (1,2),(2,3),(3,4),(4,5)])
nx.set_node_attributes(g,'degree_cent',nx.degree_centrality(g))
degree_walk =[]
node1=g.nodes()[2]
degree_walk.append(node1)
for node2 in g.neighbors(node1):
if max(g.node[node2]['degree_cent'], g.node[node2]['degree_cent'].get):
node2 = choice(g.neighbors(node1))
degree_walk.append(node2)
print degree_walk