-
Notifications
You must be signed in to change notification settings - Fork 0
/
Network_Method.py
46 lines (40 loc) · 1018 Bytes
/
Network_Method.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
from Package import Package
def uniform_com_func(net):
"""
communicate function
:param net:
:return:
"""
for node in net.node:
if node.id in net.target and random.random() <= node.prob and node.is_active:
package = Package()
node.send(net, package)
# print(package.path)
return True
def to_string(net):
"""
print information of network
:param net:
:return:
"""
min_energy = 10 ** 10
min_node = -1
for node in net.node:
if node.energy < min_energy:
min_energy = node.energy
min_node = node
min_node.print_node()
def count_package_function(net):
"""
count the number of package which can go to base
:param net:
:return:
"""
count = 0
for target_id in net.target:
package = Package(is_energy_info=True)
net.node[target_id].send(net, package)
if package.path[-1] == -1:
count += 1
return count