From 10ace2e31331c84f9634d43b516f59d0908644fc Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 6 Jan 2024 22:03:25 -0500 Subject: [PATCH] Boltzmann wealth model: Use the new model.agents API --- examples/boltzmann_wealth_model_experimental/model.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/boltzmann_wealth_model_experimental/model.py b/examples/boltzmann_wealth_model_experimental/model.py index 11a3e9587..673eaa1ca 100644 --- a/examples/boltzmann_wealth_model_experimental/model.py +++ b/examples/boltzmann_wealth_model_experimental/model.py @@ -2,7 +2,7 @@ def compute_gini(model): - agent_wealths = [agent.wealth for agent in model.schedule.agents] + agent_wealths = model.agents.get("wealth") x = sorted(agent_wealths) N = model.num_agents B = sum(xi * (N - i) for i, xi in enumerate(x)) / (N * sum(x)) @@ -21,14 +21,12 @@ def __init__(self, N=100, width=10, height=10): super().__init__() self.num_agents = N self.grid = mesa.space.MultiGrid(width, height, True) - self.schedule = mesa.time.RandomActivation(self) self.datacollector = mesa.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"} ) # Create agents for i in range(self.num_agents): a = MoneyAgent(i, 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) @@ -38,7 +36,7 @@ def __init__(self, N=100, width=10, height=10): self.datacollector.collect(self) def step(self): - self.schedule.step() + self.agents.shuffle().do("step") # collect data self.datacollector.collect(self)