Skip to content

Commit 22784df

Browse files
authored
docs/tutorial: Replace scheduler in MoneyModel (#2475)
Replace scheduler in MoneyModel with AgentSet functionality. This model is used in the Viz tutorial.
1 parent 7e9e6f5 commit 22784df

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

docs/tutorials/MoneyModel.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def compute_gini(model):
7-
agent_wealths = [agent.wealth for agent in model.schedule.agents]
7+
agent_wealths = [agent.wealth for agent in model.agents]
88
x = sorted(agent_wealths)
99
N = model.num_agents
1010
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):
6060
super().__init__(seed=seed)
6161
self.num_agents = n
6262
self.grid = mesa.space.MultiGrid(width, height, True)
63-
self.schedule = mesa.time.RandomActivation(self)
6463

6564
# Create agents
6665
for _ in range(self.num_agents):
6766
a = MoneyAgent(self)
68-
self.schedule.add(a)
6967
# Add the agent to a random grid cell
7068
x = self.random.randrange(self.grid.width)
7169
y = self.random.randrange(self.grid.height)
@@ -74,8 +72,9 @@ def __init__(self, n=10, width=10, height=10, seed=None):
7472
self.datacollector = mesa.DataCollector(
7573
model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"}
7674
)
75+
self.datacollector.collect(self)
7776

7877
def step(self):
7978
"""do one step of the model"""
79+
self.agents.shuffle_do("step")
8080
self.datacollector.collect(self)
81-
self.schedule.step()

0 commit comments

Comments
 (0)