-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
62 lines (39 loc) · 1.81 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
55
56
57
58
59
60
61
62
#File to initialize an "Agent" which simulates an investor in a market, choosing random factors and choosing to commit or withdraw
from random import randint
#TODO from some module import list of factors, factors likely dicts
#temporary "mock list" to illustrate how this would work
mock_list = ["Factor 1", "Factor 2", "Factor 3", "Factor 4", "Factor 5"]
#define class "Agent"
class Agent:
#initialization of count (to keep track of ids)
count = 0
def __init__(self):
#initialize list of focus factors, used in get_factors() method
self.focus_factors = []
#initialize agent behavior
self.behavior = "Random"
#Creation of id
self.id = id(self)
#define representation of class
def __repr__(self):
return "Instance of an Agent class with ID: " + str(self.id)
#return when printed other than a memory address
def __str__(self):
#returns statement with relevant information
statement = "ID: " + str(self.id) + "\nBehavior: " + str(self.behavior) + "\nFocus Factors: " + str(self.focus_factors)
return statement
#grabs a given number (in this mock case: 3) factors which our agent will choose to focus on
def get_factors(self):
#list of random numbers to serve as indices of list we will select from
nums = [randint(0, len(mock_list) - 1), randint(0, len(mock_list) - 1), randint(0, len(mock_list)) - 1]
#initial list for factors this agent will focus on
focus_factors = []
#for each index (num) in nums we will append the associated factor
for num in nums:
focus_factors.append(mock_list[num])
return focus_factors
agent = Agent()
for i in range(10):
print("Iteration :", i)
temp_agent = agent
print(temp_agent.get_factors())