From ef7a850a8f2f81ccaa07f25d9b7ad602e84d88c9 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 16 Feb 2014 22:41:46 +0000 Subject: Light refactoring, a good amount of testing done, added some new functions. --- src/jcgp/ea/EvolutionaryAlgorithm.java | 3 ++- src/jcgp/ea/StandardEA.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/jcgp/ea') diff --git a/src/jcgp/ea/EvolutionaryAlgorithm.java b/src/jcgp/ea/EvolutionaryAlgorithm.java index e084da0..ba70671 100644 --- a/src/jcgp/ea/EvolutionaryAlgorithm.java +++ b/src/jcgp/ea/EvolutionaryAlgorithm.java @@ -1,11 +1,12 @@ package jcgp.ea; +import jcgp.population.Chromosome; import jcgp.population.Population; public interface EvolutionaryAlgorithm { public abstract void evolve(Population population, Mutator mutator); - public abstract int getBestFitness(); + public abstract Chromosome getFittestChromosome(); } diff --git a/src/jcgp/ea/StandardEA.java b/src/jcgp/ea/StandardEA.java index 901333b..5f38513 100644 --- a/src/jcgp/ea/StandardEA.java +++ b/src/jcgp/ea/StandardEA.java @@ -13,7 +13,7 @@ import jcgp.population.Population; */ public class StandardEA implements EvolutionaryAlgorithm { - private int bestFitness = 0; + private Chromosome fittestChromosome; @Override public void evolve(Population population, Mutator mutator) { @@ -25,9 +25,11 @@ public class StandardEA implements EvolutionaryAlgorithm { fittest = i; } } - bestFitness = population.getChromosome(fittest).getFitness(); + fittestChromosome = population.getChromosome(fittest); population.setBestIndividual(fittest); - System.out.println("Best fitness: " + bestFitness); + 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++) { @@ -37,9 +39,9 @@ public class StandardEA implements EvolutionaryAlgorithm { } } } - + @Override - public int getBestFitness() { - return bestFitness; + public Chromosome getFittestChromosome() { + return fittestChromosome; } } -- cgit v1.2.3