aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-11 08:14:09 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-11 08:14:09 +0000
commitd8ab8a2424a689cff4c787b0448c893facaadf6f (patch)
treed6a459a8f4808b3042acdf33f108f485ce4ddf7c /src/jcgp/population
parent6e7747e5b85f4ca93683ed5166f6e480cc58e6fa (diff)
Worked on more tests, finished restructuring resources
Diffstat (limited to 'src/jcgp/population')
-rw-r--r--src/jcgp/population/Chromosome.java51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index 328a608..195b95c 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -9,9 +9,9 @@ public class Chromosome {
private Input[] inputs;
private Node[][] nodes;
private Output[] outputs;
-
+
private int fitness = 0;
-
+
/**
* Good citizen.
*
@@ -22,11 +22,11 @@ public class Chromosome {
*
*/
public Chromosome(int inputCount, int rows, int columns, int outputCount) {
-
+
instantiateElements(inputCount, rows, columns, outputCount);
-
+
initialiseConnections();
-
+
}
/**
@@ -40,7 +40,7 @@ public class Chromosome {
for (int i = 0; i < inputCount; i++) {
inputs[i] = new Input();
}
-
+
// rows first
nodes = new Node[rows][columns];
for (int r = 0; r < rows; r++) {
@@ -54,9 +54,9 @@ public class Chromosome {
outputs[o] = new Output(o);
}
}
-
+
private void initialiseConnections() {
-
+
// initialise nodes - [rows][columns]
for (int r = 0; r < nodes.length; r++) {
for (int c = 0; c < nodes.length; c++) {
@@ -67,13 +67,13 @@ public class Chromosome {
nodes[r][c].initialise(Utilities.getRandomFunction(), connections);
}
}
-
+
for (Output output : outputs) {
output.setConnection(Utilities.getRandomNode(this));
}
-
+
}
-
+
public int getActiveNodeCount() {
return 0;
}
@@ -81,23 +81,23 @@ public class Chromosome {
public Node getNode(int row, int column) {
return nodes[row][column];
}
-
+
public Output getOutput(int index) {
return outputs[index];
}
-
+
public Input getInput(int index) {
return inputs[index];
}
-
+
public int getFitness() {
return fitness;
}
-
+
public void setFitness(int newFitness) {
fitness = newFitness;
}
-
+
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) {
@@ -110,13 +110,18 @@ public class Chromosome {
}
}
- 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];
+ public MutableElement getRandomMutableElement() {
+ // choose output or node
+ int index = Utilities.getRandomInt(outputs.length + Parameters.getNodeCount());
+
+ if (index < outputs.length) {
+ // outputs
+ return outputs[index];
+ } else {
+ // node
+ index -= outputs.length;
+ return nodes[index / Parameters.getColumns()][index % Parameters.getColumns()];
}
- return null;
}
-
+
}