public class Chromosome extends java.lang.Object implements java.lang.Comparable<Chromosome>
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.
copyChromosome()
in Population
, but alternatively
it can be done by using the Chromosome
copy constructor and specifying the
object to copy from, or by using the copyGenes()
method.
chr1.copyGenes(chr2);
chr1 = new Chromosome(chr2);
Population
. Assuming chr1 and chr2 are indexed 1 and 2 in population
respectively,
Chromosome
offers a variety of methods to compare chromosomes as well,
such as compareGenesTo()
and compareActiveGenesTo()
. Comparable
is implemented
to compare fitness value, meaning compareTo()
returns a value depending the relative fitness
of the compared chromosomes.
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.Constructor and Description |
---|
Chromosome(Chromosome clone)
Copy constructor.
|
Chromosome(Resources resources)
Initialise a chromosome with the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
boolean |
compareActiveGenesTo(Chromosome chromosome)
Does the same as
compareGenesto() but only looks
at the active portion of the chromosome. |
boolean |
compareGenesTo(Chromosome chromosome)
Performs a deep comparison between this chromosome and the provided one.
|
int |
compareTo(Chromosome o) |
void |
copyGenes(Chromosome clone)
Creates a deep copy of the specified chromosome in the
this instance.
|
java.util.ArrayList<Node> |
getActiveNodes()
This method computes a list of active nodes (if necessary) and returns it.
|
double |
getFitness() |
Input |
getInput(int index)
Returns a reference to the indexed input.
|
Node |
getNode(int row,
int column)
Returns a reference to any node, addressed by row and column.
|
Output |
getOutput(int index)
Returns a reference to the indexed output.
|
Connection |
getRandomConnection()
This method will pick a completely random connection, independently
of levels back, including inputs.
|
Connection |
getRandomConnection(int column)
Returns a random allowed connection respecting levels back.
This method may always pick inputs, as they can be picked regardless of the column. |
Mutable |
getRandomMutable()
This method is useful for mutating chromosomes.
|
Resources |
getResources() |
void |
printNodes()
Iterates through the nodes and prints all connections and functions.
|
void |
recomputeActiveNodes()
This causes the list of active nodes to be recomputed lazily (once it is actually requested).
|
void |
reinitialiseConnections()
Sets random connections and functions across the entire
chromosome.
|
void |
setFitness(double newFitness)
Sets the fitness of the chromosome.
|
void |
setInputs(java.lang.Object... values)
Loops through the inputs and sets the specified values,
so that evaluations can be performed.
|
public Chromosome(Resources resources)
resources
- the experiment's resources.public Chromosome(Chromosome clone)
clone
- the chromosome to be copied.public void reinitialiseConnections()
public void copyGenes(Chromosome clone)
clone
- the chromosome to clone.public Input getInput(int index)
index
- the input index.public Node getNode(int row, int column)
row
- the row of the node.column
- the column of the node.public Output getOutput(int index)
index
- the output index.public double getFitness()
public void setFitness(double newFitness)
newFitness
- the fitness to assign.public void setInputs(java.lang.Object... values)
values
- the values the input should take.public Mutable getRandomMutable()
Mutable
out of the chromosome with equal
probability.public Connection getRandomConnection(int column)
column
- the column to use as reference.public Connection getRandomConnection()
public void recomputeActiveNodes()
public java.util.ArrayList<Node> getActiveNodes()
public boolean compareGenesTo(Chromosome chromosome)
chromosome
- the chromosome to compare to.public boolean compareActiveGenesTo(Chromosome chromosome)
compareGenesto()
but only looks
at the active portion of the chromosome.chromosome
- the chromosome to compare to.public void printNodes()
public Resources getResources()
public int compareTo(Chromosome o)
compareTo
in interface java.lang.Comparable<Chromosome>