aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/function')
-rw-r--r--src/jcgp/function/Addition.java18
-rw-r--r--src/jcgp/function/Function.java9
-rw-r--r--src/jcgp/function/FunctionSet.java31
-rw-r--r--src/jcgp/function/Subtraction.java16
4 files changed, 74 insertions, 0 deletions
diff --git a/src/jcgp/function/Addition.java b/src/jcgp/function/Addition.java
new file mode 100644
index 0000000..7dc17e2
--- /dev/null
+++ b/src/jcgp/function/Addition.java
@@ -0,0 +1,18 @@
+package jcgp.function;
+
+import jcgp.population.Connection;
+
+public class Addition extends Function {
+
+ @Override
+ public int run(Connection... connections) {
+ int sum = 0;
+ if (connections.length > 0) {
+ for (int i = 0; i < connections.length; i++) {
+ sum += connections[i].evaluate();
+ }
+ }
+ return sum;
+ }
+
+}
diff --git a/src/jcgp/function/Function.java b/src/jcgp/function/Function.java
new file mode 100644
index 0000000..0f0d8a3
--- /dev/null
+++ b/src/jcgp/function/Function.java
@@ -0,0 +1,9 @@
+package jcgp.function;
+
+import jcgp.population.Connection;
+
+public abstract class Function {
+
+ public abstract int run(Connection ... connections);
+
+}
diff --git a/src/jcgp/function/FunctionSet.java b/src/jcgp/function/FunctionSet.java
new file mode 100644
index 0000000..e2d04a0
--- /dev/null
+++ b/src/jcgp/function/FunctionSet.java
@@ -0,0 +1,31 @@
+package jcgp.function;
+
+import java.util.ArrayList;
+
+
+public class FunctionSet {
+ private ArrayList<Function> functionList;
+
+ public void setFunctions(Function ... functions) {
+ functionList = new ArrayList<Function>(functions.length);
+
+ for (int i = 0; i < functions.length; i++) {
+ functionList.add(functions[i]);
+ }
+ }
+
+ public void addFunction(Function newFunction) {
+ if (functionList == null) {
+ functionList = new ArrayList<Function>();
+ }
+ functionList.add(newFunction);
+ }
+
+ public int getFunctionCount() {
+ return functionList.size();
+ }
+
+ public Function getFunction(int index) {
+ return functionList.get(index);
+ }
+ } \ No newline at end of file
diff --git a/src/jcgp/function/Subtraction.java b/src/jcgp/function/Subtraction.java
new file mode 100644
index 0000000..70297c3
--- /dev/null
+++ b/src/jcgp/function/Subtraction.java
@@ -0,0 +1,16 @@
+package jcgp.function;
+
+import jcgp.population.Connection;
+
+public class Subtraction extends Function {
+
+ @Override
+ public int run(Connection... connections) {
+ int subtraction = 0;
+ if (connections.length > 1) {
+ subtraction = connections[0].evaluate() - connections[1].evaluate();
+ }
+ return subtraction;
+ }
+
+}