Пример #1
0
        /// <summary>
        /// Tworzy nową generację krzyżując obiekty z obecnej generacji.
        /// </summary>
        /// <returns>Zwraca nową generację.</returns>
        public Generation CreateNewGeneration()
        {
            if (!CurrentGeneration.WasEvaluated)
            {
                CurrentGeneration.Evaluate();
            }

            IDna[] objects = new IDna[GenerationsSize];
            for (uint i = 0; i < GenerationsSize; i++)
            {
                IDna parentA = CurrentGeneration.GetDnaBasedOnFitness();
                IDna parentB = CurrentGeneration.GetDnaBasedOnFitness();
                objects[i] = evolutionController.Crossover(parentA, parentB);
                IDna db = objects[i];
                Console.WriteLine(new string(db.GetGenes() as char[]) + " ||| " + db.Fitness);
            }

            CurrentGeneration = new Generation(evolutionController, objects);
            CurrentGeneration.Mutate(MutationChance > 100 ? (byte)100 : MutationChance);
            return(CurrentGeneration);
        }