public RandomPopulationSettings MapFrom(Individual individual)
        {
            //add age first
            var populationSettings = new RandomPopulationSettings();

            if (individual == null)
            {
                return(populationSettings);
            }

            var population = individual.OriginData.SpeciesPopulation;

            populationSettings.BaseIndividual      = individual;
            populationSettings.NumberOfIndividuals = CoreConstants.DEFAULT_NUMBER_OF_INDIVIDUALS_IN_POPULATION;
            int genderCount = individual.AvailableGenders().Count();

            foreach (var gender in individual.AvailableGenders())
            {
                populationSettings.AddGenderRatio(new GenderRatio {
                    Gender = gender, Ratio = 100 / genderCount
                });
            }

            if (population.IsAgeDependent)
            {
                var ageParameter = individual.Organism.Parameter(CoreConstants.Parameter.AGE);
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(ageParameter));
            }

            if (individual.IsPreterm)
            {
                var gestationalAgeParameter = individual.Organism.Parameter(CoreConstants.Parameter.GESTATIONAL_AGE);
                populationSettings.AddParameterRange(discretedParameterRangeFrom(gestationalAgeParameter, numericListOfValues(gestationalAgeParameter)));
            }

            if (population.IsHeightDependent)
            {
                var heightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_HEIGHT);
                populationSettings.AddParameterRange(parameterRangeFrom(heightParameter));
            }

            var weightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_WEIGHT);

            if (population.IsAgeDependent)
            {
                populationSettings.AddParameterRange(parameterRangeFrom(weightParameter));
            }
            else
            {
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(weightParameter));
            }

            if (population.IsHeightDependent)
            {
                var bmiParameter = individual.Organism.Parameter(CoreConstants.Parameter.BMI);
                populationSettings.AddParameterRange(parameterRangeFrom(bmiParameter));
            }
            return(populationSettings);
        }
Ejemplo n.º 2
0
 protected override void Context()
 {
     base.Context();
     _populationSettingsDTO    = new PopulationSettingsDTO();
     _newPopulationSettingsDTO = new PopulationSettingsDTO();
     _oldIndividual            = A.Fake <Individual>();
     A.CallTo(() => _populationSettingsMapper.MapFrom(_oldIndividual)).Returns(_populationSettingsDTO);
     A.CallTo(() => _populationSettingsMapper.MapFrom(_newIndividual)).Returns(_newPopulationSettingsDTO);
     _newIndividual = A.Fake <Individual>();
     A.CallTo(() => _newIndividual.AvailableGenders()).Returns(new List <Gender>());
     //first initialize with the old individual
     sut.PrepareForCreating(_oldIndividual);
 }
 protected override void Context()
 {
     base.Context();
     _individual = A.Fake <Individual>();
     A.CallTo(() => _individual.AvailableGenders()).Returns(new List <Gender> {
         _genderRepository.Male, _genderRepository.Female
     });
     _populationSettings                   = new RandomPopulationSettings();
     _batchPopSettings                     = new Batch.PopulationSettings();
     _batchPopSettings.Population          = "Population";
     _batchPopSettings.MinAge              = 25;
     _batchPopSettings.MaxAge              = 40;
     _batchPopSettings.MinGestationalAge   = 30;
     _batchPopSettings.MinHeight           = 10;
     _batchPopSettings.MaxHeight           = 20;
     _batchPopSettings.MinWeight           = double.NaN;
     _batchPopSettings.MaxWeight           = 40;
     _batchPopSettings.MinBMI              = 8;
     _batchPopSettings.MaxBMI              = double.NaN;
     _batchPopSettings.NumberOfIndividuals = 2589;
     _batchPopSettings.ProportionOfFemales = 40;
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.BMI
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.AGE
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_HEIGHT
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_WEIGHT
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Male
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Female
     });
     A.CallTo(() => _individualFactory.CreateStandardFor(A <OriginData> ._)).Returns(_individual);
     A.CallTo(() => _popSettingsMapper.MapFrom(_individual)).Returns(_populationSettings);
 }
        protected override void Context()
        {
            base.Context();
            _individual = A.Fake <Individual>();
            Gender male = new Gender {
                Name = CoreConstants.Gender.Male
            };
            Gender female = new Gender {
                Name = CoreConstants.Gender.Female
            };

            A.CallTo(() => _individual.AvailableGenders()).Returns(new[] { male, female });
            _settings = new RandomPopulationSettings();
            _settings.BaseIndividual = _individual;
            _settings.AddGenderRatio(new GenderRatio {
                Gender = male, Ratio = 100
            });
            _settings.AddGenderRatio(new GenderRatio {
                Gender = female, Ratio = 0
            });
        }
Ejemplo n.º 5
0
 public virtual IEnumerable <Gender> AvailableGenders()
 {
     return(Individual != null?Individual.AvailableGenders() : new List <Gender>());
 }