Exemple #1
0
        public void Recombinate()
        {
            IndividualEvaluations evaluations = new IndividualEvaluations();
            Random random = new Random();

            _populationAfterCrossing = new Population();

            for (var i = 0; i < _matingPool.Size() / 2; i++)
            {
                var chosenIndividual1 = random.Next(_matingPool.Size());
                var chosenIndividual2 = random.Next(_matingPool.Size());
                var newIndividuals    = evaluations.Cross(_matingPool.GetIndividual(chosenIndividual1), _matingPool.GetIndividual(chosenIndividual2));

                var tempCrsProb = random.NextDouble();

                if (tempCrsProb < _crossingProbability)
                {
                    _populationAfterCrossing.Add(newIndividuals[0]);
                    _populationAfterCrossing.Add(newIndividuals[1]);
                }
                else
                {
                    _populationAfterCrossing.Add(_matingPool.GetIndividual(chosenIndividual1));
                    _populationAfterCrossing.Add(_matingPool.GetIndividual(chosenIndividual2));
                }
            }
        }
Exemple #2
0
        public void Mutation()
        {
            IndividualEvaluations evaluations = new IndividualEvaluations();

            _populationAfterMutation = new Population();
            _populationAfterCrossing.GenerateProbabilities();

            for (var i = 0; i < _populationAfterCrossing.Size(); i++)
            {
                _populationAfterMutation.Add(
                    _populationAfterCrossing.GetIndividual(i).GetMutationProbability() < _mutationProbability
                        ? evaluations.Mutate(_populationAfterCrossing.GetIndividual(i))
                        : _populationAfterCrossing.GetIndividual(i));
                _populationAfterMutation.GetIndividual(i).Calculate(_function1, _function2);
            }
        }