# Modeling zombies and populations over time

This topic is 4037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've got Z number of zombies in an area and P number of people in that same area. I would like to roughly model how the populations of both people and zombies change over time. There are a couple of assumptions: 1. Zombiness is viral - it spreads to humans. 2. All humans that die of zombie attack become zombies. 3. No zombies 'die'. (for now) 4. The change in human population due to births and natural deaths is insignificant on this scale. We can, effectively, assume that the total population including both zombies and humans remains the same. I need to simulate this on a turn-by-turn basis (each turn is a week, but that doesn't matter much). Because of this, I don't need some fancy integrated equation. Having a simple dZ/dt and dP/dt would be sufficient. However, I'm at a lose as to how to calculate one them. All that I've really figured out is that dZ/dt = -dP/dt. Well, how would you do this? On IRC a while ago, we talked about this and came up with dZ/dt = P * Z * someconstant. I've been fiddling with constants and haven't come up with anything promising. It either happens way too fast (explodes once the two populations are equal) or it takes too long (player would get bored clicking on the 'next-turn' button). Another person on IRC pointed out that population growths should have an e^x of some sort in them, which we didn't. Any suggestions? Some new air in this matter would be great.

##### Share on other sites
By far the simplest and most controllable method is to make up a table yourself of turn number vs zombie percentage.

The other option is to add some more variables. For example maybe some humans are more or less likely to be infected than others due to their behaviour.

For each human each turn you work out infection percentage * Z * some constant and use that as their chance of turning into a zombie. To slow things down even more try using sqrt(Z) or even 1.0 instead of Z.

##### Share on other sites
In this game, each region is the size of a good sized country, and the populations are in the millions. I can't really model the likely-hood of individual people being infected. The law of averages would make it unnoticeable even if I did.

##### Share on other sites
There are many ways to model this, a very simple way is to assume that the rate of growth of zombies decreases as the number of available humans to feed on decreases.

Something like this should suffice:

Zombies = Total Combined Population * (1 - Exponential(-k*Time) )

The Total Combined Population = Number of Humans + Number of Zombies (and never changes).

k = a constant you can set.

Ultimately in this model the zombies will experience rapid growth initially before slowing in growth until eventually almost all the population is a zombie.

(the nice thing about this simple model is also that it really shows off the 'small bands of humans' who survive the apocalyptic zombie resurrection)

##### Share on other sites
Quote:
 Original post by Matt Lloyd...a very simple way is to assume that the rate of growth of zombies decreases as the number of available humans to feed on decreases.

This is a little unrealistic though. A result of this model is that the zombie population grows fastest when the number of zombies is small, which is in stark contrast with the viral nature of the infection.

The most appropriate choice is the logistic population model. The assumption you implicitly brought up, but never clearly stated is this:

The chance of infection per unit time is proportional to the product of the infected and uninfected populations.

This is the case as it requires a zombie and a human to be present for an infection to occur. We have two parameters: the total population n and the rate of infection k. After nondimensionalisation, the ODE system becomes:

dz/dt = k.z.p
dp/dt = -k.z.p

And hence d/dt(z + p) = 0, which reassures us that the total population is constant and allows us to write 'p = n - z'. There's no need to worry about the absence of exponentials in these expressions, as they are implicit in the differential nature of it. To see this, recognise that we have one ODE in one variable:

dz/dt = k.z.(n - z)

Separating and integrating gives:

ln(z) - ln(z - n) = n.(kt + c)

and hence

z/(z - n) = Aenkt

I'll take the liberty to rewrite and renotate this for aesthetics:

z = n / (1 - C.n.e-nkt)

That's the general solution. If we solve for C with a population of n=100, and take the infection rate to be small; k = 0.1, we end up with:

z = 100 / (1 + 99e-10t)

This is logistic growth, and it gives us a realistic-looking curve for the zombie population z in terms of nondimensionalised time t:

So it looks like you just need to tweak the parameters for your iterative simulation. Either that or you've made a coding error somewhere along the way.

##### Share on other sites
Can a twisted Game Of Life be of help? The number of cells in the 2D array is the total population. Active cells are Zombies, non active cells are human. If a human cell is surrounded by 3 sombies, it becomes active. A cell cannot become inactive (that's the difference with the normal Game of Life). Modifying the number and positions of active cells at the beginning of the game or during the game allows you to modify the progression rate of the zombification.

Note that this is not guaranteed to always grow - there might be special cases were the number of active cells remains constants.

##### Share on other sites
Check this out: Volterra-Lotka Equations

Based on that you have: http://www.codeproject.com/opengl/Wator.asp which seems similar to what you're speaking of.

##### Share on other sites

Quote:
 The chance of infection per unit time is proportional to the product of the infected and uninfected populations.

That's actually quite a bad model for most zombie outbreaks, as it doesn't take geometry into account.

Zombies are unlikely to be scattered uniformly everywhere; the rate of infection will be proportional to the area in which humans and zombies coexist (logistic in this area), which will grow as the infection spreads from ground dero.

Most recent research on zombie outbreaks supports my view; check out citeseer ;)

It's harder analytically (looks like a diffusion equation) but it's also more interesting to watch clumps of zombies spreading out.

So here are bumbling zombies in python, who can either bump into each other, bite a human, or move a step:

from random import randintdef next(Z, dim):    for z in list(Z):        x, y = z % dim, z / dim        new_x, new_y = (x + randint(-1, 1)) % dim, (y + randint(-1, 1)) % dim        new_z = new_x + (new_y * dim)        if new_z in Z:            pass        else:            Z.add(new_z)            if randint(0, 1) > 0:                Z.remove(z)def display(Z, dim):    for y in range(dim):        print ''.join(['X' if x + y * dim in Z else ' ' for x in range(dim)])z = set([ 315])for i in range(20):	display(z, 30)	next(z, 30)	print '----------------------------------------------'

##### Share on other sites
Quote:
 Original post by Anonymous PThat's actually quite a bad model for most zombie outbreaks, as it doesn't take geometry into account.

You're quite right about the lack of diffusion, but Ezbez never said anything about proximity considerations, and I get the distinct impression that he wants to keep things simple. I suppose that fact that I was envisaging a sealed hall full of panicked people desperately trying to flee their undead kin is more attributable to my perverse imagination than the matter in hand [rolleyes].

Indeed, if diffusion is an issue (as in a residential epidemic simulation) then a spatial term will be very important. I'm happy to go into the analysis behind this if necessary, but there's not too much to be gleaned from it. A spatial simulation such as Anonymous P's pseudocode will offer far more in terms of statistics, though for stability analysis, travelling-wave qualities, or critical values you'll need to work harder.

##### Share on other sites
Thanks for all the suggestions. No, I don't really need to model any location or spread of zombies. Think of the zombies and humans as randomly placed.

So, I've gone back to the simple dZ/dt = P * Z * K, aided with TheAdmiral's analysis. It's actually looking quite good right now. I also added in a military factor. The military can kill off zombies at a rate also proportional to the number of zombies and the number of military. This makes it seem much more realistic. 500 zombies, 1,000,000 humans, and 10,000 military personnel ended up leveling off at 0 zombies and ~940,000 humans after many weeks. 8,000 military, on the other hand, doesn't manage to get a grip on the zombies until after the undead population rises up into the 10,000s and *then* the zombie population starts to fall off (since it's growing slower now that there's a whole lot fewer people), eventually approaching zero. It's pretty entertaining just to watch the numbers! I still need to model the zombies killing the military, but that should be similar.

Thanks for the help. That Wikipedia page on Logistic functions was great. The alternative simulations were very interesting, also. If I get time or this one doesn't suit me in the end, I'll look into some of those.

Cheers!

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011306
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!