aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/es
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/es')
-rw-r--r--src/jcgp/backend/modules/es/EvolutionaryStrategy.java12
-rw-r--r--src/jcgp/backend/modules/es/MuPlusLambda.java32
-rw-r--r--src/jcgp/backend/modules/es/TournamentSelection.java33
3 files changed, 27 insertions, 50 deletions
diff --git a/src/jcgp/backend/modules/es/EvolutionaryStrategy.java b/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
index 70e3cd2..1a14552 100644
--- a/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
+++ b/src/jcgp/backend/modules/es/EvolutionaryStrategy.java
@@ -6,7 +6,7 @@ import jcgp.backend.population.Population;
import jcgp.backend.resources.Resources;
/**
- * This interface specifies the required behaviour of an evolutionary strategy. The evolutionary
+ * This class specifies the characteristics of an evolutionary strategy. The evolutionary
* strategy's job is to generate the next population of solutions. In JCGP this is done by modifying
* the provided population object rather than creating a new one.
* <br><br>
@@ -17,8 +17,8 @@ import jcgp.backend.resources.Resources;
* argument.
* <br><br>
* Parameters may be specified to control the implemented strategy. Any parameters
- * returned by {@code getLocalParameters()} should be displayed by the user interface,
- * if it is being used. See {@link Parameter} for more information.
+ * registered with {@code registerParameters()} should be displayed by the user interface,
+ * if it is being used. See {@link Module} for more information.
* <br><br>
* It is advisable to use {@code Resources.reportln()} and {@code Resources.report()}
* to print any relevant information. Note that reportln() and report() are affected
@@ -27,12 +27,11 @@ import jcgp.backend.resources.Resources;
* See {@link Resources} for more information.
*
* @see Module
- *
* @author Eduardo Pedroni
*
*/
-public interface EvolutionaryStrategy extends Module {
-
+public abstract class EvolutionaryStrategy extends Module {
+
/**
* Performs the selection algorithm and uses the mutator to create
* the next generation of solutions.
@@ -42,5 +41,4 @@ public interface EvolutionaryStrategy extends Module {
* @param resources parameters and utilities for optional reference.
*/
public abstract void evolve(Population population, Mutator mutator, Resources resources);
-
}
diff --git a/src/jcgp/backend/modules/es/MuPlusLambda.java b/src/jcgp/backend/modules/es/MuPlusLambda.java
index 754e89b..8186b11 100644
--- a/src/jcgp/backend/modules/es/MuPlusLambda.java
+++ b/src/jcgp/backend/modules/es/MuPlusLambda.java
@@ -1,12 +1,11 @@
package jcgp.backend.modules.es;
import jcgp.backend.modules.mutator.Mutator;
+import jcgp.backend.parameters.BooleanParameter;
+import jcgp.backend.parameters.IntegerParameter;
+import jcgp.backend.parameters.ParameterStatus;
import jcgp.backend.population.Population;
import jcgp.backend.resources.Resources;
-import jcgp.backend.resources.parameters.BooleanParameter;
-import jcgp.backend.resources.parameters.IntegerParameter;
-import jcgp.backend.resources.parameters.Parameter;
-import jcgp.backend.resources.parameters.ParameterStatus;
/**
* (μ + λ)-ES
@@ -28,7 +27,7 @@ import jcgp.backend.resources.parameters.ParameterStatus;
* @author Eduardo Pedroni
*
*/
-public class MuPlusLambda implements EvolutionaryStrategy {
+public class MuPlusLambda extends EvolutionaryStrategy {
private IntegerParameter mu, lambda;
private BooleanParameter report;
@@ -39,6 +38,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
* @param resources a reference to the experiment's resources.
*/
public MuPlusLambda(final Resources resources) {
+ super();
mu = new IntegerParameter(1, "Parents (μ)") {
@Override
public void validate(Number newValue) {
@@ -53,6 +53,7 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
}
};
+
lambda = new IntegerParameter(4, "Offspring (λ)") {
@Override
public void validate(Number newValue) {
@@ -67,17 +68,11 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
}
};
- report = new BooleanParameter(false, "Report") {
- @Override
- public void validate(Boolean newValue) {
- // nothing
- }
- };
- }
-
- @Override
- public Parameter<?>[] getLocalParameters() {
- return new Parameter[] {mu, lambda, report};
+
+ report = new BooleanParameter(false, "Report");
+
+ setName("(μ + λ)");
+ registerParameters(mu, lambda, report);
}
@Override
@@ -98,9 +93,4 @@ public class MuPlusLambda implements EvolutionaryStrategy {
if (report.get()) resources.reportln("[ES] Generation is complete");
}
-
- @Override
- public String toString() {
- return "(μ + λ)";
- }
}
diff --git a/src/jcgp/backend/modules/es/TournamentSelection.java b/src/jcgp/backend/modules/es/TournamentSelection.java
index 43fea81..209caca 100644
--- a/src/jcgp/backend/modules/es/TournamentSelection.java
+++ b/src/jcgp/backend/modules/es/TournamentSelection.java
@@ -3,13 +3,12 @@ package jcgp.backend.modules.es;
import java.util.Arrays;
import jcgp.backend.modules.mutator.Mutator;
+import jcgp.backend.parameters.BooleanParameter;
+import jcgp.backend.parameters.IntegerParameter;
+import jcgp.backend.parameters.ParameterStatus;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
import jcgp.backend.resources.Resources;
-import jcgp.backend.resources.parameters.BooleanParameter;
-import jcgp.backend.resources.parameters.IntegerParameter;
-import jcgp.backend.resources.parameters.Parameter;
-import jcgp.backend.resources.parameters.ParameterStatus;
/**
* Tournament selection
@@ -34,7 +33,7 @@ import jcgp.backend.resources.parameters.ParameterStatus;
* @author Eduardo Pedroni
*
*/
-public class TournamentSelection implements EvolutionaryStrategy {
+public class TournamentSelection extends EvolutionaryStrategy {
private IntegerParameter tournamentSize;
private BooleanParameter report;
@@ -44,7 +43,8 @@ public class TournamentSelection implements EvolutionaryStrategy {
*
* @param resources a reference to the experiment's resources.
*/
- public TournamentSelection(final Resources resources) {
+ public TournamentSelection(final Resources resources) {
+ super();
tournamentSize = new IntegerParameter(1, "Tournament size") {
@Override
public void validate(Number newValue) {
@@ -65,17 +65,11 @@ public class TournamentSelection implements EvolutionaryStrategy {
}
}
};
- report = new BooleanParameter(false, "Report") {
- @Override
- public void validate(Boolean newValue) {
- // blank
- }
- };
- }
-
- @Override
- public Parameter<?>[] getLocalParameters() {
- return new Parameter[] {tournamentSize, report};
+
+ report = new BooleanParameter(false, "Report");
+
+ setName("Tournament selection");
+ registerParameters(tournamentSize, report);
}
@Override
@@ -114,9 +108,4 @@ public class TournamentSelection implements EvolutionaryStrategy {
if (report.get()) resources.reportln("[ES] Generation is complete");
}
-
- @Override
- public String toString() {
- return "Tournament";
- }
}