示例#1
0
    public DNA <T> Crossover(DNA <T> otherParent)
    {
        DNA <T> child = new DNA <T>(Genes.Length, getRandomGene, fitnessFunction, shouldInitGenes: false);

        for (int i = 0; i < Genes.Length; i++)
        {
            child.Genes[i] = betterRandom.NextDouble() < 0.5 ? Genes[i] : otherParent.Genes[i];
        }

        return(child);
    }
示例#2
0
        public static double RandomNext()
        {
            double one = BetterRandom.NextDouble();
            double two = BetterRandom.NextDouble();

            return(Math.Sqrt(-2.0 * Math.Log(one)) * Math.Cos(6.2831853071795862 * two));
        }
示例#3
0
    private DNA <T> ChooseParent()
    {
        double randomNumber = betterRandom.NextDouble() * fitnessSum;

        for (int i = 0; i < Population.Count; i++)
        {
            if (randomNumber < Population[i].Fitness)
            {
                return(Population[i]);
            }

            randomNumber -= Population[i].Fitness;
        }

        return(null);
    }