Ejemplo n.º 1
0
        public void NextGeneration()
        {
            SpeciesCollection.ClearSpecies();
            foreach (var genome in CurrentGeneration)
            {
                SpeciesCollection.Speciate(genome);
            }
            SpeciesCollection.ClearEmptySpecies();

            int population = Population;

            var nextGeneration = SpeciesCollection.Selection(population);

            LastGenerationWithSpecies = nextGeneration;

            // fill up when there is no species or
            var remaining = population - nextGeneration.Count;

            for (int i = 0; i < remaining; i++)
            {
                nextGeneration.Add(Genome.CreateDefault(this), null);
            }

            //Populate(population);

            LastFillUp = remaining;

            LastGeneration.Clear();
            LastGeneration.AddRange(CurrentGeneration);
            CurrentGeneration.Clear();
            CurrentGeneration.AddRange(nextGeneration.Select(x => x.Key));

            Generation++;
        }
Ejemplo n.º 2
0
 public void Populate(int population)
 {
     for (var i = 0; i < population; i++)
     {
         var genome = Genome.CreateDefault(this);
         CurrentGeneration.Add(genome);
     }
 }
Ejemplo n.º 3
0
        public Genome Copy()
        {
            var genome = Genome.CreateDefault(Evaluator);

            genome.Fitness = Fitness;
            foreach (var connectionsConnection in ConnectionCollection.Connections)
            {
                genome.ConnectionCollection.AddNew(connectionsConnection.Value.Copy(this));
            }

            foreach (var node in NodeCollection.Nodes.Values)
            {
                genome.NodeCollection.AddNew(node.Copy());
            }

            return(genome);
        }