From 0e34bfdb60c28a6118ec93893ddc7ceb6fa50cb5 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 4 Feb 2014 16:53:19 +0000 Subject: Started work on StandardEA, will require some modifications. --- README | 6 ++++++ src/jcgp/CGP.java | 9 +++------ src/jcgp/ea/StandardEA.java | 4 +--- src/jcgp/population/Population.java | 4 ++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README b/README index 3241aae..6040391 100644 --- a/README +++ b/README @@ -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 { Parameters.getOutputs()); } } + + public Population(Chromosome ... chromosomes) { + population = chromosomes; + } @Override public Iterator iterator() { -- cgit v1.2.3