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());
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 public void AddPopulation(RacialTemplate racialTemplate, long count)
 {
     using (ScopedPropertyChange())
     {
         var cohortCollection = m_populations.GetOrAddValue(racialTemplate.Id, new CohortCollection(racialTemplate));
         cohortCollection.DistributePopulationAcrossCohorts(count);
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 private CohortCollection(RacialTemplate racialTemplate, CohortImpl[] cohorts, Lazy <IReadOnlyList <double> > distributionRatios)
 {
     RacialTemplate       = racialTemplate;
     m_cohorts            = cohorts;
     m_distributionRatios = distributionRatios;
 }
Ejemplo n.º 7
0
 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)))
 {
 }
Ejemplo n.º 8
0
 public CohortCollection(RacialTemplate racialTemplate)
     : this(racialTemplate, racialTemplate.CohortTemplates.Select(x => new CohortImpl(x, 0L)).ToArray(), new Lazy <IReadOnlyList <double> >(() => GetDistributionRatios(racialTemplate)))
 {
 }