Skip to content

Commit

Permalink
Basic bugfix for bug ContinuousSpace.get_neighbors (#2599)
Browse files Browse the repository at this point in the history
Co-authored-by: Ewout ter Hoeven <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ewout ter Hoeven <[email protected]>
  • Loading branch information
3 people authored and jackiekazil committed Feb 14, 2025
1 parent 6235aff commit 49b8864
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mesa/examples/basic/boid_flockers/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def __init__(

def step(self):
"""Get the Boid's neighbors, compute the new vector, and move accordingly."""
self.neighbors = self.model.space.get_neighbors(self.pos, self.vision, False)
neighbors = self.model.space.get_neighbors(self.pos, self.vision, True)
self.neighbors = [n for n in neighbors if n is not self]

# If no neighbors, maintain current direction
if not self.neighbors:
Expand Down
7 changes: 7 additions & 0 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,13 @@ def get_neighbors(
coordinates. i.e. if you are searching for the
neighbors of a given agent, True will include that
agent in the results.
Notes:
If 1 or more agents are located on pos, include_center=False will remove all these agents
from the results. So, if you really want to get the neighbors of a given agent,
you should set include_center=True, and then filter the list of agents to remove
the given agent (i.e., self when calling it from an agent).
"""
if self._agent_points is None:
self._build_agent_cache()
Expand Down

0 comments on commit 49b8864

Please sign in to comment.