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));
     }
 }
Ejemplo n.º 3
0
        public static GenomeSorterDual RecombineI(this GenomeSorterDual genomeDualSorter, IRando randy)
        {
            var kk = randy.NextUint(genomeDualSorter.StageCount);

            var recombines = genomeDualSorter.ChromosomeA.ToList().Recombo(
                genomeDualSorter.ChromosomeB.ToList(), kk);

            return(new GenomeSorterDual(
                       id: Guid.NewGuid(),
                       chromA: recombines.Item1.ToList(),
                       chromB: recombines.Item2.ToList(),
                       choices: genomeDualSorter.Choices));
        }
Ejemplo n.º 4
0
        public static Tuple <GenomeSorterDual, GenomeSorterDual> Recombine(
            this GenomeSorterDual genomeDualSorterA,
            GenomeSorterDual genomeDualSorterB,
            IRando randy)
        {
            var cA        = genomeDualSorterA.ChromosomeA.ToList();
            var cB        = genomeDualSorterA.ChromosomeB.ToList();
            var recombin1 = cA.Recombo(cB, randy.NextUint((uint)cA.Count()));
            var recombin2 = cB.Recombo(cA, randy.NextUint((uint)cA.Count()));

            if (randy.NextBool(0.5))
            {
                return(new Tuple <GenomeSorterDual, GenomeSorterDual>(
                           item1: new GenomeSorterDual(
                               id: Guid.NewGuid(),
                               chromA: recombin1.Item1,
                               chromB: recombin1.Item2,
                               choices: genomeDualSorterA.Choices),
                           item2: new GenomeSorterDual(
                               id: Guid.NewGuid(),
                               chromA: recombin2.Item1,
                               chromB: recombin2.Item2,
                               choices: genomeDualSorterA.Choices)
                           ));
            }

            return(new Tuple <GenomeSorterDual, GenomeSorterDual>(
                       item1: new GenomeSorterDual(
                           id: Guid.NewGuid(),
                           chromA: recombin1.Item2,
                           chromB: recombin1.Item1,
                           choices: genomeDualSorterA.Choices),
                       item2: new GenomeSorterDual(
                           id: Guid.NewGuid(),
                           chromA: recombin2.Item2,
                           chromB: recombin2.Item1,
                           choices: genomeDualSorterA.Choices)
                       ));
        }