From 6e7747e5b85f4ca93683ed5166f6e480cc58e6fa Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 10 Feb 2014 09:33:54 +0000 Subject: Refactored the resources mechanics, implemented a few of the chromosome tests --- src/jcgp/population/Chromosome.java | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/jcgp/population/Chromosome.java') 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; + } } -- cgit v1.2.3