public IChromosome Mutate(IChromosome c)
        {
            Random      prng = RandomFactory.Instance();
            IChromosome ret  = c as IChromosome;

            int index;

            for (int i = 0; i < _numberOfMutations; i++)
            {
                index = prng.Next(0, ret.Count);
                ret   = Perturb(ret, index);
            }
            return(ret);
        }
Beispiel #2
0
        public IChromosome Select(IList <IChromosome> population)
        {
            if (TournamentSize > population.Count)
            {
                TournamentSize = population.Count;
            }
            List <IChromosome> tournament = new List <IChromosome>(TournamentSize);
            Random             prng       = RandomFactory.Instance();

            int index;

            for (int i = 0; i < TournamentSize; i++)
            {
                index = prng.Next(population.Count);
                tournament.Add(population[index]);
            }

            return(tournament.Max());
        }
Beispiel #3
0
        public IList <IChromosome> Recombine(IList <IChromosome> parents)
        {
            IList <IChromosome> children = new IChromosome[ChildrenProduced];
            Random prng = RandomFactory.Instance();
            int    parent, count = parents.First().Count;

            for (int i = 0; i < ChildrenProduced; i++)
            {
                children[i] = parents[i].GetCopy();

                for (int j = 0; j < count; j++)
                {
                    // TODO: Generalize to more than 2 parents... but what does ParentFavortism mean then?
                    parent         = (prng.NextDouble() <= ParentFavortism) ? 0 : 1;
                    children[i][j] = parents[parent][j];
                }
            }

            return(children);
        }
Beispiel #4
0
        private bool DoMutate()
        {
            Random prng = RandomFactory.Instance();

            return((prng.NextDouble() < MutationMechanism.MutationRate) ? true : false);
        }