1 | package net.bmahe.genetics4j.moo.spea2.replacement; | |
2 | ||
3 | import java.util.Comparator; | |
4 | import java.util.List; | |
5 | import java.util.stream.Collectors; | |
6 | import java.util.stream.IntStream; | |
7 | ||
8 | import org.apache.commons.lang3.Validate; | |
9 | import org.apache.commons.lang3.tuple.ImmutablePair; | |
10 | import org.apache.commons.lang3.tuple.Pair; | |
11 | ||
12 | import net.bmahe.genetics4j.core.Population; | |
13 | ||
14 | public class SPEA2Utils { | |
15 | ||
16 | private SPEA2Utils() { | |
17 | } | |
18 | ||
19 | public static <T extends Comparable<T>> int strength(final Comparator<T> dominance, final int index, | |
20 | final T fitness, final Population<T> population) { | |
21 | Validate.isTrue(index >= 0); | |
22 | Validate.isTrue(index < population.size()); | |
23 | ||
24 | Validate.notNull(fitness); | |
25 | Validate.notNull(population); | |
26 | Validate.isTrue(population.size() > 0); | |
27 | ||
28 |
1
1. strength : Substituted 0 with 1 → NO_COVERAGE |
int dominatedCount = 0; |
29 | ||
30 |
6
1. strength : removed conditional - replaced comparison check with true → NO_COVERAGE 2. strength : removed call to net/bmahe/genetics4j/core/Population::size → NO_COVERAGE 3. strength : Substituted 0 with 1 → NO_COVERAGE 4. strength : removed conditional - replaced comparison check with false → NO_COVERAGE 5. strength : negated conditional → NO_COVERAGE 6. strength : changed conditional boundary → NO_COVERAGE |
for (int j = 0; j < population.size(); j++) { |
31 |
1
1. strength : removed call to net/bmahe/genetics4j/core/Population::getFitness → NO_COVERAGE |
final T fitnessJ = population.getFitness(j); |
32 | ||
33 |
5
1. strength : removed conditional - replaced comparison check with true → NO_COVERAGE 2. strength : removed call to java/util/Comparator::compare → NO_COVERAGE 3. strength : negated conditional → NO_COVERAGE 4. strength : changed conditional boundary → NO_COVERAGE 5. strength : removed conditional - replaced comparison check with false → NO_COVERAGE |
if (dominance.compare(fitness, fitnessJ) > 0) { |
34 |
2
1. strength : Removed increment 1 → NO_COVERAGE 2. strength : Changed increment from 1 to -1 → NO_COVERAGE |
dominatedCount++; |
35 | } | |
36 | } | |
37 | ||
38 |
1
1. strength : replaced int return with 0 for net/bmahe/genetics4j/moo/spea2/replacement/SPEA2Utils::strength → NO_COVERAGE |
return dominatedCount; |
39 | } | |
40 | ||
41 | public static <T extends Comparable<T>> int rawFitness(final Comparator<T> dominance, final double[] strengths, | |
42 | final int index, final T fitness, final Population<T> population) { | |
43 | Validate.isTrue(index >= 0); | |
44 | Validate.isTrue(index < population.size()); | |
45 | ||
46 | Validate.notNull(strengths); | |
47 | Validate.notNull(fitness); | |
48 | Validate.notNull(population); | |
49 | Validate.isTrue(population.size() > 0); | |
50 | Validate.isTrue(population.size() == strengths.length); | |
51 | ||
52 |
1
1. rawFitness : Substituted 0 with 1 → NO_COVERAGE |
int rawFitness = 0; |
53 | ||
54 |
6
1. rawFitness : removed conditional - replaced comparison check with false → NO_COVERAGE 2. rawFitness : removed call to net/bmahe/genetics4j/core/Population::size → NO_COVERAGE 3. rawFitness : changed conditional boundary → NO_COVERAGE 4. rawFitness : removed conditional - replaced comparison check with true → NO_COVERAGE 5. rawFitness : negated conditional → NO_COVERAGE 6. rawFitness : Substituted 0 with 1 → NO_COVERAGE |
for (int j = 0; j < population.size(); j++) { |
55 |
1
1. rawFitness : removed call to net/bmahe/genetics4j/core/Population::getFitness → NO_COVERAGE |
final T fitnessJ = population.getFitness(j); |
56 | ||
57 |
3
1. rawFitness : negated conditional → NO_COVERAGE 2. rawFitness : removed conditional - replaced equality check with true → NO_COVERAGE 3. rawFitness : removed conditional - replaced equality check with false → NO_COVERAGE |
if (index != j) { |
58 |
5
1. rawFitness : changed conditional boundary → NO_COVERAGE 2. rawFitness : removed call to java/util/Comparator::compare → NO_COVERAGE 3. rawFitness : removed conditional - replaced comparison check with true → NO_COVERAGE 4. rawFitness : negated conditional → NO_COVERAGE 5. rawFitness : removed conditional - replaced comparison check with false → NO_COVERAGE |
if (dominance.compare(fitness, fitnessJ) < 0) { |
59 |
1
1. rawFitness : Replaced double addition with subtraction → NO_COVERAGE |
rawFitness += strengths[j]; |
60 | } | |
61 | } | |
62 | } | |
63 | ||
64 |
1
1. rawFitness : replaced int return with 0 for net/bmahe/genetics4j/moo/spea2/replacement/SPEA2Utils::rawFitness → NO_COVERAGE |
return rawFitness; |
65 | } | |
66 | ||
67 | public static <T extends Comparable<T>> List<Pair<Integer, Double>> kthDistances( | |
68 | final double[][] distanceObjectives, final int index, final T fitness, | |
69 | final Population<T> combinedPopulation) { | |
70 | Validate.notNull(distanceObjectives); | |
71 | Validate.isTrue(index >= 0); | |
72 | Validate.isTrue(index < combinedPopulation.size()); | |
73 | ||
74 | Validate.notNull(fitness); | |
75 | Validate.notNull(combinedPopulation); | |
76 | Validate.isTrue(combinedPopulation.size() > 0); | |
77 | ||
78 |
4
1. kthDistances : replaced return value with Collections.emptyList for net/bmahe/genetics4j/moo/spea2/replacement/SPEA2Utils::kthDistances → NO_COVERAGE 2. kthDistances : removed call to java/util/stream/IntStream::range → NO_COVERAGE 3. kthDistances : Substituted 0 with 1 → NO_COVERAGE 4. kthDistances : removed call to net/bmahe/genetics4j/core/Population::size → NO_COVERAGE |
return IntStream.range(0, combinedPopulation.size()) |
79 |
1
1. kthDistances : removed call to java/util/stream/IntStream::boxed → NO_COVERAGE |
.boxed() |
80 |
6
1. lambda$kthDistances$0 : removed call to java/lang/Double::compare → NO_COVERAGE 2. lambda$kthDistances$0 : removed call to java/lang/Integer::intValue → NO_COVERAGE 3. kthDistances : removed call to java/util/stream/Stream::sorted → NO_COVERAGE 4. lambda$kthDistances$0 : removed call to java/lang/Integer::intValue → NO_COVERAGE 5. kthDistances : replaced call to java/util/stream/Stream::sorted with receiver → NO_COVERAGE 6. lambda$kthDistances$0 : replaced int return with 0 for net/bmahe/genetics4j/moo/spea2/replacement/SPEA2Utils::lambda$kthDistances$0 → NO_COVERAGE |
.sorted((a, b) -> Double.compare(distanceObjectives[index][a], distanceObjectives[index][b])) |
81 |
6
1. kthDistances : replaced call to java/util/stream/Stream::map with receiver → NO_COVERAGE 2. lambda$kthDistances$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE 3. lambda$kthDistances$1 : removed call to org/apache/commons/lang3/tuple/ImmutablePair::of → NO_COVERAGE 4. lambda$kthDistances$1 : replaced return value with null for net/bmahe/genetics4j/moo/spea2/replacement/SPEA2Utils::lambda$kthDistances$1 → NO_COVERAGE 5. kthDistances : removed call to java/util/stream/Stream::map → NO_COVERAGE 6. lambda$kthDistances$1 : removed call to java/lang/Double::valueOf → NO_COVERAGE |
.map(i -> ImmutablePair.of(i, distanceObjectives[index][i])) |
82 |
2
1. kthDistances : removed call to java/util/stream/Collectors::toList → NO_COVERAGE 2. kthDistances : removed call to java/util/stream/Stream::collect → NO_COVERAGE |
.collect(Collectors.toList()); |
83 | ||
84 | } | |
85 | ||
86 | } | |
Mutations | ||
28 |
1.1 |
|
30 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
31 |
1.1 |
|
33 |
1.1 2.2 3.3 4.4 5.5 |
|
34 |
1.1 2.2 |
|
38 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
55 |
1.1 |
|
57 |
1.1 2.2 3.3 |
|
58 |
1.1 2.2 3.3 4.4 5.5 |
|
59 |
1.1 |
|
64 |
1.1 |
|
78 |
1.1 2.2 3.3 4.4 |
|
79 |
1.1 |
|
80 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
81 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
82 |
1.1 2.2 |