blob: 6cf54295ed89d25d534428396ee60dfed71c4b19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package jcgp;
import java.util.Random;
import jcgp.ea.EvolutionaryAlgorithm;
import jcgp.ea.Mutator;
import jcgp.ea.StandardEA;
import jcgp.ea.StandardMutator;
import jcgp.fitness.FitnessFunction;
import jcgp.fitness.TestCase;
import jcgp.fitness.TruthTableEvaluator;
import jcgp.function.Addition;
import jcgp.function.FunctionSet;
import jcgp.function.Subtraction;
import jcgp.population.Population;
public final class CGP {
// CGP components
private EvolutionaryAlgorithm ea;
private Mutator mutator;
private Population population;
private FitnessFunction fitnessFunction;
public CGP() {
initialise();
fitnessFunction.evaluate(population);
ea.evolve(population, mutator);
}
/**
*
*/
private void initialise() {
// initialise function set
FunctionSet functionSet = new FunctionSet(new Addition(), new Subtraction());
// initialise utilities
Utilities.setResources(new Random(1234), functionSet);
// initialise parameters
Parameters.setColumns(3);
Parameters.setRows(3);
Parameters.setInputs(3);
Parameters.setOutputs(3);
Parameters.setLevelsBack(1);
Parameters.setMutationRate(10);
Parameters.setTotalGenerations(100);
Parameters.setTotalRuns(5);
Parameters.setMaxArity(functionSet.getMaxArity());
// initialise fitness function and truth table
TruthTable.setTestCases(new TestCase(new int[] {2, 5, 4}, new int[] {1, 10, 15}));
fitnessFunction = new TruthTableEvaluator();
// initialise EA
ea = new StandardEA();
mutator = new StandardMutator();
// initialise population
population = new Population();
}
}
|