Determining if a population of sheep is in danger of extinction due to a wolf pack
One of the most famous agent-based simulations is the sheep-wolf predation example.
The model simulates two populations of animals: sheep and wolves coexisting together on a plane. Sheep move around and eat grass that grows on the plane; eating grass gives the sheep energy. Wolves predate sheep and that is how they get their energy. To move around the plane costs the animal some energy. If any animal's energy falls below 0, it dies.
In this recipe, we will build a 300-by-300 plane (grid) and populate it with 6,000 sheep and 200 wolves (initially). We will also introduce the concept of inheritance: we will create a generic Animal
class and then derive Sheep
and Wolf ...
Get Practical Data Analysis Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.