Exemplo n.º 1
0
        CalculateSpawnLevels()
        {
            for (int i = 0; i < m_Population.Count; i++)
            {
                CGenome genome  = m_Population[i];
                float   toSpawn = 0;

                if (m_dAvFitAdj > 0)
                {
                    toSpawn = genome.GetAdjustedFitness() / m_dAvFitAdj;
                }

                genome.SetAmountToSpawn(toSpawn);
            }

            for (int i = 0; i < m_vecSpecies.Count; i++)
            {
                CSpecies species = m_vecSpecies[i];
                species.CalculateSpawnAmount();
            }
        }
Exemplo n.º 2
0
        SpeciateGenomes()
        {
            bool addedToSpecies = false;

            for (int i = 0; i < m_Population.Count; i++)
            {
                CGenome genome = m_Population[i];

                float    bestCompatability = 1000;
                CSpecies bestSpecies       = null;

                for (int j = 0; j < m_vecSpecies.Count; j++)
                {
                    CSpecies species       = m_vecSpecies[j];
                    float    compatibility = genome.GetCompatibilityScore(species.Leader());

                    // if this individual is similar to this species leader add to species
                    if (compatibility < bestCompatability)
                    {
                        bestCompatability = compatibility;
                        bestSpecies       = species;
                    }
                }

                if (bestCompatability <= _params.CompatibilityThreshold)
                {
                    bestSpecies.AddMember(genome);

                    genome.SetSpecies(bestSpecies.ID());

                    addedToSpecies = true;
                }

                if (!addedToSpecies)
                {
                    // we have not found a compatible species so a new one will be created
                    m_vecSpecies.Add(new CSpecies(genome, nextSpeciesID++));
                }

                addedToSpecies = false;
            }

            /*
             * Adjust the fitness for all members of the every species to take
             * into account fitness sharing and age of species.
             */
            for (int i = 0; i < m_vecSpecies.Count; i++)
            {
                CSpecies species = m_vecSpecies[i];
                species.AdjustFitnesses();
            }

            /*
             * Calculate new adjusted total and average fitness for the population.
             */
            for (int i = 0; i < m_Population.Count; i++)
            {
                CGenome genome = m_Population[i];
                m_dTotFitAdj += genome.GetAdjustedFitness();
            }

            m_dAvFitAdj = m_dTotFitAdj / m_Population.Count;
        }