diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-02-04 16:53:19 +0000 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-02-04 16:53:19 +0000 |
commit | 0e34bfdb60c28a6118ec93893ddc7ceb6fa50cb5 (patch) | |
tree | 77f27ba5656e31e3bd75aebf21a96a840f813667 | |
parent | 1fd678821cf133c7c431daea687f3467bb0be2dd (diff) |
Started work on StandardEA, will require some modifications.
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | src/jcgp/CGP.java | 9 | ||||
-rw-r--r-- | src/jcgp/ea/StandardEA.java | 4 | ||||
-rw-r--r-- | src/jcgp/population/Population.java | 4 |
4 files changed, 14 insertions, 9 deletions
@@ -78,4 +78,10 @@ A standard fitness function which uses TruthTable is defined in TruthTableEvalua StandardMutator has been implemented, though it looks like it may need refactoring in the future. +StandardEA presents a problem: mutating the highest fitness chromosome to generate a new population requires the +chromosome to be copied, which is not straightforward in OOP. This could be addressed by creating a shallow copy +and instantiating new Nodes during the mutation process. This is actually an implementation of a lazy copy which +takes advantage of common Nodes to save memory. Additionally, this will require the mutation to actually occur within +the chromosome and simply be triggered from the Mutator. This reduces the number of Utilities functions, which is not +necessarily a problem. diff --git a/src/jcgp/CGP.java b/src/jcgp/CGP.java index 26d1d2b..5111508 100644 --- a/src/jcgp/CGP.java +++ b/src/jcgp/CGP.java @@ -171,9 +171,6 @@ public final class CGP { private static void setMaxArity(int maxArity) { Parameters.maxArity = maxArity; } - - - } public abstract static class Utilities { @@ -371,6 +368,9 @@ public final class CGP { private void initialise() { // initialise random number generator numberGenerator = new Random(1234); + + // initialise function set + functionSet = new FunctionSet(new Addition(), new Subtraction()); // initialise parameters Parameters.setInputs(3); @@ -383,9 +383,6 @@ public final class CGP { Parameters.setPopulationSize(5); Parameters.setLevelsBack(1); - // initialise function set - functionSet = new FunctionSet(new Addition(), new Subtraction()); - // compute and set maximum arity Parameters.setMaxArity(functionSet.getMaxArity()); diff --git a/src/jcgp/ea/StandardEA.java b/src/jcgp/ea/StandardEA.java index b98fe9e..f401d9c 100644 --- a/src/jcgp/ea/StandardEA.java +++ b/src/jcgp/ea/StandardEA.java @@ -6,9 +6,7 @@ import jcgp.population.Population; public class StandardEA implements EvolutionaryAlgorithm { @Override - public void evolve(Population population, Mutator mutator) { - - + public void evolve(Population population, Mutator mutator) { for (Chromosome chromosome : population) { mutator.mutate(chromosome); } diff --git a/src/jcgp/population/Population.java b/src/jcgp/population/Population.java index e171a2f..c4a0776 100644 --- a/src/jcgp/population/Population.java +++ b/src/jcgp/population/Population.java @@ -17,6 +17,10 @@ public class Population implements Iterable<Chromosome> { Parameters.getOutputs()); } } + + public Population(Chromosome ... chromosomes) { + population = chromosomes; + } @Override public Iterator<Chromosome> iterator() { |