Skip to content

Commit 84542d4

Browse files
authored
gis/GeoSir: Replace BaseScheduler with AgentSet functionality (#210)
Replace BaseScheduler in the GeoSir gis model with AgentSet functionality, using `agents_by_type`, `shuffle_do()` and `do()`. - Remove BaseScheduler initialization and usage - Use automatic agent registration for PersonAgents - Explicitly register NeighbourhoodAgents with the model - Update step() method to use AgentSet methods for agent activation - Maintain original activation order: PersonAgents (shuffled) then NeighbourhoodAgents - Remove unnecessary scheduler.add() calls
1 parent d4b18cd commit 84542d4

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

gis/geo_sir/model.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def __init__(
2929
if it has been exposed to another infected
3030
"""
3131
super().__init__()
32-
self.schedule = mesa.time.BaseScheduler(self)
3332
self.space = mg.GeoSpace(warn_crs_conversion=False)
3433
self.steps = 0
3534
self.counts = None
@@ -52,7 +51,6 @@ def __init__(
5251
)
5352

5453
# Set up the Neighbourhood patches for every region in file
55-
# (add to schedule later)
5654
ac = mg.AgentCreator(NeighbourhoodAgent, model=self)
5755
neighbourhood_agents = ac.from_file(self.geojson_regions)
5856
self.space.add_agents(neighbourhood_agents)
@@ -64,7 +62,7 @@ def __init__(
6462
crs=self.space.crs,
6563
agent_kwargs={"init_infected": init_infected},
6664
)
67-
# Generate random location, add agent to grid and scheduler
65+
# Generate random location and add agent to grid
6866
for i in range(pop_size):
6967
this_neighbourhood = self.random.randint(
7068
0, len(neighbourhood_agents) - 1
@@ -81,12 +79,6 @@ def __init__(
8179
this_y = center_y[0] + self.random.randint(0, spread_y) - spread_y / 2
8280
this_person = ac_population.create_agent(Point(this_x, this_y))
8381
self.space.add_agents(this_person)
84-
self.schedule.add(this_person)
85-
86-
# Add the neighbourhood agents to schedule AFTER person agents,
87-
# to allow them to update their color by using BaseScheduler
88-
for agent in neighbourhood_agents:
89-
self.schedule.add(agent)
9082

9183
self.datacollector.collect(self)
9284

@@ -102,9 +94,12 @@ def reset_counts(self):
10294

10395
def step(self):
10496
"""Run one step of the model."""
105-
self.steps += 1
10697
self.reset_counts()
107-
self.schedule.step()
98+
99+
# Activate PersonAgents in random order
100+
self.agents_by_type[PersonAgent].shuffle_do("step")
101+
# For NeighbourhoodAgents the order doesn't matter, since they update independently from each other
102+
self.agents_by_type[NeighbourhoodAgent].do("step")
108103

109104
self.datacollector.collect(self)
110105

0 commit comments

Comments
 (0)