| 1 | package net.bmahe.genetics4j.core.mutation; | |
| 2 | ||
| 3 | import java.util.Arrays; | |
| 4 | import java.util.Objects; | |
| 5 | ||
| 6 | import org.apache.commons.lang3.Validate; | |
| 7 | ||
| 8 | import net.bmahe.genetics4j.core.Genotype; | |
| 9 | import net.bmahe.genetics4j.core.chromosomes.Chromosome; | |
| 10 | import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; | |
| 11 | import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext; | |
| 12 | import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy; | |
| 13 | import net.bmahe.genetics4j.core.spec.mutation.PartialMutation; | |
| 14 | ||
| 15 | public class PartialMutationPolicyHandler<T extends Comparable<T>> implements MutationPolicyHandler<T> { | |
| 16 | ||
| 17 | @Override | |
| 18 | public boolean canHandle(final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, | |
| 19 | final MutationPolicy mutationPolicy) { | |
| 20 | Objects.requireNonNull(mutationPolicyHandlerResolver); | |
| 21 | Objects.requireNonNull(mutationPolicy); | |
| 22 | ||
| 23 |
3
1. canHandle : negated conditional → NO_COVERAGE 2. canHandle : removed conditional - replaced equality check with true → NO_COVERAGE 3. canHandle : removed conditional - replaced equality check with false → NO_COVERAGE |
if (mutationPolicy instanceof PartialMutation == false) { |
| 24 |
2
1. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE 2. canHandle : Substituted 0 with 1 → NO_COVERAGE |
return false; |
| 25 | } | |
| 26 | ||
| 27 | final PartialMutation partialMutation = (PartialMutation) mutationPolicy; | |
| 28 | ||
| 29 |
1
1. canHandle : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::mutationPolicy → NO_COVERAGE |
final MutationPolicy childMutationPolicy = partialMutation.mutationPolicy(); |
| 30 |
3
1. canHandle : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::canHandle → NO_COVERAGE 2. canHandle : replaced boolean return with false for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE 3. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE |
return mutationPolicyHandlerResolver.canHandle(childMutationPolicy); |
| 31 | } | |
| 32 | ||
| 33 | @Override | |
| 34 | public Mutator createMutator(final AbstractEAExecutionContext<T> eaExecutionContext, | |
| 35 | final AbstractEAConfiguration<T> eaConfiguration, | |
| 36 | final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, final MutationPolicy mutationPolicy) { | |
| 37 | Objects.requireNonNull(eaExecutionContext); | |
| 38 | Objects.requireNonNull(eaConfiguration); | |
| 39 | Objects.requireNonNull(mutationPolicyHandlerResolver); | |
| 40 | Objects.requireNonNull(mutationPolicy); | |
| 41 | Validate.isInstanceOf(PartialMutation.class, mutationPolicy); | |
| 42 | ||
| 43 | final PartialMutation partialMutation = (PartialMutation) mutationPolicy; | |
| 44 | ||
| 45 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::chromosomeIndex → NO_COVERAGE |
final int mutatedChromosomeIndex = partialMutation.chromosomeIndex(); |
| 46 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::mutationPolicy → NO_COVERAGE |
final MutationPolicy childMutationPolicy = partialMutation.mutationPolicy(); |
| 47 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::resolve → NO_COVERAGE |
final MutationPolicyHandler<T> mutationPolicyHandler = mutationPolicyHandlerResolver.resolve(childMutationPolicy); |
| 48 | ||
| 49 | final Mutator childMutator = mutationPolicyHandler | |
| 50 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandler::createMutator → NO_COVERAGE |
.createMutator(eaExecutionContext, eaConfiguration, mutationPolicyHandlerResolver, childMutationPolicy); |
| 51 | ||
| 52 |
4
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler$1::<init> → NO_COVERAGE 2. <init> : Removed assignment to member variable val$childMutator → NO_COVERAGE 3. createMutator : replaced return value with null for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::createMutator → NO_COVERAGE 4. <init> : Removed assignment to member variable val$mutatedChromosomeIndex → NO_COVERAGE |
return new Mutator() { |
| 53 | ||
| 54 | @Override | |
| 55 | public Genotype mutate(final long generation, final Genotype original) { | |
| 56 | Validate.isTrue(generation >= 0); | |
| 57 | Objects.requireNonNull(original); | |
| 58 | ||
| 59 |
4
1. mutate : removed call to java/util/Arrays::copyOf → NO_COVERAGE 2. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE 3. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE 4. mutate : replaced call to java/util/Arrays::copyOf with argument → NO_COVERAGE |
final Chromosome[] chromosomes = Arrays.copyOf(original.getChromosomes(), original.getChromosomes().length); |
| 60 |
2
1. mutate : replaced call to net/bmahe/genetics4j/core/mutation/Mutator::mutate with argument → NO_COVERAGE 2. mutate : removed call to net/bmahe/genetics4j/core/mutation/Mutator::mutate → NO_COVERAGE |
final Genotype mutated = childMutator.mutate(generation, original); |
| 61 | ||
| 62 |
1
1. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosome → NO_COVERAGE |
chromosomes[mutatedChromosomeIndex] = mutated.getChromosome(mutatedChromosomeIndex); |
| 63 | ||
| 64 |
2
1. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler$1::mutate → NO_COVERAGE 2. mutate : removed call to net/bmahe/genetics4j/core/Genotype::<init> → NO_COVERAGE |
return new Genotype(chromosomes); |
| 65 | } | |
| 66 | }; | |
| 67 | } | |
| 68 | } | |
Mutations | ||
| 23 |
1.1 2.2 3.3 |
|
| 24 |
1.1 2.2 |
|
| 29 |
1.1 |
|
| 30 |
1.1 2.2 3.3 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 47 |
1.1 |
|
| 50 |
1.1 |
|
| 52 |
1.1 2.2 3.3 4.4 |
|
| 59 |
1.1 2.2 3.3 4.4 |
|
| 60 |
1.1 2.2 |
|
| 62 |
1.1 |
|
| 64 |
1.1 2.2 |