aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/population
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/population')
-rw-r--r--src/jcgp/backend/population/Chromosome.java5
-rw-r--r--src/jcgp/backend/population/Node.java19
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());
}
}