'Select agents by a condition out of the model and change that attribute in mesa?

For an agent based modelling I'm doing with mesa & mesa-geo I need a way, to select and manipulate the agents out of the model.py.

For example, if you take the Introductory Tutorial, each step you want a particular randomly picked percentage of all agents which have no money (self.wealth = 0) to receive one money.

Therefore you need to know from all agents the wealth, pick the ones with wealth zero, pick randomly an amount of them and set wealth = 1. But is there a way, to do this out of the model.py?

For my understanding, you can only get a list of the agents by model.grid.agents, but here you can't see there attributes and you can't change the attributes.



Solution 1:[1]

At the end I found a solution. The keyword is object oriented programing. Here is a question which answers this one quite good. At the end I realised my problem with adding functions for finding the object by a attribute criteria and then changing the attributes of those. As I already mentioned, the list of attributes can be accessed in the model itself by self.space.agents or self.grid.agents.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1