public static IEnumerable <long> ProcessTick(CohortCollection cohorts, out PopulationChangeStats stats) { var newPops = new long[cohorts.Cohorts.Count]; var totalDeaths = 0L; var racialTemplate = cohorts.RacialTemplate; var fertileFemales = (cohorts.GetPopulationWithAllFeatures(CohortFeatures.Fertile) / 2) + (cohorts.GetPopulationWithAllFeatures(CohortFeatures.LowFertile) / 4); var births = (long)(racialTemplate.BirthRatePerTick * fertileFemales); var graduatingCount = births; for (int i = 0; i < racialTemplate.CohortTemplates.Count; i++) { var cohortSize = cohorts.Cohorts[i].Population; var deathCount = (long)(cohorts.RacialTemplate.GetAverageDeathRatePerTick(i) * cohortSize); totalDeaths += deathCount; var newCohortSize = cohortSize - deathCount + graduatingCount; var template = racialTemplate.CohortTemplates[i]; graduatingCount = cohortSize / (template.PastEndAge - template.StartAge).TickOffset; newCohortSize -= graduatingCount; newPops[i] = newCohortSize; } totalDeaths += graduatingCount; stats = new PopulationChangeStats(TimeOffset.OneTick, totalDeaths, births); return(newPops); }
public void PopulationDistributionTest() { var cohorts = new CohortCollection(m_racialTemplate); cohorts.DistributePopulationAcrossCohorts(1000000000); var stats = new PopulationChangeStats(new TimeOffset(0), 0, 0); var maxDate = new TimePoint((long)(Constants.DaysPerYear * 1)); for (var date = new TimePoint(0); date < maxDate; date += TimeOffset.OneTick) { var newPops = PopulationUtility.ProcessTick(cohorts, out var tickStats); cohorts = cohorts.CloneWithNewPopulations(newPops); stats += tickStats; } }