These are the internal components of the GA and are used to come up with random ideas, solutions to problems, creatures, etc. You define a Chromosome by first initialising a class instance extended from GeneticAlgorithm (eg: myGA) and then using the following format:
Chromosome myChromosome = myGA.makeChromosome();
This allows your Chromosome to use all of the utilities in myGA. Fields in Chromosome are accessed by method to protect internal changes of future versions.
| Field Method Summary | |
| int [] | dna () Returns an integer array. The GeneticAlgorithm that the Chromosome is registered with determines the length and maximum values initialised for this array acording to dnaLength() and traitSize(). |
| float | score () Returns the fitness score of this Chromosome |
| Constructor Summary |
| Chromosome (GeneticAlgorithm
ga) Creates a Chromosome object registered with GeneticAlgorithm ga. This method of construction is detailed only for advanced users. Normally one should create Chromosomes using the makeChromosome() method of the GA. |
| Chromosome (GeneticAlgorithm ga, int [] dna) Creates a Chromosome object registered with GeneticAlgorithm ga and using a reference to an array dna (the array is not copied). This method of construction is detailed only for advanced users. Normally one should create Chromosomes using the makeChromosome() method or the makeChromosome(int [] dna) method of the GA. |
| Method Summary | |
| void | crossOver (Chromosome mate) Depending on the crossOverRate() field in the registered GA, effects an exchange of dna() between this Chromosome and Chromosome mate. |
| void | mutate () Depending on the mutationRate() field in the registered GA, effects a randomization of dna() in this Chromosome. |
| Chromosome | copy () Creates a copy of the Chromosome. This is detailed only for advanced users. Normally one is advised to use the copy() method of the registered GA instead. |
| void | kill () This deletes this Chromosome from the registered GA and decreases its poolSize() field. |
| Constructor Detail |
public Chromosome (GeneticAlgorithm ga)
Creates an Chromosome registered with GeneticAlgorithm ga. Users are discouraged from using this method as it does not automatically populate the genePool as the method makeChromosome() does. However it is detailed for advance use and understanding of the operation of the Chromosome class.
Parameters:
ga - a GeneticAlgorithm that provides methods and parameters for the functioning of the Chromosome
public Chromosome (GeneticAlgorithm ga, int [] dna)
Creates an Chromosome registered with GeneticAlgorithm ga with a reference to an array dna. The array is not copied. Users are discouraged from using this method as it does not automatically populate the genePool as the method makeChromosome() or makeChromosome(int [] dna) does. However it is detailed for advance use and understanding of the operation of the Chromosome class.
Parameters:
ga - a GeneticAlgorithm that provides methods
and parameters for the functioning of the Chromosome
dna - a reference to an integer array that
will be used as the Chromosome's dna()
| Method Detail |
public void crossOver (Chromosome mate)
This method, depending on the value of the registered GA's crossOverRate() field, effects an exchange of dna(). Depending on whether the GA is set to operate at sub-integer level or not determines how detailed the splice is. Sub-integer splicing can lead to values exceeding traitSize() up to a value of 2 to the power of traitBits(). Users can look at the table under the setTraitBits() method for a guide to the ranges of these numbers. Cross over occurs at a random given point in the dna() and all values (binary or not) are swapped over past that point from left to right.
Parameters:
mate - a Chromosome whose dna() is to be partially swapped with this Chromosome.
public void mutate ()
This method, depending on the registered GA's mutationRate() field effects a randomisation upon the values in the dna() of the Chromosome. This rate is tested for each value in the dna(). Depending on whether the GA is set to operate at sub-integer level or not determines whether that value is an integer or a binary bit. Sub-integer mutation can lead to values exceeding traitSize() up to a value of 2 to the power of traitBits(). Users can look at the table under the setTraitBits() method for a guide to the ranges of these numbers.
public Chromosome copy ()
This method returns a copy of the Chromosome that it is called from. It does not load the new Chromosome into the genePool(), any changes to parameters of the GA may not reach the cloned Chromosome. Users are advised to use the copy() method of the registered GA instead. This method has been detailed for advance use.
public void kill ()
This method deletes a Chromosome from the GA, removing it from the genePool. Users are advised to remove unwanted Chromosomes using this method
whoo nearly finished