如何为图的顶点分配固定的资源而低度的顶点得到更多?

时间:2019-11-21 10:48:49

标签: math graph

我有一个简单的问题要解决,但是我遇到了麻烦,需要您的帮助。问题如下:

我有三个节点A,B,C,其度数为11, 6, 1,我有20个资源可根据其度数分配给每个节点。我知道当我希望大型节点获得更多资源时,公式为:

just sum all degrees (11+6+1)=18 and distribute the resources as follows:
A=(20/18)*11 and similar for the other nodes

如果我希望低度节点获得比大度节点更多的资源怎么办?我的意思是,等级1的Node C比节点A和B获得更多的资源。

我尝试过:

A = (20/18)* (11)^r

例如,当r=1时,更大的学位将拥有更多的资源。但是反之则不正确,例如当r=-1时,总资源将不等于20。该怎么办?

对于相同的公式,是否可以插入r的不同值并给出低度和高度结果?

非常感谢您的帮助,谢谢您

1 个答案:

答案 0 :(得分:0)

如果至少有2个节点,则可能是r=0来获取更多资源以达到最高程度,或者r=1来获取更多资源来达到最低程度:

(degree_sum*r - nodes[n]) * resources / ((num_nodes*r - 1) * degree_sum)

简而言之,对于r=1,公式将是按“所有度的总和减去当前节点的度”的比例给出每个节点(其中nodes[n]为当前节点的度):

(degree_sum - nodes[n]) * resources / ((num_nodes - 1) * degree_sum)
So, this would give:
A: (18 - 11) * 20 / (2 * 18)
B: (18 -  6) * 20 / (2 * 18)
C: (18 -  1) * 20 / (2 * 18)

这是一个使用Python的演示程序来演示这个想法:

nodes = {'A': 11, 'B': 6, 'C': 1}
resources = 20

degree_sum = sum(nodes[n] for n in nodes)
num_nodes = len(nodes)
print("sum of all degrees:", degree_sum, "- number of nodes", num_nodes)

distribution_highest_more = {n: nodes[n] * resources / degree_sum for n in nodes}
print("higher degrees get more:", distribution_highest_more)
print("  total:", sum(distribution_highest_more[n] for n in distribution_highest_more))

distribution_lowest_more = {n: (degree_sum - nodes[n]) * resources / ((num_nodes - 1) * degree_sum) for n in nodes}
print("lower degrees get more:", distribution_lowest_more)
print("  total:", sum(distribution_lowest_more[n] for n in distribution_lowest_more))

for r in range(2):
    distribution = {n: (degree_sum*r - nodes[n]) * resources / ((num_nodes*r - 1) * degree_sum) for n in nodes}
    print("distribution for r =", r, ":")
    print("  ", distribution)
    print("  total:", sum(distribution[n] for n in distribution))

哪些印刷品:

sum of all degrees: 18 - number of nodes 3
higher degrees get more: {'A': 12.222222222222221, 'B': 6.666666666666667, 'C': 1.1111111111111112}
  total: 20.0
lower degrees get more: {'A': 3.888888888888889, 'B': 6.666666666666667, 'C': 9.444444444444445}
  total: 20.0
distribution for r = 0 :
   {'A': 12.222222222222221, 'B': 6.666666666666667, 'C': 1.1111111111111112}
  total: 20.0
distribution for r = 1 :
   {'A': 3.888888888888889, 'B': 6.666666666666667, 'C': 9.444444444444445}
  total: 20.0