Beispiel #1
0
        public override GenericIndividual <float, double> Crossover(GenericIndividual <float, double> o, Random rand, float a)
        {
            Individual child = new Individual(Utils.ArrayToIntTree <float>(Genes));

            //child.Genes = Genes.Zip(o.Genes, (a, b) => a.Zip(b,(x,y)=> (x+y)*0.5f).ToArray() ).ToArray();



            for (int i = 0; i < Genes.Length; i++)
            {
                for (int j = 0; j < Genes[i].Length; j++)
                {
                    //float diff = Math.Abs(Genes[i][j] - o.Genes[i][j]);
                    //float m;
                    //if (rand.NextDouble()<0.8)
                    //{
                    //    m = (rand.NextDouble() < 0.55) ? Genes[i][j] : o.Genes[i][j];

                    //}
                    //else
                    //{
                    //    m = Lerp(Genes[i][j], o.Genes[i][j], (float)rand.NextDouble());
                    //}
                    //child.Genes[i][j] = m;

                    //float perc = (rand.NextDouble() < 0.55) ? .75f : 0.25f;
                    // float perc = (i % 3 == 0) ? 0.15f : .85f;
                    //child.Genes[i][j] = (rand.NextDouble() < 0.5) ? Genes[i][j]  : (rand.Next()<0.5) ? Lerp(o.Genes[i][j], Genes[i][j], 0.5f) : o.Genes[i][j];
                    //child.Genes[i][j] = Lerp(o.Genes[i][j], Genes[i][j], (float)rand.NextDouble());
                    //Lerp(o.Genes[i][j], Genes[i][j], perc);
                    //child.Genes[i][j] = Lerp(Genes[i][j] - a*(o.Genes[i][j] - Genes[i][j]),o.Genes[i][j] + a*(o.Genes[i][j] - Genes[i][j]),(float)rand.NextDouble());

                    float x1 = Genes[i][j],
                          x2 = o.Genes[i][j];

                    a = rand.Next(0, 100) * 0.01f;
                    //if (o.Genes[i][j] > Genes[i][j])
                    //{
                    //    x2 = o.Genes[i][j];
                    //    x1 = Genes[i][j];
                    //}
                    //else
                    //{
                    //    x1 = o.Genes[i][j];
                    //    x2 = Genes[i][j];
                    //}


                    child.Genes[i][j] = Lerp(x1 - a * (x2 - x1), x2 + a * (x2 - x1), (float)rand.NextDouble());
                }
            }

            return(child);
        }
Beispiel #2
0
 public Individual(GenericIndividual <float, double> parent)
 {
     Genes   = parent.Genes;
     Fitness = parent.Fitness;
 }
Beispiel #3
0
 public abstract GenericIndividual<T, X> Crossover(GenericIndividual<T, X> o,Random rand,float a);