Skip to content

Commit

Permalink
Boltzmann wealth model: Use the new model.agents API
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Feb 16, 2024
1 parent 6e68e4e commit 10ace2e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions examples/boltzmann_wealth_model_experimental/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 10ace2e

Please sign in to comment.