Template:Population Reproduction Rate

From RimWorld Wiki
Jump to navigation Jump to search
Documentation icon Template documentation[view] [edit] [history] [purge]

This template calculates the number of offspring that a population of male and female animals can be expected to produce each day.

Syntax[edit]

{{Population Reproduction Rate|Name|M|F|debug}}

  1. Name = Name of animal.
  2. M = Male population count.
  3. F = Female population count.
  4. debug = optional. If present, the output is replaced with a trace of the internal calculations.

Dependencies[edit]

The animal properties used are:

The assumptions are:

  • All the animals have a synchronized sleep cycle.
  • They're all sleeping on the floor.
  • They're all within the 30 tile distance needed to see each other.

Used by[edit]

Maths[edit]

As described in Animals#Mating, while they're awake, once every Property:Mate Mtb Hours, each male will search for an unfertilised female to mate with. Upon mating, gestating animals have a 50% chance of successful fertilisation, while egg-laying animals have a 100% chance. The proportion of time spent awake can be calculated as described on Template:Rest Hours Per Day, as:

1. a = 1 - 1/(1 + RE*0.0057143/0.00237)
Where RE is the rest effectiveness. For the purpose of this template, we assume the animals are sleeping on the floor, so RE=0.8 and thus a=0.659.

We can use these to calculate the interval between effective mating attempt initiations from the male population:

2. t = b/(m*a*s)
Where b is the animal's Property:Mate Mtb Hours in days, m is the male population count, a is the proportion of time the animals spend awake, and s is the mating success chance (1 for egg-layers, 0.5 for gestators).

There are three forms of animal reproduction: Unfertilised egg-layers, gestators, and normal egg-layers.

Unfertilised egg-layers[edit]

The unfertilised egg-layers are the simplest to calculate. The fertilised eggs per day is simply the lowest of the fertilisation rate and the egg laying rate, multiplied by the clutch size:

3. p = x*min(1/t, f/e)
Where x is the Property:Eggs Per Clutch Average, t is the population mating attempt interval, f is the female population size, and e is the Property:Egg Laying Interval.

Gestators[edit]

Gestators are the next simplest. The central number to calculate is the wait time, w, which is the expected time a female in the population has to wait between giving birth and becoming fertilised again. On average, when they give birth, it will be halfway between mating attempts from the male population, so the minimum value for w is t/2. It will take on average c mating attempts for a particular female to be selected, where c is the number of simultaneous non-fertilised female animals. So, the wait time w can be calculated as:

4. w = t*(c - 1/2)
Where t is the population mating attempt interval, and c is the expected non-fertilised female population.

The value of c can be calculated by subtracting the number of pregnant animals from the female population. It will always be at least 1, since from the perspective of a female animal waiting for a mate, it will always see itself:

5. c = max(1, f - g/t)
Where f is the female population count, g is the Property:Gestation Period Days, and t is the population mating attempt interval.

Combining equations 4. and 5, we get.

6. w = t*(max(1, f - g/t) - 1/2)

Converting the wait time w to the offspring per day p is simply:

7. p = x*f/(g+w)
Where x is the Property:Average Offspring Per Birth, f is the female population, g is the Property:Gestation Period Days, and w is the expected time between birth and fertilisation.

Normal egg-layers[edit]

For egg-laying animals, the effective gestation time is reduced compared to gestators. Most egg-layers can prepare up to 50% of the egg before having to wait for fertilisation to in order to continue. If the egg-layer population is female-limited, then they can be treated as equivalent to unfertilised egg-layers (eqn. 3). If the egg-layer population is male-limited, they can be treated as equivalent to gestators with a gestation time of half their egg interval (eqn. 5-7).

8.1. p = x*min(f/((e/2) + w), f/e)
8.2. w = t*(c - 1/2)
8.3. c = max(1, f - (e/2)/t)

Pseudocode[edit]

def Population_Reproduction_Rate(animal, m, f):
   g = animal.Gestation_Period_Days
   e = animal.Egg_Laying_Interval
   
   if g is not None:
       s = 0.5
   else:
       s = 1
   a = 1 - 1/(1 + 0.8*0.0057143/0.00237)
   b = animal.Mate_Mtb_Hours/24
   t = b/(m*a*s)
   
   if g is not None:
       x = animal.Average_Offspring_Per_Birth
   else:
       x = animal.Eggs_Per_Clutch_Average
   u = animal.Can_Lay_Unfertilized_Eggs
  
   if u:
       p = x*min(1/t, f/e)
   else:
       if g is not None:
           c = max(1, f - g/t)
           w = t*(c - 1/2)
           p = x*f/(g + w)
       else:
           c = max(1, f - (e/2)/t)
           w = t*(c - 1/2)
           p = x*min(f/((e/2) + w), f/e)
   return p

Examples[edit]

Basic usage[edit]

Chicken[edit]

{{Population Reproduction Rate|Chicken|2|8}} ⇒ 3.9514337082796

Pig[edit]

{{Population Reproduction Rate|Pig|3|7}} ⇒ 1.5600078773099

Iguana[edit]

{{Population Reproduction Rate|Iguana|5|5}} ⇒ 1.3248542660307

Debug[edit]

Chicken[edit]

{{Population Reproduction Rate|Chicken|2|8|Y}}
{{Population Reproduction Rate|Chicken|2|8|Y}}
m=2, s=1, a=0.65857228471326, b=0.33333333333333 => t=b/(m*a*s)=0.25307270065158
f=8, e=1, x=1 p = x*min(1/t, f/e) = 1*min(1/0.25307270065158, 8/1 ) = 1*min(3.9514337082796, 8) = 3.951

Pig[edit]

{{Population Reproduction Rate|Pig|3|7|Y}}
{{Population Reproduction Rate|Pig|3|7|Y}}
m=3, s=0.5, a=0.65857228471326, b=0.5 => t=b/(m*a*s)=0.50614540130316
f=7, g=5.661, x=1.318 c = max(1, f - g/t) = max(1, 7 - 5.661/0.50614540130316 = 1 w = t*(c - 1/2) = 0.50614540130316*(1) p = x*f/(g + w) = 1.318*7/(5.661 + 0.253) = 1.5600078773099

Iguana[edit]

{{Population Reproduction Rate|Iguana|5|5|Y}}
{{Population Reproduction Rate|Iguana|5|5|Y}}
m=5, s=1, a=0.65857228471326, b=0.5 => t=b/(m*a*s)=0.15184362039095
f=5, e=5.661, x=1.5 c = max(1, f - (e/2)/t) = max(1, (5 - (5.661/2)/0.15184362039095)) = max(1, -13.641) = 1 w = t*(c - 1/2) = 0.15184362039095*(1 - 1/2) = 0.076 male_limited = f/((e/2) + w) = 5/((5.661/2) + 0.076) = 1.72 female_limited = f/e = 5/5.661 = 0.883 p = x*min(male_limited, female_limited) = 1.5*min(1.72, 0.883) = 1.325