private static IChromosome[] GetBestChromosomes(int n, Population population) { if (n == 0) { return(new IChromosome[0]); } var min = population.GetEvaluations().OrderByDescending(x => x).Take(n).Last(); var bestChromosomes = new IChromosome[n]; int index = 0; foreach (var chromosome in population) { if (chromosome.Evaluation >= min) { bestChromosomes[index] = chromosome.Chromosome; index++; } if (index >= n) { return(bestChromosomes); } } throw new InternalSearchException("Code 1000 (not enough best chromosomes found)"); }