aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-07 10:04:05 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-07 10:04:05 +0100
commit67ace66f66ffaa00e1bd1495c0d406c801e59c5c (patch)
tree337da2ab9bbd5eb41a0a6eafbf783340240bcffe /src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java
parentefee474689b37f43897b8572cec4e3669874b0d4 (diff)
Refactored problem types
Diffstat (limited to 'src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java')
-rw-r--r--src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java b/src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java
deleted file mode 100644
index 4b0654c..0000000
--- a/src/jcgp/backend/modules/fitness/testcase/TestCaseEvaluator.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package jcgp.backend.modules.fitness.testcase;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-import jcgp.backend.modules.fitness.FitnessFunction;
-import jcgp.backend.population.Population;
-import jcgp.backend.resources.Resources;
-
-/**
- *
- * This fitness function module implements a simple test case evaluator.
- *
- * A TestCase object is a
- *
- *
- * @author Eduardo Pedroni
- *
- */
-public abstract class TestCaseEvaluator implements FitnessFunction {
-
- public static class TestCase<T> {
-
- private T[] inputs;
- private T[] outputs;
-
- public TestCase(T[] inputs, T[] outputs) {
- this.inputs = inputs;
- this.outputs = outputs;
- }
-
- public T getInput(int index) {
- return inputs[index];
- }
-
- public T getOutput(int index) {
- return outputs[index];
- }
-
- public T[] getInputs() {
- return inputs;
- }
-
- public T[] getOutputs() {
- return outputs;
- }
- }
-
- protected ArrayList<TestCase<?>> testCases;
-
- @Override
- public void evaluate(Population population, Resources resources) {
- // for every chromosome in the population
- for (int i = 0; i < resources.getInt("popSize"); i++) {
- // assume an initial fitness of 0
- int fitness = 0;
- // for each test case
- for (int t = 0; t < testCases.size(); t++) {
- population.getChromosome(i).setInputs(testCases.get(t).getInputs());
- // check each output
- for (int o = 0; o < resources.getInt("outputs"); o++) {
- if (population.getChromosome(i).getOutput(o).calculate() == testCases.get(t).getOutput(o)) {
- fitness++;
- }
- }
- }
- // assign the resulting fitness to the respective individual
- population.getChromosome(i).setFitness(fitness);
- }
- }
-
- public int getMaxFitness() {
- int fitness = 0;
-
- for (TestCase<?> tc : testCases) {
- fitness += tc.getOutputs().length;
- }
-
- return fitness;
- }
-
- public void setTestCases(TestCase<?>... testCases) {
- this.testCases = new ArrayList<TestCase<?>>();
- Collections.addAll(this.testCases, testCases);
- }
-}
-