Exemple #1
0
        public Genome MakeChild(Genome other, BitArray mask)
        {
            BitArray leftCopy = new BitArray(this.genome);
            BitArray rightCopy = new BitArray(other.genome);
            BitArray maskCopy = new BitArray(mask);

            leftCopy.And(maskCopy);
            rightCopy.And(maskCopy.Not());

            //BitArray temp2 = new BitArray(right.And(mask.Not()));
            return new Genome(leftCopy.Or(rightCopy));
        }
Exemple #2
0
 public Genome Cross_N(Genome other, int points)
 {
     BitArray bitMask = new BitArray(this.genome.Length);
     bitMask.SetAll(false);
     for (int i = 0; i < points; i++)
         bitMask[Genetic.rand.Next(Genetic.bitLength)] = true;
     Extend_Bits(ref bitMask);
     //Console.WriteLine(bitMask.Print());
     return MakeChild( other, bitMask);
 }
Exemple #3
0
 private Genome TourneyHelp(Genome left, Genome right)
 {
     return (left._relativeFitness > right._relativeFitness) ? left : right;
 }
Exemple #4
0
 public Genome(Genome nome)
 {
     genome = new BitArray(nome.genome);
     _fitness = null;
     _relativeFitness = 0.0;
 }
Exemple #5
0
        private List<Genome> Breed_RandomTop()
        {
            const int TOP_N = 10;
            var newGeneration = new List<Genome>();

            //random breeding of most successful
            var breeders = currentGeneration.Take(TOP_N).ToArray();
            Genome newChild;
            while (newGeneration.Count < individuals)
            {
                newChild = new Genome(breeders[rand.Next(0, TOP_N)].Cross_N(breeders[rand.Next(0, TOP_N)], crossPoints));
                newGeneration.Add(newChild);
            }
            return newGeneration;
        }