Пример #1
0
        public static ISgMutantProfile ToSgMutantProfile
        (
            this ISorterGenomeEval parentGenomeEval,
            ISorterMutateParams sorterMutateParams
        )
        {
            var rando = Rando.Fast(sorterMutateParams.Seed);

            var layer = SorterLayer.Make(new[] { parentGenomeEval.SorterGenome }, 0)
                        .Reproduce(
                seed: rando.NextInt(),
                newGenomeCount: sorterMutateParams.MutantCount,
                mutationRate: sorterMutateParams.SorterMutationRate,
                insertionRate: sorterMutateParams.SorterInsertionRate,
                deletionRate: sorterMutateParams.SorterDeletionRate
                );

            var compPool = CompPool.MakeEmpty(parentGenomeEval.SorterGenome.KeyCount)
                           .AddSorterEvalsParallel(layer.Genomes.Select(g => g.ToSorter()));

            return(new SgMutantProfileImpl(
                       parentGenomeEval: parentGenomeEval,
                       sorterGenomeEvals: compPool.SorterEvals.Where(ev => ev.SwitchUseCount <= sorterMutateParams.MaxScore)
                       .Select(ev => SorterGenomeEval.Make
                               (
                                   sorterGenome: layer.GetGenome(ev.Sorter.Guid),
                                   parentGenomeEval: parentGenomeEval,
                                   sorterEval: ev,
                                   generation: 1,
                                   success: ev.Success
                               )),
                       scores: compPool.SorterEvals.Select(ev => (double)ev.SwitchUseCount),
                       sorterMutateParams: sorterMutateParams
                       ));
        }
Пример #2
0
 public SgMutantProfileImpl(
     ISorterGenomeEval parentGenomeEval,
     IEnumerable <ISorterGenomeEval> sorterGenomeEvals,
     IEnumerable <double> scores,
     ISorterMutateParams sorterMutateParams
     )
 {
     _parentGenomeEval   = parentGenomeEval;
     _sorterGenomeEvals  = sorterGenomeEvals.ToList();
     _scores             = scores.ToList();
     _sorterMutateParams = sorterMutateParams;
 }
        public static SorterGenomeEvalToJson ToJsonAdapter(this ISorterGenomeEval sorterGenomeEval)
        {
            var chromosomeUintToJson = new SorterGenomeEvalToJson
            {
                SorterGenomeToJson = sorterGenomeEval.SorterGenome.ToJsonAdapter(),
                SorterEvalToJson   = sorterGenomeEval.SorterEval.ToJsonAdapter(),
                ParentScores       = sorterGenomeEval.Ancestors,
                Generation         = sorterGenomeEval.Generation,
                Score = sorterGenomeEval.Score
            };

            return(chromosomeUintToJson);
        }
Пример #4
0
 public static ISorterGenomeEval Make(
     ISorterGenome sorterGenome,
     ISorterGenomeEval parentGenomeEval,
     ISorterEval sorterEval,
     int generation,
     bool success
     )
 {
     return(Make
            (
                sorterGenome: sorterGenome,
                ancestors: (parentGenomeEval == null) ? ImmutableStack <int> .Empty :
                parentGenomeEval.Ancestors.Push
                (
                    sorterEval.SwitchUseCount
                ),
                sorterEval: sorterEval,
                generation: generation,
                success: success
            ));
 }
Пример #5
0
 public static ISorterGenomeEvalVm ToSorterGenomeEvalVm(this ISorterGenomeEval sorterGenomeEval)
 {
     return(new SorterGenomeEvalVmImpl(sorterGenomeEval));
 }
Пример #6
0
 public SorterGenomeEvalVmImpl(ISorterGenomeEval sorterGenomeEval)
 {
     _sorterGenomeEval = sorterGenomeEval;
 }
 public static string ToJsonString(this ISorterGenomeEval sorterGenome)
 {
     return(JsonConvert.SerializeObject(sorterGenome.ToJsonAdapter(), Formatting.None));
 }