示例#1
0
        /// <summary>
        /// Species Creation
        /// </summary>
        private void SpeciesCreation()
        {
            // Loop in Genomes
            foreach (Genome genome in _genomes)
            {
                bool isNewSpecies = true;

                // Loop in Species
                foreach (Species species in _species)
                {
                    // If Genome Distance < Max Genome Distance => Genome is from this Species
                    if (Genome.GenomeDistance(genome, species.Genome, _config.disjointMutator, _config.excessMutator, _config.avgDiffMutator) < _config.maxGenomeDistance)
                    {
                        species.Genomes.Add(genome);
                        _genomesSpecies.Add(genome, species);
                        isNewSpecies = false;
                        break;
                    }
                }

                // If the Genome has no Species => Add it to a new Species
                if (isNewSpecies)
                {
                    Species newSpecies = new Species(genome);
                    _species.Add(newSpecies);
                    _genomesSpecies.Add(genome, newSpecies);
                }
            }

            // Remove Empty Species
            _species.RemoveAll(item => item.Genomes.Count == 0);

            // Order Species Genome by Fitness (Desc order)
            foreach (Species species in _species)
            {
                species.Genomes = species.Genomes.OrderByDescending(o => o.Fitness).ToList();
            }
        }