# Math for simulating city population/birth rate

I have a set of game objects positioned around a map with city models attached to them.
Each has a class Settlement attached, on a timer I execute a function in every settlement function.

public float population_growth{
get{
float housing_avalibility = Mathf.Clamp(1 - ((float)population_count/(float)housing_capacity), 0.0f, 1.0f);
float food_avalibility = Mathf.Clamp(1 - ((float)food_consumed/(float)food_produced), 0.0f, 1.0f);
float growth = ((0.5f * housing_avalibility) + (0.5f * food_avalibility)) * 0.5f;
growth = Mathf.Clamp(growth, 0.0f, 0.5f);
Debug.Log ("growth = " + growth + ", with housing at " + housing_avalibility*100 + "%, with food at "+ food_avalibility*100 + "%");
return growth;
}
}
public void ReproductionCycleUpdate(){
population_count += Mathf.RoundToInt(n_children);

n_children = Mathf.RoundToInt(population_growth * population_count);

eligable_recruits += Mathf.RoundToInt(population_count * recruits_rate);

Debug.Log ("population = " + population_count);
Debug.Log ("children = " + n_children);
Debug.Log ("eligable recruits = " + eligable_recruits);
}


I currently use population growth to calculate the growth rate, however I am not sure the best approach but I want to be able to base the growth rate of a number of variables such as how much housing is available and how much food surplus is available.

The growth cannot be lower than 0 or greater than 0.5 (presumes ruffly that 50% are females that can reproduce 1 child and that any anomalies to this balance)

Logistical growth sounds like what you are after.

How would I go about applying various values such as food surplus or housing available (if no living space is available will reduce reproduction rate and lots of empty living space will increase reproduction rate)

Logistical growth rate looks like this.

noOfNewIndividuals = currentPopulation * maxGrowthRate  / (1 - currentPopulation / maxPopulation);


In most cases the max population is calculated based on the limiting factor. In your case I’d calculate a theoretical max population for each factor, then use the lowest. This equation will also start killing people if resources disappear or the population suddenly spikes.

Something like this

float[] maxPopulationSize;
foreach (factor that can affect growth){
// Calculate a maxPopulationSize and add it to the array
}
maxPolulation = Mathf.Min(maxPopulationSize);