Exemplo n.º 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
                       ));
        }
Exemplo n.º 2
0
        public async Task OnRunAsync(CancellationTokenSource cancellationTokenSource)
        {
            Busy = true;
            _cancellationTokenSource = cancellationTokenSource;

            var rando = Rando.Fast(ScpParamsVm.Seed);

            var rbw = RecursiveBackgroundWorker.Make
                      (
                initialState: ScpWorkflow.Make
                (
                    sorterLayer: SorterLayer.Make(
                        sorterGenomes: _sorterGenomeEvals.Select(e => e.Value.SorterGenome),
                        generation: ScpParamsVm.CurrentGeneration
                        ),
                    scpParams: ScpParamsVm.GetParams,
                    generation: ScpParamsVm.CurrentGeneration
                ),

                recursion: (i, c) =>
            {
                var nextStep = i;
                while (true)
                {
                    if (_cancellationTokenSource.IsCancellationRequested)
                    {
                        return(IterationResult.Make <IScpWorkflow>(null, ProgressStatus.StepIncomplete));
                    }

                    nextStep = nextStep.Step(rando.NextInt());

                    if (nextStep.CompWorkflowState == CompWorkflowState.ReproGenomes)
                    {
                        return(IterationResult.Make(nextStep, ProgressStatus.StepComplete));
                    }
                }
            },
                totalIterations: ScpParamsVm.TotalGenerations - ScpParamsVm.CurrentGeneration,
                cancellationTokenSource: _cancellationTokenSource
                      );

            rbw.OnIterationResult.Subscribe(UpdateSorterTuneResults);
            await rbw.Start();

            Busy = false;
        }