Exemple #1
0
        public void AdvanceGeneration()//This assumes that the score has been updated externally from this process
        {
            UnityEngine.Random.InitState((int)Time.realtimeSinceStartup);
            //Sort list by score and take top x
            var newGenerationParents =
                _currentPopulation.OrderByDescending((x) => x.CurrentScore)
                .Take(_generationArguments.KeepTopCount)
                .ToList();
            //use this to re-populate the population

            var newGeneration = new List <GeneticInstance>(_generationArguments.GenerationSize);

            if (_generationArguments.KeepExactParents)
            {
                newGeneration.AddRange(newGenerationParents);
            }

            while (newGeneration.Count < _generationArguments.GenerationSize)
            {
                var parent = newGenerationParents[UnityEngine.Random.Range(0, newGenerationParents.Count)];
                var child  = new GeneticInstance(parent, _mutator);
                newGeneration.Add(child);
            }

            _currentPopulation = newGeneration;

            CurrentGeneration++;
        }
Exemple #2
0
        private void InitPopulation(PIDTunerRequirements requirements, GenerationArguments generationArguments)
        {
            //TODO:Create init mutator
            var mutator = new RandomMutator();

            while (_currentPopulation.Count < generationArguments.GenerationSize)
            {
                var newInstance = new GeneticInstance(requirements, mutator);
                _currentPopulation.Add(newInstance);
            }
        }
Exemple #3
0
            public GeneticInstance(GeneticInstance parent, MutationArguments mutator)
            {
                CurrentScore          = 0.0f;
                ControllerGeneticData = new List <TuneableController>(parent.ControllerGeneticData.Count);

                foreach (var controller in parent.ControllerGeneticData)
                {
                    var childController = controller.DeepCopy();
                    childController.Mutate(mutator);
                    ControllerGeneticData.Add(childController);
                }
            }