From e6dd7711c7dad5e000445208eb5845801f4ccffc Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 6 Apr 2014 21:58:53 +0100 Subject: About to make big changes to the way fitness works, committing just in case --- src/jcgp/backend/function/BooleanLogic.java | 60 +++++++++++------------------ 1 file changed, 22 insertions(+), 38 deletions(-) (limited to 'src/jcgp/backend/function/BooleanLogic.java') diff --git a/src/jcgp/backend/function/BooleanLogic.java b/src/jcgp/backend/function/BooleanLogic.java index e0b5c9c..9e7d1ff 100644 --- a/src/jcgp/backend/function/BooleanLogic.java +++ b/src/jcgp/backend/function/BooleanLogic.java @@ -1,7 +1,5 @@ package jcgp.backend.function; -import java.util.ArrayList; -import java.util.Arrays; import jcgp.backend.exceptions.InvalidArgumentsException; import jcgp.backend.population.Connection; @@ -19,15 +17,13 @@ public class BooleanLogic extends FunctionSet { new Nor(), new Xnor()}; - allowedFunctions = new ArrayList(Arrays.asList(functionList)); + enableAll(); } - public static class And extends Function { - private int arity = 2; - + public static class And extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -40,7 +36,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override @@ -49,12 +45,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Or extends Function { - private int arity = 2; - + public static class Or extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -67,7 +61,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override @@ -76,12 +70,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Not extends Function { - private int arity = 1; - + public static class Not extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 1) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -93,7 +85,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 1; } @Override @@ -102,12 +94,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Xor extends Function { - private int arity = 2; - + public static class Xor extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -120,7 +110,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override @@ -129,12 +119,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Nand extends Function { - private int arity = 2; - + public static class Nand extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -147,7 +135,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override @@ -156,12 +144,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Nor extends Function { - private int arity = 2; - + public static class Nor extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -174,7 +160,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override @@ -183,12 +169,10 @@ public class BooleanLogic extends FunctionSet { } } - public static class Xnor extends Function { - private int arity = 2; - + public static class Xnor extends Function { @Override public Boolean run(Connection... connections) { - if (connections.length < arity) { + if (connections.length < 2) { throw new InvalidArgumentsException("Not enough connections were given."); } else { Boolean arg1 = ((Boolean) connections[0].getValue()); @@ -201,7 +185,7 @@ public class BooleanLogic extends FunctionSet { @Override public int getArity() { - return arity; + return 2; } @Override -- cgit v1.2.3