예제 #1
0
        private void Select(ref List <Gene> genes, EnvironmentController environmentController, int size = -1)
        {
            List <(Gene gene, double fitness)> sortedGenes = new List <(Gene, double)>();
            var envAspects = environmentController.GetAspects();

            foreach (var gene in genes)
            {
                sortedGenes.Add((new Gene(gene), Fitness(gene, envAspects)));
            }
            sortedGenes.Sort((elm1, elm2) => elm2.fitness.CompareTo(elm1.fitness));

            genes.Clear();

            if (size < 0)
            {
                size = selectedSize;
            }
            for (int i = 0; i < selectedSize; ++i)
            {
                genes.Add(sortedGenes[i].gene);
            }
        }