diff options
Diffstat (limited to 'src/jcgp/backend/modules/es')
-rw-r--r-- | src/jcgp/backend/modules/es/MuPlusLambda.java | 22 | ||||
-rw-r--r-- | src/jcgp/backend/modules/es/TournamentSelection.java | 10 |
2 files changed, 14 insertions, 18 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}; } diff --git a/src/jcgp/backend/modules/es/TournamentSelection.java b/src/jcgp/backend/modules/es/TournamentSelection.java index 3954de8..8286101 100644 --- a/src/jcgp/backend/modules/es/TournamentSelection.java +++ b/src/jcgp/backend/modules/es/TournamentSelection.java @@ -1,7 +1,5 @@ package jcgp.backend.modules.es; -import java.util.HashMap; - import jcgp.backend.modules.mutator.Mutator; import jcgp.backend.population.Population; import jcgp.backend.resources.Resources; @@ -13,22 +11,18 @@ public class TournamentSelection implements EvolutionaryStrategy { private int fittestChromosome; private IntegerParameter tournament; - private HashMap<String, Parameter> localParameters; public TournamentSelection() { tournament = new IntegerParameter(1, "Tournament size") { @Override - public void validate(int newValue) { + public void validate(Number newValue) { // TODO this } }; - - localParameters = new HashMap<String, Parameter>(); - localParameters.put("tournament", tournament); } @Override - public Parameter[] getLocalParameters() { + public Parameter<?>[] getLocalParameters() { return new Parameter[] {tournament}; } |