1
|
|
package net.bmahe.genetics4j.core.selection; |
2
|
|
|
3
|
|
import java.util.Comparator; |
4
|
|
import java.util.List; |
5
|
|
import java.util.random.RandomGenerator; |
6
|
|
|
7
|
|
import org.apache.commons.lang3.Validate; |
8
|
|
import org.apache.logging.log4j.LogManager; |
9
|
|
import org.apache.logging.log4j.Logger; |
10
|
|
|
11
|
|
import net.bmahe.genetics4j.core.Genotype; |
12
|
|
import net.bmahe.genetics4j.core.Individual; |
13
|
|
import net.bmahe.genetics4j.core.Population; |
14
|
|
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; |
15
|
|
import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy; |
16
|
|
import net.bmahe.genetics4j.core.spec.selection.Tournament; |
17
|
|
|
18
|
|
public class TournamentSelector<T extends Comparable<T>> implements Selector<T> { |
19
|
|
public static final Logger logger = LogManager.getLogger(TournamentSelector.class); |
20
|
|
|
21
|
|
private final SelectionPolicy selectionPolicy; |
22
|
|
private final RandomGenerator randomGenerator; |
23
|
|
|
24
|
|
public TournamentSelector(final SelectionPolicy _selectionPolicy, final RandomGenerator _randomGenerator) { |
25
|
|
Validate.notNull(_selectionPolicy); |
26
|
|
Validate.isInstanceOf(Tournament.class, _selectionPolicy); |
27
|
|
Validate.notNull(_randomGenerator); |
28
|
|
|
29
|
1
1. <init> : Removed assignment to member variable selectionPolicy → KILLED
|
this.selectionPolicy = _selectionPolicy; |
30
|
1
1. <init> : Removed assignment to member variable randomGenerator → KILLED
|
this.randomGenerator = _randomGenerator; |
31
|
|
} |
32
|
|
|
33
|
|
@Override |
34
|
|
public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final int numIndividuals, |
35
|
|
final List<Genotype> population, final List<T> fitnessScore) { |
36
|
|
Validate.notNull(eaConfiguration); |
37
|
|
Validate.notNull(population); |
38
|
|
Validate.notNull(fitnessScore); |
39
|
|
Validate.isTrue(numIndividuals > 0); |
40
|
|
Validate.isTrue(population.size() == fitnessScore.size()); |
41
|
|
|
42
|
|
@SuppressWarnings("unchecked") |
43
|
|
final Tournament<T> tournamentSelection = (Tournament<T>) selectionPolicy; |
44
|
|
|
45
|
1
1. select : removed call to net/bmahe/genetics4j/core/spec/selection/Tournament::comparator → KILLED
|
final Comparator<Individual<T>> baseComparator = tournamentSelection.comparator(); |
46
|
6
1. select : removed call to java/lang/MatchException::<init> → NO_COVERAGE
2. select : removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::optimization → KILLED
3. select : RemoveSwitch 1 (case value 2) → KILLED
4. select : removed call to net/bmahe/genetics4j/core/spec/Optimization::ordinal → KILLED
5. select : RemoveSwitch 0 (case value 1) → KILLED
6. select : Changed switch default to be first case → KILLED
|
final Comparator<Individual<T>> comparator = switch (eaConfiguration.optimization()) { |
47
|
|
case MAXIMIZE -> baseComparator; |
48
|
2
1. select : replaced call to java/util/Comparator::reversed with receiver → KILLED
2. select : removed call to java/util/Comparator::reversed → KILLED
|
case MINIMIZE -> baseComparator.reversed(); |
49
|
|
}; |
50
|
|
|
51
|
|
logger.debug("Selecting {} individuals", numIndividuals); |
52
|
|
|
53
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
final Population<T> selectedIndividuals = new Population<>(); |
54
|
5
1. select : removed conditional - replaced comparison check with true → TIMED_OUT
2. select : removed call to net/bmahe/genetics4j/core/Population::size → TIMED_OUT
3. select : changed conditional boundary → KILLED
4. select : negated conditional → KILLED
5. select : removed conditional - replaced comparison check with false → KILLED
|
while (selectedIndividuals.size() < numIndividuals) { |
55
|
|
|
56
|
|
Individual<T> bestIndividual = null; |
57
|
|
|
58
|
6
1. select : removed conditional - replaced comparison check with true → TIMED_OUT
2. select : removed conditional - replaced comparison check with false → KILLED
3. select : negated conditional → KILLED
4. select : removed call to net/bmahe/genetics4j/core/spec/selection/Tournament::numCandidates → KILLED
5. select : changed conditional boundary → KILLED
6. select : Substituted 0 with 1 → KILLED
|
for (int i = 0; i < tournamentSelection.numCandidates(); i++) { |
59
|
3
1. select : removed call to java/util/List::size → KILLED
2. select : removed call to java/util/random/RandomGenerator::nextInt → KILLED
3. select : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
final int candidateIndex = randomGenerator.nextInt(fitnessScore.size()); |
60
|
2
1. select : removed call to java/util/List::get → KILLED
2. select : removed call to net/bmahe/genetics4j/core/Individual::of → KILLED
|
final Individual<T> candidate = Individual.of(population.get(candidateIndex), |
61
|
1
1. select : removed call to java/util/List::get → KILLED
|
fitnessScore.get(candidateIndex)); |
62
|
|
|
63
|
8
1. select : changed conditional boundary → SURVIVED
2. select : removed conditional - replaced comparison check with false → KILLED
3. select : removed call to java/util/Comparator::compare → KILLED
4. select : removed conditional - replaced comparison check with true → KILLED
5. select : negated conditional → KILLED
6. select : negated conditional → KILLED
7. select : removed conditional - replaced equality check with false → KILLED
8. select : removed conditional - replaced equality check with true → KILLED
|
if (bestIndividual == null || comparator.compare(bestIndividual, candidate) < 0) { |
64
|
|
bestIndividual = candidate; |
65
|
|
} |
66
|
|
} |
67
|
|
|
68
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::add → TIMED_OUT
|
selectedIndividuals.add(bestIndividual); |
69
|
|
} |
70
|
|
|
71
|
1
1. select : replaced return value with null for net/bmahe/genetics4j/core/selection/TournamentSelector::select → KILLED
|
return selectedIndividuals; |
72
|
|
} |
73
|
|
} |
| | Mutations |
29 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] Removed assignment to member variable selectionPolicy → KILLED
|
30 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] Removed assignment to member variable randomGenerator → KILLED
|
45 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/spec/selection/Tournament::comparator → KILLED
|
46 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::optimization → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMinimize()] RemoveSwitch 1 (case value 2) → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/spec/Optimization::ordinal → KILLED
4.4 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] RemoveSwitch 0 (case value 1) → KILLED
5.5 Location : select Killed by : none removed call to java/lang/MatchException::<init> → NO_COVERAGE
6.6 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] Changed switch default to be first case → KILLED
|
48 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMinimize()] replaced call to java/util/Comparator::reversed with receiver → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMinimize()] removed call to java/util/Comparator::reversed → KILLED
|
53 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
54 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] changed conditional boundary → KILLED
2.2 Location : select Killed by : none removed conditional - replaced comparison check with true → TIMED_OUT
3.3 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] negated conditional → KILLED
4.4 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced comparison check with false → KILLED
5.5 Location : select Killed by : none removed call to net/bmahe/genetics4j/core/Population::size → TIMED_OUT
|
58 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced comparison check with false → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] negated conditional → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/spec/selection/Tournament::numCandidates → KILLED
4.4 Location : select Killed by : none removed conditional - replaced comparison check with true → TIMED_OUT
5.5 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] changed conditional boundary → KILLED
6.6 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] Substituted 0 with 1 → KILLED
|
59 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithPostEvaluationProcessor()] removed call to java/util/List::size → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to java/util/random/RandomGenerator::nextInt → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
60 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to java/util/List::get → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to net/bmahe/genetics4j/core/Individual::of → KILLED
|
61 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to java/util/List::get → KILLED
|
63 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced comparison check with false → KILLED
2.2 Location : select Killed by : none changed conditional boundary → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()]
- net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMinimize()]
- net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithPostEvaluationProcessor()]
- net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithIntChromosome()]
- net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithBitChromosome()]
3.3 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed call to java/util/Comparator::compare → KILLED
4.4 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced comparison check with true → KILLED
5.5 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] negated conditional → KILLED
6.6 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] negated conditional → KILLED
7.7 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced equality check with false → KILLED
8.8 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] removed conditional - replaced equality check with true → KILLED
|
68 |
|
1.1 Location : select Killed by : none removed call to net/bmahe/genetics4j/core/Population::add → TIMED_OUT
|
71 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.TournamentSelectionPolicyHandlerTest]/[method:selectMaximize()] replaced return value with null for net/bmahe/genetics4j/core/selection/TournamentSelector::select → KILLED
|