Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gis/GeoSir: Replace BaseScheduler with AgentSet functionality #210

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions gis/geo_sir/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(
if it has been exposed to another infected
"""
super().__init__()
self.schedule = mesa.time.BaseScheduler(self)
self.space = mg.GeoSpace(warn_crs_conversion=False)
self.steps = 0
self.counts = None
Expand All @@ -52,7 +51,6 @@ def __init__(
)

# Set up the Neighbourhood patches for every region in file
# (add to schedule later)
ac = mg.AgentCreator(NeighbourhoodAgent, model=self)
neighbourhood_agents = ac.from_file(self.geojson_regions)
self.space.add_agents(neighbourhood_agents)
Expand All @@ -64,7 +62,7 @@ def __init__(
crs=self.space.crs,
agent_kwargs={"init_infected": init_infected},
)
# Generate random location, add agent to grid and scheduler
# Generate random location and add agent to grid
for i in range(pop_size):
this_neighbourhood = self.random.randint(
0, len(neighbourhood_agents) - 1
Expand All @@ -81,12 +79,6 @@ def __init__(
this_y = center_y[0] + self.random.randint(0, spread_y) - spread_y / 2
this_person = ac_population.create_agent(Point(this_x, this_y))
self.space.add_agents(this_person)
self.schedule.add(this_person)

# Add the neighbourhood agents to schedule AFTER person agents,
# to allow them to update their color by using BaseScheduler
for agent in neighbourhood_agents:
self.schedule.add(agent)

self.datacollector.collect(self)

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

def step(self):
"""Run one step of the model."""
self.steps += 1
self.reset_counts()
self.schedule.step()

# Activate PersonAgents in random order
self.agents_by_type[PersonAgent].shuffle_do("step")
# For NeighbourhoodAgents the order doesn't matter, since they update independently from each other
self.agents_by_type[NeighbourhoodAgent].do("step")
EwoutH marked this conversation as resolved.
Show resolved Hide resolved

self.datacollector.collect(self)

Expand Down
Loading