Skip to content

Commit

Permalink
Update agents.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vbv-shm authored Nov 26, 2024
1 parent dbb9264 commit 5c1d312
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesa/examples/basic/schelling/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def step(self) -> None:

# Count similar neighbors
similar = sum(neighbor.type == self.type for neighbor in neighbors)

# Count total neighbors
total_neighbors=len(self.model.grid.get_neighbors(self.pos,moore=True))

# If unhappy, move to a random empty cell:
if similar < self.model.homophily:
if total_neighbors!=0 and similar/total_neighbors < self.model.homophily_ratio:
self.model.grid.move_to_empty(self)
else:
self.model.happy += 1

0 comments on commit 5c1d312

Please sign in to comment.