/// <summary> /// Simulate a test population until all original people are deceased and use the /// final population distribution as a basis for distributing newly created populations. /// </summary> private static IReadOnlyList <double> GetDistributionRatios(RacialTemplate racialTemplate) { long testPopulation = 1000000; var ageRange = (double)racialTemplate.CohortTemplates.Sum(x => (x.PastEndAge - x.StartAge).TickOffset); var pops = racialTemplate.CohortTemplates .Select(cohortTemplate => { var cohortAgeRange = (double)(cohortTemplate.PastEndAge - cohortTemplate.StartAge).TickOffset; return((long)((double)testPopulation * cohortAgeRange / ageRange)); }); var testCohorts = new CohortCollection(racialTemplate, pops); var maxDate = new TimePoint(0) + testCohorts.Cohorts.Last().PastEnd; for (var date = new TimePoint(0); date < maxDate; date += TimeOffset.OneTick) { testCohorts = new CohortCollection(racialTemplate, PopulationUtility.ProcessTick(testCohorts, out var _)); } var finalTestPopulation = (double)testCohorts.TotalPopulation; return(testCohorts.Cohorts .Select(x => (double)x.Population / finalTestPopulation) .AsReadOnlyList()); }
public void SetPopulation(RacialTemplate racialTemplate, IEnumerable <long> populations) { using (ScopedPropertyChange()) { var cohortCollection = m_populations.GetOrAddValue(racialTemplate.Id, new CohortCollection(racialTemplate)); m_populations[racialTemplate.Id] = cohortCollection.CloneWithNewPopulations(populations); } }
public void AddPopulation(RacialTemplate racialTemplate, long count) { using (ScopedPropertyChange()) { var cohortCollection = m_populations.GetOrAddValue(racialTemplate.Id, new CohortCollection(racialTemplate)); cohortCollection.DistributePopulationAcrossCohorts(count); } }
public static void MakeHomeWorld(Entity entity, RacialTemplate racialTemplate) { var population = new PopulationComponent(); population.AddPopulation(GetHumanTemplate(), 1000000000); entity.AddComponent(population); var shipyard = new ShipyardComponent(); entity.AddComponent(shipyard); }
public void Setup() { var lifetimeDistribution = new GompertzMakehamDistribution(1E-5, 0.085, 5.0E-3); var cohortTemplates = CohortTemplate.CreateAll( new CohortTemplateConfiguration { InfantsRequireExtraCare = true, PhysicalMaturation = 3, MentalMaturation = 4, LowFertilityStart = 7, InfertilityStart = 9, LifetimeDistribution = lifetimeDistribution, }); var birthRate = 0.1 / Constants.DaysPerYear; m_racialTemplate = new RacialTemplate("human", "Human", lifetimeDistribution, birthRate, cohortTemplates); }
private CohortCollection(RacialTemplate racialTemplate, CohortImpl[] cohorts, Lazy <IReadOnlyList <double> > distributionRatios) { RacialTemplate = racialTemplate; m_cohorts = cohorts; m_distributionRatios = distributionRatios; }
private CohortCollection(RacialTemplate racialTemplate, IEnumerable <long> populations) : this(racialTemplate, populations.Select((pop, i) => new CohortImpl(racialTemplate.CohortTemplates[i], pop)).ToArray(), new Lazy <IReadOnlyList <double> >(() => GetDistributionRatios(racialTemplate))) { }
public CohortCollection(RacialTemplate racialTemplate) : this(racialTemplate, racialTemplate.CohortTemplates.Select(x => new CohortImpl(x, 0L)).ToArray(), new Lazy <IReadOnlyList <double> >(() => GetDistributionRatios(racialTemplate))) { }