aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-03 15:29:24 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-03 15:29:24 +0100
commit0dbf126fc524bc029d9f5803d849b7c8f43fe389 (patch)
tree35d7c23b371614388cbb7a4bc247374759b95a33 /src/jcgp/backend/modules
parent02fd2bc7059da416937beb1abe67e5ca60379030 (diff)
Visual feedback for parameters implemented.
Diffstat (limited to 'src/jcgp/backend/modules')
-rw-r--r--src/jcgp/backend/modules/Module.java6
-rw-r--r--src/jcgp/backend/modules/ea/EvolutionaryAlgorithm.java3
-rw-r--r--src/jcgp/backend/modules/ea/MuPlusLambda.java57
-rw-r--r--src/jcgp/backend/modules/ea/TournamentSelection.java18
-rw-r--r--src/jcgp/backend/modules/fitness/TestCaseEvaluator.java6
-rw-r--r--src/jcgp/backend/modules/mutator/PointMutator.java19
6 files changed, 54 insertions, 55 deletions
diff --git a/src/jcgp/backend/modules/Module.java b/src/jcgp/backend/modules/Module.java
index f9114de..82c3d80 100644
--- a/src/jcgp/backend/modules/Module.java
+++ b/src/jcgp/backend/modules/Module.java
@@ -1,11 +1,11 @@
package jcgp.backend.modules;
-import java.util.HashMap;
-
import jcgp.JCGP.Resources;
import jcgp.backend.parameters.Parameter;
public interface Module {
- public HashMap<String, Parameter> getLocalParameters();
+
+ public Parameter[] getLocalParameters();
+
public ModuleStatus getStatus(Resources resources);
}
diff --git a/src/jcgp/backend/modules/ea/EvolutionaryAlgorithm.java b/src/jcgp/backend/modules/ea/EvolutionaryAlgorithm.java
index ce457ef..7719111 100644
--- a/src/jcgp/backend/modules/ea/EvolutionaryAlgorithm.java
+++ b/src/jcgp/backend/modules/ea/EvolutionaryAlgorithm.java
@@ -3,13 +3,12 @@ package jcgp.backend.modules.ea;
import jcgp.JCGP.Resources;
import jcgp.backend.modules.Module;
import jcgp.backend.modules.mutator.Mutator;
-import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
public interface EvolutionaryAlgorithm extends Module {
public abstract void evolve(Population population, Mutator mutator, Resources parameters);
- public abstract Chromosome getFittestChromosome();
+ public abstract int getFittestChromosome();
}
diff --git a/src/jcgp/backend/modules/ea/MuPlusLambda.java b/src/jcgp/backend/modules/ea/MuPlusLambda.java
index fcfba05..22a0876 100644
--- a/src/jcgp/backend/modules/ea/MuPlusLambda.java
+++ b/src/jcgp/backend/modules/ea/MuPlusLambda.java
@@ -1,13 +1,10 @@
package jcgp.backend.modules.ea;
-import java.util.HashMap;
-
import jcgp.JCGP.Resources;
import jcgp.backend.modules.ModuleStatus;
import jcgp.backend.modules.mutator.Mutator;
import jcgp.backend.parameters.IntegerParameter;
import jcgp.backend.parameters.Parameter;
-import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
/**
@@ -19,52 +16,54 @@ import jcgp.backend.population.Population;
*/
public class MuPlusLambda implements EvolutionaryAlgorithm {
- private Chromosome fittestChromosome;
+ private int fittestChromosome;
private IntegerParameter parents, offspring;
-
- private HashMap<String, Parameter> localParameters;
-
- public MuPlusLambda() {
- parents = new IntegerParameter(1, "Parents");
- offspring = new IntegerParameter(4, "Offspring");
-
- localParameters = new HashMap<String, Parameter>();
- localParameters.put("mu", parents);
- localParameters.put("lambda", offspring);
+ public MuPlusLambda() {
+ parents = new IntegerParameter(1, "Parents") {
+ @Override
+ protected void validate(int newValue) {
+
+ }
+ };
+ offspring = new IntegerParameter(4, "Offspring") {
+ @Override
+ protected void validate(int newValue) {
+
+ }
+ };
}
@Override
- public void evolve(Population population, Mutator mutator, Resources parameters) {
+ public void evolve(Population population, Mutator mutator, Resources resources) {
+ // TODO actually use parents and offspring
// select fittest chromosome
- int fittest = 0;
+ fittestChromosome = 0;
- for (int i = 1; i < parameters.getInt("popSize"); i++) {
- if (population.getChromosome(i).getFitness() >= population.getChromosome(fittest).getFitness()) {
- fittest = i;
+ for (int i = 1; i < resources.getInt("popSize"); i++) {
+ if (population.getChromosome(i).getFitness() >= population.getChromosome(fittestChromosome).getFitness()) {
+ fittestChromosome = i;
}
}
- fittestChromosome = population.getChromosome(fittest);
- population.setBestIndividual(fittest);
+
// create copies of fittest chromosome, mutate them
- Chromosome fc = population.getChromosome(fittest);
- for (int i = 0; i < parameters.getInt("popSize"); i++) {
- if (i != fittest) {
- population.getChromosome(i).copyConnections(fc);
- mutator.mutate(population.getChromosome(i), parameters);
+ for (int i = 0; i < resources.getInt("popSize"); i++) {
+ if (i != fittestChromosome) {
+ population.copyChromosome(fittestChromosome, i);
+ mutator.mutate(population.getChromosome(i), resources);
}
}
}
@Override
- public Chromosome getFittestChromosome() {
+ public int getFittestChromosome() {
return fittestChromosome;
}
@Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
+ public Parameter[] getLocalParameters() {
+ return new Parameter[] {parents, offspring};
}
@Override
diff --git a/src/jcgp/backend/modules/ea/TournamentSelection.java b/src/jcgp/backend/modules/ea/TournamentSelection.java
index 6cbaa45..3c4a539 100644
--- a/src/jcgp/backend/modules/ea/TournamentSelection.java
+++ b/src/jcgp/backend/modules/ea/TournamentSelection.java
@@ -7,39 +7,43 @@ import jcgp.backend.modules.ModuleStatus;
import jcgp.backend.modules.mutator.Mutator;
import jcgp.backend.parameters.IntegerParameter;
import jcgp.backend.parameters.Parameter;
-import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
public class TournamentSelection implements EvolutionaryAlgorithm {
- private Chromosome fittestChromosome;
+ private int fittestChromosome;
private IntegerParameter tournament;
private HashMap<String, Parameter> localParameters;
public TournamentSelection() {
- tournament = new IntegerParameter(1, "Tournament size");
+ tournament = new IntegerParameter(1, "Tournament size") {
+ @Override
+ protected void validate(int newValue) {
+
+ }
+ };
localParameters = new HashMap<String, Parameter>();
localParameters.put("tournament", tournament);
}
@Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
+ public Parameter[] getLocalParameters() {
+ return new Parameter[] {tournament};
}
@Override
public void evolve(Population population, Mutator mutator,
Resources parameters) {
tournament.set(tournament.get() + 1);
- fittestChromosome = population.getChromosome(0);
+ fittestChromosome = 0;
// TODO implement this
}
@Override
- public Chromosome getFittestChromosome() {
+ public int getFittestChromosome() {
return fittestChromosome;
}
diff --git a/src/jcgp/backend/modules/fitness/TestCaseEvaluator.java b/src/jcgp/backend/modules/fitness/TestCaseEvaluator.java
index 3b67f28..5ff6973 100644
--- a/src/jcgp/backend/modules/fitness/TestCaseEvaluator.java
+++ b/src/jcgp/backend/modules/fitness/TestCaseEvaluator.java
@@ -1,7 +1,5 @@
package jcgp.backend.modules.fitness;
-import java.util.HashMap;
-
import jcgp.JCGP.Resources;
import jcgp.backend.modules.ModuleStatus;
import jcgp.backend.parameters.Parameter;
@@ -10,7 +8,7 @@ import jcgp.backend.population.Population;
public class TestCaseEvaluator implements FitnessFunction {
@Override
- public void evaluate(Population population, Resources resources) {
+ public void evaluate(Population population, Resources resources) {
// for every chromosome in the population
for (int i = 0; i < resources.getInt("popSize"); i++) {
int fitness = 0;
@@ -29,7 +27,7 @@ public class TestCaseEvaluator implements FitnessFunction {
}
@Override
- public HashMap<String, Parameter> getLocalParameters() {
+ public Parameter[] getLocalParameters() {
return null;
}
diff --git a/src/jcgp/backend/modules/mutator/PointMutator.java b/src/jcgp/backend/modules/mutator/PointMutator.java
index 62d827d..cdac8bb 100644
--- a/src/jcgp/backend/modules/mutator/PointMutator.java
+++ b/src/jcgp/backend/modules/mutator/PointMutator.java
@@ -1,7 +1,5 @@
package jcgp.backend.modules.mutator;
-import java.util.HashMap;
-
import jcgp.backend.function.Function;
import jcgp.backend.modules.ModuleStatus;
import jcgp.backend.parameters.DoubleParameter;
@@ -15,15 +13,16 @@ import jcgp.JCGP.Resources;
public class PointMutator implements Mutator {
private DoubleParameter mutationRate;
- private HashMap<String, Parameter> localParameters;
-
+
private ModuleStatus status = ModuleStatus.READY;
public PointMutator() {
- mutationRate = new DoubleParameter(0.5, "Percent mutation", false, false, false);
-
- localParameters = new HashMap<String, Parameter>();
- localParameters.put("mutRate", mutationRate);
+ mutationRate = new DoubleParameter(0.5, "Percent mutation", false, false) {
+ @Override
+ public void validate(double newValue) {
+ // TODO this
+ }
+ };
}
@Override
@@ -47,8 +46,8 @@ public class PointMutator implements Mutator {
}
@Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
+ public Parameter[] getLocalParameters() {
+ return new Parameter[] {mutationRate};
}
@Override