aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/function/Arithmetic.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-06 21:58:53 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-06 21:58:53 +0100
commite6dd7711c7dad5e000445208eb5845801f4ccffc (patch)
tree1454bd20a8dd7069b1283184c42f4def6d5f7e6f /src/jcgp/backend/function/Arithmetic.java
parentc7969623b44f375e30fa3f15dcd7581609276a0f (diff)
About to make big changes to the way fitness works, committing just in case
Diffstat (limited to 'src/jcgp/backend/function/Arithmetic.java')
-rw-r--r--src/jcgp/backend/function/Arithmetic.java139
1 files changed, 0 insertions, 139 deletions
diff --git a/src/jcgp/backend/function/Arithmetic.java b/src/jcgp/backend/function/Arithmetic.java
deleted file mode 100644
index 6971663..0000000
--- a/src/jcgp/backend/function/Arithmetic.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package jcgp.backend.function;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import jcgp.backend.exceptions.InvalidArgumentsException;
-import jcgp.backend.population.Connection;
-
-public class Arithmetic extends FunctionSet {
-
- public Arithmetic() {
- name = "Arithmetic";
- functionList = new Function[]{
- new Addition(),
- new Subtraction(),
- new Multiplication(),
- new Division()};
-
- allowedFunctions = new ArrayList<Function>(Arrays.asList(functionList));
- }
-
- public static class Addition extends Function {
-
- private int arity = 2;
-
- @Override
- public Integer run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Integer arg1 = ((Integer) connections[0].getValue());
- Integer arg2 = ((Integer) connections[1].getValue());
- Integer result = arg1 + arg2;
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
-
- @Override
- public String getName() {
- return "Addition";
- }
- }
-
- public static class Subtraction extends Function {
-
- private int arity = 2;
-
- @Override
- public Integer run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Integer arg1 = ((Integer) connections[0].getValue());
- Integer arg2 = ((Integer) connections[1].getValue());
- Integer result = arg1 - arg2;
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
-
- @Override
- public String getName() {
- return "Subtraction";
- }
- }
-
- public static class Multiplication extends Function {
-
- private int arity = 2;
-
- @Override
- public Integer run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Integer arg1 = ((Integer) connections[0].getValue());
- Integer arg2 = ((Integer) connections[1].getValue());
- Integer result = arg1 * arg2;
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
-
- @Override
- public String getName() {
- return "Multiplication";
- }
- }
-
- public static class Division extends Function {
-
- private int arity = 2;
-
- @Override
- public Integer run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Integer arg1 = ((Integer) connections[0].getValue());
- Integer arg2 = ((Integer) connections[1].getValue());
- Integer result;
- if (arg2 == 0) {
- result = 0;
- } else {
- result = arg1 / arg2;
- }
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
-
- @Override
- public String getName() {
- return "Division";
- }
- }
-
-}