|
The Encog Project | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.encog.solve.genetic.Chromosome<GENE_TYPE>
GENE_TYPE - The datatype for a gene.public abstract class Chromosome<GENE_TYPE>
Implements a chromosome to genetic algorithm. This is an abstract class. Other classes are provided in this book that use this base class to train neural networks or provide an answer to the traveling salesman problem. Lifeforms in this genetic algorithm consist of one single chromosome each. Therefore, this class represents a virtual lifeform. The chromosome is a string of objects that represent one solution. For a neural network, this string of objects usually represents the weight and threshold matrix. Chromosomes are made up of genes. These are of the generic type GENE_TYPE. For a neural network this type would most likely be double values.
| Constructor Summary | |
|---|---|
Chromosome()
|
|
| Method Summary | |
|---|---|
abstract void |
calculateCost()
Called to calculate the cost for this chromosome. |
int |
compareTo(Chromosome<GENE_TYPE> other)
Used to compare two chromosomes. |
double |
getCost()
|
GENE_TYPE |
getGene(int gene)
Get the specified gene. |
GENE_TYPE[] |
getGenes()
Used the get the entire gene array. |
GeneticAlgorithm<GENE_TYPE> |
getGeneticAlgorithm()
|
void |
mate(Chromosome<GENE_TYPE> father,
Chromosome<GENE_TYPE> offspring1,
Chromosome<GENE_TYPE> offspring2)
Assuming this chromosome is the "mother" mate with the passed in "father". |
abstract void |
mutate()
Called to mutate this chromosome. |
void |
setCost(double cost)
Set the cost for this chromosome. |
void |
setGene(int gene,
GENE_TYPE value)
Set the specified gene's value. |
void |
setGenes(GENE_TYPE[] genes)
Set the entire gene array. |
void |
setGenesDirect(GENE_TYPE[] genes)
Set the genes directly, not allowed to be overridden. |
void |
setGeneticAlgorithm(GeneticAlgorithm<GENE_TYPE> geneticAlgorithm)
Set the genetic algorithm. |
java.lang.String |
toString()
Convert the chromosome to a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Chromosome()
| Method Detail |
|---|
public abstract void calculateCost()
public int compareTo(Chromosome<GENE_TYPE> other)
compareTo in interface java.lang.Comparable<Chromosome<GENE_TYPE>>other - The other chromosome to compare.
public double getCost()
public GENE_TYPE getGene(int gene)
gene - The specified gene.
public GENE_TYPE[] getGenes()
public GeneticAlgorithm<GENE_TYPE> getGeneticAlgorithm()
public void mate(Chromosome<GENE_TYPE> father,
Chromosome<GENE_TYPE> offspring1,
Chromosome<GENE_TYPE> offspring2)
father - The father.offspring1 - Returns the first offspringoffspring2 - Returns the second offspring.public abstract void mutate()
public void setCost(double cost)
cost - the cost to set
public void setGene(int gene,
GENE_TYPE value)
gene - The specified gene.value - The value to set the specified gene to.public void setGenes(GENE_TYPE[] genes)
genes - the genes to setpublic final void setGenesDirect(GENE_TYPE[] genes)
genes - the genes to setpublic void setGeneticAlgorithm(GeneticAlgorithm<GENE_TYPE> geneticAlgorithm)
geneticAlgorithm - the geneticAlgorithm to setpublic java.lang.String toString()
toString in class java.lang.Object
|
The Encog Project | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||