aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/resources')
-rw-r--r--src/jcgp/backend/resources/ModifiableResources.java177
-rw-r--r--src/jcgp/backend/resources/Resources.java181
2 files changed, 177 insertions, 181 deletions
diff --git a/src/jcgp/backend/resources/ModifiableResources.java b/src/jcgp/backend/resources/ModifiableResources.java
index 048e460..53dc815 100644
--- a/src/jcgp/backend/resources/ModifiableResources.java
+++ b/src/jcgp/backend/resources/ModifiableResources.java
@@ -1,7 +1,10 @@
package jcgp.backend.resources;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
import jcgp.backend.function.FunctionSet;
import jcgp.backend.resources.parameters.IntegerParameter;
+import jcgp.backend.resources.parameters.ParameterStatus;
/**
*
@@ -10,13 +13,13 @@ import jcgp.backend.resources.parameters.IntegerParameter;
* and only classes with access to a JCGP instance may modify
* the resources.
*
- * @author eddy
+ * @author Eduardo Pedroni
*
*/
public class ModifiableResources extends Resources {
public ModifiableResources() {
- super();
+ createBaseParameters();
}
public void setValues(String filePath) {
@@ -214,21 +217,159 @@ public class ModifiableResources extends Resources {
this.console = console;
}
- /*
- * Console functionality
- * These are not affected by parameter report interval
- */
- public void println(String s) {
- System.out.println(s);
- if (console != null) {
- console.println(s);
- }
- }
-
- public void print(String s) {
- System.out.print(s);
- if (console != null) {
- console.print(s);
- }
+ private void createBaseParameters() {
+ rows = new IntegerParameter(5, "Rows", false, true) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Chromosome must have at least 1 row.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ columns = new IntegerParameter(5, "Columns", false, true) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Chromosome must have at least 1 column.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ inputs = new IntegerParameter(3, "Inputs", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Chromosome must have at least 1 input.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ outputs = new IntegerParameter(3, "Outputs", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Chromosome must have at least 1 output.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ populationSize = new IntegerParameter(5, "Population", false, true) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Population size must be at least 1.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ levelsBack = new IntegerParameter(2, "Levels back", false, true) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Levels back must be at least 1.");
+ } else if (newValue.intValue() > columns.get()) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Levels back must be less than or equal to the number of columns.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ generations = new IntegerParameter(1000000, "Generations") {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Number of generations must be greater than 0.");
+ } else if (newValue.intValue() < currentGeneration.get()) {
+ status = ParameterStatus.WARNING_RESET;
+ status.setDetails("Setting generations to less than the current generation will cause the experiment to restart.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ currentGeneration = new IntegerParameter(1, "Generation", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ // blank
+ }
+ };
+
+ runs = new IntegerParameter(5, "Runs") {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() <= 0) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Number of runs must be greater than 0.");
+ } else if (newValue.intValue() < currentRun.get()) {
+ status = ParameterStatus.WARNING_RESET;
+ status.setDetails("Setting runs to less than the current run will cause the experiment to restart.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
+
+ currentRun = new IntegerParameter(1, "Run", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ // blank
+ }
+ };
+
+ arity = new IntegerParameter(0, "Max arity", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ // blank
+ }
+ };
+
+ seed = new IntegerParameter(1234, "Seed", false, true) {
+ @Override
+ public void validate(Number newValue) {
+ status = ParameterStatus.VALID;
+ }
+ };
+ seed.valueProperty().addListener(new ChangeListener<Number>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends Number> observable,
+ Number oldValue, Number newValue) {
+ numberGenerator.setSeed(newValue.longValue());
+ }
+ });
+ numberGenerator.setSeed(seed.get());
+
+ reportInterval = new IntegerParameter(1, "Report interval", false, false) {
+ @Override
+ public void validate(Number newValue) {
+ if (newValue.intValue() > generations.get()) {
+ status = ParameterStatus.WARNING;
+ status.setDetails("No reports will be printed.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
+ }
+ };
}
}
diff --git a/src/jcgp/backend/resources/Resources.java b/src/jcgp/backend/resources/Resources.java
index e83680f..e1438f1 100644
--- a/src/jcgp/backend/resources/Resources.java
+++ b/src/jcgp/backend/resources/Resources.java
@@ -2,12 +2,9 @@ package jcgp.backend.resources;
import java.util.Random;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
import jcgp.backend.function.Function;
import jcgp.backend.function.FunctionSet;
import jcgp.backend.resources.parameters.IntegerParameter;
-import jcgp.backend.resources.parameters.ParameterStatus;
/**
*
@@ -28,10 +25,6 @@ public class Resources {
// GUI console
protected Console console;
- public Resources() {
- createBaseParameters();
- }
-
/**
* @return the rows
*/
@@ -129,162 +122,6 @@ public class Resources {
public int reportInterval() {
return reportInterval.get();
}
-
- private void createBaseParameters() {
- rows = new IntegerParameter(5, "Rows", false, true) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Chromosome must have at least 1 row.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- columns = new IntegerParameter(5, "Columns", false, true) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Chromosome must have at least 1 column.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- inputs = new IntegerParameter(3, "Inputs", true, false) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Chromosome must have at least 1 input.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- outputs = new IntegerParameter(3, "Outputs", true, false) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Chromosome must have at least 1 output.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- populationSize = new IntegerParameter(5, "Population", false, true) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Population size must be at least 1.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- levelsBack = new IntegerParameter(2, "Levels back", false, true) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Levels back must be at least 1.");
- } else if (newValue.intValue() > columns.get()) {
- status = ParameterStatus.INVALID;
- status.setDetails("Levels back must be less than or equal to the number of columns.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- generations = new IntegerParameter(1000000, "Generations") {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Number of generations must be greater than 0.");
- } else if (newValue.intValue() < currentGeneration.get()) {
- status = ParameterStatus.WARNING_RESET;
- status.setDetails("Setting generations to less than the current generation will cause the experiment to restart.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- currentGeneration = new IntegerParameter(1, "Generation", true, false) {
- @Override
- public void validate(Number newValue) {
- // blank
- }
- };
-
- runs = new IntegerParameter(5, "Runs") {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() <= 0) {
- status = ParameterStatus.INVALID;
- status.setDetails("Number of runs must be greater than 0.");
- } else if (newValue.intValue() < currentRun.get()) {
- status = ParameterStatus.WARNING_RESET;
- status.setDetails("Setting runs to less than the current run will cause the experiment to restart.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
-
- currentRun = new IntegerParameter(1, "Run", true, false) {
- @Override
- public void validate(Number newValue) {
- // blank
- }
- };
-
- arity = new IntegerParameter(0, "Max arity", true, false) {
- @Override
- public void validate(Number newValue) {
- // blank
- }
- };
-
- seed = new IntegerParameter(1234, "Seed", false, true) {
- @Override
- public void validate(Number newValue) {
- status = ParameterStatus.VALID;
- }
- };
- seed.valueProperty().addListener(new ChangeListener<Number>() {
- @Override
- public void changed(
- ObservableValue<? extends Number> observable,
- Number oldValue, Number newValue) {
- numberGenerator.setSeed(newValue.longValue());
- }
- });
- numberGenerator.setSeed(seed.get());
-
- reportInterval = new IntegerParameter(1, "Report interval", false, false) {
- @Override
- public void validate(Number newValue) {
- if (newValue.intValue() > generations.get()) {
- status = ParameterStatus.WARNING;
- status.setDetails("No reports will be printed.");
- } else {
- status = ParameterStatus.VALID;
- }
- }
- };
- }
/*
* Utility functions
@@ -355,4 +192,22 @@ public class Resources {
}
}
}
+
+ /*
+ * Console functionality
+ * These are not affected by parameter report interval
+ */
+ public void println(String s) {
+ System.out.println(s);
+ if (console != null) {
+ console.println(s);
+ }
+ }
+
+ public void print(String s) {
+ System.out.print(s);
+ if (console != null) {
+ console.print(s);
+ }
+ }
} \ No newline at end of file