Skip to content

Commit

Permalink
Added interaction method for Human agents
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Ambo committed Oct 14, 2024
1 parent 792deb7 commit e31c1ce
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Polerisation_ABM/model_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ def create_environment(self):
return self.environment

class Human:
def __init__(self, x, y, opinion):
opinion_threshold = 0.2

def __init__(self, x, y, opinion, scepticism):
self.pos = np.array([x,y])
self.opinion = opinion
#self.identity = 0
self.scepticism = scepticism
#self.influence

def move(self, x, y, env_instance):

Expand All @@ -24,6 +27,18 @@ def move(self, x, y, env_instance):
self.pos = np.array([self.newx, self.newy])
return self.pos

def calculate_distance(self, other_human_instance):
return ((self.pos[0] - other_human_instance.pos[0])**2 + (self.pos[1] - other_human_instance.pos[1])**2)**0.5

def interact(self, other_human_instance):
if abs(self.opinion - other_human_instance.opinion) <= Human.opinion_threshold:
self.opinion += (1 - self.scepticism) * (other_human_instance.opinion - self.opinion)
other_human_instance.opinion += (1 - other_human_instance.scepticism) * (self.opinion - other_human_instance.opinion)
else:
self.opinion += 0
other_human_instance.opinion += 0


def adjust_coordinate(coord, size):
'''Ensures agents do not leave the environment'''
if coord >= size:
Expand All @@ -33,4 +48,3 @@ def adjust_coordinate(coord, size):
else:
return coord + random.randint(-1, 1)


0 comments on commit e31c1ce

Please sign in to comment.