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); }
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()); }
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); }
private bool DoMutate() { Random prng = RandomFactory.Instance(); return((prng.NextDouble() < MutationMechanism.MutationRate) ? true : false); }