Applying predprey models

I haven’t learned yet. Ever have someone tell you not to start reading a book late at night? You laugh at those statements right? I did. It started when I began reading Disclosure at around 9 one night. I didn’t put the book down until I finished it at 6 the next morning. I did the same thing with Lost World, Airframe, and Timeline where I would just sit and read them straight through in nearly one sitting. Michael Crichton has that unique ability to do that to me, something that only Stephen King has been able to do in the past.

I picked up Prey a couple of months ago. Prey looked interesting (blending nanotechnology and computer programming) so I decided I would give it a shot. Man it was a great read. It just flowed right off the pages and had a lot to say about mankind’s technological terrors we create (albeit a little hard hitting and judgemental but that’s ok too).

Back when we had wood-burning computers, I did some programming around flocking technology, dynamic population models, AI etc. using some of the neural-net and heuristic algorithms available at the time (and trying to come up with my own, failing miserably). They’re all about the relationships between predetators and their prey. How they interact, what do they do when they get hungry, what patterns they follow when they hunt, do they learn from following paths that return nothing, and so on.

One algorithm was the infamous Lotka-Volterra Predprey model (which the book makes some reference to and extends). The Lotka-Volterra model is a simple model of predator-prey interactions. The differential equations were developed independently by Lotka (1925) and by Volterra (1926). It answers (or allows you to answer) the question “Do predators influence prey populations?”. The Lotka-Volterra model follows these principles:

Each prey gives rise to a constant number of offspring per year

In other words, there are no other factors limiting prey population growth apart from predation.

Each predator eats a constant proportion of the prey population per year

In other words, doubling the prey population will double the number eaten per predator, regardless of how big the prey population is.

Predator reproduction is directly proportional to prey consumed

Another way of expressing this is that a certain number of prey consumed results in one new predator; or that one prey consumed produces some fraction of a new predator.

A constant proportion of the predator population dies per year.

In other words, the predator death rate is independent of the amount of food available.

Lotka and Volterra made a number of guesses when they wrote their equations. They did not carry out any experiments and thus made a lot of assumptions that were inaccurate. The Lotka-Volterra model makes no allowance for many biological features (such as appetite). A lot of these algorithms are expressed mathematically and you can spend literally hours just looking at complex graphs and trend models all to see, well nothing. What is interesting in all this is the fact that a) you can express these models using fairly simple algorithms and b) it would be great if there was a way to demonstrate and view the evolution of such an algorithm rather that staring at graphs. The predprey model can be mathematically expressed as:

dX/dt = aX – bXY

dY/dt = cbXY – dY


X = size of the prey population

Y = size of the predator population

a = number of offspring per prey per year

b = proportion of the prey population consumed by one predator per year

c = conversion of one prey consumed into new predators (i.e. if this was 0.1 then for every 100 prey destroyed gives rise to 1 new predator)

d = proportion of predator population dying per year

Enter Terrarium

Terrarium is a sample application built by Microsoft. It’s a game for software developers that provides a great introduction to software development on the .NET Framework. In Terrarium, developers create herbivores, carnivores, or plants and then introduce them into a peer-to-peer, networked ecosystem for a survival-of-the-fittest type competition.

The Terrarium server tends to be up and down, but I highly recommend it for anyone who’s interested in trying to beat down their geek friends through programming. In the early 80s we had something called C-Robots (sometimes Pascal-Robots). These were engines that allowed you, through programming, to create a robot and battle in an arena-type environment to the death. 10 robots in, 1 comes out. I still have my “killer” bots somewhere on CD. Terrarium revisits this idea, but provides a more biological environment and, IMHO, a better way to build your predators.

You can download the client and armed with a copy of Visual Studio .NET and the documentation, you make your first creature by creating a new class (based on a base they provide) and introduce it into the ecosystem. You release it, it communicates with the server (through the Terrarium client) and starts interacting with other peoples creations. I have a 4th generation creation I call “Xymos” (after the corporation in the book). It’s a carnivore (herbivores are so boring, and plants, well…) that roams the playing field in blocks, looking for fuel and slowing down when it begins to run low (it switches from active to passive based on how it feels). My creation is pretty good and follows the predprey model. I’ve been evolving it when I find some other creature that kills it, make some changes (usually on the pathing) and re-release it. The last gen can survive for a few days but there is currently a bit of a problem gathering food so I need to try to figure that out (my first gen only survived about 10 minutes before it dropped dead of exhaustion).

Anyways, if you’re into writing games, programming in .NET, or just want to see how your creation fairs up against others give it a shot and I’ll see you on the battlefield.