diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-04 17:14:44 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-04 17:14:44 +0100 |
commit | c7969623b44f375e30fa3f15dcd7581609276a0f (patch) | |
tree | d1743df21e685fed93b7a12dd91a524e44fa42bd /src/jcgp/backend | |
parent | 0dbf126fc524bc029d9f5803d849b7c8f43fe389 (diff) |
Parameter validation refactored and fully functional.
Diffstat (limited to 'src/jcgp/backend')
-rw-r--r-- | src/jcgp/backend/modules/ea/MuPlusLambda.java | 37 | ||||
-rw-r--r-- | src/jcgp/backend/modules/ea/TournamentSelection.java | 4 | ||||
-rw-r--r-- | src/jcgp/backend/parameters/BooleanParameter.java | 9 | ||||
-rw-r--r-- | src/jcgp/backend/parameters/DoubleParameter.java | 2 | ||||
-rw-r--r-- | src/jcgp/backend/parameters/IntegerParameter.java | 2 | ||||
-rw-r--r-- | src/jcgp/backend/parameters/Parameter.java | 8 | ||||
-rw-r--r-- | src/jcgp/backend/parameters/ParameterStatus.java | 2 | ||||
-rw-r--r-- | src/jcgp/backend/population/Chromosome.java | 1 |
8 files changed, 51 insertions, 14 deletions
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 } }; diff --git a/src/jcgp/backend/parameters/BooleanParameter.java b/src/jcgp/backend/parameters/BooleanParameter.java index db78419..43825be 100644 --- a/src/jcgp/backend/parameters/BooleanParameter.java +++ b/src/jcgp/backend/parameters/BooleanParameter.java @@ -11,6 +11,13 @@ public abstract class BooleanParameter extends Parameter { this.value = new SimpleBooleanProperty(value); } + /** + * Simple BooleanParameter constructor, + * + * + * @param value + * @param name + */ public BooleanParameter(boolean value, String name) { super(name, false, false); this.value = new SimpleBooleanProperty(value); @@ -26,7 +33,7 @@ public abstract class BooleanParameter extends Parameter { } } - protected abstract void validate(boolean newValue); + public abstract void validate(boolean newValue); public SimpleBooleanProperty valueProperty() { return value; diff --git a/src/jcgp/backend/parameters/DoubleParameter.java b/src/jcgp/backend/parameters/DoubleParameter.java index 2b98991..53551f5 100644 --- a/src/jcgp/backend/parameters/DoubleParameter.java +++ b/src/jcgp/backend/parameters/DoubleParameter.java @@ -30,6 +30,6 @@ public abstract class DoubleParameter extends Parameter { return value; } - protected abstract void validate(double newValue); + public abstract void validate(double newValue); } diff --git a/src/jcgp/backend/parameters/IntegerParameter.java b/src/jcgp/backend/parameters/IntegerParameter.java index 1127817..68095d9 100644 --- a/src/jcgp/backend/parameters/IntegerParameter.java +++ b/src/jcgp/backend/parameters/IntegerParameter.java @@ -31,6 +31,6 @@ public abstract class IntegerParameter extends Parameter { return value; } - protected abstract void validate(int newValue); + public abstract void validate(int newValue); } diff --git a/src/jcgp/backend/parameters/Parameter.java b/src/jcgp/backend/parameters/Parameter.java index 26bc8f1..ddd5d5b 100644 --- a/src/jcgp/backend/parameters/Parameter.java +++ b/src/jcgp/backend/parameters/Parameter.java @@ -4,7 +4,7 @@ import javafx.beans.property.Property; public abstract class Parameter { - protected boolean monitor, critical; + protected boolean monitor, critical, reset = false; protected ParameterStatus status = ParameterStatus.VALID; @@ -24,6 +24,10 @@ public abstract class Parameter { return critical; } + public boolean requiresReset() { + return critical || reset; + } + public String getName() { return name; } @@ -33,5 +37,5 @@ public abstract class Parameter { } public abstract Property<?> valueProperty(); - + } diff --git a/src/jcgp/backend/parameters/ParameterStatus.java b/src/jcgp/backend/parameters/ParameterStatus.java index ed235d4..86abe33 100644 --- a/src/jcgp/backend/parameters/ParameterStatus.java +++ b/src/jcgp/backend/parameters/ParameterStatus.java @@ -1,7 +1,7 @@ package jcgp.backend.parameters; public enum ParameterStatus { - INVALID, WARNING, VALID; + INVALID, WARNING, WARNING_RESET, VALID; private String details; diff --git a/src/jcgp/backend/population/Chromosome.java b/src/jcgp/backend/population/Chromosome.java index 41ba06e..c7493b9 100644 --- a/src/jcgp/backend/population/Chromosome.java +++ b/src/jcgp/backend/population/Chromosome.java @@ -310,6 +310,7 @@ public class Chromosome { } public void printNodes() { + // TODO make this proper int arity = resources.getInt("arity"); for (int r = 0; r < (resources.getInt("rows")); r++) { |