aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/ea
diff options
context:
space:
mode:
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;
}
}