diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-26 19:56:24 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-26 19:56:24 +0100 |
commit | 4c8de2402f2878cde7587c7f3bbf4ffaea86efd4 (patch) | |
tree | 29156510f648a2d9f8de4df3b2617d4a056e1d90 /src/jcgp/backend/population | |
parent | b0c0698e5503c2506217117bf144fde31e6f6601 (diff) |
Moved files around to different folders, and commented some more packages. Aiming to have the entire backend fully commented by the end of today
Diffstat (limited to 'src/jcgp/backend/population')
-rw-r--r-- | src/jcgp/backend/population/Chromosome.java | 5 | ||||
-rw-r--r-- | src/jcgp/backend/population/Node.java | 19 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/jcgp/backend/population/Chromosome.java b/src/jcgp/backend/population/Chromosome.java index 9e53f85..d23f43c 100644 --- a/src/jcgp/backend/population/Chromosome.java +++ b/src/jcgp/backend/population/Chromosome.java @@ -2,7 +2,6 @@ package jcgp.backend.population; import java.util.ArrayList; -import jcgp.backend.exceptions.ParameterMismatchException; import jcgp.backend.resources.Resources; public class Chromosome implements Comparable<Chromosome> { @@ -168,7 +167,7 @@ public class Chromosome implements Comparable<Chromosome> { * @param values * @throws ParameterMismatchException */ - public void setInputs(Object ... values) throws ParameterMismatchException { + public void setInputs(Object ... values) { // if the values provided don't match the specified number of inputs, the user should be warned if (values.length == inputs.length) { // set inputs for evaluation @@ -176,7 +175,7 @@ public class Chromosome implements Comparable<Chromosome> { inputs[i].setValue(values[i]); } } else { - throw new ParameterMismatchException(); + throw new IllegalArgumentException("Received " + values.length + " inputs but needed exactly " + inputs.length); } } diff --git a/src/jcgp/backend/population/Node.java b/src/jcgp/backend/population/Node.java index 1ac5b10..74f6b54 100644 --- a/src/jcgp/backend/population/Node.java +++ b/src/jcgp/backend/population/Node.java @@ -1,9 +1,7 @@ package jcgp.backend.population; import java.util.ArrayList; -import java.util.Arrays; -import jcgp.backend.exceptions.InsufficientConnectionsException; import jcgp.backend.function.Function; @@ -22,7 +20,11 @@ public class Node extends Gene implements MutableElement, Connection { @Override public Object getValue() { - return function.run(Arrays.copyOfRange(connections, 0, function.getArity())); + Object[] args = new Object[function.getArity()]; + for (int i = 0; i < function.getArity(); i++) { + args[i] = connections[i].getValue(); + } + return function.run(args); } public void setFunction(Function newFunction) { @@ -31,23 +33,18 @@ public class Node extends Gene implements MutableElement, Connection { @Override public void setConnection(int index, Connection newConnection) { - if (newConnection instanceof Node) { - if (((Node) newConnection).getColumn() < column) { - connections[index] = newConnection; - chromosome.recomputeActiveNodes(); - } - } else if (newConnection instanceof Input) { + if (newConnection != null) { connections[index] = newConnection; chromosome.recomputeActiveNodes(); } } - public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException { + public void initialise(Function newFunction, Connection ... newConnections) { function = newFunction; if (newConnections.length == chromosome.getResources().arity()) { connections = newConnections; } else { - throw new InsufficientConnectionsException(); + throw new IllegalArgumentException("Received " + newConnections.length + " connections but needed exactly " + chromosome.getResources().arity()); } } |