Ejemplo n.º 1
0
        /// <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 override void ProcessTick(IEntityLookup entityLookup, NotificationLog notificationLog, TimePoint newTime)
        {
            var entitiesList = entityLookup.GetEntitiesMatchingKey(entityLookup.CreateComponentKey(typeof(PopulationComponent)));

            foreach (var entity in entitiesList)
            {
                var component   = entity.GetRequiredComponent <PopulationComponent>();
                var populations = component.Populations;
                foreach (var population in populations)
                {
                    var newPops = PopulationUtility.ProcessTick(population, out var _);
                    component.SetPopulation(population.RacialTemplate, newPops);
                }
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }