-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensor.py
47 lines (37 loc) · 1.24 KB
/
sensor.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
'''
Module for class Sensor
'''
class Sensor:
'''Encapsulate a sensor
Attributes:
x (int): location - first dimension
y (int): location - second dimension
std(float): each sensor has a standard deviation for receiving signals
cost (int): each sensor has a engery cost, defualt value is 1
gain_up_bound (float): upper bound of gain, gain: in context of submodular
index (int): a sensor will have an index, like it's ID
'''
def __init__(self, x, y, std, cost=1, gain_up_bound=0, index=0):
self.x = x
self.y = y
self.std = std
self.cost = cost
self.gain_up_bound = gain_up_bound
self.index = index
def __str__(self):
return "(%d, %d, %f, %d)" % (self.x, self.y, self.gain_up_bound, self.index)
def output(self):
'''Output into files
'''
return "%d %d %f\n" % (self.x, self.y, self.std)
def __lt__(self, other):
'''Override the less than method and turn it into 'more than'
'''
return self.gain_up_bound > other.gain_up_bound
def main():
'''Main
'''
sensor = Sensor(1, 3, 2.0, gain_up_bound=1.2, index=0)
print(sensor)
if __name__ == '__main__':
main()