EliteSelector implements Selector<G, C> { @Override public ISeq<Phenotype<G, C>> select( final Seq<Phenotype<G, C>> population, final int count, final Optimize opt ) { if (count < 0) { throw new IllegalArgumentException(format( "Selection count must be greater or equal then zero, but was %s.", count )); } ISeq<Phenotype<G, C>> result; if (population.isEmpty() || count <= 0) { result = ISeq.empty(); } else { final int ec = min(count, _eliteCount); result = ELITE_SELECTOR.select(population, ec, opt); result = result.append( _nonEliteSelector.select(population, max(0, count - ec), opt) ); } return result; } EliteSelector(
		final int eliteCount,
		final Selector<G, C> nonEliteSelector
	);  EliteSelector(final int eliteCount);  EliteSelector(final Selector<G, C> nonEliteSelector);  EliteSelector(); @Override ISeq<Phenotype<G, C>> select(
		final Seq<Phenotype<G, C>> population,
		final int count,
		final Optimize opt
	); @Override String toString();  }
@Test public void selectMaximum() { final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(100); for (int i = 0, n = population.size(); i < n; ++i) { final Genotype<DoubleGene> gt = Genotype.of(DoubleChromosome.of(DoubleGene.of(i, 0, n))); population.set(i, Phenotype.of(gt, 12, gt.gene().doubleValue())); } final EliteSelector<DoubleGene, Double> selector = new EliteSelector<>(); final ISeq<Phenotype<DoubleGene, Double>> selected = selector.select(population, 10, Optimize.MAXIMUM); Assert.assertEquals( population.get(population.length() - 1).genotype().gene().doubleValue(), selected.get(0).genotype().gene().doubleValue() ); }
@Test public void selectMinimum() { final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(100); for (int i = 0, n = population.size(); i < n; ++i) { final Genotype<DoubleGene> gt = Genotype.of(DoubleChromosome.of(DoubleGene.of(i, 0, n))); population.set(i, Phenotype.of(gt, 12, gt.gene().doubleValue())); } final EliteSelector<DoubleGene, Double> selector = new EliteSelector<>(); final ISeq<Phenotype<DoubleGene, Double>> selected = selector.select(population, 10, Optimize.MINIMUM); Assert.assertEquals( population.get(0).genotype().gene().doubleValue(), selected.get(0).genotype().gene().doubleValue() ); }