jcgp.backend.population.Chromosome
This class encapsulates a CGP chromosome.
A chromosome contains a matrix of nodes and arrays of inputs and outputs. These elements are all interconnected, and actually form the chromosome network itself. Individual nodes can be retrieved using {@code getNode()}which requires the row and column to be specified. The same works for inputs and outputs using the associated getters, in which case only the index is necessary.
In evolutionary computation it is often necessary to make copies of chromosomes; this can be accomplished in JCGP in two ways. The recommended way to do this is using {@code copyChromosome()} in {@code Population}, but alternatively it can be done by using the {@code Chromosome} copy constructor and specifying theobject to copy from, or by using the {@code copyGenes()} method.
To illustrate this, given two chromosomes, chr1 and chr2, the following code:
chr1.copyGenes(chr2);
will modify all of chr1's connections and functions to match those of chr2, without creating a new instance. In contrast,
chr1 = new Chromosome(chr2);
creates a new instance of chromosome which is identical to chr2 and assigns it to chr1, meaning any old references to chr1 that are not updated will still refer to a chromosome that is not identical to chr2. In practice, the most reliable way is to use the copy method in {@code Population}. Assuming chr1 and chr2 are indexed 1 and 2 in {@code population} respectively,
population.copyChromosome(2, 1);
will copy chr2 into chr1 without creating new instances or requiring access to the underlying chromosome array. {@code Chromosome} offers a variety of methods to compare chromosomes as well, such as {@code compareGenesTo()} and {@code compareActiveGenesTo()}. {@code Comparable} is implementedto compare fitness value, meaning {@code compareTo()} returns a value depending the relative fitnessof the compared chromosomes.
In order to set the chromosome's input values for decoding, {@code setInputs()} should be used. A few utility methods are provided in order to retrieve random elements from the chromosome, which are used internally to initialise with random connections but also externally by mutators when performing mutations.
@author Eduardo Pedroni