Ejemplo n.º 1
0
        public static GenomeSorterDual Mutate(this
                                              GenomeSorterDual genomeDualSorter, IRando randy)
        {
            var mutantIndex = randy.NextUint(genomeDualSorter.StageCount);
            var newChromA   = genomeDualSorter.ChromosomeA;
            var newChromB   = genomeDualSorter.ChromosomeB;

            var newChoices = genomeDualSorter.Choices;

            if (randy.NextBool(0.5))
            {
                var mutantStage = randy.RewireSorterStage(genomeDualSorter.ChromoA(mutantIndex));
                newChromA = newChromA.ReplaceAtIndex(mutantIndex, mutantStage);
            }
            else
            {
                var mutantStage = randy.RewireSorterStage(genomeDualSorter.ChromoB(mutantIndex));
                newChromB = newChromB.ReplaceAtIndex(mutantIndex, mutantStage);
            }

            return(new GenomeSorterDual(
                       id: Guid.NewGuid(),
                       chromA: newChromA,
                       chromB: newChromB,
                       choices: newChoices));
        }
Ejemplo n.º 2
0
 public static IEnumerable <ISorter> MakePhenotypes(this GenomeSorterDual genomeDualSorter,
                                                    IRando randy, int count)
 {
     for (uint i = 0; i < count; i++)
     {
         yield return(0u.CountUp(genomeDualSorter.StageCount)
                      .Select(d => genomeDualSorter.Choice(d)
                 ? genomeDualSorter.ChromoA(d)
                 : genomeDualSorter.ChromoB(d))
                      .ToSorter(id: Guid.NewGuid(), genomeId: genomeDualSorter.Id));
     }
 }