aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/ea
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-16 22:41:46 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-16 22:41:46 +0000
commitef7a850a8f2f81ccaa07f25d9b7ad602e84d88c9 (patch)
tree9f9c6206a140bdfad4bb1b44354e6c7314d8b605 /src/jcgp/ea
parente9290a500b228e2561a8537adbc13e86f1356747 (diff)
Light refactoring, a good amount of testing done, added some new functions.
Diffstat (limited to 'src/jcgp/ea')
-rw-r--r--src/jcgp/ea/EvolutionaryAlgorithm.java3
-rw-r--r--src/jcgp/ea/StandardEA.java14
2 files changed, 10 insertions, 7 deletions
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;
}
}