aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/modules')
-rw-r--r--src/jcgp/modules/Module.java1
-rw-r--r--src/jcgp/modules/function/Arithmetic.java18
-rw-r--r--src/jcgp/modules/function/BitwiseLogic.java29
-rw-r--r--src/jcgp/modules/function/BooleanLogic.java29
-rw-r--r--src/jcgp/modules/function/FunctionSet.java10
-rw-r--r--src/jcgp/modules/mutator/PointMutator.java (renamed from src/jcgp/modules/mutator/StandardMutator.java)11
6 files changed, 30 insertions, 68 deletions
diff --git a/src/jcgp/modules/Module.java b/src/jcgp/modules/Module.java
index a0da50a..b8d44d2 100644
--- a/src/jcgp/modules/Module.java
+++ b/src/jcgp/modules/Module.java
@@ -11,5 +11,4 @@ public abstract class Module {
protected final void registerParameter(String key, Parameter value) {
Parameters.add(key, value);
};
-
}
diff --git a/src/jcgp/modules/function/Arithmetic.java b/src/jcgp/modules/function/Arithmetic.java
index 73debd2..aa5e9bf 100644
--- a/src/jcgp/modules/function/Arithmetic.java
+++ b/src/jcgp/modules/function/Arithmetic.java
@@ -1,7 +1,6 @@
package jcgp.modules.function;
import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.parameters.Parameters;
import jcgp.population.Connection;
public class Arithmetic {
@@ -19,9 +18,6 @@ public class Arithmetic {
Integer arg2 = ((Integer) connections[1].getValue());
Integer result = arg1 + arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " + " + arg2 + " = " + result);
- }
return result;
}
}
@@ -45,9 +41,6 @@ public class Arithmetic {
Integer arg2 = ((Integer) connections[1].getValue());
Integer result = arg1 - arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " - " + arg2 + " = " + result);
- }
return result;
}
}
@@ -71,11 +64,6 @@ public class Arithmetic {
Integer arg2 = ((Integer) connections[1].getValue());
Integer result = arg1 * arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " * " + arg2 + " = " + result);
- }
-
-
return result;
}
}
@@ -103,12 +91,6 @@ public class Arithmetic {
} else {
result = arg1 / arg2;
}
-
-
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " / " + arg2 + " = " + result);
- }
-
return result;
}
diff --git a/src/jcgp/modules/function/BitwiseLogic.java b/src/jcgp/modules/function/BitwiseLogic.java
index a260715..c8452e6 100644
--- a/src/jcgp/modules/function/BitwiseLogic.java
+++ b/src/jcgp/modules/function/BitwiseLogic.java
@@ -1,7 +1,6 @@
package jcgp.modules.function;
import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.parameters.Parameters;
import jcgp.population.Connection;
public class BitwiseLogic {
@@ -17,9 +16,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 & arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " AND " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -41,9 +38,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 | arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " OR " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -64,9 +59,7 @@ public class BitwiseLogic {
} else {
int arg1 = ((int) connections[0].getValue());
int result = ~arg1;
- if (Parameters.getDebug()) {
- System.out.println("NOT " + arg1 + " = " + result);
- }
+
return result;
}
}
@@ -88,9 +81,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XOR " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -112,9 +103,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 & arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NAND " + arg2 + " = " + ~result);
- }
+
return ~result;
}
}
@@ -136,9 +125,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 | arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NOR " + arg2 + " = " + ~result);
- }
+
return ~result;
}
}
@@ -160,9 +147,7 @@ public class BitwiseLogic {
int arg1 = ((int) connections[0].getValue());
int arg2 = ((int) connections[1].getValue());
int result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XNOR " + arg2 + " = " + ~result);
- }
+
return ~result;
}
}
diff --git a/src/jcgp/modules/function/BooleanLogic.java b/src/jcgp/modules/function/BooleanLogic.java
index 887e0e6..f98d1db 100644
--- a/src/jcgp/modules/function/BooleanLogic.java
+++ b/src/jcgp/modules/function/BooleanLogic.java
@@ -1,7 +1,6 @@
package jcgp.modules.function;
import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.parameters.Parameters;
import jcgp.population.Connection;
public class BooleanLogic {
@@ -17,9 +16,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 && arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " AND " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -41,9 +38,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 || arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " OR " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -64,9 +59,7 @@ public class BooleanLogic {
} else {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean result = !arg1;
- if (Parameters.getDebug()) {
- System.out.println("NOT " + arg1 + " = " + result);
- }
+
return result;
}
}
@@ -88,9 +81,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XOR " + arg2 + " = " + result);
- }
+
return result;
}
}
@@ -112,9 +103,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 && arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NAND " + arg2 + " = " + !result);
- }
+
return !result;
}
}
@@ -136,9 +125,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 || arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NOR " + arg2 + " = " + !result);
- }
+
return !result;
}
}
@@ -160,9 +147,7 @@ public class BooleanLogic {
Boolean arg1 = ((Boolean) connections[0].getValue());
Boolean arg2 = ((Boolean) connections[1].getValue());
Boolean result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XNOR " + arg2 + " = " + !result);
- }
+
return !result;
}
}
diff --git a/src/jcgp/modules/function/FunctionSet.java b/src/jcgp/modules/function/FunctionSet.java
index 8a2190a..fb3724f 100644
--- a/src/jcgp/modules/function/FunctionSet.java
+++ b/src/jcgp/modules/function/FunctionSet.java
@@ -13,16 +13,18 @@ package jcgp.modules.function;
public class FunctionSet {
private Function[] functionList;
private int maxArity = 0;
+ private String name;
- public FunctionSet(Function ... functions) {
+ public FunctionSet(String name, Function ... functions) {
functionList = functions;
-
for (Function function : functionList) {
if (function.getArity() > maxArity) {
maxArity = function.getArity();
}
}
+ this.name = name;
+
}
public int getFunctionCount() {
@@ -36,4 +38,8 @@ public class FunctionSet {
public int getMaxArity(){
return maxArity;
}
+
+ public String getName() {
+ return name;
+ }
} \ No newline at end of file
diff --git a/src/jcgp/modules/mutator/StandardMutator.java b/src/jcgp/modules/mutator/PointMutator.java
index 17bd0be..b06d678 100644
--- a/src/jcgp/modules/mutator/StandardMutator.java
+++ b/src/jcgp/modules/mutator/PointMutator.java
@@ -1,17 +1,22 @@
package jcgp.modules.mutator;
import jcgp.Utilities;
+import jcgp.parameters.IntegerParameter;
import jcgp.parameters.Parameters;
import jcgp.population.Chromosome;
import jcgp.population.MutableElement;
import jcgp.population.Node;
import jcgp.population.Output;
-public class StandardMutator implements Mutator {
+public class PointMutator implements Mutator {
+ public PointMutator() {
+ Parameters.add("mutRate", new IntegerParameter(10, "Mutation rate"));
+ }
+
@Override
public void mutate(Chromosome chromosome) {
- int mutations = (int) (Parameters.getMutationRate() * (((double) Parameters.getNodeCount() + Parameters.getOutputs()) / 100));
+ int mutations = (int) (((int) Parameters.get("mutRate").getValue()) * ((((double) Parameters.get("nodes").getValue()) + ((double) Parameters.get("outputs").getValue())) / 100));
for (int i = 0; i < mutations; i++) {
MutableElement m = chromosome.getRandomMutableElement();
@@ -19,7 +24,7 @@ public class StandardMutator implements Mutator {
if (m instanceof Output) {
m.setConnection(chromosome.getRandomConnection());
} else if (m instanceof Node) {
- int geneType = Utilities.getRandomInt(1 + Parameters.getMaxArity());
+ int geneType = Utilities.getRandomInt(1 + ((int) Parameters.get("Max arity").getValue()));
if (geneType < 1) {
((Node) m).setFunction(Utilities.getRandomFunction());
} else {