我正在研究一种简单的指数退避算法,我想知道我的结果是否正确。以下是假设:
有N个站
每个电台有1个要发送的数据包
最初,所有电台都尝试发送时隙0
当两个或多个电台想要在同一时段发送其帧时发生冲突(因此所有电台的帧在第一轮中发生碰撞)
当发生冲突时,工作站使用指数退避功能计算其等待时间(即,在c冲突之后,它将等待从0到2 ^ c - 1的随机数量的时隙)
我用Java编码。以下是使用10个站点的运行结果:
Slot 0: Station 0 Station 1 Station 2 Station 3 Station 4 Station 5 Station 6 Station 7 Station 8 Station 9 Slot 1: Slot 2: Slot 3: Slot 4: Slot 5: Slot 6: Slot 7: Slot 8: Slot 9: Slot 10: Slot 11: Slot 12: Slot 13: Slot 14: Slot 15: Slot 16: Slot 17: Slot 18: Slot 19: Slot 20: Slot 21: Slot 22: Slot 23: Slot 24: Slot 25: Slot 26: Slot 27: Slot 28: Slot 29: Slot 30: Slot 31: Slot 32: Slot 33: Slot 34: Slot 35: Slot 36: Slot 37: Slot 38: Slot 39: Slot 40: Slot 41: Slot 42: Slot 43: Slot 44: Slot 45: Slot 46: Slot 47: Slot 48: Slot 49: Collisions in round 1: Station 0 Station 1 Station 2 Station 3 Station 4 Station 5 Station 6 Station 7 Station 8 Station 9 Slot 0: Slot 1: Station 1 Station 3 Station 5 Station 6 Slot 2: Station 0 Station 2 Station 4 Station 7 Station 8 Station 9 Slot 3: Slot 4: Slot 5: Slot 6: Slot 7: Slot 8: Slot 9: Slot 10: Slot 11: Slot 12: Slot 13: Slot 14: Slot 15: Slot 16: Slot 17: Slot 18: Slot 19: Slot 20: Slot 21: Slot 22: Slot 23: Slot 24: Slot 25: Slot 26: Slot 27: Slot 28: Slot 29: Slot 30: Slot 31: Slot 32: Slot 33: Slot 34: Slot 35: Slot 36: Slot 37: Slot 38: Slot 39: Slot 40: Slot 41: Slot 42: Slot 43: Slot 44: Slot 45: Slot 46: Slot 47: Slot 48: Slot 49: Collisions in round 2: Station 0 Station 1 Station 2 Station 3 Station 4 Station 5 Station 6 Station 7 Station 8 Station 9 Slot 0: Slot 1: Slot 2: Station 3 Slot 3: Station 0 Station 2 Station 4 Station 6 Slot 4: Station 1 Station 8 Station 9 Slot 5: Station 5 Station 7 Slot 6: Slot 7: Slot 8: Slot 9: Slot 10: Slot 11: Slot 12: Slot 13: Slot 14: Slot 15: Slot 16: Slot 17: Slot 18: Slot 19: Slot 20: Slot 21: Slot 22: Slot 23: Slot 24: Slot 25: Slot 26: Slot 27: Slot 28: Slot 29: Slot 30: Slot 31: Slot 32: Slot 33: Slot 34: Slot 35: Slot 36: Slot 37: Slot 38: Slot 39: Slot 40: Slot 41: Slot 42: Slot 43: Slot 44: Slot 45: Slot 46: Slot 47: Slot 48: Slot 49: Collisions in round 3: Station 0 Station 1 Station 2 Station 4 Station 5 Station 6 Station 7 Station 8 Station 9 Slot 0: Slot 1: Slot 2: Station 3 Slot 3: Slot 4: Slot 5: Station 6 Slot 6: Slot 7: Station 9 Slot 8: Station 0 Slot 9: Station 1 Station 4 Slot 10: Station 8 Slot 11: Station 2 Slot 12: Station 7 Slot 13: Station 5 Slot 14: Slot 15: Slot 16: Slot 17: Slot 18: Slot 19: Slot 20: Slot 21: Slot 22: Slot 23: Slot 24: Slot 25: Slot 26: Slot 27: Slot 28: Slot 29: Slot 30: Slot 31: Slot 32: Slot 33: Slot 34: Slot 35: Slot 36: Slot 37: Slot 38: Slot 39: Slot 40: Slot 41: Slot 42: Slot 43: Slot 44: Slot 45: Slot 46: Slot 47: Slot 48: Slot 49: Collisions in round 4: Station 1 Station 4 Slot 0: Slot 1: Slot 2: Station 3 Slot 3: Slot 4: Slot 5: Station 6 Slot 6: Slot 7: Station 9 Slot 8: Station 0 Slot 9: Slot 10: Station 8 Slot 11: Station 2 Slot 12: Station 7 Slot 13: Station 5 Slot 14: Station 1 Slot 15: Slot 16: Slot 17: Slot 18: Slot 19: Slot 20: Slot 21: Slot 22: Slot 23: Station 4 Slot 24: Slot 25: Slot 26: Slot 27: Slot 28: Slot 29: Slot 30: Slot 31: Slot 32: Slot 33: Slot 34: Slot 35: Slot 36: Slot 37: Slot 38: Slot 39: Slot 40: Slot 41: Slot 42: Slot 43: Slot 44: Slot 45: Slot 46: Slot 47: Slot 48: Slot 49: Collisions in round 5: No collisions! Total number of collisions: 77 Station 0 sent at time slot 8 with 3 collisions. Station 1 sent at time slot 14 with 4 collisions. Station 2 sent at time slot 11 with 3 collisions. Station 3 sent at time slot 2 with 2 collisions. Station 4 sent at time slot 23 with 4 collisions. Station 5 sent at time slot 13 with 3 collisions. Station 6 sent at time slot 5 with 3 collisions. Station 7 sent at time slot 12 with 3 collisions. Station 8 sent at time slot 10 with 3 collisions. Station 9 sent at time slot 7 with 3 collisions.
这看起来不错吗?我似乎无法找到使用此功能的N站的平均碰撞次数,所以我不确定我是否搞砸了。非常感谢任何帮助。
答案 0 :(得分:1)
一个电台可以尝试在一个时隙中多次发送,这似乎很奇怪。在我看来,退避值应该是电台跳过的时隙数。因此,如果站A在时间段1发生冲突并且选择跳过0个时隙,则它将被安排在时隙2处再次发送。它不会尝试在同一时隙期间重新发送。
这更有意义。一个电台在一个时段内最多可以尝试一次发送。
因此,如果每个人都试图在时隙0发送,他们都会发生冲突并选择跳过从0到2 ^ i-1(其中i是当前时隙)的随机数量的时隙。因为2 ^ i-1是0,所以他们都会尝试在时隙1发送。
平均,其中一半将尝试在时隙2期间发送,一半将尝试在时隙3期间发送。假设奇数站选择不跳过,并且均匀 - 编号的站都跳过了一个插槽。在时间段1结束时,您的州看起来像这样:
slot stations
2 1, 3, 5, 7, 9
3 2, 4, 6, 8, 10
在时段2期间也会发生冲突。每个站将选择跳过0,1,2或3个时隙。在时间段2之后,您的状态将类似于:
slot stations
3 1, 2, 4, 6, 8, 10
4 3, 7
5 9
6 5
由于时隙3中的冲突,这六个站将在时隙4到10之间展开(选择跳过0到7个时隙)。我会让你建立相应的状态。
最终,您将到达当前时段有一个站点的位置,然后该站点可以发送。
如果以这种方式考虑问题,调试代码变得更加容易,因为您可以构建表并在每个时间段结束时显示状态。这将告诉您是否正确选择了退避值,以及是否根据所选的退避值正确安排了工作站。