Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions benchmarks/Schelling/schelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ def __init__(

def step(self):
"""Run one step of the agent."""
similar = 0
neighborhood = self.cell.get_neighborhood(radius=self.radius)
for neighbor in neighborhood.agents:
if neighbor.type == self.type:
similar += 1
neighbors = self.cell.get_neighborhood(radius=self.radius).agents
similar = len(
[neighbor for neighbor in neighbors if neighbor.type == self.type]
)

# If unhappy, move:
if similar < self.homophily:
Expand Down Expand Up @@ -76,7 +75,6 @@ def __init__(
"""
super().__init__(seed=seed)
self.simulator = simulator
self.minority_pc = minority_pc
self.happy = 0

self.grid = OrthogonalMooreGrid(
Expand All @@ -92,7 +90,7 @@ def __init__(
# its contents. (coord_iter)
for cell in self.grid:
if self.random.random() < density:
agent_type = 1 if self.random.random() < self.minority_pc else 0
agent_type = 1 if self.random.random() < minority_pc else 0
SchellingAgent(self, agent_type, radius, homophily, cell)

def step(self):
Expand Down
Loading