我试图计算一个非常大的图中几个节点的中间性。我一直在用NetworkX。问题是它不能让我选择需要中心化的节点。我试图修改源代码,但它给了我错误。以下是我所做的:betweenness = dict.fromkeys(G, 0.0) # b[v]=0 for v in G
if k is None:
nodes = G
#nodes = nx.Graph()
#for indx in range(0, G.size()):
#if indx in subset:
#nodes.add_node(allNodes[indx])
else:
random.seed(seed)
nodes = random.sample(G.nodes(), k)
for s in nodes:
n = nodes.nodes().index(s)
if n in subset:
# single source shortest paths
if weight is None: # use BFS
S, P, sigma = _single_source_shortest_path_basic(G, s)
else: # use Dijkstra's algorithm
S, P, sigma = _single_source_dijkstra_path_basic(G, s, weight)
# accumulation
if endpoints:
betweenness = _accumulate_endpoints(betweenness, S, P, sigma, s)
else:
betweenness = _accumulate_basic(betweenness, S, P, sigma, s)
# rescaling
betweenness = _rescale(betweenness, len(interCommNodes),
normalized=normalized,
directed=G.is_directed(),
k=k)
return betweenness
子集包含原始图中的所有节点索引。虽然“index”似乎是一个无效函数,我无法找到获取它的方法。在
有人能看看这个吗?在
谢谢!在