public GeneticAlgorithm(IGeneticFunctions <T> funcs, GeneticSettings settings) : this(funcs, settings, from item in Enumerable.Range(0, settings.PopulationCount) select funcs.Random()) { }
public GeneticAlgorithm(IGeneticFunctions <T> funcs, GeneticSettings settings, IEnumerable <T> population) { this.functions = funcs; this.settings = settings; var tempCount = population.Count(); var collection = new List <T>(this.settings.PopulationCount); if (tempCount < settings.PopulationCount) { collection.AddRange(population); collection.AddRange(Enumerable.Range(0, this.settings.PopulationCount - tempCount).Select(x => funcs.Random())); } this.currentPopulation = (from person in collection select new Individual(person, this.functions.Fitness(person))).ToList(); this.currentPopulation = (from person in this.currentPopulation orderby person.Fitness descending select person).ToList(); }