Пример #1
0
        // Exchanges gene values between two genes according to the CrossingPoint
        private void CrossoverGeneValues(ref ListGenomes geneOne, ref ListGenomes geneTwo)
        {
            for (int i = 0; i < this.CrossoverPoint; i++)
            {
                geneOne.List[i] = geneTwo.List[i];
            }

            for (int i = this.CrossoverPoint; i < Length; i++)
            {
                geneTwo.List[i] = geneOne.List[i];
            }
        }
Пример #2
0
        public override Genome Crossover(Genome g)
        {
            // Generate the firstGene as copy of g and the second one as copy of this genome
            ListGenomes originalGenome = (ListGenomes)g;
            ListGenomes firstGene      = new ListGenomes(g, originalGenome.Min, originalGenome.Max);
            ListGenomes secondGene     = new ListGenomes((Genome)this, originalGenome.Min, originalGenome.Max);

            CrossoverGeneValues(ref firstGene, ref secondGene);

            // Take the better gene that made out from the crossover, randomly
            // TODO: Maybe change this check to fitness check
            if (s_seed.Next(2) == 1)
            {
                return(firstGene);
            }
            else
            {
                return(secondGene);
            }
        }