Skip to content

Commit

Permalink
model: Shuffle agents in select_agents to avoid bias
Browse files Browse the repository at this point in the history
When n is defined, it should randomly select n agents. Therefore a shuffle step is added.
  • Loading branch information
EwoutH committed Dec 18, 2023
1 parent 3ce1afe commit c8c7a58
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def select_agents(
# Convert to list if sorting is needed or n is specified
if sort and direction or n is not None:
agents_iter = list(agents_iter)
# If n is specified, shuffle the agents to avoid bias
self.random.shuffle(agents_iter)

# If only a specific number of agents is needed without sorting, limit early
if n is not None and not (sort and direction):
Expand Down

0 comments on commit c8c7a58

Please sign in to comment.