public final class Genotype<G extends Gene<?,G>> extends Object implements BaseSeq<Chromosome<G>>, Factory<Genotype<G>>, Verifiable, Serializable
Genotype
. It is the
structural representative of an individual. This class is the encoded problem
solution with one to many Chromosome
.
The chromosomes of a genotype doesn't have to have necessarily the same size. It is only required that all genes are from the same type and the genes within a chromosome have the same constraints; e. g. the same min- and max values for number genes.
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.Chromosome
,
Phenotype
,
Serialized FormModifier and Type | Method and Description |
---|---|
Chromosome<G> |
chromosome()
Return the first chromosome.
|
boolean |
equals(Object obj) |
G |
gene()
|
int |
geneCount()
Return the number of genes this genotype consists of.
|
Chromosome<G> |
get(int index)
Return the chromosome at the given index.
|
G |
get(int chromosomeIndex,
int geneIndex)
Deprecated.
Use
get(chromosomeIndex).get(geneIndex) instead |
Chromosome<G> |
getChromosome()
Deprecated.
Use
chromosome() instead |
Chromosome<G> |
getChromosome(int index)
|
G |
getGene()
Deprecated.
Use
gene() instead |
int |
hashCode() |
boolean |
isValid()
Test if this genotype is valid.
|
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 . |
ISeq<Chromosome<G>> |
toSeq()
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
iterator, listIterator, spliterator, stream
public Chromosome<G> get(int index)
get
in interface BaseSeq<Chromosome<G extends Gene<?,G>>>
index
- the chromosome indexIndexOutOfBoundsException
- if
(index < 0 || index >= _length)
.public int length()
public Chromosome<G> chromosome()
final Genotype<DoubleGene>; gt = ...
final Chromosome<DoubleGene> chromosome = gt.get(0);
public G gene()
Gene
of the first Chromosome
of this
Genotype
. This is an alias for
final Genotype<DoubleGene> gt = ...
final DoubleGene gene = gt.get(0).get(0);
Gene
of the first Chromosome
of this
Genotype
.@Deprecated public Chromosome<G> getChromosome(int index)
index
- Chromosome index.IndexOutOfBoundsException
- if
(index < 0 || index >= _length)
.@Deprecated public Chromosome<G> getChromosome()
chromosome()
instead final Genotype<DoubleGene>; gt = ...
final Chromosome<DoubleGene> chromosome = gt.get(0);
@Deprecated public G getGene()
gene()
insteadGene
of the first Chromosome
of this
Genotype
. This is a shortcut for
final Genotype<DoubleGene> gt = ...
final DoubleGene gene = gt.get(0).get(0);
Gene
of the first Chromosome
of this
Genotype
.@Deprecated public G get(int chromosomeIndex, int geneIndex)
get(chromosomeIndex).get(geneIndex)
insteadgt.getChromosome(chromosomeIndex).getGene(geneIndex)
.chromosomeIndex
- the chromosome indexgeneIndex
- the gene index within the chromosomeIndexOutOfBoundsException
- if the given indexes are not within the
allowed range@Deprecated public ISeq<Chromosome<G>> toSeq()
BaseSeq
, it
is no longer necessary to get a sequence with genes. If it is
necessary to create an ISeq
from a genotype, use
ISeq.of(genotype)
instead. This method will be
removed in the next major release.public int geneCount()
public boolean isValid()
Chromosome
s are valid.isValid
in interface Verifiable
public 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 Genotype
rest
- 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 Chromosome
s the returned genotype consists
ofGenotype
from the given chromosomesNullPointerException
- if chromosomes
is null
or
one of its element.IllegalArgumentException
- if chromosome.length() < 1
.© 2007-2020 Franz Wilhelmstötter (2020-02-18 20:01)