wsngenerator.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:rpl-attacks 作者: dhondta 项目源码 文件源码
def _malicious():
    """
    This function places the malicious mote in the middle of the network, not too close by the root.
    """
    global min_range, motes
    # add the malicious mote in the middle of the network
    # get the average of the squared x and y deltas
    avg_x = average([sign(m['x']) * m['x'] ** 2 for m in motes])
    x = sign(avg_x) * sqrt(abs(avg_x))
    avg_y = average([sign(m['y']) * m['y'] ** 2 for m in motes])
    y = sign(avg_y) * sqrt(abs(avg_y))
    # if malicious mote is too close by the root, just push it away
    radius = sqrt(x ** 2 + y ** 2)
    if radius < min_range:
        angle = arccos(x / radius)
        x, y = min_range * cos(angle), min_range * sin(angle)
    return {'id': len(motes), 'type': 'malicious', 'x': x, 'y': y, 'z': 0}


# ************************************** NETWORK GENERATION FUNCTIONS ****************************************
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号