| 1 | package net.bmahe.genetics4j.gp.spec; | |
| 2 | ||
| 3 | import java.util.random.RandomGenerator; | |
| 4 | ||
| 5 | import org.apache.commons.lang3.Validate; | |
| 6 | ||
| 7 | import net.bmahe.genetics4j.core.chromosomes.factory.ImmutableChromosomeFactoryProvider; | |
| 8 | import net.bmahe.genetics4j.core.spec.ImmutableEAExecutionContext; | |
| 9 | import net.bmahe.genetics4j.core.spec.ImmutableEAExecutionContext.Builder; | |
| 10 | import net.bmahe.genetics4j.gp.chromosomes.factory.ProgramTreeChromosomeFactory; | |
| 11 | import net.bmahe.genetics4j.gp.combination.ProgramRandomCombineHandler; | |
| 12 | import net.bmahe.genetics4j.gp.mutation.NodeReplacementPolicyHandler; | |
| 13 | import net.bmahe.genetics4j.gp.mutation.ProgramRandomMutatePolicyHandler; | |
| 14 | import net.bmahe.genetics4j.gp.mutation.ProgramRandomPrunePolicyHandler; | |
| 15 | import net.bmahe.genetics4j.gp.mutation.ProgramRulesApplicatorPolicyHandler; | |
| 16 | import net.bmahe.genetics4j.gp.mutation.TrimTreePolicyHandler; | |
| 17 | import net.bmahe.genetics4j.gp.program.ProgramGenerator; | |
| 18 | import net.bmahe.genetics4j.gp.program.ProgramHelper; | |
| 19 | import net.bmahe.genetics4j.gp.program.RampedHalfAndHalfProgramGenerator; | |
| 20 | ||
| 21 | /** | |
| 22 | * Defines multiple factory and helper methods to create and manage EAExecutionContexts appropriate for Genetic | |
| 23 | * Programming | |
| 24 | */ | |
| 25 | public class GPEAExecutionContexts { | |
| 26 | ||
| 27 | private GPEAExecutionContexts() { | |
| 28 | } | |
| 29 | ||
| 30 | /** | |
| 31 | * Create a new EAExecutionContext pre-configured to support Genetic Programming. | |
| 32 | * <p>It adds support for some operators to select, mutate and combine programs. | |
| 33 | * | |
| 34 | * @param <T> Type of the fitness measurement | |
| 35 | * @param randomGenerator Random Generator | |
| 36 | * @param programHelper Instance of ProgramHelper | |
| 37 | * @param programGenerator Instance of a program generator which will be used to generate individuals | |
| 38 | * @return A new instance of a EAExecutionContext | |
| 39 | */ | |
| 40 | public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator, | |
| 41 | final ProgramHelper programHelper, final ProgramGenerator programGenerator) { | |
| 42 | Validate.notNull(randomGenerator); | |
| 43 | Validate.notNull(programHelper); | |
| 44 | Validate.notNull(programGenerator); | |
| 45 | ||
| 46 |
1
1. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext::builder → NO_COVERAGE |
final var builder = ImmutableEAExecutionContext.<T>builder(); |
| 47 |
2
1. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator with receiver → NO_COVERAGE 2. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator → NO_COVERAGE |
builder.randomGenerator(randomGenerator); |
| 48 | ||
| 49 |
8
1. forGP : Substituted 5 with 6 → NO_COVERAGE 2. forGP : Substituted 1 with 0 → NO_COVERAGE 3. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories with receiver → NO_COVERAGE 4. forGP : Substituted 0 with 1 → NO_COVERAGE 5. forGP : Substituted 2 with 3 → NO_COVERAGE 6. forGP : Substituted 3 with 4 → NO_COVERAGE 7. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories → NO_COVERAGE 8. forGP : Substituted 4 with 5 → NO_COVERAGE |
builder.addMutationPolicyHandlerFactories( |
| 50 |
3
1. lambda$forGP$0 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$0 → NO_COVERAGE 2. lambda$forGP$0 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE 3. lambda$forGP$0 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::<init> → NO_COVERAGE |
gsd -> new ProgramRandomPrunePolicyHandler<>(gsd.randomGenerator(), programHelper), |
| 51 |
3
1. lambda$forGP$1 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$1 → NO_COVERAGE 2. lambda$forGP$1 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomMutatePolicyHandler::<init> → NO_COVERAGE 3. lambda$forGP$1 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE |
gsd -> new ProgramRandomMutatePolicyHandler<>(gsd.randomGenerator(), programGenerator), |
| 52 |
2
1. lambda$forGP$2 : removed call to net/bmahe/genetics4j/gp/mutation/NodeReplacementPolicyHandler::<init> → NO_COVERAGE 2. lambda$forGP$2 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$2 → NO_COVERAGE |
gsd -> new NodeReplacementPolicyHandler<>(randomGenerator, programHelper), |
| 53 |
2
1. lambda$forGP$3 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRulesApplicatorPolicyHandler::<init> → NO_COVERAGE 2. lambda$forGP$3 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$3 → NO_COVERAGE |
gsd -> new ProgramRulesApplicatorPolicyHandler<>(), |
| 54 |
2
1. lambda$forGP$4 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$4 → NO_COVERAGE 2. lambda$forGP$4 : removed call to net/bmahe/genetics4j/gp/mutation/TrimTreePolicyHandler::<init> → NO_COVERAGE |
gsd -> new TrimTreePolicyHandler<>(randomGenerator, programGenerator)); |
| 55 | ||
| 56 |
5
1. lambda$forGP$5 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$5 → NO_COVERAGE 2. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories with receiver → NO_COVERAGE 3. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories → NO_COVERAGE 4. lambda$forGP$5 : removed call to net/bmahe/genetics4j/gp/combination/ProgramRandomCombineHandler::<init> → NO_COVERAGE 5. lambda$forGP$5 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE |
builder.addChromosomeCombinatorHandlerFactories(gsd -> new ProgramRandomCombineHandler<T>(gsd.randomGenerator())); |
| 57 | ||
| 58 |
1
1. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider::builder → NO_COVERAGE |
final var chromosomeFactoryProviderBuilder = ImmutableChromosomeFactoryProvider.builder(); |
| 59 |
2
1. forGP : replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator with receiver → NO_COVERAGE 2. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator → NO_COVERAGE |
chromosomeFactoryProviderBuilder.randomGenerator(randomGenerator); |
| 60 | chromosomeFactoryProviderBuilder | |
| 61 |
4
1. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator → NO_COVERAGE 2. lambda$forGP$6 : removed call to net/bmahe/genetics4j/gp/chromosomes/factory/ProgramTreeChromosomeFactory::<init> → NO_COVERAGE 3. forGP : replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator with receiver → NO_COVERAGE 4. lambda$forGP$6 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$6 → NO_COVERAGE |
.addChromosomeFactoriesGenerator(cdp -> new ProgramTreeChromosomeFactory(programGenerator)); |
| 62 |
3
1. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider → NO_COVERAGE 2. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::build → NO_COVERAGE 3. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider with receiver → NO_COVERAGE |
builder.chromosomeFactoryProvider(chromosomeFactoryProviderBuilder.build()); |
| 63 | ||
| 64 |
1
1. forGP : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE |
return builder; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Create a new EAExecutionContext pre-configured to support Genetic Programming. | |
| 69 | * <p>It adds support for some operators to select, mutate and combine programs. It also configure a default program | |
| 70 | * generation based on ramped hald and half. | |
| 71 | * | |
| 72 | * @param <T> Type of the fitness measurement | |
| 73 | * @param randomGenerator Random Generator | |
| 74 | * @return A new instance of a EAExecutionContext | |
| 75 | */ | |
| 76 | public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator) { | |
| 77 | Validate.notNull(randomGenerator); | |
| 78 | ||
| 79 |
1
1. forGP : removed call to net/bmahe/genetics4j/gp/program/ProgramHelper::<init> → NO_COVERAGE |
final var programHelper = new ProgramHelper(randomGenerator); |
| 80 |
1
1. forGP : removed call to net/bmahe/genetics4j/gp/program/RampedHalfAndHalfProgramGenerator::<init> → NO_COVERAGE |
final var programGenerator = new RampedHalfAndHalfProgramGenerator(randomGenerator, programHelper); |
| 81 | ||
| 82 |
2
1. forGP : removed call to net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE 2. forGP : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE |
return forGP(randomGenerator, programHelper, programGenerator); |
| 83 | } | |
| 84 | } | |
Mutations | ||
| 46 |
1.1 |
|
| 47 |
1.1 2.2 |
|
| 49 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 50 |
1.1 2.2 3.3 |
|
| 51 |
1.1 2.2 3.3 |
|
| 52 |
1.1 2.2 |
|
| 53 |
1.1 2.2 |
|
| 54 |
1.1 2.2 |
|
| 56 |
1.1 2.2 3.3 4.4 5.5 |
|
| 58 |
1.1 |
|
| 59 |
1.1 2.2 |
|
| 61 |
1.1 2.2 3.3 4.4 |
|
| 62 |
1.1 2.2 3.3 |
|
| 64 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 82 |
1.1 2.2 |