public final class Genotype<G extends Gene<?,G>> extends Object implements Factory<Genotype<G>>, Iterable<Chromosome<G>>, Verifiable, Serializable
Genotype. It is the
structural representative of an individual. This class is the encoded problem
solution with one to many Chromosome.
final Genotype<DoubleGene> genotype = Genotype.of(
DoubleChromosome.of(0.0, 1.0, 8),
DoubleChromosome.of(1.0, 2.0, 10),
DoubleChromosome.of(0.0, 10.0, 9),
DoubleChromosome.of(0.1, 0.9, 5)
);DoubleGene has been chosen as
gene type.| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
G |
get(int chromosomeIndex,
int geneIndex)
Return the gene from the given chromosome- and gene index.
|
Chromosome<G> |
getChromosome()
Return the first chromosome.
|
Chromosome<G> |
getChromosome(int index)
Return the chromosome at the given index.
|
G |
getGene()
|
int |
getNumberOfGenes()
Return the number of genes this genotype consists of.
|
int |
hashCode() |
boolean |
isValid()
Test if this genotype is valid.
|
Iterator<Chromosome<G>> |
iterator() |
int |
length()
Getting the number of chromosomes of this genotype.
|
Genotype<G> |
newInstance()
Return a new, random genotype by creating new, random chromosomes (calling
the
Factory.newInstance() method) from the chromosomes of this
genotype. |
static <G extends Gene<?,G>> |
of(Chromosome<G> first,
Chromosome<G>... rest)
Create a new
Genotype from a given array of Chromosomes. |
static <G extends Gene<?,G>> |
of(Factory<? extends Chromosome<G>> factory,
int n)
Create a new
Genotype which consists of n chromosomes,
which are created by the given factory. |
static <G extends Gene<?,G>> |
of(Iterable<? extends Chromosome<G>> chromosomes)
Create a new
Genotype from a given array of chromosomes. |
Stream<Chromosome<G>> |
stream()
Returns a sequential
Stream of chromosomes with this genotype as
its source. |
ISeq<Chromosome<G>> |
toSeq() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic Chromosome<G> getChromosome(int index)
index - Chromosome index.IndexOutOfBoundsException - if
(index < 0 || index >= _length).public Chromosome<G> getChromosome()
final Genotype<DoubleGene>; gt = ...
final Chromosome<DoubleGene> chromosome = gt.getChromosome(0);public G getGene()
Gene of the first Chromosome of this
Genotype. This is a shortcut for
final Genotype<DoubleGene> gt = ...
final DoubleGene gene = gt.getChromosome(0).getGene(0);Gene of the first Chromosome of this
Genotype.public G get(int chromosomeIndex, int geneIndex)
gt.getChromosome(chromosomeIndex).getGene(geneIndex).chromosomeIndex - the chromosome indexgeneIndex - the gene index within the chromosomeIndexOutOfBoundsException - if the given indexes are not within the
allowed rangepublic ISeq<Chromosome<G>> toSeq()
public Iterator<Chromosome<G>> iterator()
public Stream<Chromosome<G>> stream()
Stream of chromosomes with this genotype as
its source.Stream of chromosomespublic int length()
public int getNumberOfGenes()
public boolean isValid()
Chromosomes are valid.isValid in interface Verifiablepublic Genotype<G> newInstance()
Factory.newInstance() method) from the chromosomes of this
genotype.@SafeVarargs public static <G extends Gene<?,G>> Genotype<G> of(Chromosome<G> first, Chromosome<G>... rest)
Genotype from a given array of Chromosomes.G - the gene typefirst - the first Chromosome of the Genotyperest - the rest of the genotypes chromosomes.Genotype from the given chromosomesNullPointerException - if chromosomes is null or
one of its element.public static <G extends Gene<?,G>> Genotype<G> of(Factory<? extends Chromosome<G>> factory, int n)
Genotype which consists of n chromosomes,
which are created by the given factory. This method can be used
for easily creating a gene matrix. The following example will
create a 10x5 DoubleGene matrix.
final Genotype<DoubleGene> gt = Genotype
.of(DoubleChromosome.of(0.0, 1.0, 10), 5);G - the gene typefactory - the factory which creates the chromosomes this genotype
consists ofn - the number of chromosomes this genotype consists ofGenotype containing n chromosomesIllegalArgumentException - if n < 1.NullPointerException - if the factory is null.public static <G extends Gene<?,G>> Genotype<G> of(Iterable<? extends Chromosome<G>> chromosomes)
Genotype from a given array of chromosomes.G - the gene typechromosomes - the Chromosomes the returned genotype consists
ofGenotype from the given chromosomesNullPointerException - if chromosomes is null or
one of its element.IllegalArgumentException - if chromosome.length() < 1.© 2007-2016 Franz Wilhelmstötter (2016-04-24 10:25)