From f12fd3fcc50cc1fe600b7bffc1f5f21d4737cdc4 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Sat, 9 Nov 2024 16:26:08 +0100 Subject: [PATCH] docs/tutorial: Replace scheduler in MoneyModel --- docs/tutorials/MoneyModel.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/MoneyModel.py b/docs/tutorials/MoneyModel.py index b25f4ffb9ac..8932a7d890d 100644 --- a/docs/tutorials/MoneyModel.py +++ b/docs/tutorials/MoneyModel.py @@ -4,7 +4,7 @@ def compute_gini(model): - agent_wealths = [agent.wealth for agent in model.schedule.agents] + agent_wealths = [agent.wealth for agent in model.agents] x = sorted(agent_wealths) N = model.num_agents B = sum(xi * (N - i) for i, xi in enumerate(x)) / (N * sum(x)) @@ -60,12 +60,10 @@ def __init__(self, n=10, width=10, height=10, seed=None): super().__init__(seed=seed) self.num_agents = n self.grid = mesa.space.MultiGrid(width, height, True) - self.schedule = mesa.time.RandomActivation(self) # Create agents for _ in range(self.num_agents): a = MoneyAgent(self) - self.schedule.add(a) # Add the agent to a random grid cell x = self.random.randrange(self.grid.width) y = self.random.randrange(self.grid.height) @@ -74,8 +72,9 @@ def __init__(self, n=10, width=10, height=10, seed=None): self.datacollector = mesa.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"} ) + self.datacollector.collect(self) def step(self): """do one step of the model""" + self.agents.shuffle_do("step") self.datacollector.collect(self) - self.schedule.step()