aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/function')
-rw-r--r--src/jcgp/function/Arithmetic.java1
-rw-r--r--src/jcgp/function/BitwiseLogic.java1
-rw-r--r--src/jcgp/function/BooleanLogic.java1
-rw-r--r--src/jcgp/function/FunctionSet.java19
4 files changed, 16 insertions, 6 deletions
diff --git a/src/jcgp/function/Arithmetic.java b/src/jcgp/function/Arithmetic.java
index 7ec1366..b61ee65 100644
--- a/src/jcgp/function/Arithmetic.java
+++ b/src/jcgp/function/Arithmetic.java
@@ -9,7 +9,6 @@ import jcgp.population.Connection;
public class Arithmetic extends FunctionSet {
public Arithmetic() {
- maxArity = 2;
name = "Arithmetic";
functionList = new Function[]{
new Addition(),
diff --git a/src/jcgp/function/BitwiseLogic.java b/src/jcgp/function/BitwiseLogic.java
index 033534d..7ced8e8 100644
--- a/src/jcgp/function/BitwiseLogic.java
+++ b/src/jcgp/function/BitwiseLogic.java
@@ -9,7 +9,6 @@ import jcgp.population.Connection;
public class BitwiseLogic extends FunctionSet {
public BitwiseLogic() {
- maxArity = 2;
name = "32-bit Logic";
functionList = new Function[]{
new And(),
diff --git a/src/jcgp/function/BooleanLogic.java b/src/jcgp/function/BooleanLogic.java
index d31b798..7e441f2 100644
--- a/src/jcgp/function/BooleanLogic.java
+++ b/src/jcgp/function/BooleanLogic.java
@@ -9,7 +9,6 @@ import jcgp.population.Connection;
public class BooleanLogic extends FunctionSet {
public BooleanLogic() {
- maxArity = 2;
name = "1-bit Logic";
functionList = new Function[]{
new And(),
diff --git a/src/jcgp/function/FunctionSet.java b/src/jcgp/function/FunctionSet.java
index 49ff7e7..fef8f88 100644
--- a/src/jcgp/function/FunctionSet.java
+++ b/src/jcgp/function/FunctionSet.java
@@ -12,7 +12,6 @@ import java.util.Iterator;
public abstract class FunctionSet {
protected Function[] functionList;
protected ArrayList<Function> allowedFunctions;
- protected int maxArity;
protected String name;
public int getAllowedFunctionCount() {
@@ -23,12 +22,22 @@ public abstract class FunctionSet {
return functionList.length;
}
- public Function getFunction(int index) {
+ public Function getAllowedFunction(int index) {
return allowedFunctions.get(index);
}
+ public Function getFunction(int index) {
+ return functionList[index];
+ }
+
public int getMaxArity(){
- return maxArity;
+ int arity = 0;
+ for (Function function : allowedFunctions) {
+ if (function.getArity() > arity) {
+ arity = function.getArity();
+ }
+ }
+ return arity;
}
public String getName() {
@@ -58,4 +67,8 @@ public abstract class FunctionSet {
public String toString() {
return name;
}
+
+ public boolean isEnabled(Function f) {
+ return allowedFunctions.contains(f);
+ }
} \ No newline at end of file