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