Class AbstractListChromosome<T>
java.lang.Object
org.apache.commons.math3.genetics.Chromosome
org.apache.commons.math3.genetics.AbstractListChromosome<T>
- Type Parameters:
T
- type of the representation list
- All Implemented Interfaces:
Comparable<Chromosome>
,Fitness
- Direct Known Subclasses:
BinaryChromosome
,RandomKey
Chromosome represented by an immutable list of a fixed length.
- Since:
- 2.0
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractListChromosome
(List<T> representation) Constructor, copying the input representation.AbstractListChromosome
(List<T> representation, boolean copyList) Constructor.AbstractListChromosome
(T[] representation) Constructor, copying the input representation. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
checkValidity
(List<T> chromosomeRepresentation) Asserts thatrepresentation
can represent a valid chromosome.int
Returns the length of the chromosome.Returns the (immutable) inner representation of the chromosome.abstract AbstractListChromosome
<T> newFixedLengthChromosome
(List<T> chromosomeRepresentation) Creates a new instance of the same class asthis
is, with a givenarrayRepresentation
.toString()
Methods inherited from class org.apache.commons.math3.genetics.Chromosome
compareTo, findSameChromosome, getFitness, isSame, searchForFitnessUpdate
-
Constructor Details
-
AbstractListChromosome
Constructor, copying the input representation.- Parameters:
representation
- inner representation of the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
AbstractListChromosome
Constructor, copying the input representation.- Parameters:
representation
- inner representation of the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
AbstractListChromosome
Constructor.- Parameters:
representation
- inner representation of the chromosomecopyList
- iftrue
, the representation will be copied, otherwise it will be referenced.- Since:
- 3.3
-
-
Method Details
-
checkValidity
protected abstract void checkValidity(List<T> chromosomeRepresentation) throws InvalidRepresentationException Asserts thatrepresentation
can represent a valid chromosome.- Parameters:
chromosomeRepresentation
- representation of the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
getRepresentation
Returns the (immutable) inner representation of the chromosome.- Returns:
- the representation of the chromosome
-
getLength
public int getLength()Returns the length of the chromosome.- Returns:
- the length of the chromosome
-
newFixedLengthChromosome
public abstract AbstractListChromosome<T> newFixedLengthChromosome(List<T> chromosomeRepresentation) Creates a new instance of the same class asthis
is, with a givenarrayRepresentation
. This is needed in crossover and mutation operators, where we need a new instance of the same class, but with different array representation.Usually, this method just calls a constructor of the class.
- Parameters:
chromosomeRepresentation
- the inner array representation of the new chromosome.- Returns:
- new instance extended from FixedLengthChromosome with the given arrayRepresentation
-
toString
-