aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/problem
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/problem')
-rw-r--r--src/jcgp/backend/modules/problem/DigitalCircuitProblem.java20
-rw-r--r--src/jcgp/backend/modules/problem/Problem.java28
-rw-r--r--src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java28
-rw-r--r--src/jcgp/backend/modules/problem/TestCaseProblem.java8
-rw-r--r--src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java43
5 files changed, 93 insertions, 34 deletions
diff --git a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java
index 3c30e4c..099f527 100644
--- a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java
+++ b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java
@@ -1,6 +1,6 @@
package jcgp.backend.modules.problem;
-import jcgp.backend.function.BitwiseLogic;
+import jcgp.backend.function.DigitalCircuitFunctions;
import jcgp.backend.function.UnsignedInteger;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
@@ -10,14 +10,13 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> {
public DigitalCircuitProblem(Resources resources) {
super(resources);
- functionSet = new BitwiseLogic();
+ functionSet = new DigitalCircuitFunctions();
+ setProblemName("Symbolic regression");
+ setFileExtension(".plu");
}
@Override
public void evaluate(Population population, Resources resources) {
- // set fittest to 0, change it whenever a fitter one is found
- population.setFittest(0);
-
// for every chromosome in the population
for (int i = 0; i < resources.populationSize(); i++) {
// assume an initial fitness of 0
@@ -42,10 +41,10 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> {
// assign the resulting fitness to the respective individual
population.getChromosome(i).setFitness(fitness);
- if (fitness >= population.getFittest().getFitness()) {
- population.setFittest(i);
- }
}
+
+ // sort population
+ population.sortAscending();
}
@Override
@@ -77,9 +76,4 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> {
public boolean isPerfectSolution(Chromosome fittest) {
return fittest.getFitness() >= maxFitness.get();
}
-
- @Override
- public String getFileExtension() {
- return ".plu";
- }
}
diff --git a/src/jcgp/backend/modules/problem/Problem.java b/src/jcgp/backend/modules/problem/Problem.java
index d01f5b0..07183ea 100644
--- a/src/jcgp/backend/modules/problem/Problem.java
+++ b/src/jcgp/backend/modules/problem/Problem.java
@@ -1,14 +1,19 @@
package jcgp.backend.modules.problem;
+import java.io.File;
+
import jcgp.backend.function.FunctionSet;
import jcgp.backend.modules.Module;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
+import jcgp.backend.resources.ModifiableResources;
import jcgp.backend.resources.Resources;
public abstract class Problem implements Module {
protected FunctionSet functionSet;
+ private String fileExtension = ".*";
+ private String name = this.getClass().getSimpleName();
public abstract void evaluate(Population population, Resources resources);
@@ -17,4 +22,27 @@ public abstract class Problem implements Module {
}
public abstract boolean isPerfectSolution(Chromosome fittest);
+
+ public abstract void parse(File file, ModifiableResources resources);
+
+ public void setFileExtension(String fileExtension) {
+ this.fileExtension = fileExtension;
+ }
+
+ public String getFileExtension() {
+ return fileExtension;
+ }
+
+ public void setProblemName(String newName) {
+ this.name = newName;
+ }
+
+ public String getProblemName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
}
diff --git a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
index 52df0f2..5468157 100644
--- a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
+++ b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
@@ -1,6 +1,6 @@
package jcgp.backend.modules.problem;
-import jcgp.backend.function.DoubleArithmetic;
+import jcgp.backend.function.SymbolicRegressionFunctions;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
import jcgp.backend.resources.Resources;
@@ -16,7 +16,9 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
public SymbolicRegressionProblem(Resources resources) {
super(resources);
- functionSet = new DoubleArithmetic();
+ functionSet = new SymbolicRegressionFunctions();
+ setProblemName("Symbolic regression");
+ setFileExtension(".dat");
errorThreshold = new DoubleParameter(0.01, "Error threshold") {
@Override
public void validate(Number newValue) {
@@ -45,7 +47,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
}
}
};
- hitsBasedFitness = new BooleanParameter(true, "Hits-based fitness") {
+ hitsBasedFitness = new BooleanParameter(true, "HITS-based fitness") {
@Override
public void validate(Boolean newValue) {
// blank
@@ -55,9 +57,6 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
@Override
public void evaluate(Population population, Resources resources) {
- // set fittest to 0, change it whenever a fitter one is found
- population.setFittest(0);
-
// for every chromosome in the population
for (int i = 0; i < resources.populationSize(); i++) {
// assume an initial fitness of 0
@@ -81,18 +80,12 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
}
// assign the resulting fitness to the respective individual
population.getChromosome(i).setFitness(fitness);
- if (fitness >= population.getFittest().getFitness()) {
- population.setFittest(i);
- }
}
+
+ // sort population
+ population.sortAscending();
}
-
- @Override
- public String toString() {
- return "Symbolic regression";
- }
-
@Override
public void addTestCase(String[] inputs, String[] outputs) {
Double[] inputCases = new Double[inputs.length];
@@ -116,9 +109,4 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
public Parameter<?>[] getLocalParameters() {
return new Parameter[]{maxFitness, errorThreshold, perfectionThreshold, hitsBasedFitness};
}
-
- @Override
- public String getFileExtension() {
- return ".dat";
- }
}
diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java
index d8dd32b..6c4a7dc 100644
--- a/src/jcgp/backend/modules/problem/TestCaseProblem.java
+++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java
@@ -1,9 +1,12 @@
package jcgp.backend.modules.problem;
+import java.io.File;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
+import jcgp.backend.parsers.TestCaseParser;
+import jcgp.backend.resources.ModifiableResources;
import jcgp.backend.resources.Resources;
import jcgp.backend.resources.parameters.DoubleParameter;
import jcgp.backend.resources.parameters.Parameter;
@@ -116,7 +119,10 @@ public abstract class TestCaseProblem<U extends Object> extends Problem {
testCases.clear();
}
- public abstract String getFileExtension();
+ public void parse(File file, ModifiableResources resources) {
+ TestCaseParser.parseParameters(file, resources);
+ TestCaseParser.parse(file, this, resources);
+ }
}
diff --git a/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java b/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java
new file mode 100644
index 0000000..6491ec6
--- /dev/null
+++ b/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java
@@ -0,0 +1,43 @@
+package jcgp.backend.modules.problem;
+
+import java.io.File;
+
+import jcgp.backend.function.TravellingSalesmanFunctions;
+import jcgp.backend.population.Chromosome;
+import jcgp.backend.population.Population;
+import jcgp.backend.resources.ModifiableResources;
+import jcgp.backend.resources.Resources;
+import jcgp.backend.resources.parameters.Parameter;
+
+public class TravellingSalesmanProblem extends Problem {
+
+ public TravellingSalesmanProblem(Resources resources) {
+ functionSet = new TravellingSalesmanFunctions();
+ setProblemName("Travelling salesman");
+ setFileExtension(".tsp");
+ }
+
+ @Override
+ public Parameter<?>[] getLocalParameters() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void evaluate(Population population, Resources resources) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isPerfectSolution(Chromosome fittest) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void parse(File file, ModifiableResources resources) {
+ // TODO Auto-generated method stub
+
+ }
+}