Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 25, 2024
1 parent a51aa5c commit 178d3d1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mesa/examples/basic/schelling/agents.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from mesa import Agent


class SchellingAgent(Agent):
"""Schelling segregation agent."""

def __init__(self, model, agent_type: int) -> None:
"""Create a new Schelling agent.
Args:
Expand All @@ -16,21 +18,21 @@ def step(self) -> None:
neighbors = self.model.grid.iter_neighbors(
self.pos, moore=True, radius=self.model.radius
)

# Filter out empty cells
similar_neighbors = [
neighbor for neighbor in neighbors
if hasattr(neighbor, 'type') and neighbor.type == self.type
neighbor
for neighbor in neighbors
if hasattr(neighbor, "type") and neighbor.type == self.type
]
total_neighbors = [
neighbor for neighbor in neighbors
if hasattr(neighbor, 'type')
neighbor for neighbor in neighbors if hasattr(neighbor, "type")
]

# Calculate fraction of similar neighbors
if len(total_neighbors) > 0:
similarity_fraction = len(similar_neighbors) / len(total_neighbors)

Check warning on line 34 in mesa/examples/basic/schelling/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/schelling/agents.py#L34

Added line #L34 was not covered by tests

# If unhappy, move to a random empty cell
if similarity_fraction < self.model.homophily / 8.0:
self.model.grid.move_to_empty(self)

Check warning on line 38 in mesa/examples/basic/schelling/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/schelling/agents.py#L38

Added line #L38 was not covered by tests
Expand Down

0 comments on commit 178d3d1

Please sign in to comment.