Skip to content

Commit f59fa99

Browse files
committed
docs: Add space and time advancement sections to overview
Expand the Mesa overview documentation to fully cover all core features: - Add comprehensive section on spaces including grid-based, network, and Voronoi spaces, with code examples - Add section on property layers and continuous space functionality - Add new section on time advancement covering basic steps, agent activation patterns, and event-based scheduling - Include practical code examples demonstrating each feature - Maintain consistency with existing documentation style and structure This update brings the overview in line with Mesa's paper, ensuring all major features are properly documented in one place.
1 parent a2e38b9 commit f59fa99

File tree

1 file changed

+91
-4
lines changed

1 file changed

+91
-4
lines changed

docs/overview.md

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,102 @@ class MyModel(mesa.Model):
4343
self.agents.shuffle_do("step")
4444
```
4545

46-
If you instantiate a model and run it for one step, like so:
46+
### Spaces in Mesa
47+
48+
Mesa provides several types of spaces where agents can exist and interact:
49+
50+
#### Discrete Spaces
51+
Mesa implements discrete spaces using a doubly-linked structure where each cell maintains connections to its neighbors. Available variants include:
52+
53+
1. **Grid-based Spaces:**
54+
```python
55+
# Create a Von Neumann grid (4 neighbors per cell)
56+
grid = mesa.space.OrthogonalVonNeumannGrid((width, height), torus=False)
57+
58+
# Create a Moore grid (8 neighbors per cell)
59+
grid = mesa.space.OrthogonalMooreGrid((width, height), torus=True)
60+
61+
# Create a hexagonal grid
62+
grid = mesa.space.HexGrid((width, height), torus=False)
63+
```
64+
65+
2. **Network Space:**
66+
```python
67+
# Create a network-based space
68+
network = mesa.space.NetworkGrid(network)
69+
```
70+
71+
3. **Voronoi Space:**
72+
```python
73+
# Create an irregular tessellation
74+
mesh = mesa.space.VoronoiMesh(points)
75+
```
76+
77+
#### Property Layers
78+
Discrete spaces support PropertyLayers - efficient numpy-based arrays for storing cell-level properties:
4779

4880
```python
49-
model = MyModel(5)
50-
model.step()
81+
# Create and use a property layer
82+
grid.create_property_layer("elevation", default_value=10)
83+
high_ground = grid.elevation.select_cells(lambda x: x > 50)
84+
```
85+
86+
#### Continuous Space
87+
For models requiring continuous movement:
88+
89+
```python
90+
# Create a continuous space
91+
space = mesa.space.ContinuousSpace(x_max, y_max, torus=True)
92+
93+
# Move an agent to specific coordinates
94+
space.move_agent(agent, (new_x, new_y))
5195
```
5296

53-
You should see agents 1-5, activated in random order. See the [tutorial](tutorials/intro_tutorial) or API documentation for more detail on how to add model functionality.
97+
### Time Advancement and Agent Activation
98+
99+
Mesa supports multiple approaches to advancing time and activating agents:
100+
101+
#### Basic Time Steps
102+
The simplest approach runs the model for a specified number of steps:
54103

104+
```python
105+
model = MyModel(seed=42)
106+
for _ in range(100):
107+
model.step()
108+
```
109+
110+
#### Agent Activation Patterns
111+
Mesa 3.0 provides flexible agent activation through the AgentSet API:
112+
113+
```python
114+
# Sequential activation
115+
model.agents.do("step")
116+
117+
# Random activation
118+
model.agents.shuffle_do("step")
119+
120+
# Multi-stage activation
121+
for stage in ["move", "eat", "reproduce"]:
122+
model.agents.do(stage)
123+
124+
# Activation by agent type
125+
for klass in model.agent_types:
126+
model.agents_by_type[klass].do("step")
127+
```
128+
129+
#### Event-Based Scheduling
130+
Mesa also supports event-based time progression (experimental):
131+
132+
```python
133+
# Pure event-based
134+
simulator = mesa.experimental.DiscreteEventSimulator()
135+
model = MyModel(seed=42, simulator=simulator)
136+
simulator.schedule_event_relative(some_function, 3.1415)
137+
138+
# Hybrid time-step and event scheduling
139+
model = MyModel(seed=42, simulator=mesa.experimental.ABMSimulator())
140+
model.simulator.schedule_event_next_tick(some_function)
141+
```
55142

56143
### AgentSet and model.agents
57144
Mesa 3.0 makes `model.agents` and the AgentSet class central in managing and activating agents.

0 commit comments

Comments
 (0)