1 | package net.bmahe.genetics4j.core.selection; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.Objects; | |
5 | import java.util.stream.Collectors; | |
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.spec.AbstractEAConfiguration; | |
12 | import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext; | |
13 | import net.bmahe.genetics4j.core.spec.selection.MultiSelections; | |
14 | import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy; | |
15 | ||
16 | public class MultiSelectionsPolicyHandler<T extends Comparable<T>> implements SelectionPolicyHandler<T> { | |
17 | ||
18 | public MultiSelectionsPolicyHandler() { | |
19 | } | |
20 | ||
21 | @Override | |
22 | public boolean canHandle(final SelectionPolicy selectionPolicy) { | |
23 | Objects.requireNonNull(selectionPolicy); | |
24 |
2
1. canHandle : replaced boolean return with false for net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler::canHandle → NO_COVERAGE 2. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler::canHandle → NO_COVERAGE |
return selectionPolicy instanceof MultiSelections; |
25 | } | |
26 | ||
27 | @Override | |
28 | public Selector<T> resolve(final AbstractEAExecutionContext<T> eaExecutionContext, | |
29 | final AbstractEAConfiguration<T> eaConfiguration, | |
30 | final SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver, | |
31 | final SelectionPolicy selectionPolicy) { | |
32 | Objects.requireNonNull(selectionPolicy); | |
33 | Validate.isInstanceOf(MultiSelections.class, selectionPolicy); | |
34 | ||
35 | final MultiSelections multiSelections = (MultiSelections) selectionPolicy; | |
36 |
1
1. resolve : removed call to net/bmahe/genetics4j/core/spec/selection/MultiSelections::selectionPolicies → NO_COVERAGE |
final List<SelectionPolicy> selectionPolicies = multiSelections.selectionPolicies(); |
37 | Validate.isTrue(selectionPolicies.isEmpty() == false); | |
38 | ||
39 |
1
1. resolve : removed call to java/util/List::stream → NO_COVERAGE |
final List<Selector<T>> selectors = selectionPolicies.stream() |
40 |
2
1. resolve : removed call to java/util/stream/Stream::map → NO_COVERAGE 2. resolve : replaced call to java/util/stream/Stream::map with receiver → NO_COVERAGE |
.map((sp) -> { |
41 | ||
42 |
1
1. lambda$resolve$0 : removed call to net/bmahe/genetics4j/core/selection/SelectionPolicyHandlerResolver::resolve → NO_COVERAGE |
final SelectionPolicyHandler<T> spHandler = selectionPolicyHandlerResolver.resolve(sp); |
43 |
2
1. lambda$resolve$0 : removed call to net/bmahe/genetics4j/core/selection/SelectionPolicyHandler::resolve → NO_COVERAGE 2. lambda$resolve$0 : replaced return value with null for net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler::lambda$resolve$0 → NO_COVERAGE |
return spHandler.resolve(eaExecutionContext, eaConfiguration, selectionPolicyHandlerResolver, sp); |
44 | }) | |
45 |
2
1. resolve : removed call to java/util/stream/Stream::collect → NO_COVERAGE 2. resolve : removed call to java/util/stream/Collectors::toList → NO_COVERAGE |
.collect(Collectors.toList()); |
46 | ||
47 |
3
1. resolve : replaced return value with null for net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler::resolve → NO_COVERAGE 2. resolve : removed call to net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler$1::<init> → NO_COVERAGE 3. <init> : Removed assignment to member variable val$selectors → NO_COVERAGE |
return new Selector<T>() { |
48 | ||
49 | @Override | |
50 | public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final long generation, | |
51 | final int numIndividuals, final List<Genotype> population, final List<T> fitnessScore) { | |
52 |
2
1. select : Replaced integer division with multiplication → NO_COVERAGE 2. select : removed call to java/util/List::size → NO_COVERAGE |
final int incrementSelection = numIndividuals / selectors.size(); |
53 | ||
54 |
1
1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → NO_COVERAGE |
final Population<T> selectedIndividuals = new Population<>(); |
55 | for (final Selector<T> selector : selectors) { | |
56 |
1
1. select : removed call to net/bmahe/genetics4j/core/Population::addAll → NO_COVERAGE |
selectedIndividuals.addAll( |
57 |
1
1. select : removed call to net/bmahe/genetics4j/core/selection/Selector::select → NO_COVERAGE |
selector.select(eaConfiguration, generation, incrementSelection, population, fitnessScore)); |
58 | } | |
59 | ||
60 |
1
1. select : Substituted 0 with 1 → NO_COVERAGE |
int i = 0; |
61 |
5
1. select : removed call to net/bmahe/genetics4j/core/Population::size → NO_COVERAGE 2. select : changed conditional boundary → NO_COVERAGE 3. select : removed conditional - replaced comparison check with true → NO_COVERAGE 4. select : negated conditional → NO_COVERAGE 5. select : removed conditional - replaced comparison check with false → NO_COVERAGE |
while (selectedIndividuals.size() < numIndividuals) { |
62 | ||
63 |
2
1. select : removed call to java/util/List::get → NO_COVERAGE 2. select : removed call to net/bmahe/genetics4j/core/Population::addAll → NO_COVERAGE |
selectedIndividuals.addAll(selectors.get(i) |
64 |
1
1. select : removed call to net/bmahe/genetics4j/core/selection/Selector::select → NO_COVERAGE |
.select(eaConfiguration, generation, incrementSelection, population, fitnessScore)); |
65 | ||
66 |
4
1. select : Substituted 1 with 0 → NO_COVERAGE 2. select : removed call to java/util/List::size → NO_COVERAGE 3. select : Replaced integer modulus with multiplication → NO_COVERAGE 4. select : Replaced integer addition with subtraction → NO_COVERAGE |
i = (i + 1) % selectors.size(); |
67 | } | |
68 | ||
69 |
1
1. select : replaced return value with null for net/bmahe/genetics4j/core/selection/MultiSelectionsPolicyHandler$1::select → NO_COVERAGE |
return selectedIndividuals; |
70 | } | |
71 | }; | |
72 | } | |
73 | } | |
Mutations | ||
24 |
1.1 2.2 |
|
36 |
1.1 |
|
39 |
1.1 |
|
40 |
1.1 2.2 |
|
42 |
1.1 |
|
43 |
1.1 2.2 |
|
45 |
1.1 2.2 |
|
47 |
1.1 2.2 3.3 |
|
52 |
1.1 2.2 |
|
54 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 2.2 3.3 4.4 5.5 |
|
63 |
1.1 2.2 |
|
64 |
1.1 |
|
66 |
1.1 2.2 3.3 4.4 |
|
69 |
1.1 |