aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population/Chromosome.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/population/Chromosome.java')
-rw-r--r--src/jcgp/population/Chromosome.java42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index df2a9d4..1f0b312 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -52,20 +52,20 @@ public class Chromosome {
*
*/
private void instantiateElements() {
- inputs = new Input[Parameters.getInputs()];
- for (int i = 0; i < Parameters.getInputs(); i++) {
+ inputs = new Input[((int) Parameters.get("inputs").getValue())];
+ for (int i = 0; i < ((int) Parameters.get("inputs").getValue()); i++) {
inputs[i] = new Input(i);
}
// rows first
- nodes = new Node[Parameters.getRows()][Parameters.getColumns()];
- for (int r = 0; r < Parameters.getRows(); r++) {
- for (int c = 0; c < Parameters.getColumns(); c++) {
+ nodes = new Node[((int) Parameters.get("rows").getValue())][((int) Parameters.get("columns").getValue())];
+ for (int r = 0; r < ((int) Parameters.get("rows").getValue()); r++) {
+ for (int c = 0; c < ((int) Parameters.get("columns").getValue()); c++) {
nodes[r][c] = new Node(this, r, c);
}
}
- outputs = new Output[Parameters.getOutputs()];
- for (int o = 0; o < Parameters.getOutputs(); o++) {
+ outputs = new Output[((int) Parameters.get("outputs").getValue())];
+ for (int o = 0; o < ((int) Parameters.get("outputs").getValue()); o++) {
outputs[o] = new Output(this, o);
}
}
@@ -78,7 +78,7 @@ public class Chromosome {
// initialise nodes - [rows][columns]
for (int r = 0; r < nodes.length; r++) {
for (int c = 0; c < nodes[r].length; c++) {
- Connection[] connections = new Connection[Parameters.getMaxArity()];
+ Connection[] connections = new Connection[((int) Parameters.get("maxArity").getValue())];
for (int i = 0; i < connections.length; i++) {
connections[i] = getRandomConnection(c);
}
@@ -100,7 +100,7 @@ public class Chromosome {
for (int r = 0; r < nodes.length; r++) {
for (int c = 0; c < nodes[r].length; c++) {
// make array of connections to initialise with
- Connection[] connections = new Connection[Parameters.getMaxArity()];
+ Connection[] connections = new Connection[((int) Parameters.get("maxArity").getValue())];
// populate with connections equivalent to clone
Connection copyConnection;
for (int i = 0; i < connections.length; i++) {
@@ -177,7 +177,7 @@ public class Chromosome {
*/
public MutableElement getRandomMutableElement() {
// choose output or node
- int index = Utilities.getRandomInt(outputs.length + Parameters.getNodeCount());
+ int index = Utilities.getRandomInt(outputs.length + ((int) Parameters.get("rows").getValue()) * ((int) Parameters.get("columns").getValue()));
if (index < outputs.length) {
// outputs
@@ -185,7 +185,7 @@ public class Chromosome {
} else {
// node
index -= outputs.length;
- return nodes[index / Parameters.getColumns()][index % Parameters.getColumns()];
+ return nodes[index / ((int) Parameters.get("columns").getValue())][index % ((int) Parameters.get("columns").getValue())];
}
}
@@ -199,7 +199,7 @@ public class Chromosome {
*/
public Connection getRandomConnection(int column) {
// work out the allowed range obeying levels back
- int allowedColumns = ((column >= Parameters.getLevelsBack()) ? Parameters.getLevelsBack() : column);
+ int allowedColumns = ((column >= ((int) Parameters.get("levelsBack").getValue())) ? ((int) Parameters.get("levelsBack").getValue()) : column);
int offset = ((column - allowedColumns) * nodes.length) - inputs.length;
// choose input or allowed node
@@ -226,7 +226,7 @@ public class Chromosome {
*/
public Connection getRandomConnection() {
// choose output or node
- int index = Utilities.getRandomInt(inputs.length + Parameters.getNodeCount());
+ int index = Utilities.getRandomInt(inputs.length + ((int) Parameters.get("columns").getValue()) * ((int) Parameters.get("rows").getValue()));
if (index < inputs.length) {
// outputs
@@ -234,7 +234,7 @@ public class Chromosome {
} else {
// node
index -= inputs.length;
- return nodes[index / Parameters.getColumns()][index % Parameters.getColumns()];
+ return nodes[index / ((int) Parameters.get("columns").getValue())][index % ((int) Parameters.get("columns").getValue())];
}
}
@@ -269,15 +269,15 @@ public class Chromosome {
}
public boolean compareTo(Chromosome chromosome) {
- for (int r = 0; r < Parameters.getRows(); r++) {
- for (int c = 0; c < Parameters.getColumns(); c++) {
+ for (int r = 0; r < ((int) Parameters.get("rows").getValue()); r++) {
+ for (int c = 0; c < ((int) Parameters.get("columns").getValue()); c++) {
if (!(nodes[r][c].copyOf(chromosome.getNode(r, c)))) {
return false;
}
}
}
- for (int o = 0; o < Parameters.getOutputs(); o++) {
+ for (int o = 0; o < ((int) Parameters.get("outputs").getValue()); o++) {
if (!(outputs[o].copyOf(chromosome.getOutput(o)))) {
return false;
}
@@ -302,11 +302,11 @@ public class Chromosome {
}
public void printNodes() {
- for (int r = 0; r < Parameters.getRows(); r++) {
+ for (int r = 0; r < ((int) Parameters.get("rows").getValue()); r++) {
System.out.print("r: " + r + "\t");
- for (int c = 0; c < Parameters.getColumns(); c++) {
+ for (int c = 0; c < ((int) Parameters.get("columns").getValue()); c++) {
System.out.print("N: (" + r + ", " + c + ") ");
- for (int i = 0; i < Parameters.getMaxArity(); i++) {
+ for (int i = 0; i < ((int) Parameters.get("maxArity").getValue()); i++) {
System.out.print("C" + i + ": (" + nodes[r][c].getConnection(i).getDescription() + ") ");
}
System.out.print("F: " + nodes[r][c].getFunction().toString() + "\t");
@@ -314,7 +314,7 @@ public class Chromosome {
System.out.print("\n");
}
- for (int o = 0; o < Parameters.getOutputs(); o++) {
+ for (int o = 0; o < ((int) Parameters.get("outputs").getValue()); o++) {
System.out.print("o: " + o + " (" + outputs[o].getSource().getDescription() + ")\t");
}
}