| 1 | package net.bmahe.genetics4j.gp.postevaluationprocess; | |
| 2 | ||
| 3 | import java.util.Objects; | |
| 4 | import java.util.function.Function; | |
| 5 | import java.util.random.RandomGenerator; | |
| 6 | ||
| 7 | import org.apache.commons.lang3.Validate; | |
| 8 | import org.immutables.value.Value; | |
| 9 | ||
| 10 | import net.bmahe.genetics4j.core.Genotype; | |
| 11 | import net.bmahe.genetics4j.core.Population; | |
| 12 | import net.bmahe.genetics4j.core.chromosomes.TreeChromosome; | |
| 13 | import net.bmahe.genetics4j.core.spec.PostEvaluationProcessor; | |
| 14 | ||
| 15 | @Value.Immutable | |
| 16 | public abstract class TarpeianMethod implements PostEvaluationProcessor<Double> { | |
| 17 | ||
| 18 | @Value.Parameter | |
| 19 | public abstract RandomGenerator randomGenerator(); | |
| 20 | ||
| 21 | @Value.Parameter | |
| 22 | public abstract Function<Genotype, Integer> sizeFunction(); | |
| 23 | ||
| 24 | @Value.Parameter | |
| 25 | public abstract double probability(); | |
| 26 | ||
| 27 | @Value.Parameter | |
| 28 | public abstract double newValue(); | |
| 29 | ||
| 30 | @Value.Check | |
| 31 | protected void check() { | |
| 32 | Validate.inclusiveBetween(0.0d, 1.0d, probability()); | |
| 33 | } | |
| 34 | ||
| 35 | @Override | |
| 36 | public Population<Double> apply(final long generation, final Population<Double> population) { | |
| 37 | Validate.isTrue(generation >= 0); | |
| 38 | Objects.requireNonNull(population); | |
| 39 | ||
| 40 |
4
1. apply : removed call to net/bmahe/genetics4j/core/Population::isEmpty → NO_COVERAGE 2. apply : removed conditional - replaced equality check with false → NO_COVERAGE 3. apply : removed conditional - replaced equality check with true → NO_COVERAGE 4. apply : negated conditional → NO_COVERAGE |
if (population.isEmpty()) { |
| 41 |
1
1. apply : replaced return value with null for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::apply → NO_COVERAGE |
return population; |
| 42 | } | |
| 43 | ||
| 44 |
1
1. apply : removed call to net/bmahe/genetics4j/core/Population::getAllGenotypes → NO_COVERAGE |
final double averageSize = population.getAllGenotypes() |
| 45 |
1
1. apply : removed call to java/util/List::stream → NO_COVERAGE |
.stream() |
| 46 |
6
1. lambda$apply$0 : replaced Integer return value with 0 for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::lambda$apply$0 → NO_COVERAGE 2. apply : removed call to java/util/stream/Stream::map → NO_COVERAGE 3. lambda$apply$0 : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::sizeFunction → NO_COVERAGE 4. apply : replaced call to java/util/stream/Stream::map with receiver → NO_COVERAGE 5. lambda$apply$0 : replaced call to java/util/function/Function::apply with argument → NO_COVERAGE 6. lambda$apply$0 : removed call to java/util/function/Function::apply → NO_COVERAGE |
.map(genotype -> sizeFunction().apply(genotype)) |
| 47 |
3
1. apply : removed call to java/util/stream/Stream::mapToInt → NO_COVERAGE 2. lambda$apply$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE 3. lambda$apply$1 : replaced int return with 0 for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::lambda$apply$1 → NO_COVERAGE |
.mapToInt(i -> i) |
| 48 |
1
1. apply : removed call to java/util/stream/IntStream::average → NO_COVERAGE |
.average() |
| 49 |
1
1. apply : removed call to java/util/OptionalDouble::getAsDouble → NO_COVERAGE |
.getAsDouble(); |
| 50 | ||
| 51 |
1
1. apply : removed call to net/bmahe/genetics4j/core/Population::<init> → NO_COVERAGE |
final Population<Double> newPopulation = new Population<>(); |
| 52 |
6
1. apply : removed conditional - replaced comparison check with false → NO_COVERAGE 2. apply : removed conditional - replaced comparison check with true → NO_COVERAGE 3. apply : changed conditional boundary → NO_COVERAGE 4. apply : negated conditional → NO_COVERAGE 5. apply : Substituted 0 with 1 → NO_COVERAGE 6. apply : removed call to net/bmahe/genetics4j/core/Population::size → NO_COVERAGE |
for (int i = 0; i < population.size(); i++) { |
| 53 | ||
| 54 |
1
1. apply : removed call to net/bmahe/genetics4j/core/Population::getGenotype → NO_COVERAGE |
final Genotype genotype = population.getGenotype(i); |
| 55 |
4
1. apply : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::sizeFunction → NO_COVERAGE 2. apply : removed call to java/lang/Integer::intValue → NO_COVERAGE 3. apply : removed call to java/util/function/Function::apply → NO_COVERAGE 4. apply : replaced call to java/util/function/Function::apply with argument → NO_COVERAGE |
final int size = sizeFunction().apply(genotype); |
| 56 | ||
| 57 |
2
1. apply : removed call to java/lang/Double::doubleValue → NO_COVERAGE 2. apply : removed call to net/bmahe/genetics4j/core/Population::getFitness → NO_COVERAGE |
double fitness = population.getFitness(i); |
| 58 |
11
1. apply : removed conditional - replaced comparison check with false → NO_COVERAGE 2. apply : changed conditional boundary → NO_COVERAGE 3. apply : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::probability → NO_COVERAGE 4. apply : removed conditional - replaced comparison check with false → NO_COVERAGE 5. apply : removed conditional - replaced comparison check with true → NO_COVERAGE 6. apply : negated conditional → NO_COVERAGE 7. apply : changed conditional boundary → NO_COVERAGE 8. apply : removed call to java/util/random/RandomGenerator::nextDouble → NO_COVERAGE 9. apply : negated conditional → NO_COVERAGE 10. apply : removed conditional - replaced comparison check with true → NO_COVERAGE 11. apply : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::randomGenerator → NO_COVERAGE |
if (size > averageSize && randomGenerator().nextDouble() < probability()) { |
| 59 |
1
1. apply : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::newValue → NO_COVERAGE |
fitness = newValue(); |
| 60 | } | |
| 61 | ||
| 62 |
2
1. apply : removed call to net/bmahe/genetics4j/core/Population::add → NO_COVERAGE 2. apply : removed call to java/lang/Double::valueOf → NO_COVERAGE |
newPopulation.add(genotype, fitness); |
| 63 | } | |
| 64 | ||
| 65 |
1
1. apply : replaced return value with null for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::apply → NO_COVERAGE |
return newPopulation; |
| 66 | } | |
| 67 | ||
| 68 | public static TarpeianMethod of(final RandomGenerator randomGenerator, | |
| 69 | final Function<Genotype, Integer> sizeFunction, final double probability, final double newValue) { | |
| 70 |
2
1. of : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/ImmutableTarpeianMethod::of → NO_COVERAGE 2. of : replaced return value with null for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::of → NO_COVERAGE |
return ImmutableTarpeianMethod.of(randomGenerator, sizeFunction, probability, newValue); |
| 71 | } | |
| 72 | ||
| 73 | public static TarpeianMethod ofTreeChromosome(final RandomGenerator randomGenerator, final int chromosomeIndex, | |
| 74 | final double probability, final double newValue) { | |
| 75 | ||
| 76 |
2
1. ofTreeChromosome : removed call to net/bmahe/genetics4j/gp/postevaluationprocess/ImmutableTarpeianMethod::of → NO_COVERAGE 2. ofTreeChromosome : replaced return value with null for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::ofTreeChromosome → NO_COVERAGE |
return ImmutableTarpeianMethod.of(randomGenerator, |
| 77 |
3
1. lambda$ofTreeChromosome$2 : replaced Integer return value with 0 for net/bmahe/genetics4j/gp/postevaluationprocess/TarpeianMethod::lambda$ofTreeChromosome$2 → NO_COVERAGE 2. lambda$ofTreeChromosome$2 : removed call to net/bmahe/genetics4j/core/Genotype::getChromosome → NO_COVERAGE 3. lambda$ofTreeChromosome$2 : removed call to java/lang/Integer::valueOf → NO_COVERAGE |
(genotype) -> genotype.getChromosome(chromosomeIndex, TreeChromosome.class) |
| 78 |
1
1. lambda$ofTreeChromosome$2 : removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::getSize → NO_COVERAGE |
.getSize(), |
| 79 | probability, | |
| 80 | newValue); | |
| 81 | } | |
| 82 | } | |
Mutations | ||
| 40 |
1.1 2.2 3.3 4.4 |
|
| 41 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 47 |
1.1 2.2 3.3 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 51 |
1.1 |
|
| 52 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 54 |
1.1 |
|
| 55 |
1.1 2.2 3.3 4.4 |
|
| 57 |
1.1 2.2 |
|
| 58 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 |
|
| 59 |
1.1 |
|
| 62 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 70 |
1.1 2.2 |
|
| 76 |
1.1 2.2 |
|
| 77 |
1.1 2.2 3.3 |
|
| 78 |
1.1 |