Ejemplo n.º 1
0
        public Individual <T>[][] Apply(Individual <T>[] population, int parentGroupsCount, int parentsPerGroup)
        {
            double[] expectations = fitnessScaling.CalculateExpectations(population);
            Roulette roulette     = Roulette.CreateFromPositive(expectations, rng);

            var parentGroups = new Individual <T> [parentGroupsCount][];

            for (int group = 0; group < parentGroupsCount; ++group)
            {
                parentGroups[group] = new Individual <T> [parentsPerGroup];
                for (int parent = 0; parent < parentsPerGroup; ++parent)
                {
                    Individual <T> individual = population[roulette.SpinWheelWithBall()];
                    if (!allowIdenticalParents)
                    {
                        while (parentGroups[group].Contains <Individual <T> >(individual))
                        {
                            individual = population[roulette.SpinWheelWithBall()];
                        }
                    }
                    parentGroups[group][parent] = individual;
                }
            }
            return(parentGroups);
        }
Ejemplo n.º 2
0
        protected override sealed Individual <T>[] RemainderPhase(Individual <T>[] population, double[] fractionalParts,
                                                                  int extrasParentsCount)
        {
            Roulette roulette     = Roulette.CreateFromPositive(fractionalParts, RNG);
            var      extraParents = new Individual <T> [extrasParentsCount];

            for (int i = 0; i < extrasParentsCount; ++i)
            {
                extraParents[i] = population[roulette.SpinWheelWithBall()];
            }
            return(extraParents);
        }
        private Individual <T>[] SampleAllAtOnce(Individual <T>[] population, int totalParentsCount)
        {
            double[] expectations = fitnessScaling.CalculateExpectations(population);
            Roulette roulette     = Roulette.CreateFromPositive(expectations, rng);

            int[] selectedIndexes = roulette.SpinWheelWithPointers(totalParentsCount);

            var allParents = new Individual <T> [totalParentsCount];

            for (int i = 0; i < totalParentsCount; ++i)
            {
                allParents[i] = population[selectedIndexes[i]];
            }
            return(allParents);
        }