From 9ac2848be66c39acdc291dc3b48b91178acc1a05 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 24 Apr 2014 10:34:30 +0100 Subject: Refactored parsers and parameters, had to install e(fx)clipse to deploy application. --- .../modules/problem/DigitalCircuitProblem.java | 4 +- .../backend/modules/problem/TestCaseProblem.java | 43 +++------------------- 2 files changed, 7 insertions(+), 40 deletions(-) (limited to 'src/jcgp/backend/modules/problem') diff --git a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java index e92989e..3c30e4c 100644 --- a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java +++ b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java @@ -49,8 +49,8 @@ public class DigitalCircuitProblem extends TestCaseProblem { } @Override - protected int getMaxFitness() { - int maxFitness = (int) Math.pow(2.0, (double) resources.inputs()) * resources.outputs(); + protected double getMaxFitness() { + double maxFitness = Math.pow(2.0, (double) resources.inputs()) * resources.outputs(); return maxFitness; } diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index ff13c2e..d8dd32b 100644 --- a/src/jcgp/backend/modules/problem/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -1,13 +1,11 @@ package jcgp.backend.modules.problem; -import java.io.File; import java.util.List; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import jcgp.backend.parser.TestCaseParser; import jcgp.backend.resources.Resources; -import jcgp.backend.resources.parameters.IntegerParameter; +import jcgp.backend.resources.parameters.DoubleParameter; import jcgp.backend.resources.parameters.Parameter; /** @@ -49,43 +47,21 @@ public abstract class TestCaseProblem extends Problem { } protected ObservableList> testCases; - protected IntegerParameter maxFitness; + protected DoubleParameter maxFitness; protected Resources resources; - protected TestCaseParser parser; - public TestCaseProblem(Resources resources) { super(); this.resources = resources; - maxFitness = new IntegerParameter(0, "Max fitness", true, false) { + maxFitness = new DoubleParameter(0, "Max fitness", true, false) { @Override public void validate(Number newValue) { // blank } }; testCases = FXCollections.observableArrayList(); - - parser = new TestCaseParser(this); - } - - public TestCaseProblem(Resources resources, File testCase) { - super(); - - this.resources = resources; - - maxFitness = new IntegerParameter(0, "Max fitness", true, false) { - @Override - public void validate(Number newValue) { - // blank - } - }; - testCases = FXCollections.observableArrayList(); - - parser = new TestCaseParser(this); - - parser.parse(testCase); } @Override @@ -93,7 +69,7 @@ public abstract class TestCaseProblem extends Problem { return new Parameter[]{maxFitness}; } - protected int getMaxFitness() { + protected double getMaxFitness() { int fitness = 0; for (TestCase tc : testCases) { @@ -115,7 +91,7 @@ public abstract class TestCaseProblem extends Problem { public abstract void addTestCase(String[] inputs, String[] outputs); - public void addTestCase(TestCase testCase) { + protected final void addTestCase(TestCase testCase) { if (testCase.getInputs().length != resources.inputs()) { throw new IllegalArgumentException("Received test case with " + testCase.getInputs().length + " inputs but need exactly " + resources.inputs()); @@ -128,11 +104,6 @@ public abstract class TestCaseProblem extends Problem { } } - public void removeTestCase(TestCase testCase) { - testCases.remove(testCase); - maxFitness.set(getMaxFitness()); - } - public int getInputCount() { return resources.inputs(); } @@ -141,10 +112,6 @@ public abstract class TestCaseProblem extends Problem { return resources.outputs(); } - public void parse(File file) { - parser.parse(file); - } - public void clearTestCases() { testCases.clear(); } -- cgit v1.2.3