networking - 网络 X:考虑网络指标中节点的权重,例如中介中心性
问题描述
我最近开始使用网络 X 并遇到以下问题。
我有一个加权图:
- 这些节点具有不同的大小,因为它们代表在办公室工作的人数。
- 办公室通过加权边相互关联,加权边表示办公室之间的距离(从一个部门到另一个部门需要多长时间)。
我想知道,复印机放在哪个办公室(哪个节点)。为了做到这一点,我想使用中介中心性和接近中心性的网络指标。
问题:应用指标并不困难。但是,它们只考虑边缘的重量(距离),而不是办公室工作的人数。这当然要考虑到,否则复印机会放在一个办公室里,这个办公室离其他办公室很近,而且有很多最短的路径,但是所有旅行的人的总距离会太远。
作为一种解决方案,我想将办公室节点细分为代表员工的节点。因此,在同一个办公室工作的人与一个权重为零的边链接(他们基本上是堆叠的),而每个员工也与其他办公室的员工有链接。基于这个新图表,我现在可以计算指标。
但是,我不确定这在数学上是否正确,以及我现在如何将员工网络指标转换回办公室网络指标。
感谢你的帮助!
请在下面找到带有代码的示例:
概念在这里,您可以在括号中看到 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,21, weight =3)
G.add_edge(21,31, weight =2)
G.add_edge(31,51, weight =4)
G.add_edge(21,41, weight =1)
G.add_edge(41,51, 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,24, 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,23, weight =3)
G.add_edge(21,24, weight =3)
G.add_edge(21,31, weight =2)
G.add_edge(22,31, weight =2)
G.add_edge(23,31, weight =2)
G.add_edge(24,31, weight =2)
G.add_edge(21,32, weight =2)
G.add_edge(22,32, weight =2)
G.add_edge(23,32, weight =2)
G.add_edge(24,32, weight =2)
G.add_edge(31,51, weight =4)
G.add_edge(32,51, weight =4)
G.add_edge(31,52, weight =4)
G.add_edge(32,52, weight =4)
G.add_edge(21,41, weight =1)
G.add_edge(41,51, weight =5)
G.add_edge(41,52, weight =5)
nx.draw_networkx(G)
#Calculate the weighted closeness centrality,
CCW_new = nx.closeness_centrality(G, u=None, distance='weight', 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,21, weight=3)
G.add_edge(21,31, weight=2)
G.add_edge(31,51, weight=4)
G.add_edge(21,41, weight=1)
G.add_edge(41,51, 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
.
推荐阅读
- python - 用范围内的随机数填充矩阵?
- android - Expo 网络响应超时,无法在 Android 模拟器上运行 Expo 应用
- c - 如何让两个并发线程监听一个输入?
- reactjs - 使 localStorage 在 React 中的页面刷新时保留其内容
- django - Django-forms:提高 forms.ValidationError 不起作用
- python - 如何将连续数据从 Matlab 套接字客户端发送到 C 套接字服务器?
- java - 添加两个以反向链表形式存储的数字
- vue.js - 如何使组件内的按钮更改 vue 路由器路径
- c - 分配的内存 - 带有数组的结构已经分配
- css - 网格表单元格在 reStructuredText 中使用 Sphinx 对齐不正确 阅读文档主题