-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
54 lines (43 loc) · 1.57 KB
/
agent.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
class Agent(object):
def __init__(self, vertex, initial_state, identification = None):
self.graph_vertex = vertex
self.states = initial_state;
self.neighbors = list()
#used to prevent having to call len() on the neighbors list:
self.neighbor_count = 0
self.identification = identification
def changeState(self, new_state):
self.states = new_state
def getState(self):
return self.states
def addNeighbor(self,agent):
self.neighbor_count += 1
self.neighbors.append(agent)
def getNeighbors(self):
return self.neighbors
def validateNeighbor(self, agent):
if agent in self.neighbors:
return True
else:
return False
'''
not sure what to name this method. Essentially is a validator or will retreive
an agent at a defined numeric index.
The simulator will use this method to retreive a random neighbor of an agent.
'''
def getNeighbor(self,agent):
if type(agent) == int:
#validate range, return at index
if agent < len(self.neighbors):
return self.neighbors[agent]
else:
#perhaps throw an error
return False
elif type(agent) == Agent:
return self.validateNeighbor(agent)
def getNeighborCount(self):
return self.neighbor_count
def getIdentification(self):
return self.identification
def getVertex(self):
return self.graph_vertex