aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules')
-rw-r--r--src/jcgp/backend/modules/es/EvolutionaryStrategy.java4
-rw-r--r--src/jcgp/backend/modules/es/MuPlusLambda.java22
-rw-r--r--src/jcgp/backend/modules/es/TournamentSelection.java8
-rw-r--r--src/jcgp/backend/modules/problem/TestCaseProblem.java13
4 files changed, 10 insertions, 37 deletions
diff --git a/src/jcgp/backend/modules/es/EvolutionaryStrategy.java b/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
index 1117e99..8ab287d 100644
--- a/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
+++ b/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
@@ -8,7 +8,5 @@ import jcgp.backend.resources.Resources;
public interface EvolutionaryStrategy extends Module {
public abstract void evolve(Population population, Mutator mutator, Resources resources);
-
- public abstract int getFittestChromosome();
-
+
}
diff --git a/src/jcgp/backend/modules/es/MuPlusLambda.java b/src/jcgp/backend/modules/es/MuPlusLambda.java
index 67236f9..6a3883b 100644
--- a/src/jcgp/backend/modules/es/MuPlusLambda.java
+++ b/src/jcgp/backend/modules/es/MuPlusLambda.java
@@ -17,8 +17,6 @@ import jcgp.backend.resources.parameters.ParameterStatus;
*/
public class MuPlusLambda implements EvolutionaryStrategy {
- private int fittestChromosome;
-
private IntegerParameter parents, offspring;
private BooleanParameter report;
@@ -62,22 +60,13 @@ public class MuPlusLambda implements EvolutionaryStrategy {
@Override
public void evolve(Population population, Mutator mutator, Resources resources) {
// select fittest chromosomes
- fittestChromosome = 0;
-
- if (report.get()) resources.reportln("[ES] Selecting fittest chromosome...");
- for (int i = 0; i < resources.populationSize(); i++) {
- if (report.get()) resources.reportln("[ES] Chromosome " + i + ", fitness: " + population.getChromosome(i).getFitness());
- if (population.getChromosome(i).getFitness() >= population.getChromosome(fittestChromosome).getFitness()) {
- fittestChromosome = i;
- }
- }
- if (report.get()) resources.reportln("[ES] Selected chromosome: " + fittestChromosome);
+ if (report.get()) resources.reportln("[ES] Selected chromosome: " + population.getFittestIndex());
// create copies of fittest chromosome, mutate them
for (int i = 0; i < resources.populationSize(); i++) {
- if (i != fittestChromosome) {
+ if (i != population.getFittestIndex()) {
if (report.get()) resources.reportln("[ES] Copying fittest chromosome to population position " + i);
- population.copyChromosome(fittestChromosome, i);
+ population.copyChromosome(population.getFittestIndex(), i);
if (report.get()) resources.reportln("[ES] Mutating copied chromosome");
mutator.mutate(population.getChromosome(i), resources);
}
@@ -88,11 +77,6 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
@Override
- public int getFittestChromosome() {
- return fittestChromosome;
- }
-
- @Override
public Parameter<?>[] getLocalParameters() {
return new Parameter[] {parents, offspring, report};
}
diff --git a/src/jcgp/backend/modules/es/TournamentSelection.java b/src/jcgp/backend/modules/es/TournamentSelection.java
index 8286101..4070468 100644
--- a/src/jcgp/backend/modules/es/TournamentSelection.java
+++ b/src/jcgp/backend/modules/es/TournamentSelection.java
@@ -8,8 +8,6 @@ import jcgp.backend.resources.parameters.Parameter;
public class TournamentSelection implements EvolutionaryStrategy {
- private int fittestChromosome;
-
private IntegerParameter tournament;
public TournamentSelection() {
@@ -30,15 +28,9 @@ public class TournamentSelection implements EvolutionaryStrategy {
public void evolve(Population population, Mutator mutator,
Resources parameters) {
tournament.set(tournament.get() + 1);
- fittestChromosome = 0;
// TODO implement this
}
-
- @Override
- public int getFittestChromosome() {
- return fittestChromosome;
- }
@Override
public String toString() {
diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java
index 68318cf..ee72860 100644
--- a/src/jcgp/backend/modules/problem/TestCaseProblem.java
+++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java
@@ -52,8 +52,6 @@ public abstract class TestCaseProblem<U extends Object> extends Problem {
private IntegerParameter maxFitness;
private final int inputCount, outputCount;
- private U type;
-
public TestCaseProblem(Resources resources) {
super();
@@ -67,12 +65,14 @@ public abstract class TestCaseProblem<U extends Object> extends Problem {
}
};
testCases = FXCollections.observableArrayList();
- //testCases = new ObservableList<TestCase<U>>();
}
@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
@@ -89,6 +89,9 @@ public abstract class TestCaseProblem<U extends Object> extends Problem {
}
// assign the resulting fitness to the respective individual
population.getChromosome(i).setFitness(fitness);
+ if (fitness >= population.getFittest().getFitness()) {
+ population.setFittest(i);
+ }
}
}
@@ -147,10 +150,6 @@ public abstract class TestCaseProblem<U extends Object> extends Problem {
public int getOutputCount() {
return outputCount;
}
-
- public Class<?> getType() {
- return type.getClass();
- }
}