Skip to content

Commit

Permalink
Replace the remaining schedulers with AgentSet functionality (#202)
Browse files Browse the repository at this point in the history
This PR completes the migration from schedulers to AgentSet functionality across the mesa-examples repository for all regular (non-`gis`/-`rl`) examples. Key changes include:

- Replaced `RandomActivation`, `SimultaneousActivation`, and `RandomActivationByType` schedulers with appropriate AgentSet methods
- Updated `Model.step()` implementations to use AgentSet activation
- Removed references to `schedule.steps`, `schedule.agents`, and `schedule.agents_by_type`
- Updated agent addition/removal logic to work with AgentSets
- Adjusted data collection and visualization code to use `Model.steps` and `Model.agents`

For more details on migrating from schedulers to AgentSets, see the migration guide: https://mesa.readthedocs.io/en/latest/migration_guide.html#time-and-schedulers
  • Loading branch information
EwoutH authored Sep 21, 2024
1 parent 5e90bf5 commit 438bff1
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions examples/wolf_sheep/wolf_sheep/test_random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from mesa import Model
from mesa.space import MultiGrid
from mesa.time import RandomActivation
from mesa.visualization.TextVisualization import TextGrid, TextVisualization
from wolf_sheep.random_walk import RandomWalker

Expand Down Expand Up @@ -40,17 +39,15 @@ def __init__(self, width, height, agent_count):
self.grid = MultiGrid(self.width, self.height, torus=True)
self.agent_count = agent_count

self.schedule = RandomActivation(self)
# Create agents
for i in range(self.agent_count):
x = self.random.randrange(self.width)
y = self.random.randrange(self.height)
a = WalkerAgent(i, (x, y), self, True)
self.schedule.add(a)
self.grid.place_agent(a, (x, y))

def step(self):
self.schedule.step()
self.agents.shuffle_do("step")


class WalkerWorldViz(TextVisualization):
Expand Down

0 comments on commit 438bff1

Please sign in to comment.