/// <summary> /// Selects all chromosomes with positive fitness from given population /// </summary> /// <param name="population">Population</param> /// <returns></returns> public static IList <IChromosome> SelectProfitableChromosomes(this PopulationBase population) { var completeList = new List <IChromosome>(); foreach (var g in population.Generations) { completeList.AddRange(g.Chromosomes); } return(completeList.SelectDistinct() .Where(c => c.Fitness != null && c.Fitness.Value > 0) .OrderByDescending(c => c.Fitness.Value) .ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="GeneticAlgorithm"/> class. /// </summary> /// <param name="population">The chromosomes population.</param> /// <param name="fitness">The fitness evaluation function.</param> /// <param name="taskExecutor">Task executor.</param> public GeneticAlgorithm( PopulationBase population, IFitness fitness, ITaskExecutor taskExecutor) { Population = population; Fitness = fitness; TaskExecutor = taskExecutor; // Initial state values -> TimeEvolving = TimeSpan.Zero; State = GeneticAlgorithmState.NotStarted; // Init mutation - Will replace a gene at random position with a new randomly generated gene -> Mutation = new UniformMutation(); // Collection of crossover operators to use -> CrossoverCollection = new List <ICrossover>(); }