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(); } }