1
|
|
package net.bmahe.genetics4j.core.replacement; |
2
|
|
|
3
|
|
import java.util.Comparator; |
4
|
|
import java.util.List; |
5
|
|
import java.util.stream.IntStream; |
6
|
|
|
7
|
|
import org.apache.commons.lang3.Validate; |
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.DeleteNLast; |
14
|
|
|
15
|
|
public class DeleteNLastImpl<T extends Comparable<T>> implements ReplacementStrategyImplementor<T> { |
16
|
|
|
17
|
|
private final DeleteNLast deleteNLastSpec; |
18
|
|
private final Selector<T> offspringSelector; |
19
|
|
|
20
|
|
public DeleteNLastImpl(final DeleteNLast _deleteNLastSpec, final Selector<T> _offspringSelector) { |
21
|
|
Validate.notNull(_deleteNLastSpec); |
22
|
|
Validate.notNull(_offspringSelector); |
23
|
|
|
24
|
1
1. <init> : Removed assignment to member variable deleteNLastSpec → KILLED
|
this.deleteNLastSpec = _deleteNLastSpec; |
25
|
1
1. <init> : Removed assignment to member variable offspringSelector → KILLED
|
this.offspringSelector = _offspringSelector; |
26
|
|
} |
27
|
|
|
28
|
|
@Override |
29
|
|
public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final int numIndividuals, |
30
|
|
final List<Genotype> population, final List<T> populationScores, final List<Genotype> offsprings, |
31
|
|
final List<T> offspringScores) { |
32
|
|
Validate.notNull(eaConfiguration); |
33
|
|
Validate.isTrue(numIndividuals > 0); |
34
|
|
Validate.notNull(population); |
35
|
|
Validate.notNull(populationScores); |
36
|
|
Validate.isTrue(population.size() == populationScores.size()); |
37
|
|
Validate.notNull(offsprings); |
38
|
|
Validate.notNull(offspringScores); |
39
|
|
Validate.isTrue(offsprings.size() == offspringScores.size()); |
40
|
|
|
41
|
1
1. select : removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::fitnessComparator → KILLED
|
final Comparator<T> populationComparator = eaConfiguration.fitnessComparator(); |
42
|
|
|
43
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
final Population<T> selected = new Population<>(); |
44
|
|
|
45
|
2
1. select : Replaced double multiplication with division → KILLED
2. select : removed call to net/bmahe/genetics4j/core/spec/replacement/DeleteNLast::weakRatio → KILLED
|
final int weakestN = (int) (numIndividuals * deleteNLastSpec.weakRatio()); |
46
|
|
|
47
|
3
1. select : removed call to java/util/List::size → KILLED
2. select : removed call to java/util/stream/IntStream::range → KILLED
3. select : Substituted 0 with 1 → KILLED
|
IntStream.range(0, populationScores.size()) |
48
|
1
1. select : removed call to java/util/stream/IntStream::boxed → KILLED
|
.boxed() |
49
|
8
1. lambda$select$0 : removed call to java/lang/Integer::intValue → SURVIVED
2. lambda$select$0 : replaced int return with 0 for net/bmahe/genetics4j/core/replacement/DeleteNLastImpl::lambda$select$0 → KILLED
3. lambda$select$0 : removed call to java/util/List::get → KILLED
4. select : replaced call to java/util/stream/Stream::sorted with receiver → KILLED
5. lambda$select$0 : removed call to java/lang/Integer::intValue → KILLED
6. lambda$select$0 : removed call to java/util/List::get → KILLED
7. select : removed call to java/util/stream/Stream::sorted → KILLED
8. lambda$select$0 : removed call to java/util/Comparator::compare → KILLED
|
.sorted((a, b) -> populationComparator.compare(populationScores.get(a), populationScores.get(b))) |
50
|
2
1. select : removed call to java/util/stream/Stream::skip → KILLED
2. select : replaced call to java/util/stream/Stream::skip with receiver → KILLED
|
.skip(weakestN) |
51
|
1
1. select : removed call to java/util/stream/Stream::forEach → KILLED
|
.forEach(index -> { |
52
|
5
1. lambda$select$1 : removed call to java/lang/Integer::intValue → SURVIVED
2. lambda$select$1 : removed call to net/bmahe/genetics4j/core/Population::add → KILLED
3. lambda$select$1 : removed call to java/util/List::get → KILLED
4. lambda$select$1 : removed call to java/lang/Integer::intValue → KILLED
5. lambda$select$1 : removed call to java/util/List::get → KILLED
|
selected.add(population.get(index), populationScores.get(index)); |
53
|
|
}); |
54
|
|
|
55
|
|
final Population<T> selectedOffspring = offspringSelector |
56
|
1
1. select : removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
.select(eaConfiguration, weakestN, offsprings, offspringScores); |
57
|
1
1. select : removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
selected.addAll(selectedOffspring); |
58
|
|
|
59
|
1
1. select : replaced return value with null for net/bmahe/genetics4j/core/replacement/DeleteNLastImpl::select → KILLED
|
return selected; |
60
|
|
} |
61
|
|
} |
| | Mutations |
24 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] Removed assignment to member variable deleteNLastSpec → KILLED
|
25 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] Removed assignment to member variable offspringSelector → KILLED
|
41 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::fitnessComparator → KILLED
|
43 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
|
45 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] Replaced double multiplication with division → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/spec/replacement/DeleteNLast::weakRatio → KILLED
|
47 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/List::size → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/stream/IntStream::range → KILLED
3.3 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] Substituted 0 with 1 → KILLED
|
48 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/stream/IntStream::boxed → KILLED
|
49 |
|
1.1 Location : lambda$select$0 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] replaced int return with 0 for net/bmahe/genetics4j/core/replacement/DeleteNLastImpl::lambda$select$0 → KILLED
2.2 Location : lambda$select$0 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/List::get → KILLED
3.3 Location : lambda$select$0 Killed by : none removed call to java/lang/Integer::intValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()]
4.4 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] replaced call to java/util/stream/Stream::sorted with receiver → KILLED
5.5 Location : lambda$select$0 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/lang/Integer::intValue → KILLED
6.6 Location : lambda$select$0 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/List::get → KILLED
7.7 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/stream/Stream::sorted → KILLED
8.8 Location : lambda$select$0 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/Comparator::compare → KILLED
|
50 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/stream/Stream::skip → KILLED
2.2 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] replaced call to java/util/stream/Stream::skip with receiver → KILLED
|
51 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/stream/Stream::forEach → KILLED
|
52 |
|
1.1 Location : lambda$select$1 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/Population::add → KILLED
2.2 Location : lambda$select$1 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/List::get → KILLED
3.3 Location : lambda$select$1 Killed by : none removed call to java/lang/Integer::intValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()]
4.4 Location : lambda$select$1 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/lang/Integer::intValue → KILLED
5.5 Location : lambda$select$1 Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to java/util/List::get → KILLED
|
56 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/selection/Selector::select → KILLED
|
57 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] removed call to net/bmahe/genetics4j/core/Population::addAll → KILLED
|
59 |
|
1.1 Location : select Killed by : net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.replacement.DeleteNLastImplTest]/[method:select()] replaced return value with null for net/bmahe/genetics4j/core/replacement/DeleteNLastImpl::select → KILLED
|