-
Notifications
You must be signed in to change notification settings - Fork 0
/
WSNnode.py
96 lines (74 loc) · 1.6 KB
/
WSNnode.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class WSNnode():
def __init__(self,myid):
if myid==0:
self.id="A"
elif myid==1:
self.id="B"
elif myid==2:
self.id="C"
elif myid==3:
self.id="D"
elif myid==4:
self.id="E"
elif myid==5:
self.id="F"
elif myid==6:
self.id="G"
self.uncov=0
self.first_uncovered_value=1
self.dom=0
self.IsInDS=0
self.num_of_neighbors=0
self.isDSprevious=0
self.energy=0.0
self.neighbors=[]
def getID(self):
return self.id
def isMyNeighbor(self,id):
neighbor_found=0
for i in range(len(self.neighbors)):
if (self.neighbors[i].getID()==id):
neighbor_found=1
break
#endif
#endfor
if(neighbor_found==1):
return 1
#endif
else:
return 0
#endelse
def getEnergy(self):
return self.energy
def getUncovered(self):
return self.uncov
def getDom(self):
return self.dom
def getIsInDS(self):
return self.IsInDS
def getNumOfNeighbors(self):
return self.num_of_neighbors
def getFirstUncovered(self):
return self.first_uncovered_value
def setID(self,id):
self.id=id
def setEnergy(self,enrg):
self.energy=enrg
def setFirstUncoveredVal(self,val):
self.first_uncovered_value=val
def setUncovered(self,uncov):
self.uncov=uncov
def setDom(self,dom):
self.dom=dom
def setIsInDS(self,val):
self.IsInDS=val
def addToNeighbors(self,node):
self.neighbors.append(node)
self.num_of_neighbors = self.num_of_neighbors + 1
self.first_uncovered_value = self.first_uncovered_value +1
def IncDomVal(self):
self.dom = self.dom + 1
def setIsDSprevious(self,val):
self.isDSprevious=val
def getDSprevious(self):
return self.isDSprevious