Ejemplo n.º 1
0
        public RandomPopulationSettings MapFrom(PopulationSettingsDTO populationSettingsDTO)
        {
            var populationSettings = new RandomPopulationSettings();

            populationSettings.BaseIndividual      = _cloner.Clone(populationSettingsDTO.Individual);
            populationSettings.NumberOfIndividuals = populationSettingsDTO.NumberOfIndividuals.ConvertedTo <int>();

            //first add one gender with ration 100 for each available gender
            populationSettingsDTO.AvailableGenders().Each(g => populationSettings.AddGenderRatio(new GenderRatio {
                Gender = g, Ratio = 100
            }));

            //in case of multiple gender, adjust the ration according to the feamales proportion
            if (populationSettingsDTO.HasMultipleGenders)
            {
                populationSettings.GenderRatio(populationSettingsDTO.Female).Ratio = populationSettingsDTO.ProportionOfFemales;
                populationSettings.GenderRatio(populationSettingsDTO.Male).Ratio   = 100 - populationSettingsDTO.ProportionOfFemales;
            }

            populationSettingsDTO.Parameters.Each(p => populationSettings.AddParameterRange(p.ParameterRange));
            return(populationSettings);
        }
Ejemplo n.º 2
0
        public PopulationSettingsDTO MapFrom(RandomPopulationSettings populationSettings)
        {
            var populationSettingsDTO = new PopulationSettingsDTO();

            populationSettingsDTO.Individual          = populationSettings.BaseIndividual;
            populationSettingsDTO.NumberOfIndividuals = populationSettings.NumberOfIndividuals.ConvertedTo <uint>();
            //use clone since we do not want to override the value if the user clicks cancel
            //in case of multiple gender, adjust the ration according to the feamales proportion
            if (populationSettingsDTO.HasMultipleGenders)
            {
                var femaleRatio = populationSettings.GenderRatio(populationSettingsDTO.Female);
                populationSettingsDTO.ProportionOfFemales = femaleRatio.Ratio;
            }
            populationSettings.ParameterRanges.Each(pr => populationSettingsDTO.Parameters.Add(new ParameterRangeDTO(pr.Clone())));

            return(populationSettingsDTO);
        }
 public void should_update_the_gender_ration()
 {
     _result.GenderRatio(_genderRepository.Male).Ratio.ShouldBeEqualTo(60);
     _result.GenderRatio(_genderRepository.Female).Ratio.ShouldBeEqualTo(40);
 }
 public void should_return_a_population_settings_with_the_accurate_gender_distribution()
 {
     _result.GenderRatios.Count().ShouldBeEqualTo(2);
     _result.GenderRatio(_male).Ratio.ShouldBeEqualTo(20);
     _result.GenderRatio(_female).Ratio.ShouldBeEqualTo(80);
 }