aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/JCGP.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/JCGP.java')
-rw-r--r--src/jcgp/JCGP.java109
1 files changed, 63 insertions, 46 deletions
diff --git a/src/jcgp/JCGP.java b/src/jcgp/JCGP.java
index 21161fa..dc121c9 100644
--- a/src/jcgp/JCGP.java
+++ b/src/jcgp/JCGP.java
@@ -5,7 +5,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
-import java.util.Set;
import javafx.beans.property.Property;
import jcgp.function.Arithmetic;
@@ -34,12 +33,12 @@ public class JCGP {
*
*/
public static class Resources {
- private HashMap<String, Parameter> moduleParameters = new HashMap<String, Parameter>();
- private HashMap<String, Parameter> coreParameters = new HashMap<String, Parameter>();
- private HashMap<String, Parameter> allParameters = new HashMap<String, Parameter>();
+ private HashMap<String, Parameter> parameters = new HashMap<String, Parameter>();
private Random numberGenerator;
+ private TestCase[] testCases;
+
// function sets
private FunctionSet[] functionSets = new FunctionSet[] {
new Arithmetic(),
@@ -47,86 +46,91 @@ public class JCGP {
new BooleanLogic() };
private FunctionSet functionSet = functionSets[0];
- private TestCase[] testCases;
-
public Resources() {
createCoreParameters();
numberGenerator = new Random((int) get("seed"));
- functionSet = functionSets[0];
set("arity", functionSet.getMaxArity());
}
public Object get(String key) {
- return allParameters.get(key).getValue();
+ return parameters.get(key).getValue();
+ }
+
+ public int getInt(String key) {
+ return (int) parameters.get(key).getValue();
+ }
+
+ public double getDouble(String key) {
+ return (double) parameters.get(key).getValue();
+ }
+
+ public boolean getBoolean(String key) {
+ return (boolean) parameters.get(key).getValue();
}
public void set(String key, Object value) {
- allParameters.get(key).setValue(value);
+ parameters.get(key).setValue(value);
}
public Property<?> getProperty(String key) {
- return allParameters.get(key).valueProperty();
+ return parameters.get(key).valueProperty();
+ }
+
+ public Parameter getParameter(String key) {
+ return parameters.get(key);
}
public void setManagedParameter(String key, boolean value) {
- allParameters.get(key).setManaged(value);
+ parameters.get(key).setManaged(value);
}
public void setHiddenParameter(String key, boolean value) {
- allParameters.get(key).setHidden(value);
+ parameters.get(key).setHidden(value);
}
public boolean contains(String key) {
- return allParameters.containsKey(key);
+ return parameters.containsKey(key);
}
private void createCoreParameters() {
- coreParameters.put("rows", new IntegerParameter(9, "Rows"));
- coreParameters.put("columns", new IntegerParameter(10, "Columns"));
- coreParameters.put("inputs", new IntegerParameter(3, "Inputs"));
- coreParameters.put("outputs", new IntegerParameter(3, "Outputs"));
- coreParameters.put("popSize", new IntegerParameter(5, "Population"));
- coreParameters.put("levelsBack", new IntegerParameter(2, "Levels back"));
+ parameters.put("rows", new IntegerParameter(8, "Rows"));
+ parameters.put("columns", new IntegerParameter(9, "Columns"));
+ parameters.put("inputs", new IntegerParameter(3, "Inputs"));
+ parameters.put("outputs", new IntegerParameter(3, "Outputs"));
+ parameters.put("popSize", new IntegerParameter(5, "Population"));
+ parameters.put("levelsBack", new IntegerParameter(2, "Levels back"));
- coreParameters.put("nodes", new IntegerParameter(90, "Nodes", true, true));
+ parameters.put("nodes", new IntegerParameter(72, "Nodes", true, true));
- coreParameters.put("generations", new IntegerParameter(1000000, "Generations"));
- coreParameters.put("currentGen", new IntegerParameter(0, "Generation"));
- coreParameters.put("runs", new IntegerParameter(5, "Runs"));
+ parameters.put("generations", new IntegerParameter(1000000, "Generations"));
+ parameters.put("currentGen", new IntegerParameter(0, "Generation", true, false));
+ parameters.put("runs", new IntegerParameter(5, "Runs"));
- coreParameters.put("arity", new IntegerParameter(0, "Max arity", true, true));
+ parameters.put("arity", new IntegerParameter(0, "Max arity", true, true));
- coreParameters.put("seed", new IntegerParameter(123, "Random seed", true, true));
+ parameters.put("seed", new IntegerParameter(123, "Seed"));
- coreParameters.put("debug", new BooleanParameter(false, "Debug"));
-
- allParameters.putAll(coreParameters);
+ parameters.put("debug", new BooleanParameter(false, "Debug"));
+ parameters.put("report", new IntegerParameter(1, "Report"));
}
+ // TODO fix this up
private void resetParameters(EvolutionaryAlgorithm ea, Mutator mu, FitnessFunction ff) {
- Iterator<Entry<String, Parameter>> it = coreParameters.entrySet().iterator();
+ Iterator<Entry<String, Parameter>> it = parameters.entrySet().iterator();
while (it.hasNext()) {
((Parameter) ((Map.Entry<String, Parameter>) it.next()).getValue()).reset();
}
-
- allParameters.clear();
- allParameters.putAll(coreParameters);
- addModuleParameters(ea, mu, ff);
}
- private void addModuleParameters(EvolutionaryAlgorithm ea, Mutator mu, FitnessFunction ff) {
- moduleParameters.clear();
- moduleParameters.putAll(ea.activate(this));
- moduleParameters.putAll(mu.activate(this));
- moduleParameters.putAll(ff.activate(this));
-
- allParameters.putAll(moduleParameters);
- }
-
+ /**
+ *
+ *
+ * @return the iterator for the set of base parameters
+ */
public Iterator<Entry<String, Parameter>> iterator() {
- return allParameters.entrySet().iterator();
+ return parameters.entrySet().iterator();
}
/*
@@ -145,10 +149,10 @@ public class JCGP {
}
/*
- * Function set functions
+ * FunctionSet functions
*/
public Function getRandomFunction() {
- return functionSet.getFunction(numberGenerator.nextInt(functionSet.getFunctionCount()));
+ return functionSet.getFunction(numberGenerator.nextInt(functionSet.getAllowedFunctionCount()));
}
public Function getFunction(int index) {
@@ -159,6 +163,20 @@ public class JCGP {
functionSet = functionSets[index];
}
+ /**
+ * @return the functionSets
+ */
+ public FunctionSet[] getFunctionSets() {
+ return functionSets;
+ }
+
+ /**
+ * @return the functionSet
+ */
+ public FunctionSet getFunctionSet() {
+ return functionSet;
+ }
+
/*
* Test cases
*/
@@ -204,7 +222,6 @@ public class JCGP {
public JCGP() {
- resources.addModuleParameters(evolutionaryAlgorithm, mutator, fitnessFunction);
resources.setTestCases(new TestCase(new Integer[]{1, 2, 3}, new Integer[]{4, 5, 6}),
new TestCase(new Integer[]{1, 12, 4}, new Integer[]{6, 21, 2}));