- All Superinterfaces:
BaseSeq<G>
,Factory<Chromosome<G>>
,Iterable<G>
,RandomAccess
,Verifiable
- All Known Subinterfaces:
BoundedChromosome<A,
,G> NumericChromosome<N,
,G> TreeChromosome<A,
G>
- All Known Implementing Classes:
AbstractChromosome
,AbstractTreeChromosome
,AnyChromosome
,BigIntegerChromosome
,BitChromosome
,CharacterChromosome
,DoubleChromosome
,IntegerChromosome
,LongChromosome
,PermutationChromosome
,ProgramChromosome
public interface Chromosome<G extends Gene<?,G>>
extends BaseSeq<G>, Factory<Chromosome<G>>, Verifiable
A chromosome consists of one or more genes. It also provides a factory
method for creating new, random chromosome instances of the same type and the
same constraint.
- Since:
- 1.0
- Version:
- 6.0
- See Also:
- Implementation Requirements:
- Implementations of the
Chromosome
interface must be immutable and guarantee efficient random access (O(1)
) to the genes. AChromosome
must contains at least oneGene
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <C extends Chromosome<G>>
CCasts thisChromosome
to an instance of typeC
.default G
gene()
Return the first gene of this chromosome.default boolean
isValid()
Check if this object is valid.newInstance
(ISeq<G> genes) A factory method which creates a newChromosome
of specific type and the givengenes
.Methods inherited from interface io.jenetics.util.BaseSeq
forEach, get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, stream
Methods inherited from interface io.jenetics.util.Factory
instances, newInstance
-
Method Details
-
gene
Return the first gene of this chromosome. Each chromosome must contain at least one gene.- Returns:
- the first gene of this chromosome.
- Since:
- 5.2
-
isValid
Description copied from interface:Verifiable
Check if this object is valid.- Specified by:
isValid
in interfaceVerifiable
- Returns:
- true if this object is valid, false otherwise.
-
newInstance
A factory method which creates a newChromosome
of specific type and the givengenes
.- Parameters:
genes
- the genes of the new chromosome. The given genes array is not copied.- Returns:
- A new
Chromosome
of the same type with the given genes. - Throws:
NullPointerException
- if the givengene
s arenull
.IllegalArgumentException
- if the length of the given gene sequence is smaller than one.
-
as
Casts thisChromosome
to an instance of typeC
. This is a convenient method for an ordinary cast and allows seamless method-chaining. Instead ofyou can writefinal Genotype<BitGene> gt = ... final int count = ((BitChromosome)gt.chromosome()).bitCount()
This may lead to a more elegant programming style in some cases.final Genotype<BitGene> gt = ... final int count = gt.chromosome() .as(BitChromosome.class) .bitCount()
- Type Parameters:
C
- the target chromosome type- Parameters:
type
- the target type class- Returns:
- this chromosome cast as
C
- Throws:
NullPointerException
- if the target type class isnull
ClassCastException
- if this chromosome can't be cast to a chromosome of typeC
- Since:
- 3.7
-