From c7969623b44f375e30fa3f15dcd7581609276a0f Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 4 Apr 2014 17:14:44 +0100 Subject: Parameter validation refactored and fully functional. --- src/jcgp/backend/modules/ea/MuPlusLambda.java | 37 ++++++++++++++++++---- .../backend/modules/ea/TournamentSelection.java | 4 +-- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'src/jcgp/backend/modules/ea') diff --git a/src/jcgp/backend/modules/ea/MuPlusLambda.java b/src/jcgp/backend/modules/ea/MuPlusLambda.java index 22a0876..ad8c5d8 100644 --- a/src/jcgp/backend/modules/ea/MuPlusLambda.java +++ b/src/jcgp/backend/modules/ea/MuPlusLambda.java @@ -3,8 +3,10 @@ package jcgp.backend.modules.ea; import jcgp.JCGP.Resources; import jcgp.backend.modules.ModuleStatus; import jcgp.backend.modules.mutator.Mutator; +import jcgp.backend.parameters.BooleanParameter; import jcgp.backend.parameters.IntegerParameter; import jcgp.backend.parameters.Parameter; +import jcgp.backend.parameters.ParameterStatus; import jcgp.backend.population.Population; /** @@ -19,18 +21,41 @@ public class MuPlusLambda implements EvolutionaryAlgorithm { private int fittestChromosome; private IntegerParameter parents, offspring; + private BooleanParameter report; - public MuPlusLambda() { + public MuPlusLambda(final Resources resources) { parents = new IntegerParameter(1, "Parents") { @Override - protected void validate(int newValue) { - + public void validate(int newValue) { + if (newValue + offspring.get() != resources.getInt("popSize")) { + status = ParameterStatus.INVALID; + status.setDetails("Parents + offspring must equal population size."); + } else if (newValue <= 0) { + status = ParameterStatus.INVALID; + status.setDetails("EA needs at least 1 parent."); + } else { + status = ParameterStatus.VALID; + } } }; offspring = new IntegerParameter(4, "Offspring") { @Override - protected void validate(int newValue) { - + public void validate(int newValue) { + if (newValue + parents.get() != resources.getInt("popSize")) { + status = ParameterStatus.INVALID; + status.setDetails("Parents + offspring must equal population size."); + } else if (newValue <= 0) { + status = ParameterStatus.INVALID; + status.setDetails("EA needs at least 1 offspring."); + } else { + status = ParameterStatus.VALID; + } + } + }; + report = new BooleanParameter(false, "Report") { + @Override + public void validate(boolean newValue) { + // nothing } }; } @@ -63,7 +88,7 @@ public class MuPlusLambda implements EvolutionaryAlgorithm { @Override public Parameter[] getLocalParameters() { - return new Parameter[] {parents, offspring}; + return new Parameter[] {parents, offspring, report}; } @Override diff --git a/src/jcgp/backend/modules/ea/TournamentSelection.java b/src/jcgp/backend/modules/ea/TournamentSelection.java index 3c4a539..32ac54d 100644 --- a/src/jcgp/backend/modules/ea/TournamentSelection.java +++ b/src/jcgp/backend/modules/ea/TournamentSelection.java @@ -19,8 +19,8 @@ public class TournamentSelection implements EvolutionaryAlgorithm { public TournamentSelection() { tournament = new IntegerParameter(1, "Tournament size") { @Override - protected void validate(int newValue) { - + public void validate(int newValue) { + // TODO this } }; -- cgit v1.2.3