TruncationSelector implements Selector<G, C> { @Override public ISeq<Phenotype<G, C>> select( final Seq<Phenotype<G, C>> population, final int count, final Optimize opt ) { requireNonNull(population, "Population"); requireNonNull(opt, "Optimization"); if (count < 0) { throw new IllegalArgumentException(format( "Selection count must be greater or equal then zero, but was %s", count )); } final MSeq<Phenotype<G, C>> selection = MSeq .ofLength(population.isEmpty() ? 0 : count); if (count > 0 && !population.isEmpty()) { final MSeq<Phenotype<G, C>> copy = population.asISeq().copy(); copy.sort((a, b) -> opt.<C>descending().compare(a.fitness(), b.fitness())); int size = count; do { final int length = min(min(copy.size(), size), _n); for (int i = 0; i < length; ++i) { selection.set((count - size) + i, copy.get(i)); } size -= length; } while (size > 0); } return selection.toISeq(); } TruncationSelector(final int n);  TruncationSelector(); @Override ISeq<Phenotype<G, C>> select(
		final Seq<Phenotype<G, C>> population,
		final int count,
		final Optimize opt
	); @Override String toString();  }
@Test public void worstIndividual() { final int size = 20; final MSeq<Phenotype<DoubleGene, Integer>> population = MSeq.ofLength(size); for (int i = 0; i < size; ++i) { final DoubleGene gene = DoubleGene.of(i, 0, size + 10); final DoubleChromosome ch = DoubleChromosome.of(gene); final Genotype<DoubleGene> gt = Genotype.of(ch); final Phenotype<DoubleGene, Integer> pt = Phenotype.of( gt, 1, gt.gene().intValue() ); population.set(i, pt); } final TruncationSelector<DoubleGene, Integer> selector = new TruncationSelector<>(5); final ISeq<Phenotype<DoubleGene, Integer>> selected = selector.select(population.toISeq(), 10, Optimize.MINIMUM); for (Phenotype<DoubleGene, Integer> pt : selected) { Assert.assertTrue(pt.fitness() < 5); } }