@Test public void testSelection6() { SelectionStrategy<String, String> strategy = new TruncationSelection<>(10); assertEquals(of("a", "b", "c", "d", "e", "f", "a", "b", "c", "d"), strategy.select(population, context.getRandomForThread())); }
@Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { int ratioCount = (int) round(ratio * individuals.size()); int numIndividuals = selectionSize != UNKNOWN ? selectionSize : individuals.size(); final List<T> selection = new ArrayList<T>(numIndividuals); ratioCount = ratioCount > numIndividuals ? numIndividuals : ratioCount; do { int count = min(ratioCount, numIndividuals - selection.size()); for (int i = 0; i < count; i++) { selection.add(individuals.get(i).getIndividual()); } } while (selection.size() < numIndividuals); return selection; }
TruncationSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { int ratioCount = (int) round(ratio * individuals.size()); int numIndividuals = selectionSize != UNKNOWN ? selectionSize : individuals.size(); final List<T> selection = new ArrayList<T>(numIndividuals); ratioCount = ratioCount > numIndividuals ? numIndividuals : ratioCount; do { int count = min(ratioCount, numIndividuals - selection.size()); for (int i = 0; i < count; i++) { selection.add(individuals.get(i).getIndividual()); } } while (selection.size() < numIndividuals); return selection; } }
TruncationSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { int ratioCount = (int) round(ratio * individuals.size()); int numIndividuals = selectionSize != UNKNOWN ? selectionSize : individuals.size(); final List<T> selection = new ArrayList<T>(numIndividuals); ratioCount = ratioCount > numIndividuals ? numIndividuals : ratioCount; do { int count = min(ratioCount, numIndividuals - selection.size()); for (int i = 0; i < count; i++) { selection.add(individuals.get(i).getIndividual()); } } while (selection.size() < numIndividuals); return selection; } @AccessedViaReflection  TruncationSelection(double ratio); @AccessedViaReflection  TruncationSelection(int selectionSize); @AccessedViaReflection  TruncationSelection(double ratio, int selectionSize); }
TruncationSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { int ratioCount = (int) round(ratio * individuals.size()); int numIndividuals = selectionSize != UNKNOWN ? selectionSize : individuals.size(); final List<T> selection = new ArrayList<T>(numIndividuals); ratioCount = ratioCount > numIndividuals ? numIndividuals : ratioCount; do { int count = min(ratioCount, numIndividuals - selection.size()); for (int i = 0; i < count; i++) { selection.add(individuals.get(i).getIndividual()); } } while (selection.size() < numIndividuals); return selection; } @AccessedViaReflection  TruncationSelection(double ratio); @AccessedViaReflection  TruncationSelection(int selectionSize); @AccessedViaReflection  TruncationSelection(double ratio, int selectionSize); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random); @Override String toString(); }
TruncationSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { int ratioCount = (int) round(ratio * individuals.size()); int numIndividuals = selectionSize != UNKNOWN ? selectionSize : individuals.size(); final List<T> selection = new ArrayList<T>(numIndividuals); ratioCount = ratioCount > numIndividuals ? numIndividuals : ratioCount; do { int count = min(ratioCount, numIndividuals - selection.size()); for (int i = 0; i < count; i++) { selection.add(individuals.get(i).getIndividual()); } } while (selection.size() < numIndividuals); return selection; } @AccessedViaReflection  TruncationSelection(double ratio); @AccessedViaReflection  TruncationSelection(int selectionSize); @AccessedViaReflection  TruncationSelection(double ratio, int selectionSize); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random); @Override String toString();  }