- 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
Chromosomeinterface must be immutable and guarantee efficient random access (O(1)) to the genes. AChromosomemust contains at least oneGene.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <C extends Chromosome<G>>
CCasts thisChromosometo an instance of typeC.default Ggene()Return the first gene of this chromosome.default booleanisValid()Check if this object is valid.newInstance(ISeq<G> genes) A factory method which creates a newChromosomeof specific type and the givengenes.Methods inherited from interface io.jenetics.util.BaseSeq
forEach, get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, streamMethods 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:VerifiableCheck if this object is valid.- Specified by:
isValidin interfaceVerifiable- Returns:
- true if this object is valid, false otherwise.
-
newInstance
A factory method which creates a newChromosomeof specific type and the givengenes.- Parameters:
genes- the genes of the new chromosome. The given genes array is not copied.- Returns:
- A new
Chromosomeof the same type with the given genes. - Throws:
NullPointerException- if the givengenes arenull.IllegalArgumentException- if the length of the given gene sequence is smaller than one.
-
as
Casts thisChromosometo 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 isnullClassCastException- if this chromosome can't be cast to a chromosome of typeC- Since:
- 3.7
-