From a02f1fff03ab58416da812597e67a0c7e21fdbd5 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 31 Jan 2014 13:06:54 +0000 Subject: Created most of the classes that will be necessary, content is blank for now. --- src/jcgp/function/Addition.java | 18 ++++++++++++++++++ src/jcgp/function/Function.java | 9 +++++++++ src/jcgp/function/FunctionSet.java | 31 +++++++++++++++++++++++++++++++ src/jcgp/function/Subtraction.java | 16 ++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 src/jcgp/function/Addition.java create mode 100644 src/jcgp/function/Function.java create mode 100644 src/jcgp/function/FunctionSet.java create mode 100644 src/jcgp/function/Subtraction.java (limited to 'src/jcgp/function') 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 functionList; + + public void setFunctions(Function ... functions) { + functionList = new ArrayList(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(); + } + 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; + } + +} -- cgit v1.2.3