Skip to content

Commit

Permalink
Update into_tutorial for 3.0 (projectmesa#2372)
Browse files Browse the repository at this point in the history
- Adds user challenges
- Correct headers
- Add AgentSet functionality section
- Change N parameter to n to be consistent with examples
- Improve grammar and readability
- Fix build failures
- Make visualization portions independent to avoid computational overhead #TODO Find a better way
  • Loading branch information
tpike3 authored Oct 22, 2024
1 parent f3ac06d commit 470ab0a
Show file tree
Hide file tree
Showing 4 changed files with 840 additions and 239 deletions.
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

0 comments on commit 470ab0a

Please sign in to comment.