/// <summary> /// Mutation Predicate. /// Modifies a DNA string by changing one of its bases to be a random new value /// </summary> /// <param name="mut_index"> /// The point in which mutation is applied. /// </param> /// <param name="randomGene"> /// The function used to supply random Genes /// </param> public static Mutant mutate(int mut_index, DNA original, getRandomGeneFunct randomGene) { Mutant m; DNA g_dna; DNAPartial g_partial; DNAPartial rest; Gene g; g=randomGene(); while (original.Contains(g)) g = randomGene(); g_dna = new DNA(); g_dna.Add(g); var sp_mut = split(mut_index-1, original); g_partial = split(0, g_dna).back; // remove the base at the location that mutation is to occur DNA back = join(new DNAPartial(), sp_mut.back); back.RemoveAt(0); // add mutated item back = join(g_partial, split(0,back).back); DNA front = join(new DNAPartial(), sp_mut.front); // join front, mutation, and rest, lists together rest = split(0, join(split(0,front).back, split(0, back).back)).back; m = new Mutant(join(new DNAPartial(), rest)); return m; }