Beispiel #1
0
        public override Chromosome PerformMutation(Chromosome chromosome)
        {
            Chromosome mutated = new Chromosome(shouldInitGenes: false);

            mutated.Genes = new List <int>(chromosome.Genes);

            if (Random.NextDouble() < Settings.MutationRate)
            {
                // Generate a random gene
                //mutated.GetRandomGenes();
                Shuffle(mutated.Genes);
                mutated.MakeProperGenes();
                //Console.WriteLine("{0}", string.Join(",", chromosome.GetReadableGenes()));
                //Console.WriteLine("{0}\n", string.Join(",", mutated.GetReadableGenes()));

                mutated.CalculateFitness();
            }

            return(mutated);
        }
Beispiel #2
0
        public override Chromosome PerformMutation(Chromosome chromosome)
        {
            Chromosome mutated = new Chromosome(shouldInitGenes: false);

            mutated.Genes = new List <int>(chromosome.Genes);
            List <int> listJobs = mutated.Genes.Where(x => x < 100).ToList();

            if (Random.NextDouble() < Settings.MutationRate)
            {
                int randJob         = listJobs[Random.Next(0, listJobs.Count)];
                int randDestination = listJobs[Random.Next(0, listJobs.Count)];
                int randJobPosition = mutated.Genes.FindLastIndex(x => x == randJob);
                mutated.Genes.Remove(randJob);
                mutated.Genes.Insert(randDestination, randJob);
                mutated.MakeProperGenes();
                //Console.WriteLine("{0}", string.Join(",", chromosome.GetReadableGenes()));
                //Console.WriteLine("{0}\n", string.Join(",", mutated.GetReadableGenes()));
            }

            return(mutated);
        }