GPEAExecutionContexts.java

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
23
 * EAExecutionContexts appropriate for Genetic Programming
24
 */
25
public class GPEAExecutionContexts {
26
27
	private GPEAExecutionContexts() {
28
	}
29
30
	/**
31
	 * Create a new EAExecutionContext pre-configured to support Genetic
32
	 * Programming.
33
	 * <p>
34
	 * It adds support for some operators to select, mutate and combine programs.
35
	 * 
36
	 * @param <T>              Type of the fitness measurement
37
	 * @param randomGenerator  Random Generator
38
	 * @param programHelper    Instance of ProgramHelper
39
	 * @param programGenerator Instance of a program generator which will be used to
40
	 *                         generate individuals
41
	 * @return A new instance of a EAExecutionContext
42
	 */
43
	public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator,
44
			final ProgramHelper programHelper, final ProgramGenerator programGenerator) {
45
		Validate.notNull(randomGenerator);
46
		Validate.notNull(programHelper);
47
		Validate.notNull(programGenerator);
48
49 1 1. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext::builder → NO_COVERAGE
		final var builder = ImmutableEAExecutionContext.<T>builder();
50 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);
51
52 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(
53 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),
54 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),
55 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),
56 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<>(),
57 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));
58
59 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()));
60
61 1 1. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider::builder → NO_COVERAGE
		final var chromosomeFactoryProviderBuilder = ImmutableChromosomeFactoryProvider.builder();
62 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);
63
		chromosomeFactoryProviderBuilder
64 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));
65 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());
66
67 1 1. forGP : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE
		return builder;
68
	}
69
70
	/**
71
	 * Create a new EAExecutionContext pre-configured to support Genetic
72
	 * Programming.
73
	 * <p>
74
	 * It adds support for some operators to select, mutate and combine programs. It
75
	 * also configure a default program generation based on ramped hald and half.
76
	 * 
77
	 * @param <T>             Type of the fitness measurement
78
	 * @param randomGenerator Random Generator
79
	 * @return A new instance of a EAExecutionContext
80
	 */
81
	public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator) {
82
		Validate.notNull(randomGenerator);
83
84 1 1. forGP : removed call to net/bmahe/genetics4j/gp/program/ProgramHelper::<init> → NO_COVERAGE
		final var programHelper = new ProgramHelper(randomGenerator);
85 1 1. forGP : removed call to net/bmahe/genetics4j/gp/program/RampedHalfAndHalfProgramGenerator::<init> → NO_COVERAGE
		final var programGenerator = new RampedHalfAndHalfProgramGenerator(randomGenerator, programHelper);
86
87 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);
88
	}
89
}

Mutations

49

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext::builder → NO_COVERAGE

50

1.1
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator with receiver → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator → NO_COVERAGE

52

1.1
Location : forGP
Killed by : none
Substituted 5 with 6 → NO_COVERAGE

2.2
Location : forGP
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories with receiver → NO_COVERAGE

4.4
Location : forGP
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

5.5
Location : forGP
Killed by : none
Substituted 2 with 3 → NO_COVERAGE

6.6
Location : forGP
Killed by : none
Substituted 3 with 4 → NO_COVERAGE

7.7
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories → NO_COVERAGE

8.8
Location : forGP
Killed by : none
Substituted 4 with 5 → NO_COVERAGE

53

1.1
Location : lambda$forGP$0
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$0 → NO_COVERAGE

2.2
Location : lambda$forGP$0
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

3.3
Location : lambda$forGP$0
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::<init> → NO_COVERAGE

54

1.1
Location : lambda$forGP$1
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$1 → NO_COVERAGE

2.2
Location : lambda$forGP$1
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomMutatePolicyHandler::<init> → NO_COVERAGE

3.3
Location : lambda$forGP$1
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

55

1.1
Location : lambda$forGP$2
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/NodeReplacementPolicyHandler::<init> → NO_COVERAGE

2.2
Location : lambda$forGP$2
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$2 → NO_COVERAGE

56

1.1
Location : lambda$forGP$3
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRulesApplicatorPolicyHandler::<init> → NO_COVERAGE

2.2
Location : lambda$forGP$3
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$3 → NO_COVERAGE

57

1.1
Location : lambda$forGP$4
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$4 → NO_COVERAGE

2.2
Location : lambda$forGP$4
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/TrimTreePolicyHandler::<init> → NO_COVERAGE

59

1.1
Location : lambda$forGP$5
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$5 → NO_COVERAGE

2.2
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories with receiver → NO_COVERAGE

3.3
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories → NO_COVERAGE

4.4
Location : lambda$forGP$5
Killed by : none
removed call to net/bmahe/genetics4j/gp/combination/ProgramRandomCombineHandler::<init> → NO_COVERAGE

5.5
Location : lambda$forGP$5
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

61

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider::builder → NO_COVERAGE

62

1.1
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator with receiver → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator → NO_COVERAGE

64

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator → NO_COVERAGE

2.2
Location : lambda$forGP$6
Killed by : none
removed call to net/bmahe/genetics4j/gp/chromosomes/factory/ProgramTreeChromosomeFactory::<init> → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator with receiver → NO_COVERAGE

4.4
Location : lambda$forGP$6
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$6 → NO_COVERAGE

65

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::build → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider with receiver → NO_COVERAGE

67

1.1
Location : forGP
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

84

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/ProgramHelper::<init> → NO_COVERAGE

85

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/RampedHalfAndHalfProgramGenerator::<init> → NO_COVERAGE

87

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

2.2
Location : forGP
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.6