aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population/Chromosome.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-10 09:33:54 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-10 09:33:54 +0000
commit6e7747e5b85f4ca93683ed5166f6e480cc58e6fa (patch)
treee1243f2eb6f743a547b89362e37e516e22f647e8 /src/jcgp/population/Chromosome.java
parent0e34bfdb60c28a6118ec93893ddc7ceb6fa50cb5 (diff)
Refactored the resources mechanics, implemented a few of the chromosome tests
Diffstat (limited to 'src/jcgp/population/Chromosome.java')
-rw-r--r--src/jcgp/population/Chromosome.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index f060e14..328a608 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -1,7 +1,8 @@
package jcgp.population;
-import jcgp.CGP.Parameters;
-import jcgp.CGP.Utilities;
+import jcgp.Parameters;
+import jcgp.Utilities;
+import jcgp.fitness.ParameterMismatchException;
public class Chromosome {
@@ -41,16 +42,16 @@ public class Chromosome {
}
// rows first
- nodes = new Node[Parameters.getRows()][Parameters.getColumns()];
+ nodes = new Node[rows][columns];
for (int r = 0; r < rows; r++) {
//nodes[r] = new Node[Parameters.getColumns()];
for (int c = 0; c < columns; c++) {
- nodes[r][c] = new Node(c);
+ nodes[r][c] = new Node(r, c);
}
}
outputs = new Output[outputCount];
for (int o = 0; o < outputCount; o++) {
- outputs[o] = new Output();
+ outputs[o] = new Output(o);
}
}
@@ -97,16 +98,25 @@ public class Chromosome {
fitness = newFitness;
}
- public void setInputs(int ... values) {
- // if the values provided dont match the specified number of inputs, the user should be warned
+ public void setInputs(int ... values) throws ParameterMismatchException {
+ // 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
for (int i = 0; i < values.length; i++) {
inputs[i].setValue(values[i]);
}
} else {
- System.out.println("Input mismatch: chromosome has a different number of inputs than the truth table.");
+ throw new ParameterMismatchException();
}
}
+
+ public MutableElement getMutableElement(int row, int column) {
+ if (column < Parameters.getColumns() && column >= 0) {
+ return nodes[row][column];
+ } else if (column == Parameters.getColumns()) {
+ return outputs[row];
+ }
+ return null;
+ }
}