Beispiel #1
0
        Epoch(Dictionary <int, float> fitnessScores)
        {
            if (fitnessScores.Count != m_Population.Count)
            {
                Debug.LogError("scores and genomes mismatch error. (" + fitnessScores.Count + " / " + m_Population.Count + ")");
                return(null);
            }

            ResetAndKill();

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

            SortAndRecord();
            SpeciateGenomes();
            CalculateSpawnLevels();

            Debug.Log("best fitness last gen: " + m_Population[0].Fitness());

            List <CGenome> newPopulation = new List <CGenome> ();

            int numSpawned = SpawnLeaders(newPopulation);

            for (int i = 0; i < m_vecSpecies.Count; i++)
            {
                CSpecies species = m_vecSpecies[i];
                numSpawned = SpawnOffspring(species, numSpawned, newPopulation);
            }

            /*
             * Tournament selection is used over the entire population if due
             * to a underflow of the species amount to spawn the offspring
             * doesn't fill the entire population additional children needs to
             * created.
             */
            if (numSpawned < _params.NumGenomesToSpawn)
            {
                int numMoreToSpawn = _params.NumGenomesToSpawn - numSpawned;

                while (numMoreToSpawn-- > 0)
                {
                    CGenome baby = new CGenome(TournamentSelection(m_PopSize / 5));
                    baby.SetID(++nextGenomeID);
                    newPopulation.Add(baby);
                }
            }

            m_Population = newPopulation;

            m_iGeneration++;

            return(CreatePhenotypes());
        }