网络 X:考虑网络指标中节点的权重,例如中介中心性

问题描述

我最近开始使用网络 X 并遇到以下问题。

我有一个加权图:

  • 节点具有不同的大小,因为它们代表在办公室工作的人数。
  • 办公室通过加权边相互连接,加权边代表办公室之间的距离(从一个部门到另一个部门需要多长时间)。

我想知道,在哪个办公室(哪个节点)放置复印机。为此,我想使用中介中心性和密切中心性的网络指标。

问题: 应用这些指标并不困难。然而,他们只考虑边缘的重量(距离),而不考虑在办公室工作的人数。这当然应该考虑到,否则复印机将被放置在办公室,该办公室距离其他办公室非常近,并且在许多最短路径上,但所有人员旅行的总距离会太多。

作为一个解决方案,我想将办公室节点细分为代表员工的节点。因此,在同一个办公室工作的人用权重为零的边链接(他们基本上是堆叠的),而每个员工也与其他办公室的员工有链接。根据这个新图表,我现在可以计算指标。

但是,我不确定这在数学上是否正确,以及我现在如何将员工网络指标转换回办公室网络指标。

感谢您的帮助!

请在下面找到带有代码的示例:

Concept 在这里你可以看到 5 个不同权重的节点在括号中。

import networkx as nx

#Generate example graph with 5 nodes
G = nx.Graph()
G.add_nodes_from([11,21,31,41,51])

#Office-graph
G.add_edge(11,weight =3)
G.add_edge(21,weight =2)
G.add_edge(31,51,weight =4)
G.add_edge(21,weight =1)
G.add_edge(41,weight =5)
nx.draw_networkx(G)

#Calculate the weighted closeness centrality,CCW = nx.closeness_centrality(G,u=None,distance='weight',wf_improved=True)
CCW

#devide nodes into subnodes with weight of 1
G.add_node(22)
G.add_node(23)
G.add_node(24)
G.add_node(32)
G.add_node(52)

#add respective edges
G.add_edge(22,23,weight =0)
G.add_edge(22,24,weight =0)
G.add_edge(23,weight =0)


G.add_edge(31,32,weight =0)
G.add_edge(51,52,weight =0)


G.add_edge(21,22,weight =3)


G.add_edge(21,weight =2)
G.add_edge(22,weight =2)
G.add_edge(23,weight =2)
G.add_edge(24,weight =2)

G.add_edge(21,weight =2)

G.add_edge(31,weight =4)
G.add_edge(32,weight =4)

G.add_edge(31,weight =4)

G.add_edge(21,weight =1)

G.add_edge(41,weight =5)
G.add_edge(41,weight =5)

nx.draw_networkx(G)

#Calculate the weighted closeness centrality,CCW_new = nx.closeness_centrality(G,wf_improved=True)
CCW1_new

解决方法

正如我在上面的评论中所说的,在我看来,您希望尽量减少到复印机的总距离。鉴于图表的性质,我更喜欢一个简单的、蛮力的解决方案。这是我的方法:

import networkx as nx

from itertools import combinations

#Generate example graph with 5 nodes
G = nx.Graph()
G.add_nodes_from([11,21,31,41,51])

#Office-graph
G.add_edge(11,weight=3)
G.add_edge(21,weight=2)
G.add_edge(31,51,weight=4)
G.add_edge(21,weight=1)
G.add_edge(41,weight=5)

# let's make sure we know the correct answer by assigning one office 99% of the workforce
office_to_people = {11: 5,21: 2,31: 1000,41:0,51:10}

node_to_cost = {ii : 0 for ii in G.nodes}
for source,target in combinations(list(G.nodes),2):
    path_length = nx.shortest_path_length(G,source,target,weight='weight')
    node_to_cost[source] += office_to_people[target] * path_length
    node_to_cost[target] += office_to_people[source] * path_length

office,minimum_cost = sorted(node_to_cost.items(),key=lambda x: x[1])[0]
print(f"{office}")
# 31 

如果您想考虑非统一复印机的使用,则可以通过简单地计算每个办公室的复印机总使用量,并将 office_to_people 替换为等效的 office_to_total_use .

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...