Need help #1473
Replies: 1 comment 1 reply
-
For the former requirement, an example would be in this Sugarscape code mesa/examples/sugarscape_cg/sugarscape_cg/model.py Lines 49 to 53 in b6accc6 for _, x, y in self.grid.coord_iter():
max_sugar = sugar_distribution[x, y]
if max_sugar <= 0:
continue
sugar = Sugar(agent_id, (x, y), self, max_sugar)
agent_id += 1
self.grid.place_agent(sugar, (x, y))
self.schedule.add(sugar) i.e. it skips the creation of the For the latter requirement, it is better to solve this problem instead: generate a matrix that consists of only 0s and 1s, where each matrix element is constrained to have a certain condition for its number of neighbors. You could start by a matrix of all zeros, and set one random position in it to 1, and then set N of its neighborhood to 1, while doing a constraint check before every step to ensure that your change to the matrix satisfies the overall number of neighbors constraint. There could already be a solution for generating this matrix if you model it in a Networkx directed graph, but I wouldn't do this as a first resort. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I would like to implement an agent-based model, and for that, I need a function that allows me to place an agent in a grid according to a specific condition, otherwise, according to a condition (x) I decide the number of neighbors of an agent, the function must be checked for all the agents of the grid.
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions