| 1 | package net.bmahe.genetics4j.gp.mutation; | |
| 2 | ||
| 3 | import java.util.Objects; | |
| 4 | import java.util.random.RandomGenerator; | |
| 5 | ||
| 6 | import org.apache.commons.lang3.Validate; | |
| 7 | ||
| 8 | import net.bmahe.genetics4j.core.mutation.MutationPolicyHandler; | |
| 9 | import net.bmahe.genetics4j.core.mutation.MutationPolicyHandlerResolver; | |
| 10 | import net.bmahe.genetics4j.core.mutation.Mutator; | |
| 11 | import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; | |
| 12 | import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext; | |
| 13 | import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy; | |
| 14 | import net.bmahe.genetics4j.gp.program.ProgramHelper; | |
| 15 | import net.bmahe.genetics4j.gp.spec.mutation.ProgramRandomPrune; | |
| 16 | ||
| 17 | public class ProgramRandomPrunePolicyHandler<T extends Comparable<T>> implements MutationPolicyHandler<T> { | |
| 18 | ||
| 19 | final RandomGenerator randomGenerator; | |
| 20 | final ProgramHelper programHelper; | |
| 21 | ||
| 22 | public ProgramRandomPrunePolicyHandler(final RandomGenerator _randomGenerator, final ProgramHelper _programHelper) { | |
| 23 | Objects.requireNonNull(_randomGenerator); | |
| 24 | Objects.requireNonNull(_programHelper); | |
| 25 | ||
| 26 |
1
1. <init> : Removed assignment to member variable randomGenerator → KILLED |
this.randomGenerator = _randomGenerator; |
| 27 |
1
1. <init> : Removed assignment to member variable programHelper → KILLED |
this.programHelper = _programHelper; |
| 28 | } | |
| 29 | ||
| 30 | @Override | |
| 31 | public boolean canHandle(final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, | |
| 32 | final MutationPolicy mutationPolicy) { | |
| 33 | Objects.requireNonNull(mutationPolicyHandlerResolver); | |
| 34 | Objects.requireNonNull(mutationPolicy); | |
| 35 | ||
| 36 |
2
1. canHandle : replaced boolean return with true for net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::canHandle → KILLED 2. canHandle : replaced boolean return with false for net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::canHandle → KILLED |
return mutationPolicy instanceof ProgramRandomPrune; |
| 37 | } | |
| 38 | ||
| 39 | @Override | |
| 40 | public Mutator createMutator(final AbstractEAExecutionContext<T> eaExecutionContext, | |
| 41 | final AbstractEAConfiguration<T> eaConfiguration, | |
| 42 | final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, final MutationPolicy mutationPolicy) { | |
| 43 | Objects.requireNonNull(eaExecutionContext); | |
| 44 | Objects.requireNonNull(eaConfiguration); | |
| 45 | Objects.requireNonNull(mutationPolicyHandlerResolver); | |
| 46 | Objects.requireNonNull(mutationPolicy); | |
| 47 | Validate.isInstanceOf(ProgramRandomPrune.class, mutationPolicy); | |
| 48 | ||
| 49 | final ProgramRandomPrune programRandomPrune = (ProgramRandomPrune) mutationPolicy; | |
| 50 |
1
1. createMutator : removed call to net/bmahe/genetics4j/gp/spec/mutation/ProgramRandomPrune::populationMutationProbability → SURVIVED |
final double populationMutationProbability = programRandomPrune.populationMutationProbability(); |
| 51 | ||
| 52 |
2
1. createMutator : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomPruneMutator::<init> → KILLED 2. createMutator : replaced return value with null for net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::createMutator → KILLED |
return new ProgramRandomPruneMutator(programHelper, |
| 53 | randomGenerator, | |
| 54 | eaConfiguration, | |
| 55 | populationMutationProbability); | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 26 |
1.1 |
|
| 27 |
1.1 |
|
| 36 |
1.1 2.2 |
|
| 50 |
1.1 |
|
| 52 |
1.1 2.2 |