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 Jan 7, 2024
1 parent 356c1ee commit 0bc6097
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 @@ -20,14 +20,12 @@ class BoltzmannWealthModel(mesa.Model):
def __init__(self, N=100, width=10, height=10):
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 @@ -37,7 +35,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 0bc6097

Please sign in to comment.