Skip to content

Commit 0bc6097

Browse files
committed
Boltzmann wealth model: Use the new model.agents API
1 parent 356c1ee commit 0bc6097

File tree

1 file changed

+2
-4
lines changed
  • examples/boltzmann_wealth_model_experimental

1 file changed

+2
-4
lines changed

examples/boltzmann_wealth_model_experimental/model.py

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

33

44
def compute_gini(model):
5-
agent_wealths = [agent.wealth for agent in model.schedule.agents]
5+
agent_wealths = model.agents.get("wealth")
66
x = sorted(agent_wealths)
77
N = model.num_agents
88
B = sum(xi * (N - i) for i, xi in enumerate(x)) / (N * sum(x))
@@ -20,14 +20,12 @@ class BoltzmannWealthModel(mesa.Model):
2020
def __init__(self, N=100, width=10, height=10):
2121
self.num_agents = N
2222
self.grid = mesa.space.MultiGrid(width, height, True)
23-
self.schedule = mesa.time.RandomActivation(self)
2423
self.datacollector = mesa.DataCollector(
2524
model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"}
2625
)
2726
# Create agents
2827
for i in range(self.num_agents):
2928
a = MoneyAgent(i, self)
30-
self.schedule.add(a)
3129
# Add the agent to a random grid cell
3230
x = self.random.randrange(self.grid.width)
3331
y = self.random.randrange(self.grid.height)
@@ -37,7 +35,7 @@ def __init__(self, N=100, width=10, height=10):
3735
self.datacollector.collect(self)
3836

3937
def step(self):
40-
self.schedule.step()
38+
self.agents.shuffle().do("step")
4139
# collect data
4240
self.datacollector.collect(self)
4341

0 commit comments

Comments
 (0)