1
|
|
package net.bmahe.genetics4j.core.replacement; |
2
|
|
|
3
|
|
import java.util.List; |
4
|
|
|
5
|
|
import org.apache.commons.lang3.Validate; |
6
|
|
import org.apache.logging.log4j.LogManager; |
7
|
|
import org.apache.logging.log4j.Logger; |
8
|
|
|
9
|
|
import net.bmahe.genetics4j.core.Genotype; |
10
|
|
import net.bmahe.genetics4j.core.Population; |
11
|
|
import net.bmahe.genetics4j.core.selection.Selector; |
12
|
|
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; |
13
|
|
import net.bmahe.genetics4j.core.spec.replacement.Elitism; |
14
|
|
|
15
|
|
public class ElitismImpl<T extends Comparable<T>> implements ReplacementStrategyImplementor<T> { |
16
|
|
final static public Logger logger = LogManager.getLogger(ElitismImpl.class); |
17
|
|
|
18
|
|
private final Elitism elitismSpec; |
19
|
|
private final Selector<T> offspringSelector; |
20
|
|
private final Selector<T> survivorSelector; |
21
|
|
|
22
|
|
public ElitismImpl(final Elitism _elistismSpec, final Selector<T> _offspringSelector, |
23
|
|
final Selector<T> _survivorSelector) { |
24
|
|
Validate.notNull(_elistismSpec); |
25
|
|
Validate.notNull(_offspringSelector); |
26
|
|
Validate.notNull(_survivorSelector); |
27
|
|
|
28
|
1
1. <init> : Removed assignment to member variable elitismSpec → KILLED
|
this.elitismSpec = _elistismSpec; |
29
|
1
1. <init> : Removed assignment to member variable offspringSelector → KILLED
|
this.offspringSelector = _offspringSelector; |
30
|
1
1. <init> : Removed assignment to member variable survivorSelector → KILLED
|
this.survivorSelector = _survivorSelector; |
31
|
|
} |
32
|
|
|
33
|
|
@Override |
34
|
|
public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final int numIndividuals, |
35
|
|
final List<Genotype> population, final List<T> populationScores, final List<Genotype> offsprings, |
36
|
|
final List<T> offspringScores) { |
37
|
|
Validate.notNull(eaConfiguration); |
38
|
|
Validate.isTrue(numIndividuals > 0); |
39
|
|
Validate.notNull(population); |
40
|
|
Validate.notNull(populationScores); |
41
|
|
Validate.isTrue(population.size() == populationScores.size()); |
42
|
|
Validate.notNull(offsprings); |
43
|
|
Validate.notNull(offspringScores); |
44
|
|
Validate.isTrue(offsprings.size() == offspringScores.size()); |
45
|
|
Validate.isTrue(elitismSpec.atLeastNumOffsprings() + elitismSpec.atLeastNumSurvivors() <= numIndividuals); |
46
|
|
|
47
|
2
1. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::offspringRatio → KILLED
2. select : Replaced double multiplication with division → KILLED
|
final int scaledOffspring = (int) (elitismSpec.offspringRatio() * numIndividuals); |
48
|
3
1. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumOffsprings → SURVIVED
2. select : removed call to java/lang/Math::max → KILLED
3. select : replaced call to java/lang/Math::max with argument → KILLED
|
final int offspringNeeded = Math.max(scaledOffspring, elitismSpec.atLeastNumOffsprings()); |
49
|
1
1. select : Replaced integer subtraction with addition → KILLED
|
final int survivorNeeded = numIndividuals - offspringNeeded; |
50
|
|
|
51
|
|
final int adjustedOffspringNeeded; |
52
|
|
final int adjustedSurvivorNeeded; |
53
|
5
1. select : changed conditional boundary → SURVIVED
2. select : removed conditional - replaced comparison check with false → KILLED
3. select : negated conditional → KILLED
4. select : removed conditional - replaced comparison check with true → KILLED
5. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
|
if (survivorNeeded < elitismSpec.atLeastNumSurvivors()) { |
54
|
|
// Alternatively, it could be numIndividuals - elitismSpec.atLeastNumSurvivors() |
55
|
3
1. select : Replaced integer subtraction with addition → KILLED
2. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
3. select : Replaced integer subtraction with addition → KILLED
|
adjustedOffspringNeeded = offspringNeeded - (elitismSpec.atLeastNumSurvivors() - survivorNeeded); |
56
|
1
1. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
|
adjustedSurvivorNeeded = elitismSpec.atLeastNumSurvivors(); |
57
|
|
} else { |
58
|
|
adjustedOffspringNeeded = offspringNeeded; |
59
|
|
adjustedSurvivorNeeded = survivorNeeded; |
60
|
|
} |
61
|
|
|
62
|
|
logger.debug("We have {} individuals requested and an offspring ratio of {}. Survivors:{}, Offsprings:{}", |
63
|
1
1. select : removed call to java/lang/Integer::valueOf → SURVIVED
|
numIndividuals, |
64
|
2
1. select : removed call to java/lang/Double::valueOf → SURVIVED
2. select : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::offspringRatio → SURVIVED
|
elitismSpec.offspringRatio(), |
65
|
1
1. select : removed call to java/lang/Integer::valueOf → SURVIVED
|
adjustedSurvivorNeeded, |
66
|
1
1. select : removed call to java/lang/Integer::valueOf → SURVIVED
|
adjustedOffspringNeeded); |
67
|
|
|
68
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
final Population<T> selected = new Population<>(); |
69
|
|
|
70
|
|
logger.info("Selecting {} offsprings", adjustedOffspringNeeded); |
71
|
|
final Population<T> selectedOffspring = offspringSelector |
72
|
1
1. select : removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
.select(eaConfiguration, adjustedOffspringNeeded, offsprings, offspringScores); |
73
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
selected.addAll(selectedOffspring); |
74
|
|
|
75
|
|
logger.info("Selecting {} survivors", adjustedSurvivorNeeded); |
76
|
|
final Population<T> selectedSurvivors = survivorSelector |
77
|
1
1. select : removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
.select(eaConfiguration, adjustedSurvivorNeeded, population, populationScores); |
78
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
selected.addAll(selectedSurvivors); |
79
|
|
|
80
|
1
1. select : replaced return value with null for net/bmahe/genetics4j/core/replacement/ElitismImpl::select → KILLED
|
return selected; |
81
|
|
} |
82
|
|
} |
| | Mutations |
28 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] Removed assignment to member variable elitismSpec → KILLED
|
29 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] Removed assignment to member variable offspringSelector → KILLED
|
30 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] Removed assignment to member variable survivorSelector → KILLED
|
47 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::offspringRatio → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] Replaced double multiplication with division → KILLED
|
48 |
|
1.1 Location : select Killed by : none removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumOffsprings → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to java/lang/Math::max → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] replaced call to java/lang/Math::max with argument → KILLED
|
49 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] Replaced integer subtraction with addition → KILLED
|
53 |
|
1.1 Location : select Killed by : none changed conditional boundary → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] removed conditional - replaced comparison check with false → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] negated conditional → KILLED
4.4 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed conditional - replaced comparison check with true → KILLED
5.5 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
|
55 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] Replaced integer subtraction with addition → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] Replaced integer subtraction with addition → KILLED
|
56 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()] removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → KILLED
|
63 |
|
1.1 Location : select Killed by : none removed call to java/lang/Integer::valueOf → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
|
64 |
|
1.1 Location : select Killed by : none removed call to java/lang/Double::valueOf → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
2.2 Location : select Killed by : none removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism::offspringRatio → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
|
65 |
|
1.1 Location : select Killed by : none removed call to java/lang/Integer::valueOf → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
|
66 |
|
1.1 Location : select Killed by : none removed call to java/lang/Integer::valueOf → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()]
- net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:atLeastSpecified()]
- 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()]
|
68 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
72 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
73 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
77 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
78 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
80 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.ElitismImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.ElitismImplTest]/[method:simple()] replaced return value with null for net/bmahe/genetics4j/core/replacement/ElitismImpl::select → KILLED
|