-
Notifications
You must be signed in to change notification settings - Fork 0
/
agents.py
70 lines (53 loc) · 1.62 KB
/
agents.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
"""
Akshay Mohabey
Python 3.12.4
Mac OSX
19 July 2024
Network Game
Agents File
"""
# Importing Dependencies
import mesa
import parameters as p
import random
import functions as f
import copy
# Agent Class
class People(mesa.Agent):
def __init__(self,unique_ID, model):
# Initialize Parent Class
super().__init__(unique_ID,model)
self.ID = unique_ID
self.state = random.choice(range(p.num_states))
self.incoming_connections = []
self.outgoing_connections = []
# Print Agent ID & State
# print(f'Agent{self.ID} | State {self.state}')
# @property
def return_ID(self):
return self.ID
# @property
def return_state(self):
return self.state
# Connection setter
def set_connections(self,connection_list):
self.incoming_connections = copy.copy(connection_list)
self.outgoing_connections = copy.copy(connection_list)
# Returns State List
def return_connection_states_list(self):
states_list = []
for agent in self.incoming_connections:
states_list.append(agent.state)
return states_list
# Modifying States
def modify_state(self,state_list):
most_common = f.most_common_list(state_list)
self.state = random.choice(most_common)
# # Should this come here
# def return_connections(self):
# return self.incoming_connections
def step(self):
# Print Neighbors list
# print(f'Agent: {self.ID} | State: {self.state}')
states_list = self.return_connection_states_list()
self.modify_state(states_list)