示例#1
0
 public static IPermutation Mutate(this Permutation permutation, IRando rando, float mutationRate)
 {
     if (rando.NextDouble() < mutationRate)
     {
         return(rando.ToPermutation(permutation.Order));
     }
     return(permutation);
 }
示例#2
0
 public static ISortable Mutate(this ISortable sortable, IRando rando, float replacementRate)
 {
     if (rando.NextDouble() < replacementRate)
     {
         return(rando.ToPermutation(sortable.Order).ToSortable());
     }
     return(sortable);
 }
示例#3
0
 public static StageDimer ToGenomeStageDimer(this IRando randy, uint order)
 {
     return(new StageDimer(
                stage1: randy.ToFullTwoCyclePermutation(order),
                stage2: randy.ToFullTwoCyclePermutation(order),
                modifier: randy.ToPermutation(order)
                ));
 }
示例#4
0
 public static GenomeSorterConjOrbit ToGenomeConjOrbit(this IRando randy, uint order, uint stageCount)
 {
     return(new GenomeSorterConjOrbit(
                id: Guid.NewGuid(),
                twoCycle: randy.ToFullTwoCyclePermutation(order),
                conj: randy.ToPermutation(order),
                order: order,
                stageCount: stageCount));
 }
示例#5
0
        public static GaData UpdateSortablesDirect(
            this GaData sortingGaData, IRando randy)
        {
            var data                = sortingGaData.Data.Copy();
            var sortableWinRate     = data.GetSortableWinRate();
            var bestSortablePool    = data.GetBestSortablePool();
            var wholeSortablePool   = data.GetSortablePool();
            var sortableMutantCount = (uint)(wholeSortablePool.Sortables.Count * (1.0 - sortableWinRate));

            var sortableNextGen = bestSortablePool.Sortables.Values.Concat(
                0u.CountUp(sortableMutantCount)
                .Select(s => randy.ToPermutation(bestSortablePool.Order).ToSortable())
                );

            data.SetSortablePool(new SortablePool(Guid.NewGuid(), sortableNextGen));
            return(new GaData(data: data));
        }
示例#6
0
        public static GaDualSorter EvolveSortables(this GaDualSorter gaDualSorter,
                                                   Dictionary <Guid, SortableResult> sortableResults,
                                                   IRando randy,
                                                   double replacementRate)
        {
            var winSortablesCount   = (int)(gaDualSorter.SortablePool.Count() * (1.0 - replacementRate));
            var looseSortablesCount = gaDualSorter.SortablePool.Count() - winSortablesCount;
            var newSortables        = Enumerable.Range(0, looseSortablesCount)
                                      .Select(i => randy.ToPermutation(gaDualSorter.SorterPool.Order).ToSortable());

            var bestSortables = sortableResults.Values
                                .OrderByDescending(r => r.AverageSortedness)
                                .Take(winSortablesCount)
                                .Select(sr => sr.Sortable);

            var newSortablePool = new SortablePool(Guid.NewGuid(), bestSortables.Concat(newSortables));

            return(new GaDualSorter(
                       genomePoolDualSorter: gaDualSorter.GenomePoolDualSorter,
                       sortablePool: newSortablePool,
                       randy: randy));
        }
示例#7
0
 public static IPermutation ConjugateByRandomPermutation(this IPermutation perm, IRando randy)
 {
     return(perm.ConjugateBy(randy.ToPermutation(perm.Order)));
 }
示例#8
0
 public static SortablePool ToRandomSortablePool(this IRando rando, uint order, uint poolCount)
 {
     return new SortablePool(Guid.NewGuid(),
         0u.CountUp(poolCount).Select(i=>
         rando.ToPermutation(order).ToSortable()));
 }