diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-09 23:32:05 +0000 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-09 23:32:05 +0000 |
commit | c0269683bcc7fde0d437ae84cd89a93d9d8fd81b (patch) | |
tree | 62ef738e29ae310dff513cc44193c5169c4ea4ca /src/jcgp/modules/function | |
parent | d63d3145f0f2abcee1bb88457324f4aaf9b9320e (diff) |
Started refactoring backend in preparation for integration with the GUI
Diffstat (limited to 'src/jcgp/modules/function')
-rw-r--r-- | src/jcgp/modules/function/Arithmetic.java | 18 | ||||
-rw-r--r-- | src/jcgp/modules/function/BitwiseLogic.java | 29 | ||||
-rw-r--r-- | src/jcgp/modules/function/BooleanLogic.java | 29 | ||||
-rw-r--r-- | src/jcgp/modules/function/FunctionSet.java | 10 |
4 files changed, 22 insertions, 64 deletions
diff --git a/src/jcgp/modules/function/Arithmetic.java b/src/jcgp/modules/function/Arithmetic.java index 73debd2..aa5e9bf 100644 --- a/src/jcgp/modules/function/Arithmetic.java +++ b/src/jcgp/modules/function/Arithmetic.java @@ -1,7 +1,6 @@ package jcgp.modules.function; import jcgp.exceptions.InvalidArgumentsException; -import jcgp.parameters.Parameters; import jcgp.population.Connection; public class Arithmetic { @@ -19,9 +18,6 @@ public class Arithmetic { Integer arg2 = ((Integer) connections[1].getValue()); Integer result = arg1 + arg2; - if (Parameters.getDebug()) { - System.out.println(arg1 + " + " + arg2 + " = " + result); - } return result; } } @@ -45,9 +41,6 @@ public class Arithmetic { Integer arg2 = ((Integer) connections[1].getValue()); Integer result = arg1 - arg2; - if (Parameters.getDebug()) { - System.out.println(arg1 + " - " + arg2 + " = " + result); - } return result; } } @@ -71,11 +64,6 @@ public class Arithmetic { Integer arg2 = ((Integer) connections[1].getValue()); Integer result = arg1 * arg2; - if (Parameters.getDebug()) { - System.out.println(arg1 + " * " + arg2 + " = " + result); - } - - return result; } } @@ -103,12 +91,6 @@ public class Arithmetic { } else { result = arg1 / arg2; } - - - if (Parameters.getDebug()) { - System.out.println(arg1 + " / " + arg2 + " = " + result); - } - return result; } diff --git a/src/jcgp/modules/function/BitwiseLogic.java b/src/jcgp/modules/function/BitwiseLogic.java index a260715..c8452e6 100644 --- a/src/jcgp/modules/function/BitwiseLogic.java +++ b/src/jcgp/modules/function/BitwiseLogic.java @@ -1,7 +1,6 @@ package jcgp.modules.function; import jcgp.exceptions.InvalidArgumentsException; -import jcgp.parameters.Parameters; import jcgp.population.Connection; public class BitwiseLogic { @@ -17,9 +16,7 @@ public class BitwiseLogic { 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; } } @@ -41,9 +38,7 @@ public class BitwiseLogic { 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; } } @@ -64,9 +59,7 @@ public class BitwiseLogic { } else { int arg1 = ((int) connections[0].getValue()); int result = ~arg1; - if (Parameters.getDebug()) { - System.out.println("NOT " + arg1 + " = " + result); - } + return result; } } @@ -88,9 +81,7 @@ public class BitwiseLogic { 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; } } @@ -112,9 +103,7 @@ public class BitwiseLogic { 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; } } @@ -136,9 +125,7 @@ public class BitwiseLogic { 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; } } @@ -160,9 +147,7 @@ public class BitwiseLogic { 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; } } diff --git a/src/jcgp/modules/function/BooleanLogic.java b/src/jcgp/modules/function/BooleanLogic.java index 887e0e6..f98d1db 100644 --- a/src/jcgp/modules/function/BooleanLogic.java +++ b/src/jcgp/modules/function/BooleanLogic.java @@ -1,7 +1,6 @@ package jcgp.modules.function; import jcgp.exceptions.InvalidArgumentsException; -import jcgp.parameters.Parameters; import jcgp.population.Connection; public class BooleanLogic { @@ -17,9 +16,7 @@ public class BooleanLogic { 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; } } @@ -41,9 +38,7 @@ public class BooleanLogic { 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; } } @@ -64,9 +59,7 @@ public class BooleanLogic { } else { Boolean arg1 = ((Boolean) connections[0].getValue()); Boolean result = !arg1; - if (Parameters.getDebug()) { - System.out.println("NOT " + arg1 + " = " + result); - } + return result; } } @@ -88,9 +81,7 @@ public class BooleanLogic { 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; } } @@ -112,9 +103,7 @@ public class BooleanLogic { 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; } } @@ -136,9 +125,7 @@ public class BooleanLogic { 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; } } @@ -160,9 +147,7 @@ public class BooleanLogic { 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; } } diff --git a/src/jcgp/modules/function/FunctionSet.java b/src/jcgp/modules/function/FunctionSet.java index 8a2190a..fb3724f 100644 --- a/src/jcgp/modules/function/FunctionSet.java +++ b/src/jcgp/modules/function/FunctionSet.java @@ -13,16 +13,18 @@ package jcgp.modules.function; public class FunctionSet { private Function[] functionList; private int maxArity = 0; + private String name; - public FunctionSet(Function ... functions) { + public FunctionSet(String name, Function ... functions) { functionList = functions; - for (Function function : functionList) { if (function.getArity() > maxArity) { maxArity = function.getArity(); } } + this.name = name; + } public int getFunctionCount() { @@ -36,4 +38,8 @@ public class FunctionSet { public int getMaxArity(){ return maxArity; } + + public String getName() { + return name; + } }
\ No newline at end of file |