Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update into_tutorial #2372

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

This guide provides concise instructions and examples to help you start with common tasks in Mesa.

## Implementing Different Activation Regimes


### Random Activation

self.agents.shuffle_do("<agent function>")

### Random Activation By Type

```python
for agent_class in self.agent_types:
self.agents_by_type[agent_class].shuffle_do("<agent function>")
```
### Only Activating Certain Agent Types

```python
self.agents_by_type[AgentType].shuffle_do("<agent function>")
```

### Staged Activation

```python
for stage in ["stage1", "stage2", "stage3"]:
self.agents.do(stage)
```

If you want to `shuffle` and/or `shuffle_between_stages` options:
```python

stages = ["stage1", "stage2", "stage3"]
if shuffle:
self.random.shuffle(stages)
for stage in stages:
if shuffle_between_stages:
self.agents.shuffle_do(stage)
else:
self.agents.do(stage)
```

## Models with Discrete Time

For models involving agents of multiple types, including those with a time attribute, you can construct a discrete-time model. This setup allows each agent to perform actions in steps that correspond to the model's discrete time.
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/MoneyModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def step(self):
class MoneyModel(mesa.Model):
"""A model with some number of agents."""

def __init__(self, N, width, height, seed=None):
def __init__(self, n, width, height, seed=None):
"""Initialize a MoneyModel instance.

Args:
Expand All @@ -58,7 +58,7 @@ def __init__(self, N, width, height, seed=None):
height: Height of the grid.
"""
super().__init__(seed=seed)
self.num_agents = N
self.num_agents = n
self.grid = mesa.space.MultiGrid(width, height, True)
self.schedule = mesa.time.RandomActivation(self)

Expand Down
Loading
Loading