aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-11 08:30:36 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-11 08:30:36 +0000
commit3fc4bf4a2ea7c6cff9810b76964dd3c1388c0b3f (patch)
treef9f939b61474b5d201dede252881c2d4f526dc72 /src/jcgp/population
parentd8ab8a2424a689cff4c787b0448c893facaadf6f (diff)
Updated README, made a few changes to Chromosome's mutation methods, will be working on that throughout the day
Diffstat (limited to 'src/jcgp/population')
-rw-r--r--src/jcgp/population/Chromosome.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index 195b95c..0dc3ff9 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -123,5 +123,51 @@ public class Chromosome {
return nodes[index / Parameters.getColumns()][index % Parameters.getColumns()];
}
}
+
+ /**
+ * Returns a random allowed connection respecting levels back.
+ * This method may always pick inputs, as they can be picked
+ * regardless of the column.
+ *
+ * @param column the column to use as reference
+ * @return a random connection
+ */
+ public Connection getRandomConnection(int column) {
+
+
+
+ return null;
+
+ }
+
+ /**
+ * Returns a random allowed connection.
+ *
+ * This method may always pick inputs, as they can be picked
+ * regardless of the column.
+ *
+ * TODO optimise for less random generations
+ *
+ * @param column the column to use as reference
+ * @param levelsBack whether or not to respect levels back
+ * @return a random connection
+ */
+ public Connection getRandomConnection(int column, boolean levelsBack) {
+
+ if (levelsBack) {
+ return getRandomConnection(chromosome, column);
+ } else {
+ // choose input or node
+ int connectionType = Utilities.getRandomInt(inputs.length + (nodes.length * column));
+ if (connectionType < inputs.length) {
+ // input
+ return chromosome.getInput(getRandomInt(Parameters.getInputs()));
+ } else {
+ // node
+ return chromosome.getNode(getRandomInt(Parameters.getRows()), getRandomInt(column));
+ }
+ }
+
+ }
}