package jcgp.population;
import java.util.ArrayList;
import jcgp.CGP.Utilities;
public class Chromosome {
private final ArrayList inputs = new ArrayList ();
private final ArrayList> nodes = new ArrayList>();;
private final ArrayList outputs = new ArrayList();
private int fitness = 0;
/**
* Good citizen.
*
* @param outputs
* @param columns
* @param rows
* @param inputs
*
*/
public Chromosome(int inputCount, int rows, int columns, int outputCount) {
instantiateElements(inputCount, rows, columns, outputCount);
initialiseConnections();
}
private void initialiseConnections() {
// initialise nodes
for (int r = 0; r < nodes.size(); r++) {
for (int c = 0; c < nodes.size(); c++) {
Connection[] connections = new Connection[Utilities.getMaxArity()];
for (int i = 0; i < connections.length; i++) {
connections[i] = Utilities.getRandomConnection(this, c);
}
nodes.get(r).get(c).initialise(Utilities.getRandomFunction(), connections);
}
}
for (Output output : outputs) {
output.setConnection(Utilities.getRandomNode(this));
}
}
/**
* @param inputCount
* @param rows
* @param columns
* @param outputCount
*/
private void instantiateElements(int inputCount, int rows, int columns, int outputCount) {
for (int i = 0; i < inputCount; i++) {
inputs.add(new Input());
}
// rows first
for (int r = 0; r < rows; r++) {
nodes.add(new ArrayList(columns));
for (int c = 0; c < columns; c++) {
nodes.get(r).add(new Node());
}
}
for (int o = 0; o < outputCount; o++) {
outputs.add(new Output());
}
}
public int getActiveNodeCount() {
return 0;
}
/**
* @return the inputs
*/
public ArrayList getInputs() {
return inputs;
}
/**
* @return the nodes
*/
public ArrayList> getNodes() {
return nodes;
}
/**
* @return the outputs
*/
public ArrayList getOutputs() {
return outputs;
}
public Node getNode(int row, int column) {
return nodes.get(row).get(column);
}
public Output getOutput(int index) {
return outputs.get(index);
}
public Input getInput(int index) {
return inputs.get(index);
}
public int getFitness() {
return fitness;
}
public void setFitness(int newFitness) {
fitness = newFitness;
}
}