You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migration_guide.md
+72Lines changed: 72 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,78 @@ This guide contains breaking changes between major Mesa versions and how to reso
4
4
Non-breaking changes aren't included, for those see our [Release history](https://github.com/mesa/mesa/releases).
5
5
6
6
## Mesa 3.5.0
7
+
### Event scheduling and time advancement
8
+
Mesa 3.5 introduces public methods for event scheduling and time advancement directly on `Model`, replacing the need for `Simulator` classes.
9
+
10
+
#### Time-based advancement replaces step loops
11
+
```python
12
+
# Old
13
+
for _ inrange(10):
14
+
model.step()
15
+
16
+
# New
17
+
model.run_for(10) # Functionally equivalent for standard ABMs
18
+
model.run_until(10) # You can now also run until a specific time
19
+
```
20
+
`run_for(1)` produces identical results to `step()` for traditional models.
21
+
22
+
#### One-off event scheduling
23
+
24
+
```python
25
+
# Schedule a single event at or after a specific time
26
+
model.schedule_event(callback, at=50.0) # Absolute time
27
+
model.schedule_event(callback, after=5.0) # Relative time
28
+
29
+
# Cancel if needed
30
+
event = model.schedule_event(callback, at=100.0)
31
+
event.cancel()
32
+
```
33
+
34
+
#### Recurring event scheduling
35
+
```python
36
+
from mesa.time import Schedule
37
+
38
+
# Schedule an event every 10 time units
39
+
model.schedule_recurring(func, Schedule(interval=10)) # By default, starting after 1 interval (t=10 in this case)
40
+
model.schedule_recurring(func, Schedule(interval=10, start=0)) # Start immediately or at any other time
41
+
42
+
# Save the event and stop it when needed
43
+
gen = model.schedule_recurring(func, Schedule(interval=5.0))
0 commit comments