aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/JCGP.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/JCGP.java')
-rw-r--r--src/jcgp/JCGP.java55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/jcgp/JCGP.java b/src/jcgp/JCGP.java
index 70b01a8..a19e085 100644
--- a/src/jcgp/JCGP.java
+++ b/src/jcgp/JCGP.java
@@ -1,10 +1,14 @@
package jcgp;
+import java.util.ArrayList;
+
import jcgp.backend.modules.ea.EvolutionaryAlgorithm;
import jcgp.backend.modules.ea.MuPlusLambda;
import jcgp.backend.modules.ea.TournamentSelection;
-import jcgp.backend.modules.fitness.FitnessFunction;
-import jcgp.backend.modules.fitness.testcase.TestCaseEvaluator.TestCase;
+import jcgp.backend.modules.fitness.DigitalCircuit;
+import jcgp.backend.modules.fitness.Problem;
+import jcgp.backend.modules.fitness.SymbolicRegression;
+import jcgp.backend.modules.fitness.TestCaseProblem.TestCase;
import jcgp.backend.modules.mutator.Mutator;
import jcgp.backend.modules.mutator.PointMutator;
import jcgp.backend.population.Population;
@@ -50,30 +54,34 @@ public class JCGP {
new TournamentSelection()};
private EvolutionaryAlgorithm evolutionaryAlgorithm;
- // fitness evaluators
- private FitnessFunction[] fitnessFunctions = new FitnessFunction[] {
- /*new TestCaseEvaluator()*/ };
- private FitnessFunction fitnessFunction;
+ // problem types
+ private Problem[] problems = new Problem[] {
+ new SymbolicRegression(),
+ new DigitalCircuit() };
+ private Problem problem;
/*
* the population of chromosomes
*/
private Population population;
-
private boolean finished = false;
public JCGP() {
+ setEvolutionaryAlgorithm(0);
+ setMutator(0);
+ setProblem(0);
population = new Population(resources);
-
- evolutionaryAlgorithm = evolutionaryAlgorithms[0];
- mutator = mutators[0];
+ ArrayList<TestCase<Integer>> tc = new ArrayList<TestCase<Integer>>();
+ tc.add(new TestCase<Integer>(new Integer[]{1, 2, 3}, new Integer[]{-4, 5, 6}));
- //fitnessFunction = fitnessFunctions[0];
+ ((SymbolicRegression) problem).setTestCases(tc);
- //resources.setTestCases(new TestCase(new Integer[]{1, 2, 3}, new Integer[]{-4, 5, 6}));
-
+ ArrayList<TestCase<Integer>> tcdc = new ArrayList<TestCase<Integer>>();
+ tcdc.add(new TestCase<Integer>(new Integer[]{1, 2, 3}, new Integer[]{-4, 5, 6}));
+
+ ((DigitalCircuit) problems[1]).setTestCases(tc);
}
public ModifiableResources getResources() {
@@ -119,16 +127,16 @@ public class JCGP {
/**
* @return the fitnessFunctions
*/
- public FitnessFunction[] getFitnessFunctions() {
- return fitnessFunctions;
+ public Problem[] getProblems() {
+ return problems;
}
/**
* @return the fitnessFunction
*/
- public FitnessFunction getFitnessFunction() {
- return fitnessFunction;
+ public Problem getProblem() {
+ return problem;
}
@@ -149,21 +157,21 @@ public class JCGP {
/**
- * @param fitnessFunction the fitnessFunction to set
+ * @param problem the fitnessFunction to set
*/
- public void setFitnessFunction(int index) {
- this.fitnessFunction = fitnessFunctions[index];
+ public void setProblem(int index) {
+ this.problem = problems[index];
+ resources.setFunctionSet(problem.getFunctionSet());
}
public void nextGeneration() {
if (!finished) {
- fitnessFunction.evaluate(population, (Resources) resources);
-
+ problem.evaluate(population, (Resources) resources);
report();
if (resources.getInt("currentGen") < resources.getInt("generations")) {
// we still have generations left to go
- if (population.getChromosome(evolutionaryAlgorithm.getFittestChromosome()).getFitness() >= resources.getInt("maxFitness")) {
+ if (problem.isPerfectSolution(population.getChromosome(evolutionaryAlgorithm.getFittestChromosome()))) {
// solution has been found, start next run
resources.println("Solution found on generation " + resources.getInt("currentGen") + ", chromosome: " + evolutionaryAlgorithm.getFittestChromosome());
@@ -181,7 +189,6 @@ public class JCGP {
} else {
resources.set("currentGen", resources.getInt("currentGen") + 1);
}
-
} else {
// the run has ended, check if any more runs must be done
resources.println("Solution not found, highest fitness achieved was "