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)); }
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); }
private Genome TourneyHelp(Genome left, Genome right) { return (left._relativeFitness > right._relativeFitness) ? left : right; }
public Genome(Genome nome) { genome = new BitArray(nome.genome); _fitness = null; _relativeFitness = 0.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; }