Top Description Fields Constructors Methods
org.apache.commons.math3.genetics

public abstract Class AbstractListChromosome<T>

extends Chromosome
Class Inheritance
Known Direct Subclasses
org.apache.commons.math3.genetics.BinaryChromosome, org.apache.commons.math3.genetics.RandomKey
Type Parameters
<T>
type of the representation list
Imports
java.util.ArrayList, .Arrays, .Collections, .List

Chromosome represented by an immutable list of a fixed length.
Since
2.0

Field Summary

Modifier and TypeField and Description
private final List<T>
representation

List representing the chromosome

Constructor Summary

AccessConstructor and Description
public
AbstractListChromosome(final List<T>
inner representation of the chromosome
representation
)

Constructor, copying the input representation.

public
AbstractListChromosome(final T[]
inner representation of the chromosome
representation
)

Constructor, copying the input representation.

public
AbstractListChromosome(final List<T>
inner representation of the chromosome
representation
,
final boolean
if true, the representation will be copied, otherwise it will be referenced.
copyList
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected abstract void
checkValidity(List<T>
representation of the chromosome
chromosomeRepresentation
)

Asserts that representation can represent a valid chromosome.

public int

Returns:

the length of the chromosome
getLength
()

Returns the length of the chromosome.

protected List<T>

Returns:

the representation of the chromosome
getRepresentation
()

Returns the (immutable) inner representation of the chromosome.

public abstract AbstractListChromosome<T>

Returns:

new instance extended from FixedLengthChromosome with the given arrayRepresentation
newFixedLengthChromosome
(final List<T>
the inner array representation of the new chromosome.
chromosomeRepresentation
)

Creates a new instance of the same class as this is, with a given arrayRepresentation.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.commons.math3.genetics.Chromosome:
compareTofindSameChromosomegetFitnessisSamesearchForFitnessUpdate

Field Detail

representationback to summary
private final List<T> representation

List representing the chromosome

Constructor Detail

AbstractListChromosomeback to summary
public AbstractListChromosome(final List<T> representation) throws InvalidRepresentationException

Constructor, copying the input representation.

Parameters
representation:List<T>

inner representation of the chromosome

Exceptions
InvalidRepresentationException:
iff the representation can not represent a valid chromosome
AbstractListChromosomeback to summary
public AbstractListChromosome(final T[] representation) throws InvalidRepresentationException

Constructor, copying the input representation.

Parameters
representation:T[]

inner representation of the chromosome

Exceptions
InvalidRepresentationException:
iff the representation can not represent a valid chromosome
AbstractListChromosomeback to summary
public AbstractListChromosome(final List<T> representation, final boolean copyList)

Constructor.

Parameters
representation:List<T>

inner representation of the chromosome

copyList:boolean

if true, the representation will be copied, otherwise it will be referenced.

Since
3.3

Method Detail

checkValidityback to summary
protected abstract void checkValidity(List<T> chromosomeRepresentation) throws InvalidRepresentationException

Asserts that representation can represent a valid chromosome.

Parameters
chromosomeRepresentation:List<T>

representation of the chromosome

Exceptions
InvalidRepresentationException:
iff the representation can not represent a valid chromosome
getLengthback to summary
public int getLength()

Returns the length of the chromosome.

Returns:int

the length of the chromosome

getRepresentationback to summary
protected List<T> getRepresentation()

Returns the (immutable) inner representation of the chromosome.

Returns:List<T>

the representation of the chromosome

newFixedLengthChromosomeback to summary
public abstract AbstractListChromosome<T> newFixedLengthChromosome(final List<T> chromosomeRepresentation)

Creates a new instance of the same class as this is, with a given arrayRepresentation. 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:List<T>

the inner array representation of the new chromosome.

Returns:AbstractListChromosome<T>

new instance extended from FixedLengthChromosome with the given arrayRepresentation

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override