diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-15 18:00:11 +0000 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-15 18:00:11 +0000 |
commit | d3527a63e12c0e5288f1e7d2e2dc18e61d16b760 (patch) | |
tree | 95a134d7d9a2e1409040cf41240c6d522cf31a06 /src | |
parent | c0269683bcc7fde0d437ae84cd89a93d9d8fd81b (diff) |
Did some more refactoring, fixed issues with eclipse crashing.
Diffstat (limited to 'src')
-rw-r--r-- | src/jcgp/CGP.java | 29 | ||||
-rw-r--r-- | src/jcgp/parameters/BooleanParameter.java | 15 | ||||
-rw-r--r-- | src/jcgp/parameters/DoubleParameter.java | 14 | ||||
-rw-r--r-- | src/jcgp/parameters/IntegerParameter.java | 14 | ||||
-rw-r--r-- | src/jcgp/parameters/Parameter.java | 4 | ||||
-rw-r--r-- | src/jcgp/parameters/Parameters.java | 21 |
6 files changed, 54 insertions, 43 deletions
diff --git a/src/jcgp/CGP.java b/src/jcgp/CGP.java index 1004001..16d2be7 100644 --- a/src/jcgp/CGP.java +++ b/src/jcgp/CGP.java @@ -3,6 +3,7 @@ package jcgp; import java.util.HashMap; import java.util.Random; +import javafx.beans.property.Property; import javafx.beans.property.SimpleIntegerProperty; import jcgp.modules.ea.EvolutionaryAlgorithm; import jcgp.modules.ea.StandardEA; @@ -19,7 +20,6 @@ import jcgp.parameters.BooleanParameter; import jcgp.parameters.DoubleParameter; import jcgp.parameters.IntegerParameter; import jcgp.parameters.Parameter; -import jcgp.parameters.Parameters; import jcgp.population.Population; public class CGP { @@ -66,14 +66,14 @@ public class CGP { private Population population; - private static HashMap<String, Parameter> parameters = new HashMap<String, Parameter>(); + private HashMap<String, Parameter> parameters = new HashMap<String, Parameter>(); public CGP() { createBaseParameters(); - for (int i = 0; i < Parameters.getTotalGenerations(); i++) { + for (int i = 0; i < (int) get("generations"); i++) { - ((SimpleIntegerProperty) get("currentGen").getValue()).set(i); + set("currentGen", ((int) get("currentGen")) + 1); fitnessFunction.evaluate(population); evolutionaryAlgorithm.evolve(population, mutator); @@ -123,15 +123,28 @@ public class CGP { // } // Parameter methods - public static void registerParameter(String key, Parameter value) { + public void register(String key, Parameter value) { parameters.put(key, value); } - public static Parameter get(String key) { - return parameters.get(key); + /** + * @param key + * @return + */ + public Object get(String key) { + return parameters.get(key).getValue(); } - public static boolean contains(String key) { + public void set(String key, Object value) { + parameters.get(key).setValue(value); + } + + @SuppressWarnings("rawtypes") + public Property getProperty(String key) { + return parameters.get(key).valueProperty(); + } + + public boolean contains(String key) { return parameters.containsKey(key); } diff --git a/src/jcgp/parameters/BooleanParameter.java b/src/jcgp/parameters/BooleanParameter.java index 9402620..aff0bc5 100644 --- a/src/jcgp/parameters/BooleanParameter.java +++ b/src/jcgp/parameters/BooleanParameter.java @@ -3,6 +3,8 @@ package jcgp.parameters; import javafx.beans.property.SimpleBooleanProperty; public class BooleanParameter extends Parameter { + + SimpleBooleanProperty value; public BooleanParameter(boolean value, String name) { this.value = new SimpleBooleanProperty(value); @@ -16,18 +18,19 @@ public class BooleanParameter extends Parameter { this.hidden = hidden; } - public void setValue(boolean value) { - ((SimpleBooleanProperty) this.value).set(value); - } - @Override public Object getValue() { - return ((SimpleBooleanProperty) this.value).get(); + return this.value.get(); } @Override public SimpleBooleanProperty valueProperty() { - return (SimpleBooleanProperty) value; + return value; + } + + @Override + public void setValue(Object value) { + this.value.set((boolean) value); } } diff --git a/src/jcgp/parameters/DoubleParameter.java b/src/jcgp/parameters/DoubleParameter.java index 2c2ec34..2725457 100644 --- a/src/jcgp/parameters/DoubleParameter.java +++ b/src/jcgp/parameters/DoubleParameter.java @@ -3,6 +3,8 @@ package jcgp.parameters; import javafx.beans.property.SimpleDoubleProperty; public class DoubleParameter extends Parameter { + + SimpleDoubleProperty value; public DoubleParameter(double value, String name) { this.value = new SimpleDoubleProperty(value); @@ -17,16 +19,22 @@ public class DoubleParameter extends Parameter { } public void setValue(double value) { - ((SimpleDoubleProperty) this.value).set(value); + this.value.set(value); } @Override public Object getValue() { - return ((SimpleDoubleProperty) this.value).get(); + return this.value.get(); } public SimpleDoubleProperty valueProperty() { - return (SimpleDoubleProperty) value; + return value; + } + + @Override + public void setValue(Object value) { + this.value.set((double) value); + } } diff --git a/src/jcgp/parameters/IntegerParameter.java b/src/jcgp/parameters/IntegerParameter.java index 6b4c20f..f0109f7 100644 --- a/src/jcgp/parameters/IntegerParameter.java +++ b/src/jcgp/parameters/IntegerParameter.java @@ -4,6 +4,8 @@ import javafx.beans.property.SimpleIntegerProperty; public class IntegerParameter extends Parameter { + SimpleIntegerProperty value; + public IntegerParameter(int value, String name) { this.value = new SimpleIntegerProperty(value); this.name = name; @@ -17,17 +19,23 @@ public class IntegerParameter extends Parameter { } public void setValue(int value) { - ((SimpleIntegerProperty) this.value).set(value); + this.value.set(value); } @Override public Object getValue() { - return ((SimpleIntegerProperty) this.value).get(); + return this.value.get(); } @Override public SimpleIntegerProperty valueProperty() { - return (SimpleIntegerProperty) value; + return value; + } + + @Override + public void setValue(Object value) { + this.value.set((int) value); + } } diff --git a/src/jcgp/parameters/Parameter.java b/src/jcgp/parameters/Parameter.java index ffcf3b4..64b19c8 100644 --- a/src/jcgp/parameters/Parameter.java +++ b/src/jcgp/parameters/Parameter.java @@ -7,8 +7,6 @@ public abstract class Parameter { protected boolean managed = false; protected boolean hidden = false; protected String name; - @SuppressWarnings("rawtypes") - protected Property value; public void setManaged(boolean value) { managed = value; @@ -32,6 +30,8 @@ public abstract class Parameter { public abstract Object getValue(); + public abstract void setValue(Object value); + @SuppressWarnings("rawtypes") public abstract Property valueProperty(); } diff --git a/src/jcgp/parameters/Parameters.java b/src/jcgp/parameters/Parameters.java deleted file mode 100644 index 723c5dc..0000000 --- a/src/jcgp/parameters/Parameters.java +++ /dev/null @@ -1,21 +0,0 @@ -package jcgp.parameters; - -import java.util.HashMap; - -public class Parameters { - - - -// private static int rows = 0, columns = 0, inputs = 0, outputs = 0, levelsBack = 0, -// mutationRate = 0, totalGenerations = 0, parents = 0, offspring = 0, -// currentGeneration = 0, totalRuns = 0, currentRun = 0, -// maxArity = 0, maxFitness = 0; - -// private static boolean debug = false; - - - - - - -} |