From f13ebf70037a6aa28dc53804c1f0cef6e2f23102 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 19 May 2014 01:36:03 +0100 Subject: Minor refactorings --- .../backend/modules/problem/DigitalCircuitProblem.java | 12 ++++++------ src/jcgp/backend/modules/problem/Problem.java | 2 +- .../modules/problem/SymbolicRegressionProblem.java | 4 ++-- src/jcgp/backend/modules/problem/TestCaseProblem.java | 16 ---------------- 4 files changed, 9 insertions(+), 25 deletions(-) (limited to 'src/jcgp/backend/modules') diff --git a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java index e2f17c3..ff77a0d 100644 --- a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java +++ b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java @@ -31,9 +31,9 @@ public class DigitalCircuitProblem extends TestCaseProblem { } @Override - public void evaluate(Population population, Resources resources) { + public void evaluate(Population population) { // for every chromosome in the population - for (int i = 0; i < resources.populationSize(); i++) { + for (int i = 0; i < getResources().populationSize(); i++) { // assume an initial fitness of 0 int fitness = 0; @@ -41,13 +41,13 @@ public class DigitalCircuitProblem extends TestCaseProblem { for (int t = 0; t < testCases.size(); t++) { population.get(i).setInputs((Object[]) testCases.get(t).getInputs()); // check each output - for (int o = 0; o < resources.outputs(); o++) { + for (int o = 0; o < getResources().outputs(); o++) { Integer output = ((UnsignedInteger) population.get(i).getOutput(o).calculate()).get(); - Integer matches = ~(output ^ testCases.get(t).getOutput(o).get()); + Integer matches = ~(output ^ testCases.get(t).getOutputs()[o].get()); // check only the relevant bits int bits; - if (resources.inputs() < 5) { - bits = (int) Math.pow(2.0, (double) resources.inputs()); + if (getResources().inputs() < 5) { + bits = (int) Math.pow(2.0, (double) getResources().inputs()); } else { bits = 32; } diff --git a/src/jcgp/backend/modules/problem/Problem.java b/src/jcgp/backend/modules/problem/Problem.java index 2af2373..6785733 100644 --- a/src/jcgp/backend/modules/problem/Problem.java +++ b/src/jcgp/backend/modules/problem/Problem.java @@ -74,7 +74,7 @@ public abstract class Problem extends Module { * @param population the population to be evaluated. * @param resources parameters and utilities for optional reference. */ - public abstract void evaluate(Population population, Resources resources); + public abstract void evaluate(Population population); /** * Used to assert whether a given population contains a perfect solution diff --git a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java index 3b5f539..6bc4790 100644 --- a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java +++ b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java @@ -84,7 +84,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem { } @Override - public void evaluate(Population population, Resources resources) { + public void evaluate(Population population) { // for every chromosome in the population for (int i = 0; i < getResources().populationSize(); i++) { // assume an initial fitness of 0 @@ -95,7 +95,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem { // check each output for (int o = 0; o < getResources().outputs(); o++) { Double cgpValue = (Double) population.get(i).getOutput(o).calculate(); - Double dataValue = testCases.get(t).getOutput(o); + Double dataValue = testCases.get(t).getOutputs()[o]; if (hitsBasedFitness.get()) { if (Math.abs(cgpValue - dataValue) <= errorThreshold.get()) { fitness++; diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index 188e236..964860c 100644 --- a/src/jcgp/backend/modules/problem/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -49,22 +49,6 @@ public abstract class TestCaseProblem extends Problem { this.outputs = outputs; } - /** - * @param index the index to return. - * @return the indexed input. - */ - public U getInput(int index) { - return inputs[index]; - } - - /** - * @param index the index to return. - * @return the indexed output. - */ - public U getOutput(int index) { - return outputs[index]; - } - /** * @return the complete array of inputs. */ -- cgit v1.2.3