public static bool GeneticallyEqual(Gene gene1, Gene gene2) { if (gene1.Dna.Count != gene2.Dna.Count) { return(false); } for (int i = 0; i < gene1.Dna.Count; i++) { if (!GeneticallyEqual(gene1.Dna[i], gene2.Dna[i])) { return(false); } } return(true); }
public void Mutate() { int locus1 = _random.Next(0, Genotype.GeneCount); int locus2 = _random.Next(0, Genotype.GeneCount); Gene gene1 = _genes[locus1]; Gene gene2 = _genes[locus2]; switch (Genotype.MutationType) { case MutationType.Random: _genes[locus1] = Gene.RandomGene(Genotype.GeneLength); _genes[locus1].SetMutation(); break; case MutationType.Swap: _genes[locus1] = gene2; _genes[locus2] = gene1; _genes[locus1].SetMutation(); _genes[locus2].SetMutation(); break; } }
public void Copy(Gene parent) { _gene = parent._gene; }
public void AddGene(Gene g) { _genes.Add(g); }