From e9290a500b228e2561a8537adbc13e86f1356747 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sat, 15 Feb 2014 21:43:35 +0000 Subject: Population and Chromosome classes refactored so that EAs are easier to implement. --- src/jcgp/fitness/ParameterMismatchException.java | 10 ---------- src/jcgp/fitness/TestCase.java | 1 + src/jcgp/fitness/TruthTableEvaluator.java | 17 +++++++++-------- 3 files changed, 10 insertions(+), 18 deletions(-) delete mode 100644 src/jcgp/fitness/ParameterMismatchException.java (limited to 'src/jcgp/fitness') diff --git a/src/jcgp/fitness/ParameterMismatchException.java b/src/jcgp/fitness/ParameterMismatchException.java deleted file mode 100644 index 0ca69a7..0000000 --- a/src/jcgp/fitness/ParameterMismatchException.java +++ /dev/null @@ -1,10 +0,0 @@ -package jcgp.fitness; - -public class ParameterMismatchException extends RuntimeException { - - /** - * - */ - private static final long serialVersionUID = -3161318886125868134L; - -} diff --git a/src/jcgp/fitness/TestCase.java b/src/jcgp/fitness/TestCase.java index 4c10de7..e506d38 100644 --- a/src/jcgp/fitness/TestCase.java +++ b/src/jcgp/fitness/TestCase.java @@ -1,6 +1,7 @@ package jcgp.fitness; import jcgp.Parameters; +import jcgp.exceptions.ParameterMismatchException; public class TestCase { diff --git a/src/jcgp/fitness/TruthTableEvaluator.java b/src/jcgp/fitness/TruthTableEvaluator.java index 4c26d60..2281b3f 100644 --- a/src/jcgp/fitness/TruthTableEvaluator.java +++ b/src/jcgp/fitness/TruthTableEvaluator.java @@ -2,26 +2,27 @@ package jcgp.fitness; import jcgp.Parameters; import jcgp.TruthTable; -import jcgp.population.Chromosome; import jcgp.population.Population; public class TruthTableEvaluator implements FitnessFunction { @Override public void evaluate(Population population) { - for (Chromosome chromosome : population) { + // for every chromosome in the population + for (int i = 0; i < Parameters.getPopulationSize(); i++) { + int fitness = 0; + // for every test case for (int t = 0; t < TruthTable.getTestCaseCount(); t++) { - chromosome.setInputs(TruthTable.getTestCase(t).getInputs()); - int fitness = 0; + population.getChromosome(i).setInputs(TruthTable.getTestCase(t).getInputs()); + // check every output for (int o = 0; o < Parameters.getOutputs(); o++) { - if (chromosome.getOutput(o).calculate() == TruthTable.getTestCase(t).getOutput(o)) { + if (population.getChromosome(i).getOutput(o).calculate() == TruthTable.getTestCase(t).getOutput(o)) { fitness++; } } - chromosome.setFitness(fitness); - System.out.println("Fitness: " + fitness); } + population.getChromosome(i).setFitness(fitness); + System.out.println("active nodes: " + population.getChromosome(i).getActiveNodes().size()); } } - } -- cgit v1.2.3