Beispiel #1
0
        public override Candidate Mutate(Candidate candidate)
        {
            double    chance = RandomMutator.NextDouble();
            Candidate mutant = new Candidate(candidate);

            if (chance < mutationChance)
            {
                int endIndex;
                int startIndex = RandomMutator.Next(0, candidate.chromoson.Count());
                do
                {
                    endIndex = RandomMutator.Next(0, candidate.chromoson.Count());
                } while (startIndex == endIndex);
                if (startIndex > endIndex)
                {
                    int temp = startIndex;
                    startIndex = endIndex;
                    endIndex   = temp;
                }


                mutant.chromoson.Reverse(startIndex, endIndex - startIndex);
            }
            mutant.CountFitness();
            return(mutant);
        }