@Test public void testSelection() { SelectionStrategy<String, String> strategy = new TournamentSelection<>(4, 3); List<EvaluatedIndividual<String>> population = new ArrayList<>(4); population.add(new EvaluatedIndividual<>("a", 10.0)); population.add(new EvaluatedIndividual<>("b", 9.5)); population.add(new EvaluatedIndividual<>("c", 9.8)); population.add(new EvaluatedIndividual<>("d", 1.6)); population.add(new EvaluatedIndividual<>("e", 5.6)); population.add(new EvaluatedIndividual<>("f", 2.1)); ThreadedContext context = new ThreadedContext(123); assertEquals(of("a", "c", "e", "a"), strategy.select(population, context.getRandomForThread())); }
@Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final List<T> selection = new ArrayList<>(selectionSize); for (int i = 0; i < selectionSize; i++) { selection.add(tournament(individuals, random)); } return selection; }
TournamentSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final List<T> selection = new ArrayList<>(selectionSize); for (int i = 0; i < selectionSize; i++) { selection.add(tournament(individuals, random)); } return selection; } }
TournamentSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final List<T> selection = new ArrayList<>(selectionSize); for (int i = 0; i < selectionSize; i++) { selection.add(tournament(individuals, random)); } return selection; } @AccessedViaReflection  TournamentSelection(int selectionSize, int tournamentSize); }
TournamentSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final List<T> selection = new ArrayList<>(selectionSize); for (int i = 0; i < selectionSize; i++) { selection.add(tournament(individuals, random)); } return selection; } @AccessedViaReflection  TournamentSelection(int selectionSize, int tournamentSize); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random); @Override String toString(); }
TournamentSelection implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final List<T> selection = new ArrayList<>(selectionSize); for (int i = 0; i < selectionSize; i++) { selection.add(tournament(individuals, random)); } return selection; } @AccessedViaReflection  TournamentSelection(int selectionSize, int tournamentSize); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random); @Override String toString();  }