Skip to content

Commit 6fcd5b0

Browse files
authored
fix: pass model.random to schedulers (#2359)
As pionted out in by @EwoutH, #2350 broke the tutorial. This is due to not updating the schedulers to pass model.random. This fixes that bug (and does a few minor updates to the tutorial). The tutorial needs a complete update to remove schedulers and use (in my view) the new grid spaces. I am not going to do that in this PR.
1 parent 3f75fc4 commit 6fcd5b0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/tutorials/MoneyModel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def step(self):
4949
class MoneyModel(mesa.Model):
5050
"""A model with some number of agents."""
5151

52-
def __init__(self, N, width, height):
52+
def __init__(self, N, width, height, seed=None):
5353
"""Initialize a MoneyModel instance.
5454
5555
Args:
5656
N: The number of agents.
5757
width: width of the grid.
5858
height: Height of the grid.
5959
"""
60-
super().__init__()
60+
super().__init__(seed=seed)
6161
self.num_agents = N
6262
self.grid = mesa.space.MultiGrid(width, height, True)
6363
self.schedule = mesa.time.RandomActivation(self)

mesa/time.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, model: Model, agents: Iterable[Agent] | None = None) -> None:
7777
if agents is None:
7878
agents = []
7979

80-
self._agents: AgentSet = AgentSet(agents, model)
80+
self._agents: AgentSet = AgentSet(agents, model.random)
8181

8282
self._remove_warning_given = False
8383
self._agents_key_warning_given = False
@@ -312,7 +312,9 @@ def __init__(self, model: Model, agents: Iterable[Agent] | None = None) -> None:
312312
try:
313313
self._agents_by_type[type(agent)].add(agent)
314314
except KeyError:
315-
self._agents_by_type[type(agent)] = AgentSet([agent], self.model)
315+
self._agents_by_type[type(agent)] = AgentSet(
316+
[agent], self.model.random
317+
)
316318

317319
def add(self, agent: Agent) -> None:
318320
"""Add an Agent object to the schedule.
@@ -325,7 +327,7 @@ def add(self, agent: Agent) -> None:
325327
try:
326328
self._agents_by_type[type(agent)].add(agent)
327329
except KeyError:
328-
self._agents_by_type[type(agent)] = AgentSet([agent], self.model)
330+
self._agents_by_type[type(agent)] = AgentSet([agent], self.model.random)
329331

330332
def remove(self, agent: Agent) -> None:
331333
"""Remove all instances of a given agent from the schedule.

0 commit comments

Comments
 (0)