diff options
Diffstat (limited to 'src/jcgp/fitness')
-rw-r--r-- | src/jcgp/fitness/ParameterMismatchException.java | 10 | ||||
-rw-r--r-- | src/jcgp/fitness/TestCase.java | 1 | ||||
-rw-r--r-- | src/jcgp/fitness/TruthTableEvaluator.java | 17 |
3 files changed, 10 insertions, 18 deletions
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()); } } - } |