aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/es/MuPlusLambda.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/es/MuPlusLambda.java')
-rw-r--r--src/jcgp/backend/modules/es/MuPlusLambda.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/jcgp/backend/modules/es/MuPlusLambda.java b/src/jcgp/backend/modules/es/MuPlusLambda.java
index 53fb932..67236f9 100644
--- a/src/jcgp/backend/modules/es/MuPlusLambda.java
+++ b/src/jcgp/backend/modules/es/MuPlusLambda.java
@@ -25,11 +25,11 @@ public class MuPlusLambda implements EvolutionaryStrategy {
public MuPlusLambda(final Resources resources) {
parents = new IntegerParameter(1, "Parents") {
@Override
- public void validate(int newValue) {
- if (newValue + offspring.get() != resources.getInt("popSize")) {
+ public void validate(Number newValue) {
+ if (newValue.intValue() + offspring.get() != resources.populationSize()) {
status = ParameterStatus.INVALID;
status.setDetails("Parents + offspring must equal population size.");
- } else if (newValue <= 0) {
+ } else if (newValue.intValue() <= 0) {
status = ParameterStatus.INVALID;
status.setDetails("EA needs at least 1 parent.");
} else {
@@ -39,11 +39,11 @@ public class MuPlusLambda implements EvolutionaryStrategy {
};
offspring = new IntegerParameter(4, "Offspring") {
@Override
- public void validate(int newValue) {
- if (newValue + parents.get() != resources.getInt("popSize")) {
+ public void validate(Number newValue) {
+ if (newValue.intValue() + parents.get() != resources.populationSize()) {
status = ParameterStatus.INVALID;
status.setDetails("Parents + offspring must equal population size.");
- } else if (newValue <= 0) {
+ } else if (newValue.intValue() <= 0) {
status = ParameterStatus.INVALID;
status.setDetails("EA needs at least 1 offspring.");
} else {
@@ -53,7 +53,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
};
report = new BooleanParameter(false, "Report") {
@Override
- public void validate(boolean newValue) {
+ public void validate(Boolean newValue) {
// nothing
}
};
@@ -65,7 +65,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
fittestChromosome = 0;
if (report.get()) resources.reportln("[ES] Selecting fittest chromosome...");
- for (int i = 0; i < resources.getInt("popSize"); i++) {
+ 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;
@@ -74,7 +74,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
if (report.get()) resources.reportln("[ES] Selected chromosome: " + fittestChromosome);
// create copies of fittest chromosome, mutate them
- for (int i = 0; i < resources.getInt("popSize"); i++) {
+ for (int i = 0; i < resources.populationSize(); i++) {
if (i != fittestChromosome) {
if (report.get()) resources.reportln("[ES] Copying fittest chromosome to population position " + i);
population.copyChromosome(fittestChromosome, i);
@@ -83,6 +83,8 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
}
+ if (report.get()) resources.reportln("[ES] Generation is complete.");
+
}
@Override
@@ -91,7 +93,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
@Override
- public Parameter[] getLocalParameters() {
+ public Parameter<?>[] getLocalParameters() {
return new Parameter[] {parents, offspring, report};
}