Exemplo n.º 1
0
 public double FailureRate(TimeOffset t)
 {
     return(m_lambda);
 }
Exemplo n.º 2
0
 public double Reliability(TimeOffset t)
 {
     return(Exp(-m_lambda * (double)t.TickOffset));
 }
Exemplo n.º 3
0
 public double ConditionalReliability(TimeOffset age, TimeOffset t)
 {
     return(Exp(-m_lambda * (double)t.TickOffset));
 }
Exemplo n.º 4
0
 public double Cdf(TimeOffset t)
 {
     return(1.0 - Exp(-m_lambda * (double)t.TickOffset));
 }
Exemplo n.º 5
0
 public double Pdf(TimeOffset t)
 {
     return(m_lambda * Exp(-m_lambda * (double)t.TickOffset));
 }
Exemplo n.º 6
0
 public PopulationChangeStats(TimeOffset timeSpan, long deaths, long births)
 {
     TimeSpan = timeSpan;
     Deaths   = deaths;
     Births   = births;
 }
Exemplo n.º 7
0
 public CohortTemplate(CohortFeatures features, TimeOffset startAge, TimeOffset pastEndAge)
 {
     Features   = features;
     StartAge   = startAge;
     PastEndAge = pastEndAge;
 }
Exemplo n.º 8
0
        public static CohortTemplate[] CreateAll(CohortTemplateConfiguration config)
        {
            if (config.LowFertilityStart < config.PhysicalMaturation)
            {
                throw new ArgumentException($"{nameof(CohortTemplateConfiguration.LowFertilityStart)} must be after {nameof(CohortTemplateConfiguration.PhysicalMaturation)}.", nameof(config));
            }
            if (config.InfertilityStart <= config.PhysicalMaturation)
            {
                throw new ArgumentException($"{nameof(CohortTemplateConfiguration.InfertilityStart)} must be after {nameof(CohortTemplateConfiguration.PhysicalMaturation)}.", nameof(config));
            }
            if (config.LowFertilityStart > config.InfertilityStart)
            {
                throw new ArgumentException($"{nameof(CohortTemplateConfiguration.InfertilityStart)} must be at or after {nameof(CohortTemplateConfiguration.LowFertilityStart)}.", nameof(config));
            }
            if (config.LifetimeDistribution is null)
            {
                throw new ArgumentException($"{nameof(CohortTemplateConfiguration.LifetimeDistribution)} must be specified.", nameof(config));
            }

            var templates = new List <CohortTemplate>();
            int index     = 0;

            while (true)
            {
                var cohortStartAge   = new TimeOffset(CohortLengthInDays * index);
                var cohortPastEndAge = new TimeOffset(CohortLengthInDays * (index + 1));
                var startFailureRate = config.LifetimeDistribution.FailureRate(cohortStartAge);

                var features = CohortFeatures.None;
                if (config.InfantsRequireExtraCare && index == 0)
                {
                    features |= CohortFeatures.RequiresExtraCare;
                }
                else
                {
                    if (index < config.MentalMaturation)
                    {
                        features |= CohortFeatures.Student;
                    }

                    if (index < config.PhysicalMaturation)
                    {
                        features |= CohortFeatures.RequiresCare;
                    }
                    else if (index < config.LowFertilityStart)
                    {
                        features |= CohortFeatures.Fertile;
                    }
                    else if (index < config.InfertilityStart)
                    {
                        features |= CohortFeatures.LowFertile;
                    }

                    if (startFailureRate >= ExtraCareRequiredThreshold)
                    {
                        features |= CohortFeatures.RequiresExtraCare;
                    }
                    else if (startFailureRate >= CareRequiredThreshold)
                    {
                        features |= CohortFeatures.RequiresCare;
                    }
                }

                templates.Add(new CohortTemplate(features, cohortStartAge, cohortPastEndAge));

                if (startFailureRate >= 1.0)
                {
                    break;
                }
                index++;
                if (index > MaxCohortIndex)
                {
                    throw new InvalidOperationException($"Cohort index exceeded {MaxCohortIndex}.");
                }
            }

            return(templates.ToArray());
        }