Skip to content

Commit

Permalink
Make agent move to actual random closest position (projectmesa#2119)
Browse files Browse the repository at this point in the history
This fixes a bug in which move_agent_to_one_of is deterministic when pos has multiple closest choices and selection="closest".
  • Loading branch information
EwoutH authored and vitorfrois committed Jul 15, 2024
1 parent e09d26b commit 3f61d41
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def move_agent_to_one_of(
# Find the closest position without sorting all positions
closest_pos = None
min_distance = float("inf")
agent.random.shuffle(pos)
for p in pos:
distance = self._distance_squared(p, current_pos)
if distance < min_distance:
Expand Down

0 comments on commit 3f61d41

Please sign in to comment.