Update wolf-sheep example to use new event scheduling API#3278
Update wolf-sheep example to use new event scheduling API#3278
Conversation
Updates the wolf-sheep example to use the new public event scheduling API (`model.schedule_event()`) instead of the deprecated `ABMSimulator`. - **agents.py**: Replace `simulator.schedule_event_relative()` with `model.schedule_event(after=...)` - **model.py**: Remove `simulator` parameter and setup - **app.py**: Remove simulator initialization and passing The model behavior remains functionally identical - grass regrowth events are still scheduled at the same times, just using the new API.
instead of trying to be clever with property setters, just make explicit methods for the two state transitions (eating and regrowing).
| """Regrow the grass.""" | ||
| self.fully_grown = True | ||
|
|
||
| def eat(self): |
There was a problem hiding this comment.
A pit of a nitpick, but this naming is not ideal. it suggest the grass eats, rather than the grass being eaten.
There was a problem hiding this comment.
Shall I rename to get_eaten()?
It makes sense to use some distribution for this. I would not use integers, because that's uniform. But a triangular distribution or so, and flooring the number to an integer should work and create nicer dynamics. |
|
Really nice how this PR also cleans up our test and benchmark code. |
I initially misread your comment and then updated it afterwards. |


Summary
Updates the wolf-sheep example to use the new public event scheduling API (
model.schedule_event()) instead of the deprecatedABMSimulator, and refactorsGrassPatchfor cleaner, more Pythonic code.Implementation
The main change is migrating from
simulator.schedule_event_relative()tomodel.schedule_event(after=...), and removing the old simulator objects.agents.pyalso received some refactoring. The oldGrassPatchimplementation used a property setter with side effects—settingfully_grown = Falsewould automatically schedule a regrowth event usingsetattras a callback. This was clever but opaque. The new implementation adds explicitregrow()andeat()methods that make the grass lifecycle clear: when eaten, grass schedules its own regrowth. TheSheep.feed()method now callsgrass_patch.eat()instead of directly assigning to the property.Grass is now regrowing:

Additional Notes