aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-01-31 13:06:54 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-01-31 13:06:54 +0000
commita02f1fff03ab58416da812597e67a0c7e21fdbd5 (patch)
tree0192f0db1d1bc8d6d29433f4e84d4c94a89ed2ac /src/jcgp/function
parent8f7874fa75c532bab994af8e6553d37afe42ec4c (diff)
Created most of the classes that will be necessary, content is blank for now.
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;
+ }
+
+}