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 ****************************************
评论列表
文章目录