What are the functions available for OrthogonalMooreGrid?
I have been trying to find documentation on the website on which functions are available for cells and agents when on an orthogonal moore grid, but there isn't any I can see, and I keep running into the issue that it doesn't support certain functions available on MultiGrid and SingleGrid.
I could really use some help with this asap (sorry haha my project is due tomorrow and I am running into this issue now). An example is that OrthogonalMooreGrid doesn't have a move_to_empty() option.
Thank you!
Hey @Ravencar11, thanks for reaching out.
The grids in Mesa are cell-focused, meaning agents interact based on their current cell. You can check out our examples in the main repository for more clarity.
An example is that OrthogonalMooreGrid doesn't have a move_to_empty() option.
In this case, you need to associate a cell with your agent and subclass CellAgent. Here's an example:
class CustomAgent(CellAgent):
def __init__(self, cell, model, ...):
super().__init__(model)
self.cell = cell
# ... (rest of your logic)
def step(self):
self.cell = self.model.grid.select_random_empty_cell() # Move to a random empty cell
Then, you can assign the cells to agents. For example:
class CustomModel(Model):
def __init__(self, seed, ...):
super().__init__(seed=seed)
self.grid = OrthogonalMooreGrid((width, height), random=self.random)
# a very basic example of assigning cells to agents
for cell in self.grid.all_cells: # to access all the cells
CustomAgent(
self, cell, ...(other properties to pass)
)
# ... (rest of your logic)
def step(self):
self.agents.shuffle_do("step") # Randomly call the agents' step methods
And the docs can be found here