diff options
Diffstat (limited to 'src/jcgp/ea')
-rw-r--r-- | src/jcgp/ea/EvolutionaryAlgorithm.java | 12 | ||||
-rw-r--r-- | src/jcgp/ea/Mutator.java | 9 | ||||
-rw-r--r-- | src/jcgp/ea/StandardEA.java | 47 | ||||
-rw-r--r-- | src/jcgp/ea/StandardMutator.java | 31 |
4 files changed, 0 insertions, 99 deletions
diff --git a/src/jcgp/ea/EvolutionaryAlgorithm.java b/src/jcgp/ea/EvolutionaryAlgorithm.java deleted file mode 100644 index ba70671..0000000 --- a/src/jcgp/ea/EvolutionaryAlgorithm.java +++ /dev/null @@ -1,12 +0,0 @@ -package jcgp.ea; - -import jcgp.population.Chromosome; -import jcgp.population.Population; - -public interface EvolutionaryAlgorithm { - - public abstract void evolve(Population population, Mutator mutator); - - public abstract Chromosome getFittestChromosome(); - -} diff --git a/src/jcgp/ea/Mutator.java b/src/jcgp/ea/Mutator.java deleted file mode 100644 index df3fe1c..0000000 --- a/src/jcgp/ea/Mutator.java +++ /dev/null @@ -1,9 +0,0 @@ -package jcgp.ea; - -import jcgp.population.Chromosome; - -public interface Mutator { - - void mutate(Chromosome chromosome); - -} diff --git a/src/jcgp/ea/StandardEA.java b/src/jcgp/ea/StandardEA.java deleted file mode 100644 index 5f38513..0000000 --- a/src/jcgp/ea/StandardEA.java +++ /dev/null @@ -1,47 +0,0 @@ -package jcgp.ea; - -import jcgp.Parameters; -import jcgp.population.Chromosome; -import jcgp.population.Population; - -/** - * (1 + λ) EA. - * - * - * @author Eduardo Pedroni - * - */ -public class StandardEA implements EvolutionaryAlgorithm { - - private Chromosome fittestChromosome; - - @Override - public void evolve(Population population, Mutator mutator) { - // select fittest chromosome - int fittest = 0; - - for (int i = 1; i < Parameters.getPopulationSize(); i++) { - if (population.getChromosome(i).getFitness() >= population.getChromosome(fittest).getFitness()) { - fittest = i; - } - } - fittestChromosome = population.getChromosome(fittest); - population.setBestIndividual(fittest); - if (Parameters.getDebug()) { - System.out.println("Best fitness: " + fittestChromosome.getFitness()); - } - // create copies of fittest chromosome, mutate them - Chromosome fc = population.getChromosome(fittest); - for (int i = 0; i < Parameters.getPopulationSize(); i++) { - if (i != fittest) { - population.getChromosome(i).copyConnections(fc); - mutator.mutate(population.getChromosome(i)); - } - } - } - - @Override - public Chromosome getFittestChromosome() { - return fittestChromosome; - } -} diff --git a/src/jcgp/ea/StandardMutator.java b/src/jcgp/ea/StandardMutator.java deleted file mode 100644 index b9c0a4e..0000000 --- a/src/jcgp/ea/StandardMutator.java +++ /dev/null @@ -1,31 +0,0 @@ -package jcgp.ea; - -import jcgp.Parameters; -import jcgp.Utilities; -import jcgp.population.Chromosome; -import jcgp.population.MutableElement; -import jcgp.population.Node; -import jcgp.population.Output; - -public class StandardMutator implements Mutator { - - @Override - public void mutate(Chromosome chromosome) { - int mutations = (int) (Parameters.getMutationRate() * (((double) Parameters.getNodeCount() + Parameters.getOutputs()) / 100)); - - for (int i = 0; i < mutations; i++) { - MutableElement m = chromosome.getRandomMutableElement(); - - if (m instanceof Output) { - m.setConnection(chromosome.getRandomConnection()); - } else if (m instanceof Node) { - int geneType = Utilities.getRandomInt(1 + Parameters.getMaxArity()); - if (geneType < 1) { - ((Node) m).setFunction(Utilities.getRandomFunction()); - } else { - m.setConnection(chromosome.getRandomConnection(((Node) m).getColumn())); - } - } - } - } -} |