aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/function')
-rw-r--r--src/jcgp/function/Arithmetic.java123
-rw-r--r--src/jcgp/function/BitwiseLogic.java178
-rw-r--r--src/jcgp/function/BooleanLogic.java178
-rw-r--r--src/jcgp/function/Function.java12
-rw-r--r--src/jcgp/function/FunctionSet.java39
5 files changed, 0 insertions, 530 deletions
diff --git a/src/jcgp/function/Arithmetic.java b/src/jcgp/function/Arithmetic.java
deleted file mode 100644
index b0bd5ca..0000000
--- a/src/jcgp/function/Arithmetic.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package jcgp.function;
-
-import jcgp.Parameters;
-import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.population.Connection;
-
-public class Arithmetic {
-
- 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;
-
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " + " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- 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;
-
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " - " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- 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;
-
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " * " + arg2 + " = " + result);
- }
-
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- 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;
- }
-
-
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " / " + arg2 + " = " + result);
- }
-
-
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
-}
diff --git a/src/jcgp/function/BitwiseLogic.java b/src/jcgp/function/BitwiseLogic.java
deleted file mode 100644
index 55f5df0..0000000
--- a/src/jcgp/function/BitwiseLogic.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package jcgp.function;
-
-import jcgp.Parameters;
-import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.population.Connection;
-
-public class BitwiseLogic {
-
- public static class And extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 & arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " AND " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Or extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 | arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " OR " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Not extends Function {
- private int arity = 1;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int result = ~arg1;
- if (Parameters.getDebug()) {
- System.out.println("NOT " + arg1 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Xor extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XOR " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Nand extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 & arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NAND " + arg2 + " = " + ~result);
- }
- return ~result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Nor extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 | arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NOR " + arg2 + " = " + ~result);
- }
- return ~result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Xnor extends Function {
- private int arity = 2;
-
- @Override
- public Object run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- int arg1 = ((int) connections[0].getValue());
- int arg2 = ((int) connections[1].getValue());
- int result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XNOR " + arg2 + " = " + ~result);
- }
- return ~result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
-
-
-}
diff --git a/src/jcgp/function/BooleanLogic.java b/src/jcgp/function/BooleanLogic.java
deleted file mode 100644
index 713dcf8..0000000
--- a/src/jcgp/function/BooleanLogic.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package jcgp.function;
-
-import jcgp.Parameters;
-import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.population.Connection;
-
-public class BooleanLogic {
-
- public static class And extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 && arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " AND " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Or extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 || arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " OR " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Not extends Function {
- private int arity = 1;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean result = !arg1;
- if (Parameters.getDebug()) {
- System.out.println("NOT " + arg1 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Xor extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XOR " + arg2 + " = " + result);
- }
- return result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Nand extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 && arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NAND " + arg2 + " = " + !result);
- }
- return !result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Nor extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 || arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " NOR " + arg2 + " = " + !result);
- }
- return !result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
- public static class Xnor extends Function {
- private int arity = 2;
-
- @Override
- public Boolean run(Connection... connections) {
- if (connections.length < arity) {
- throw new InvalidArgumentsException("Not enough connections were given.");
- } else {
- Boolean arg1 = ((Boolean) connections[0].getValue());
- Boolean arg2 = ((Boolean) connections[1].getValue());
- Boolean result = arg1 ^ arg2;
- if (Parameters.getDebug()) {
- System.out.println(arg1 + " XNOR " + arg2 + " = " + !result);
- }
- return !result;
- }
- }
-
- @Override
- public int getArity() {
- return arity;
- }
- }
-
-
-
-}
diff --git a/src/jcgp/function/Function.java b/src/jcgp/function/Function.java
deleted file mode 100644
index 584421a..0000000
--- a/src/jcgp/function/Function.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package jcgp.function;
-
-import jcgp.exceptions.InvalidArgumentsException;
-import jcgp.population.Connection;
-
-public abstract class Function {
-
- public abstract Object run(Connection ... connections) throws InvalidArgumentsException;
-
- public abstract int getArity();
-
-}
diff --git a/src/jcgp/function/FunctionSet.java b/src/jcgp/function/FunctionSet.java
deleted file mode 100644
index cbe2f05..0000000
--- a/src/jcgp/function/FunctionSet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package jcgp.function;
-
-/**
- *
- * TODO: if function set flexibility is desired (i.e. add more functions as the program runs)
- * an add function method should be created
- * this would lead to concurrency problems, so tread lightly!
- *
- *
- * @author Eduardo Pedroni
- *
- */
-public class FunctionSet {
- private Function[] functionList;
- private int maxArity = 0;
-
- public FunctionSet(Function ... functions) {
- functionList = functions;
-
- for (Function function : functionList) {
- if (function.getArity() > maxArity) {
- maxArity = function.getArity();
- }
- }
-
- }
-
- public int getFunctionCount() {
- return functionList.length;
- }
-
- public Function getFunction(int index) {
- return functionList[index];
- }
-
- public int getMaxArity(){
- return maxArity;
- }
- } \ No newline at end of file