Exemplo n.º 1
0
 public static GenomeSorterDual ToDualSorterGenome(this IRando randy, uint order, uint stageCount)
 {
     return(new GenomeSorterDual(
                id: Guid.NewGuid(),
                chromA: 0u.CountUp(stageCount)
                .Select(i => randy.ToFullSorterStage(order, i)),
                chromB: 0u.CountUp(stageCount)
                .Select(i => randy.ToFullSorterStage(order, i)),
                choices: 0u.CountUp(stageCount)
                .Select(i => randy.NextBool(0.5))
                ));
 }
Exemplo n.º 2
0
        public static ISorter Mutate(this ISorter sorter, IRando rando, StageReplacementMode stageReplacementMode)
        {
            var          mutantIndex    = rando.NextUint(sorter.StageCount);
            var          stageToReplace = sorter[(int)mutantIndex];
            ISorterStage mutantStage    = null;

            switch (stageReplacementMode)
            {
            case StageReplacementMode.RandomReplace:
                mutantStage = rando.ToFullSorterStage(order: sorter.Order, stageNumber: mutantIndex);
                break;

            case StageReplacementMode.RandomRewire:
                mutantStage = rando.RewireSorterStage(stageToReplace);
                break;

            case StageReplacementMode.RandomConjugate:
                mutantStage = stageToReplace.ConjugateByRandomPermutation(rando).ToSorterStage(mutantIndex);
                break;

            case StageReplacementMode.RCTC:
                mutantStage = stageToReplace.ConjugateByRandomSingleTwoCycle(rando).ToSorterStage(mutantIndex);
                break;

            default:
                throw new Exception($"{stageReplacementMode.ToString()}");
            }

            return(sorter.SorterStages.ReplaceAtIndex(mutantIndex, mutantStage)
                   .ToSorter(id: Guid.NewGuid(), genomeId: Guid.Empty));
        }
Exemplo n.º 3
0
 public static ISorter ToSorter(this IRando randy, uint order, uint stageCount)
 {
     return(new Sorter(
                id: Guid.NewGuid(),
                genomeId: Guid.Empty,
                stages: 0u.CountUp(stageCount)
                .Select(i => randy.ToFullSorterStage(order, i))));
 }