aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README7
-rw-r--r--src/jcgp/CGP.java29
-rw-r--r--src/jcgp/parameters/BooleanParameter.java15
-rw-r--r--src/jcgp/parameters/DoubleParameter.java14
-rw-r--r--src/jcgp/parameters/IntegerParameter.java14
-rw-r--r--src/jcgp/parameters/Parameter.java4
-rw-r--r--src/jcgp/parameters/Parameters.java21
7 files changed, 60 insertions, 44 deletions
diff --git a/README b/README
index 529a270..982f18e 100644
--- a/README
+++ b/README
@@ -166,4 +166,9 @@ Added some more functions.
8/3
-Adding GUI package, refactoring CGP class to interact appropriately with GUI. \ No newline at end of file
+Adding GUI package, refactoring CGP class to interact appropriately with GUI.
+
+15/3
+
+Currently refactoring Parameters. It is now a part of CGP.class as stated in the phase report. The rest of the program will now be refactored to accommodate these changes. Inversion of
+will be employed to avoid static accesses to CGP, and the tests will be modified accordingly. This will allow multiple instances of CGP to co-exist. \ No newline at end of file
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;
-
-
-
-
-
-
-}