public static IEnumerable <ISorter> Mutate(this ISorter sorter, IRando rando, double mutationRate) { var randoK = rando.Spawn(); var keyPairList = KeyPairRepository.KeyPairSet(sorter.KeyCount).KeyPairs; var newb = randoK.Pick(keyPairList).ToMoveNext(); while (true) { yield return(new SorterImpl ( keyPairs: sorter.KeyPairs.MutateInsertDelete ( rando.Spawn().ToBoolEnumerator(mutationRate), rando.Spawn().ToBoolEnumerator(mutationRate), rando.Spawn().ToBoolEnumerator(mutationRate), T => newb.Next(), T => newb.Next(), T => newb.Next() ), guid: randoK.NextGuid(), keyCount: sorter.KeyCount )); } }
public static Tuple <ISorterGenome, ISorterGenome> Recombine(this Tuple <ISorterGenome, ISorterGenome> parents, IRando rando, double recombinationRate) { var newChromosomes = parents.Item1.Chromosome.Recombine ( Chromosome.StandardRecombinator <IGeneUintModN>( rando: rando.Spawn(), recombinationRate: recombinationRate ), parents.Item2.Chromosome.Blocks ); return(new Tuple <ISorterGenome, ISorterGenome>( Make(parents.Item1.Guid, parents.Item1.ParentGuid, (IChromosomeUint)newChromosomes.Item1, parents.Item1.KeyCount, parents.Item1.KeyPairCount), Make(parents.Item2.Guid, parents.Item2.ParentGuid, (IChromosomeUint)newChromosomes.Item2, parents.Item2.KeyCount, parents.Item2.KeyPairCount) )); }