Skip to content

Commit 72e8acc

Browse files
quaquelpre-commit-ci[bot]EwoutH
authored
Basic bugfix for bug ContinuousSpace.get_neighbors (#2599)
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]>
1 parent 696923f commit 72e8acc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mesa/examples/basic/boid_flockers/agents.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def __init__(
5858

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

6364
# If no neighbors, maintain current direction
6465
if not self.neighbors:

mesa/space.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,13 @@ def get_neighbors(
14151415
coordinates. i.e. if you are searching for the
14161416
neighbors of a given agent, True will include that
14171417
agent in the results.
1418+
1419+
Notes:
1420+
If 1 or more agents are located on pos, include_center=False will remove all these agents
1421+
from the results. So, if you really want to get the neighbors of a given agent,
1422+
you should set include_center=True, and then filter the list of agents to remove
1423+
the given agent (i.e., self when calling it from an agent).
1424+
14181425
"""
14191426
if self._agent_points is None:
14201427
self._build_agent_cache()

0 commit comments

Comments
 (0)