A simple ecological model, consisting of three agent types: wolves, sheep, and grass. The wolves and the sheep wander around the grid at random. Wolves and sheep both expend energy moving around, and replenish it by eating. Sheep eat grass, and wolves eat sheep if they end up on the same grid cell.
If wolves and sheep have enough energy, they reproduce, creating a new wolf or sheep (in this simplified model, only one parent is needed for reproduction). The grass on each cell regrows at a constant rate. If any wolves and sheep run out of energy, they die.
In this modified version, both wolves and sheep age at every step, and they die when they become 20 years old.
To install the dependencies use pip and the requirements.txt in this directory. e.g.
$ pip install -r requirements.txt
To run the model interactively, run run.py
in this directory. e.g.
$ python run.py
Then open your browser to http://127.0.0.1:8521/ and press Reset, then Run.
There has been some changes over the classes in this new version: new classes have been added in order to keep them more concrete and small and to apply DRY. The class diagram has been designen taking advantage of Python's multi-inheritance capabilities.
wolf_sheep/entities/living_entity.py
: Defines a living entity. It provides abstract methods to be used as a template when implementing subclasses.wolf_sheep/entities/energy_consuming_entity.py
: Defines an energy consuming entity and implements someLivingEntity
methods related to energy levels and consumtion.wolf_sheep/entities/aging_entity.py
: Defines an aging entity and implements someLivingEntity
methods related to age.wolf_sheep/agents/energy_consuming_entity.py
: Defines an energy consumingAgent
and implements the step method. It re-implements the methods ofEnergyConsumingEntity
in order to allow subclasses to easily deactivate the energy handling capabilities.wolf_sheep/agents/aging_agent.py
: Defines an agingAgent
and implements the step method.wolf_sheep/agents/animal_agent.py
: Defines an animalAgent
. Implements some of the missing methods ofLivingEntity
and re-implements others.
wolf_sheep/agents.py -> wolf_sheep/agents/agents.py
: Defines theWolf
,Sheep
, andGrassPatch
agent classes.Wolf
andSheep
have been refactored so they are implemented by inheriting the newly addedAnimalAgent
class, and they also implement the_eat
method.wolf_sheep/model.py
: Defines the Wolf-Sheep Predation model itself. Added age related parameters, and also a method function so randomization on agent reproduction is encapsulated whithin the model itself.wolf_sheep/server.py
: Sets up the interactive visualization server. Added age related inputs so they can be changed from the client, render chart with average ages for each animal agent.
wolf_sheep/random_walker.py
: This defines theRandomWalker
agent, which implements the behavior of moving randomly across a grid, one cell at a time. Both the Wolf and Sheep agents will inherit from it.wolf_sheep/test_random_walk.py
: Defines a simple model and a text-only visualization intended to make sure the RandomWalk class was working as expected. This doesn't actually model anything, but serves as an ad-hoc unit test. To run it,cd
into thewolf_sheep
directory and runpython test_random_walk.py
. You'll see a series of ASCII grids, one per model step, with each cell showing a count of the number of agents in it.wolf_sheep/schedule.py
: Defines a custom variant on the RandomActivation scheduler, where all agents of one class are activated (in random order) before the next class goes -- e.g. all the wolves go, then all the sheep, then all the grass.run.py
: Launches a model visualization server.
This model is closely based on the NetLogo Wolf-Sheep Predation Model:
Wilensky, U. (1997). NetLogo Wolf Sheep Predation model. http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
See also the Lotka–Volterra equations for an example of a classic differential-equation model with similar dynamics.