public Individual(Generation generation, Individual father, bool wasFatherSelectedByElitism,
            Individual mother, bool wasMotherSelectedByElitism)
        {
            Initialize(generation);

            _chromosomes = new Chromosome[TotalChromosomes];


            // Initialize Secondary Mutation Chromosomes
            Chromosome[] parentChromosomes = new Chromosome[SecondaryMutationChromosomesAmount];

            bool getFromFather = false;
            for (int i = 0; i < SecondaryMutationChromosomesAmount; i++)
            {
                parentChromosomes[i] = (getFromFather ? father : mother)._chromosomes[i];
                getFromFather = !getFromFather;
            }
            parentChromosomes = parentChromosomes.RandomizeArray();

            for (int i = 0; i < SecondaryMutationChromosomesAmount; i++) { _chromosomes[i] = parentChromosomes[i]; }



            // Divide The Rest Of The Chromosomes Based On Elitism
            float getChromosomeFromFatherChance = wasFatherSelectedByElitism == wasMotherSelectedByElitism ? 0.5f
                : wasFatherSelectedByElitism ? ElitismChromosomeChance : 1f - ElitismChromosomeChance;

            for (int i = SecondaryMutationChromosomesAmount; i < TotalChromosomes; i++)
            {
                _chromosomes[i] = (RandomManager.EvaluatePercentage(getChromosomeFromFatherChance) ? father : mother)._chromosomes[i];
            }


            SimulateMutation();
        }
Exemple #2
0
        public Generation(Results results, int generationNumber, Generation previousGeneration)
        {
            _resultsInfo      = results;
            _generationNumber = generationNumber;

            int totalElitismPicks        = SettingsManager.SelectionsByElitism;
            int individualsPerGeneration = SettingsManager.IndividualsPerGeneration;

            for (int i = 0; i < totalElitismPicks; i++)
            {
                if (SettingsManager.GuaranteedSurvivalForElites)
                {
                    RecordResult(previousGeneration._results[i].tester.RunResult);
                    continue;
                }

                Individual father      = previousGeneration._results[i].tester;
                int        motherIndex = RandomManager.RandomIntWithHollowSpot(0, individualsPerGeneration - 1, i);
                Individual mother      = previousGeneration._results[motherIndex].tester;

                RecordResult(new Individual(this, father, true, mother, motherIndex < totalElitismPicks).RunResult);
            }

            for (int i = totalElitismPicks; i < individualsPerGeneration; i++)
            {
                Individual father      = previousGeneration._results[i].tester;
                int        motherIndex = RandomManager.RandomIntWithHollowSpot(0, individualsPerGeneration - 1, i);
                Individual mother      = previousGeneration._results[motherIndex].tester;

                RecordResult(new Individual(this, father, false, mother, motherIndex < totalElitismPicks).RunResult);
            }
        }
        public Individual(Generation generation)
        {
            Initialize(generation);

            // Initialize Chromosomes
            _chromosomes = new Chromosome[TotalChromosomes];
            for (int i = 0; i < TotalChromosomes; i++)
            {
                _chromosomes[i] = new Chromosome(this, RandomManager.RandomInt(0, 1) == 0);
            }
        }
        public void SimulateMutation()
        {
            int totalChanges = 0;
            for (int i = 0; i < TotalChromosomes; i++)
            {
                if (totalChanges > MaxMutableChromosomes) { break; }
                if (!RandomManager.EvaluatePercentage(MutationChance)) { continue; }

                _chromosomes[i] = new Chromosome(this, !_chromosomes[i].Usable);
                totalChanges++;
            }
        }
        private void Initialize(Generation generation)
        {
            _generation = generation;
            _name = NextIndividualName;

            // Generate Individual Color
            _drawColor = Color.White;
            while (_drawColor.IsSimilarToColor(Color.White))
            {
                _drawColor = Color.FromArgb(255, RandomManager.RandomInt(0, 255),
                    RandomManager.RandomInt(0, 255), RandomManager.RandomInt(0, 255));
            }
        }