示例#1
0
        /// <summary>
        /// Generates a child for the given species
        /// </summary>
        /// <param name="species">The species to get the child from</param>
        /// <returns>The child</returns>
        private Genome GetChild(Species species)
        {
            return(Rnd.NextDouble() * 100 >= CrossoverProbability
                   //Crossover child
                ? Mutator.Mutate(species.Members[Rnd.Next(species.Members.Count)]
                                 .Crossover(species.Members[Rnd.Next(species.Members.Count)]))

                   //Clone Child
                : Mutator.Mutate(species.Members[Rnd.Next(species.Members.Count)].Clone()));
        }
示例#2
0
        /// <summary>
        /// Populates the population
        /// </summary>
        public void Populate()
        {
            if (BaseGenome == null)
            {
                throw new Exception("BaseGenome has to be set first!");
            }

            if (Mutator == null)
            {
                throw new Exception("Mutator has to be set first!");
            }

            //Add mutated versions of the base genome
            for (var i = 0; i < PopulationSize; i++)
            {
                FindSpecies(CurrentPopulation, Mutator.Mutate(BaseGenome.Clone()));
            }
        }