Ejemplo n.º 1
0
        private static double[] RecombineArrays(double[] firstParam, double[] secondParam, RecombinationFunction recombinationType)
        {
            if (firstParam.Length != secondParam.Length)
            {
                throw new ArgumentOutOfRangeException("Unequal Length");
            }

            double[] recombined = new double[firstParam.Length];

            for (int i = 0; i < recombined.Length; ++i)
            {
                recombined[i] = recombinationType(firstParam[i], secondParam[i]);
            }
            return(recombined);
        }
Ejemplo n.º 2
0
        public static List <Individual> Recombine(ref List <Individual> parents, int lambda, RecombinationFunction recombinationTypeGenes, RecombinationFunction recombinationTypeSigma)
        {
            if (lambda <= 1)
            {
                throw new ArgumentOutOfRangeException("lambda", "Lambda too low");
            }


            int rand1, rand2;
            List <Individual> childs = new List <Individual>(lambda);

            for (int i = 0; i < lambda; i++)
            {
                //TODO rand1 could be rand2 ...
                rand1 = RandomNumbers.GetRandomIntNumber(0, parents.Count);
                do
                {
                    rand2 = RandomNumbers.GetRandomIntNumber(0, parents.Count);
                } while (rand2 == rand1 || parents.Count < 2);

                childs.Add(Recombine(parents[rand1], parents[rand2], recombinationTypeGenes, recombinationTypeSigma));
            }
            return(childs);
        }
Ejemplo n.º 3
0
        private static Individual Recombine(Individual firstIndividual, Individual secondIndividual, RecombinationFunction recombinationTypeGenes, RecombinationFunction recombinationTypeSigma)
        {
            Individual individual = new Individual();

            //TODO securitycheckshere length etc
            individual.genes   = RecombineArrays(firstIndividual.genes, secondIndividual.genes, recombinationTypeGenes);
            individual.sigma   = RecombineArrays(firstIndividual.sigma, secondIndividual.sigma, recombinationTypeSigma);
            individual.fitness = float.PositiveInfinity;
            return(individual);
        }