Ejemplo n.º 1
0
        public override Gene Crossover(Gene mate)
        {
            PixelGene childGene      = new PixelGene(this.Bitmap.Width, this.Bitmap.Height, this.MutationRangeMax);
            PixelGene mateStaticGene = (PixelGene)mate;

            bool chooseFromThisGeneFirst = Utilities.Random.Next(0, 100) > 50;

            for (int i = 0; i < childGene.Bitmap.Width; i++)
            {
                for (int j = 0; j < childGene.Bitmap.Height; j++)
                {
                    childGene.Bitmap.SetPixel(i, j, new SKColor(
                                                  Utilities.Random.Next(0, this.MutationRangeMax) == this.MutationNumber ?
                                                  Convert.ToByte(Utilities.Random.Next(0, 255)) :
                                                  (chooseFromThisGeneFirst == true ? this.Bitmap.GetPixel(i, j).Red : mateStaticGene.Bitmap.GetPixel(i, j).Red),
                                                  Utilities.Random.Next(0, this.MutationRangeMax) == this.MutationNumber ?
                                                  Convert.ToByte(Utilities.Random.Next(0, 255)) :
                                                  (chooseFromThisGeneFirst != true ? this.Bitmap.GetPixel(i, j).Green : mateStaticGene.Bitmap.GetPixel(i, j).Green),
                                                  Utilities.Random.Next(0, this.MutationRangeMax) == this.MutationNumber ?
                                                  Convert.ToByte(Utilities.Random.Next(0, 255)) :
                                                  (chooseFromThisGeneFirst == true ? this.Bitmap.GetPixel(i, j).Blue : mateStaticGene.Bitmap.GetPixel(i, j).Blue),
                                                  Utilities.Random.Next(0, this.MutationRangeMax) == this.MutationNumber ?
                                                  Convert.ToByte(Utilities.Random.Next(0, 255)) :
                                                  (chooseFromThisGeneFirst != true ? this.Bitmap.GetPixel(i, j).Alpha : mateStaticGene.Bitmap.GetPixel(i, j).Alpha)
                                                  ));
                }
            }

            return(childGene);
        }
Ejemplo n.º 2
0
 public void GeneratePixelGenePopulation(Engine.RunConfig runConfig)
 {
     for (int i = 0; i < this.numberOfGenes; i++)
     {
         Gene gene = new PixelGene(this.targetBitmap.Width, this.targetBitmap.Height, runConfig.MutationRangeMax);
         gene.InitRandomly();
         this.genes.Add(gene);
     }
 }