本文整理汇总了Python中Sink.Sink.reached_target方法的典型用法代码示例。如果您正苦于以下问题:Python Sink.reached_target方法的具体用法?Python Sink.reached_target怎么用?Python Sink.reached_target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sink.Sink
的用法示例。
在下文中一共展示了Sink.reached_target方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Sink import Sink [as 别名]
# 或者: from Sink.Sink import reached_target [as 别名]
#.........这里部分代码省略.........
node = Node(pos, duty_cycle)
node.start()
self.nodes.append(node)
def define_sink_route(self, sink_route, speed_sink):
if len(sink_route) < 2:
raise Exception('Esperado, ao menos, lista com duas listas contendo posição inicial e destino')
init_sink_position = sink_route[0]
del sink_route[0]
target_sink_position = (sink_route[0])
del sink_route[0]
self.sink = Sink(init_sink_position, speed_sink, target_sink_position)
self.sink_route = sink_route
def check_nodes_in_sink_radius(self, clock):
packets_transmitted = 0
packets_lost = 0
nodes_founds = []
nodes_lost = []
more_energy = [0, None]
more_close = [self.transmission_range + 1, None]
for node in self.nodes:
node_on = node.wait_beacon(clock)
if self.strategy == Environment.DUTY_CICLE:
if not node_on:
continue
x = node.position[0] - self.sink.position[0]
y = node.position[1] - self.sink.position[1]
distance = sqrt(x ** 2 + y ** 2)
if distance <= self.transmission_range:
nodes_founds.append(node.id)
if node.energy < Node.cost_send_package:
nodes_lost.append(node.id)
else:
if more_energy[0] < node.energy:
more_energy[0] = node.energy
more_energy[1] = node
if more_close[0] > distance:
more_close[0] = distance
more_close[1] = node
if self.strategy == Environment.ENERGY:
if more_energy[0] >= Node.cost_send_package:
if more_energy[1].package_transmission():
packets_transmitted += 1
packets_lost = len(nodes_founds) - len(nodes_lost) - 1
else: # self.strategy == Environment.NEAR:
if more_close[0] <= self.transmission_range:
if more_close[1].package_transmission():
packets_transmitted += 1
packets_lost = len(nodes_founds) - len(nodes_lost) - 1
def check_environment(self):
packets_lost = 0
sink_pos = self.sink.position
nodes_founds = []
Node.sink_position = self.sink.position # atualiza posição do sink
Node.environment.append(Node.BEACON)
nodes_in_radius = 0
for node in Node.environment:
if type(node) == Node:
x = node.position[0] - sink_pos[0]
y = node.position[1] - sink_pos[1]
distance = sqrt(x ** 2 + y ** 2)
if distance <= self.transmission_range:
nodes_founds.append(node.id)
nodes_in_radius += 1
debug('Nó ' + str(node.id) + ' encontrado pelo Sink')
if nodes_in_radius > 1:
packets_transmitted = 0
packets_lost = nodes_in_radius
else:
packets_transmitted = nodes_in_radius
Node.environment.remove(Node.BEACON)
self.sink.reached_target() # movimentação do sink
if self.sink.in_target and len(self.sink_route):
self.sink.update_target(self.sink_route[0])
del self.sink_route[0]
return packets_transmitted, packets_lost, nodes_founds, Node.nodes_discharged
def end_sink_turn(self):
if len(self.sink_route) == 0 and self.sink.in_target:
return True
else:
return False
def energy_network_level(self):
energy = 0
for node in self.nodes:
energy += node.energy
return energy
def nodes_lost(self):
return len(Node.nodes_discharged)
def finalize(self):
Node.is_run = False
sleep(0.01)